11 #ifndef ShowerProducedPtrsHolder_HH 12 #define ShowerProducedPtrsHolder_HH 19 class ShowerUniqueProduerPtrBase;
31 template <
class L,
class R,
class D>
46 virtual void reset() = 0;
67 showeruniqueptr = std::make_unique<std::vector<T> >();
68 InstanceName = Instancename;
74 return showeruniqueptr;
82 showeruniqueptr.reset(
new std::vector<T>());
89 mf::LogError(
"ShowerProducedPtrsHolder") <<
"Trying to add data product: " << Name <<
". This element does not exist in the element holder" <<
std::endl;
95 mf::LogError(
"ShowerProducedPtrsHolder") <<
"Trying to add data product: " << Name <<
". This element does not exist in the element holder" <<
std::endl;
98 showeruniqueptr->push_back(product);
109 return cet::demangle_symbol(
typeid(showeruniqueptr.get()).
name());
119 return showeruniqueptr->size();
148 showeruniqueptr = std::make_unique<T>();
149 InstanceName = Instancename;
155 return showeruniqueptr;
163 showeruniqueptr.reset(
new T());
173 throw cet::exception(
"ShowerUniqueAssnPtr") <<
"The creator of this code has failed you. Please contact Dominic Bakrer" <<
std::endl;
178 return cet::demangle_symbol(
typeid(showeruniqueptr.get()).
name());
210 virtual bool CheckPtrMaker()
const = 0;
214 virtual void Reset() = 0;
228 InstanceName = Instancename;
242 if(ptrmaker ==
nullptr){
253 if(ptrmaker ==
nullptr){
256 return (*ptrmaker)(iter);
269 throw cet::exception(
"ShowerPtrMaker") <<
"Trying to reset ptr but it has not been set in the first place. Please contatc Dom Barker" <<
std::endl;
271 ptrmaker.
reset(
nullptr);
299 if(showerassnPtrs.find(Name) != showerassnPtrs.end()){
300 mf::LogWarning(
"ShowerProducedPtrsHolder") <<
"Trying to set Element: " << Name <<
". This element has already been set. Please check." <<
std::endl;
305 if(!CheckForMultipleTypes(
type<T>(), Name, Instance)){
306 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Trying to set multiple objects with same type with no instance name or same instance name" <<
std::endl;
309 showerassnPtrs[
Name] = std::make_unique<ShowerUniqueAssnPtr<T> >(Instance);
318 if(showerproductPtrs.find(Name) != showerproductPtrs.end()){
319 mf::LogWarning(
"ShowerProducedPtrsHolder") <<
"Trying to set Element: " << Name <<
". This element has already been set. Please check." <<
std::endl;
324 if(!CheckForMultipleTypes(
type<std::vector<T> >(), Name, Instance)){
325 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Trying to set multiple objects with same type with no instance name or same instance name" <<
std::endl;
328 if(showerPtrMakers.find(Name) != showerPtrMakers.end()){
329 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker already exist. It should not be set again" <<
std::endl;
331 showerPtrMakers[
Name] = std::make_unique<ShowerPtrMaker<T> >(Instance);
332 showerproductPtrs[
Name] = std::make_unique<ShowerUniqueProductPtr<std::vector<T > > >(Instance);
339 if(showerproductPtrs.find(Name) != showerproductPtrs.end()){
342 if(showerassnPtrs.find(Name) != showerassnPtrs.end()){
350 for(
auto const& showerptr: showerproductPtrs){
351 (showerptr.second)->
reset();
353 for(
auto const& showerptr: showerassnPtrs){
354 (showerptr.second)->
reset();
362 for(
auto const& showerproductPtr: showerproductPtrs){
363 (showerproductPtr.second)->AddDataProduct(selement_holder, showerproductPtr.first);
369 for(
auto const& showerproductPtr: showerproductPtrs){
370 (showerproductPtr.second)->MoveToEvent(evt);
372 for(
auto const& showerassnPtr: showerassnPtrs){
373 (showerassnPtr.second)->MoveToEvent(evt);
379 for(
auto const& showerproductPtr: showerproductPtrs){
380 if(showerproductPtr.first ==
"shower"){
continue;}
381 checked *= selement_holder.
CheckElement(showerproductPtr.first);
390 auto const showerproductPtrsIt = showerproductPtrs.find(Name);
391 if(showerproductPtrsIt != showerproductPtrs.end()){
393 return prod->GetPtr();
396 auto const showerassnPtrsIt = showerassnPtrs.find(Name);
397 if(showerassnPtrsIt != showerassnPtrs.end()){
402 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Trying to get Ptr for: " << Name <<
" but Element does not exist" <<
std::endl;
407 template <
class T,
class A,
class B>
409 auto const showerassnPtrsIt = showerassnPtrs.find(Name);
410 if(showerassnPtrsIt == showerassnPtrs.end()){
411 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Trying to get the association: " << Name <<
"Element does not exist" <<
std::endl;
414 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Element type is not an assoication please only use this for assocations" <<
std::endl;
417 if(assnptr ==
nullptr){
418 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Failed to cast back. Maybe you got the type wrong or you are accidently accessing a differently named product" <<
std::endl;
421 T* assn =
dynamic_cast<T*
>(assnptr->
GetPtr().get());
423 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Something went wrong trying to cast tothe assn. Maybe the name: " << Name <<
" exists but its not an assn" <<
std::endl;
426 assn->addSingle(a,b);
432 for(
auto const& showerPtrMaker: showerPtrMakers){
433 if(showerPtrMakers.find(showerPtrMaker.first) == showerPtrMakers.end()){
436 showerPtrMakers[showerPtrMaker.first]->SetPtrMaker(evt);
443 auto const showerPtrMakersIt = showerPtrMakers.find(Name);
444 if(showerPtrMakersIt == showerPtrMakers.end()){
448 if(!showerPtrMakersIt->second->CheckPtrMaker()){
459 auto const showerPtrMakersIt = showerPtrMakers.find(Name);
460 if(showerPtrMakersIt == showerPtrMakers.end()){
461 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker does not exist for " << Name <<
" Did you initialise this? " <<
std::endl;
464 if(!showerPtrMakersIt->second->CheckPtrMaker()){
465 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker is not set. This is an issue for the devlopment team me. Contact Dom Barker" <<
std::endl;
468 if(ptrmaker ==
nullptr){
469 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Failed to cast back. Maybe you got the type wrong or you are accidently accessing a differently named product" <<
std::endl;
477 for(
auto const& showerPtrMaker: showerPtrMakers){
478 (showerPtrMaker.second)->Reset();
484 auto const showerproductPtrsIt = showerproductPtrs.find(Name);
485 if(showerproductPtrsIt != showerproductPtrs.end()){
486 return showerproductPtrsIt->second->GetVectorPtrSize();
488 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Product: " << Name <<
" has not been set in the producers map" <<
std::endl;
493 auto const showerproductPtrsIt = showerproductPtrs.find(Name);
494 if(showerproductPtrsIt != showerproductPtrs.end()){
496 const std::string InstanceName = showerproductPtrsIt->second->GetInstanceName();
497 std::cout <<
"Element Name: " << Name <<
" Instance Name: " << InstanceName <<
" Type: " << Type <<
std::endl;
500 auto const showerassnPtrsIt = showerassnPtrs.find(Name);
501 if(showerassnPtrsIt != showerassnPtrs.end()){
503 const std::string InstanceName = showerassnPtrsIt->second->GetInstanceName();
504 std::cout <<
"Element Name: " << Name <<
" Instance Name: " << InstanceName <<
" Type: " << Type <<
std::endl;
507 mf::LogError(
"ShowerProducedPtrsHolder") <<
"Trying to print Element: " << Name <<
". This element does not exist in the element holder" <<
std::endl;
515 unsigned int maxname = 0;
516 for(
auto const& showerprodPtr: showerproductPtrs){
517 if(showerprodPtr.first.size() > maxname){
518 maxname = showerprodPtr.first.size();
521 for(
auto const& showerassnPtr: showerassnPtrs){
522 if(showerassnPtr.first.size() > maxname){
523 maxname = showerassnPtr.first.size();
527 std::map<std::string,std::pair<std::string,std::string> > Type_showerprodPtrs;
528 std::map<std::string,std::pair<std::string,std::string> > Type_showerassnPtrs;
529 for(
auto const& showerprodPtr: showerproductPtrs){
531 const std::string InstanceName = (showerprodPtr.second)->GetInstanceName();
532 Type_showerprodPtrs[showerprodPtr.first] = std::make_pair(InstanceName,Type);
534 for(
auto const& showerassnPtr: showerassnPtrs){
536 const std::string InstanceName = (showerassnPtr.second)->GetInstanceName();
537 Type_showerassnPtrs[showerassnPtr.first] = std::make_pair(InstanceName,Type);
540 unsigned int maxtype = 0;
541 unsigned int maxinstname = 0;
542 for(
auto const& Type_showerprodPtr: Type_showerprodPtrs){
543 if(Type_showerprodPtr.second.second.size() > maxtype){
544 maxtype = Type_showerprodPtr.second.second.size();
546 if(Type_showerprodPtr.second.first.size() > maxinstname){
547 maxinstname = Type_showerprodPtr.second.first.size();
550 for(
auto const& Type_showerassnPtr: Type_showerassnPtrs){
551 if(Type_showerassnPtr.second.second.size() > maxtype){
552 maxtype = Type_showerassnPtr.second.second.size();
554 if(Type_showerassnPtr.second.first.size() > maxinstname){
555 maxinstname = Type_showerassnPtr.second.first.size();
559 unsigned int n = maxname + maxtype + maxinstname + 51;
561 std::cout <<
"Unique Ptrs that are added to the event" <<
std::endl;
563 for(
auto const& Type_showerprodPtr: Type_showerprodPtrs){
568 for(
auto const& Type_showerassnPtr: Type_showerassnPtrs){
588 for(
auto const& assn: showerassnPtrs){
590 if(assnptr !=
nullptr){
602 for(
auto const& product: showerproductPtrs){
605 if(prod->GetInstanceName() == Instance){
return false;}
614 std::map<std::string,std::unique_ptr<reco::shower::ShowerUniqueProduerPtrBase > >
showerproductPtrs;
617 std::map<std::string,std::unique_ptr<reco::shower::ShowerUniqueProduerPtrBase > >
showerassnPtrs;
620 std::map<std::string,std::unique_ptr<reco::shower::ShowerPtrMakerBase> >
showerPtrMakers;
int GetVectorPtrSize() const override
void AddDataProduct(const reco::shower::ShowerElementHolder &selement_holder, const std::string &Name) override
art::PtrMaker< T > & GetPtrMaker(const std::string &Name)
art::Ptr< T > GetArtPtr(int iter) const
bool CheckPtrMaker() const override
bool CheckForMultipleTypes(type< std::vector< T > >, const std::string &Name, const std::string &Instance) const
void AddDataProducts(const reco::shower::ShowerElementHolder &selement_holder)
std::string GetType() const override
std::unique_ptr< std::vector< T > > showeruniqueptr
ChannelGroupService::Name Name
std::unique_ptr< art::PtrMaker< T > > ptrmaker
int SetShowerUniqueProduerPtr(type< std::vector< T > >, const std::string &Name, const std::string &Instance="")
void SetPtrMaker(art::Event &evt) override
ShowerPtrMaker(const std::string &Instancename)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void MoveAllToEvent(art::Event &evt)
void PrintPtr(const std::string &Name) const
bool CheckUniqueProduerPtr(const std::string &Name) const
std::unique_ptr< T > & GetPtr()
std::unique_ptr< T > showeruniqueptr
void MoveToEvent(art::Event &evt) override
std::map< std::string, std::unique_ptr< reco::shower::ShowerUniqueProduerPtrBase > > showerproductPtrs
std::map< std::string, std::unique_ptr< reco::shower::ShowerUniqueProduerPtrBase > > showerassnPtrs
std::unique_ptr< T > & GetPtr()
QTextStream & reset(QTextStream &s)
std::string GetInstanceName() const override
void AddSingle(A &a, B &b, const std::string &Name)
T & GetPtr(const std::string &Name)
bool CheckElement(const std::string &Name) const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
void SetPtrMakers(art::Event &evt)
int GetElement(const std::string &Name, T &Element) const
void err(const char *fmt,...)
Q_EXPORT QTSManip setw(int w)
void MoveToEvent(art::Event &evt) override
virtual int GetVectorPtrSize() const
bool CheckAllProducedElements(reco::shower::ShowerElementHolder &selement_holder) const
void AddDataProduct(const reco::shower::ShowerElementHolder &selement_holder, const std::string &Name) override
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string GetType() const override
ShowerUniqueAssnPtr(const std::string &Instancename)
art::Ptr< T > GetArtPtr(const std::string &Name, const int &iter) const
std::map< std::string, std::unique_ptr< reco::shower::ShowerPtrMakerBase > > showerPtrMakers
std::string GetInstanceName() const override
int SetShowerUniqueProduerPtr(type< T >, const std::string &Name, const std::string &Instance="")
Q_EXPORT QTSManip setfill(int f)
bool CheckForMultipleTypes(type< T >, const std::string &Name, const std::string &Instance) const
int GetVectorPtrSize(const std::string &Name) const
cet::coded_exception< error, detail::translate > exception
art::PtrMaker< T > & GetPtrMaker()
QTextStream & endl(QTextStream &s)