10 #ifndef ShowerProduedPtrsHolder_HH 11 #define ShowerProduedPtrsHolder_HH 28 class ShowerUniqueProduerPtrBase;
41 template <
class L,
class R,
class D>
56 virtual void reset() = 0;
77 showeruniqueptr = std::make_unique<std::vector<T> >();
78 InstanceName = Instancename;
84 return showeruniqueptr;
88 return showeruniqueptr;
93 showeruniqueptr.reset(
new std::vector<T>());
101 mf::LogError(
"ShowerProduedPtrsHolder") <<
"Trying to add data product: " << Name <<
". This element does not exist in the element holder" <<
std::endl;
104 showeruniqueptr->push_back(product);
116 return abi::__cxa_demangle(
typeid(showeruniqueptr.get()).
name(),NULL,NULL,&status);
126 return showeruniqueptr->size();
155 showeruniqueptr = std::make_unique<T>();
156 InstanceName = Instancename;
162 return showeruniqueptr;
166 return showeruniqueptr;
171 showeruniqueptr.reset(
new T());
181 throw cet::exception(
"ShowerUniqueAssnPtr") <<
"The creator of this code has failed you. Please contact Dominic Bakrer" <<
std::endl;
187 return abi::__cxa_demangle(
typeid(showeruniqueptr.get()).
name(),NULL,NULL,&status);
219 virtual bool CheckPtrMaker() = 0;
223 virtual void Reset() = 0;
237 InstanceName = Instancename;
251 if(ptrmaker == NULL){
263 if(ptrmaker == NULL){
266 return (*ptrmaker)(iter);
269 return (*ptrmaker)(0);
280 throw cet::exception(
"ShowerPtrMaker") <<
"Trying to reset ptr but it has not been set in the first place. Please contatc Dom Barker" <<
std::endl;
282 ptrmaker.
reset(
nullptr);
310 if(showerassnPtrs.find(Name) != showerassnPtrs.end()){
311 mf::LogWarning(
"ShowerProduedPtrsHolder") <<
"Trying to set Element: " << Name <<
". This element has already been set. Please check." <<
std::endl;
316 if(!CheckForMultipleTypes(
type<T>(), Name, Instance)){
317 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Trying to set multiple objects with same type with no instance name or same instance name" <<
std::endl;
330 if(showerproductPtrs.find(Name) != showerproductPtrs.end()){
331 mf::LogWarning(
"ShowerProduedPtrsHolder") <<
"Trying to set Element: " << Name <<
". This element has already been set. Please check." <<
std::endl;
336 if(!CheckForMultipleTypes(
type<std::vector<T> >(), Name, Instance)){
337 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Trying to set multiple objects with same type with no instance name or same instance name" <<
std::endl;
341 if(showerPtrMakers.find(Name) != showerPtrMakers.end()){
342 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"PtrMaker already exist. It should not be set again" <<
std::endl;
353 if(showerproductPtrs.find(Name) != showerproductPtrs.end()){
356 if(showerassnPtrs.find(Name) != showerassnPtrs.end()){
364 for(
auto const& showerptr: showerproductPtrs){
365 (showerptr.second)->
reset();
367 for(
auto const& showerptr: showerassnPtrs){
368 (showerptr.second)->
reset();
376 for(
auto const& showerproductPtr: showerproductPtrs){
377 (showerproductPtr.second)->AddDataProduct(selement_holder, showerproductPtr.first);
383 for(
auto const& showerproductPtr: showerproductPtrs){
384 (showerproductPtr.second)->MoveToEvent(evt);
386 for(
auto const& showerassnPtr: showerassnPtrs){
387 (showerassnPtr.second)->MoveToEvent(evt);
393 for(
auto const& showerproductPtr: showerproductPtrs){
394 if(showerproductPtr.first ==
"shower"){
continue;}
395 checked *= selement_holder.
CheckElement(showerproductPtr.first);
404 if(showerproductPtrs.find(Name) != showerproductPtrs.end()){
406 return prod->GetPtr();
408 else if(showerassnPtrs.find(Name) != showerassnPtrs.end()){
413 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Trying to get Ptr for: " << Name <<
" but Element does not exist" <<
std::endl;
420 template <
class T,
class A,
class B>
422 if(showerassnPtrs.find(Name) == showerassnPtrs.end()){
423 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Trying to get the association: " << Name <<
"Element does not exist" <<
std::endl;
427 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Element type is not an assoication please only use this for assocations" <<
std::endl;
432 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Failed to cast back. Maybe you got the type wrong or you are accidently accessing a differently named product" <<
std::endl;
435 T* assn =
dynamic_cast<T*
>(assnptr->
GetPtr().get());
437 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Something went wrong trying to cast tothe assn. Maybe the name: " << Name <<
" exists but its not an assn" <<
std::endl;
440 assn->addSingle(a,b);
446 for(
auto const& showerPtrMaker: showerPtrMakers){
447 if(showerPtrMakers.find(showerPtrMaker.first) == showerPtrMakers.end()){
450 showerPtrMakers[showerPtrMaker.first]->SetPtrMaker(evt);
457 if(showerPtrMakers.find(Name) == showerPtrMakers.end()){
461 if(!showerPtrMakers[Name]->CheckPtrMaker()){
472 if(showerPtrMakers.find(Name) == showerPtrMakers.end()){
473 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"PtrMaker does not exist for " << Name <<
" Did you initialise this? " <<
std::endl;
476 if(!showerPtrMakers[Name]->CheckPtrMaker()){
477 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"PtrMaker is not set. This is an issue for the devlopment team me. Contact Dom Barker" <<
std::endl;
480 if(ptrmaker == NULL){
481 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Failed to cast back. Maybe you got the type wrong or you are accidently accessing a differently named product" <<
std::endl;
489 for(
auto const& showerPtrMaker: showerPtrMakers){
490 (showerPtrMaker.second)->Reset();
496 if(showerproductPtrs.find(Name) != showerproductPtrs.end()){
497 return showerproductPtrs[
Name]->GetVectorPtrSize();
499 throw cet::exception(
"ShowerProduedPtrsHolder") <<
"Product: " << Name <<
" has not been set in the producers map" <<
std::endl;
504 if(showerproductPtrs.find(Name) != showerproductPtrs.end()){
507 std::cout <<
"Element Name: " << Name <<
" Instance Name: " << InstanceName <<
" Type: " << Type <<
std::endl;
510 if(showerassnPtrs.find(Name) != showerassnPtrs.end()){
513 std::cout <<
"Element Name: " << Name <<
" Instance Name: " << InstanceName <<
" Type: " << Type <<
std::endl;
516 mf::LogError(
"ShowerProduedPtrsHolder") <<
"Trying to print Element: " << Name <<
". This element does not exist in the element holder" <<
std::endl;
524 unsigned int maxname = 0;
525 for(
auto const& showerprodPtr: showerproductPtrs){
526 if(showerprodPtr.first.size() > maxname){
527 maxname = showerprodPtr.first.size();
530 for(
auto const& showerassnPtr: showerassnPtrs){
531 if(showerassnPtr.first.size() > maxname){
532 maxname = showerassnPtr.first.size();
536 std::map<std::string,std::pair<std::string,std::string> > Type_showerprodPtrs;
537 std::map<std::string,std::pair<std::string,std::string> > Type_showerassnPtrs;
538 for(
auto const& showerprodPtr: showerproductPtrs){
540 std::string InstanceName = (showerprodPtr.second)->GetInstanceName();
541 Type_showerprodPtrs[showerprodPtr.first] = std::make_pair(InstanceName,Type);
543 for(
auto const& showerassnPtr: showerassnPtrs){
545 std::string InstanceName = (showerassnPtr.second)->GetInstanceName();
546 Type_showerassnPtrs[showerassnPtr.first] = std::make_pair(InstanceName,Type);
549 unsigned int maxtype = 0;
550 unsigned int maxinstname = 0;
551 for(
auto const& Type_showerprodPtr: Type_showerprodPtrs){
552 if(Type_showerprodPtr.second.second.size() > maxtype){
553 maxtype = Type_showerprodPtr.second.second.size();
555 if(Type_showerprodPtr.second.first.size() > maxinstname){
556 maxinstname = Type_showerprodPtr.second.first.size();
559 for(
auto const& Type_showerassnPtr: Type_showerassnPtrs){
560 if(Type_showerassnPtr.second.second.size() > maxtype){
561 maxtype = Type_showerassnPtr.second.second.size();
563 if(Type_showerassnPtr.second.first.size() > maxinstname){
564 maxinstname = Type_showerassnPtr.second.first.size();
568 unsigned int n = maxname + maxtype + maxinstname + 51;
570 std::cout <<
"Unique Ptrs that are added to the event" <<
std::endl;
572 for(
auto const& Type_showerprodPtr: Type_showerprodPtrs){
577 for(
auto const& Type_showerassnPtr: Type_showerassnPtrs){
597 for(
auto const& assn: showerassnPtrs){
611 for(
auto const& product: showerproductPtrs){
614 if(prod->GetInstanceName() == Instance){
return false;}
623 std::map<std::string,std::unique_ptr<reco::shower::ShowerUniqueProduerPtrBase > >
showerproductPtrs;
626 std::map<std::string,std::unique_ptr<reco::shower::ShowerUniqueProduerPtrBase > >
showerassnPtrs;
629 std::map<std::string,std::unique_ptr<reco::shower::ShowerPtrMakerBase> >
showerPtrMakers;
std::map< std::string, std::unique_ptr< reco::shower::ShowerPtrMakerBase > > showerPtrMakers
void PrintPtr(std::string Name)
void AddDataProduct(reco::shower::ShowerElementHolder &selement_holder, std::string Name) override
art::Ptr< T > GetArtPtr(std::string Name, int iter)
std::string GetInstanceName() override
std::unique_ptr< std::vector< T > > showeruniqueptr
std::string GetType() override
virtual int GetVectorPtrSize()
std::unique_ptr< art::PtrMaker< T > > ptrmaker
void SetPtrMaker(art::Event &evt) override
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void MoveAllToEvent(art::Event &evt)
std::unique_ptr< T > & GetPtr()
std::unique_ptr< T > showeruniqueptr
void MoveToEvent(art::Event &evt) override
bool CheckUniqueProduerPtr(std::string Name)
std::unique_ptr< T > & GetPtr()
QTextStream & reset(QTextStream &s)
bool CheckAllProducedElements(reco::shower::ShowerElementHolder &selement_holder)
art::PtrMaker< T > & GetPtrMaker(std::string Name)
int SetShowerUniqueProduerPtr(type< std::vector< T > >, std::string Name, std::string Instance="")
void AddSingle(A &a, B &b, std::string Name)
bool CheckForMultipleTypes(type< T >, std::string Name, std::string Instance)
int GetVectorPtrSize(std::string Name)
void err(const char *fmt,...)
T & GetPtr(std::string Name)
Q_EXPORT QTSManip setw(int w)
void MoveToEvent(art::Event &evt) override
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
std::map< std::string, std::unique_ptr< reco::shower::ShowerUniqueProduerPtrBase > > showerproductPtrs
void AddDataProduct(reco::shower::ShowerElementHolder &selement_holder, std::string Name) override
bool CheckElement(std::string Name)
int SetShowerUniqueProduerPtr(type< T >, std::string Name, std::string Instance="")
bool CheckPtrMaker() override
int GetVectorPtrSize() override
const GenericPointer< typename T::ValueType > T2 value
int GetElement(std::string Name, T &Element)
void SetPtrMakers(art::Event &evt)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
bool CheckForMultipleTypes(type< std::vector< T > >, std::string Name, std::string Instance)
ShowerPtrMaker(std::string Instancename)
std::map< std::string, std::unique_ptr< reco::shower::ShowerUniqueProduerPtrBase > > showerassnPtrs
std::string GetType() override
std::string GetInstanceName() override
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
void AddDataProducts(reco::shower::ShowerElementHolder &selement_holder)
art::Ptr< T > GetArtPtr(int iter)
Q_EXPORT QTSManip setfill(int f)
ShowerUniqueAssnPtr(std::string &Instancename)
cet::coded_exception< error, detail::translate > exception
art::PtrMaker< T > & GetPtrMaker()
QTextStream & endl(QTextStream &s)