11 #ifndef ShowerProducedPtrsHolder_HH
12 #define ShowerProducedPtrsHolder_HH
17 #include "art/Framework/Principal/Event.h"
18 #include "art/Persistency/Common/PtrMaker.h"
19 #include "canvas/Persistency/Common/Assns.h"
20 #include "canvas/Persistency/Common/Ptr.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
22 #include "cetlib_except/demangle.h"
23 #include "cetlib_except/exception.h"
26 class ShowerUniqueProduerPtrBase;
45 template <
class L,
class R,
class D>
46 struct is_assn<art::Assns< L, R, D > >{
static const int value = 1; };
60 virtual void reset() = 0;
66 virtual std::string
GetType()
const = 0;
81 showeruniqueptr = std::make_unique<std::vector<T> >();
82 InstanceName = Instancename;
88 return showeruniqueptr;
91 throw cet::exception(
"ShowerUniqueProduerPtr") <<
"Element does not exist" << std::endl;
96 showeruniqueptr.reset(
new std::vector<T>());
103 mf::LogError(
"ShowerProducedPtrsHolder") <<
"Trying to add data product: " << Name <<
". This element does not exist in the element holder" << std::endl;
109 mf::LogError(
"ShowerProducedPtrsHolder") <<
"Trying to add data product: " << Name <<
". This element does not exist in the element holder" << std::endl;
112 showeruniqueptr->push_back(product);
118 evt.put(std::move(showeruniqueptr),InstanceName);
123 return cet::demangle_symbol(
typeid(showeruniqueptr.get()).
name());
133 return showeruniqueptr->size();
172 throw cet::exception(
"ShowerUniqueAssnPtr") <<
"Element does not exist" << std::endl;
187 throw cet::exception(
"ShowerUniqueAssnPtr") <<
"The creator of this code has failed you. Please contact Dominic Bakrer" << std::endl;
228 virtual void Reset() = 0;
257 throw cet::exception(
"ShowerPtrMaker") <<
"Ptr maker ptr is null" << std::endl;
261 throw cet::exception(
"ShowerPtrMaker") <<
"Trying to get a ptrmaker that does not exists" << std::endl;
268 throw cet::exception(
"ShowerPtrMaker") <<
"Ptr maker ptr is null" << std::endl;
272 throw cet::exception(
"ShowerPtrMaker") <<
"Trying to get a ptrmaker that does not exists" << std::endl;
283 throw cet::exception(
"ShowerPtrMaker") <<
"Trying to reset ptr but it has not been set in the first place. Please contatc Dom Barker" << std::endl;
314 mf::LogWarning(
"ShowerProducedPtrsHolder") <<
"Trying to set Element: " << Name <<
". This element has already been set. Please check." << std::endl;
320 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Trying to set multiple objects with same type with no instance name or same instance name" << std::endl;
333 mf::LogWarning(
"ShowerProducedPtrsHolder") <<
"Trying to set Element: " << Name <<
". This element has already been set. Please check." << std::endl;
339 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Trying to set multiple objects with same type with no instance name or same instance name" << std::endl;
343 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker already exist. It should not be set again" << std::endl;
365 (showerptr.second)->
reset();
368 (showerptr.second)->
reset();
377 (showerproductPtr.second)->AddDataProduct(selement_holder, showerproductPtr.first);
384 (showerproductPtr.second)->MoveToEvent(evt);
387 (showerassnPtr.second)->MoveToEvent(evt);
394 if(showerproductPtr.first ==
"shower"){
continue;}
395 checked *= selement_holder.
CheckElement(showerproductPtr.first);
407 return prod->GetPtr();
416 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Trying to get Ptr for: " << Name <<
" but Element does not exist" << std::endl;
421 template <
class T,
class A,
class B>
425 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Trying to get the association: " << Name <<
"Element does not exist" << std::endl;
428 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Element type is not an assoication please only use this for assocations" << std::endl;
431 if(assnptr ==
nullptr){
432 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;
435 T* assn =
dynamic_cast<T*
>(assnptr->
GetPtr().get());
437 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"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);
447 if(showerPtrMakers.find(showerPtrMaker.first) == showerPtrMakers.end()){
448 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker was empty. This is concerning" << std::endl;
450 showerPtrMakers[showerPtrMaker.first]->SetPtrMaker(evt);
459 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker does not exist" << std::endl;
462 if(!showerPtrMakersIt->second->CheckPtrMaker()){
463 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker is not set" << std::endl;
475 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker does not exist for " << Name <<
" Did you initialise this? " << std::endl;
478 if(!showerPtrMakersIt->second->CheckPtrMaker()){
479 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker is not set. This is an issue for the devlopment team me. Contact Dom Barker" << std::endl;
482 if(ptrmaker ==
nullptr){
483 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;
492 (showerPtrMaker.second)->Reset();
500 return showerproductPtrsIt->second->GetVectorPtrSize();
502 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"Product: " << Name <<
" has not been set in the producers map" << std::endl;
509 const std::string
Type = showerproductPtrsIt->second->GetType();
510 const std::string InstanceName = showerproductPtrsIt->second->GetInstanceName();
511 std::cout <<
"Element Name: " << Name <<
" Instance Name: " << InstanceName <<
" Type: " << Type << std::endl;
516 const std::string
Type = showerassnPtrsIt->second->GetType();
517 const std::string InstanceName = showerassnPtrsIt->second->GetInstanceName();
518 std::cout <<
"Element Name: " << Name <<
" Instance Name: " << InstanceName <<
" Type: " << Type << std::endl;
521 mf::LogError(
"ShowerProducedPtrsHolder") <<
"Trying to print Element: " << Name <<
". This element does not exist in the element holder" << std::endl;
529 unsigned int maxname = 0;
531 if(showerprodPtr.first.size() > maxname){
532 maxname = showerprodPtr.first.size();
536 if(showerassnPtr.first.size() > maxname){
537 maxname = showerassnPtr.first.size();
541 std::map<std::string,std::pair<std::string,std::string> > Type_showerprodPtrs;
542 std::map<std::string,std::pair<std::string,std::string> > Type_showerassnPtrs;
543 for(
auto const& showerprodPtr: showerproductPtrs){
544 const std::string
Type = (showerprodPtr.second)->GetType();
545 const std::string InstanceName = (showerprodPtr.second)->GetInstanceName();
546 Type_showerprodPtrs[showerprodPtr.first] = std::make_pair(InstanceName,Type);
548 for(
auto const& showerassnPtr: showerassnPtrs){
549 const std::string
Type = (showerassnPtr.second)->GetType();
550 const std::string InstanceName = (showerassnPtr.second)->GetInstanceName();
551 Type_showerassnPtrs[showerassnPtr.first] = std::make_pair(InstanceName,Type);
554 unsigned int maxtype = 0;
555 unsigned int maxinstname = 0;
556 for(
auto const& Type_showerprodPtr: Type_showerprodPtrs){
557 if(Type_showerprodPtr.second.second.size() > maxtype){
558 maxtype = Type_showerprodPtr.second.second.size();
560 if(Type_showerprodPtr.second.first.size() > maxinstname){
561 maxinstname = Type_showerprodPtr.second.first.size();
564 for(
auto const& Type_showerassnPtr: Type_showerassnPtrs){
565 if(Type_showerassnPtr.second.second.size() > maxtype){
566 maxtype = Type_showerassnPtr.second.second.size();
568 if(Type_showerassnPtr.second.first.size() > maxinstname){
569 maxinstname = Type_showerassnPtr.second.first.size();
573 unsigned int n = maxname + maxtype + maxinstname + 51;
575 std::cout <<
"Unique Ptrs that are added to the event" << std::endl;
577 for(
auto const& Type_showerprodPtr: Type_showerprodPtrs){
578 std::cout <<
std::left << std::setfill(
' ') << std::setw(21) <<
"* Data Product Name: " << std::setw(maxname) << Type_showerprodPtr.first;
579 std::cout <<
std::left << std::setfill(
' ') <<
" * Instance Name: " << std::setw(maxinstname) << Type_showerprodPtr.second.first;
580 std::cout <<
std::left << std::setfill(
' ') <<
" * Type: " << std::setw(maxtype) << Type_showerprodPtr.second.second <<
" *" << std::endl;
582 for(
auto const& Type_showerassnPtr: Type_showerassnPtrs){
583 std::cout <<
std::left << std::setfill(
' ') << std::setw(maxname) << std::setw(21) <<
"* Association Name: " << std::setw(maxname) << Type_showerassnPtr.first;
584 std::cout <<
std::left << std::setfill(
' ') <<
" * Instance Name: " << std::setw(maxinstname) << Type_showerassnPtr.second.first;
585 std::cout <<
std::left << std::setfill(
' ') <<
" * Type: " << std::setw(maxtype) << Type_showerassnPtr.second.second<<
" *" << std::endl;
604 if(assnptr !=
nullptr){
619 if(prod->GetInstanceName() == Instance){
return false;}
628 std::map<std::string,std::unique_ptr<reco::shower::ShowerUniqueProduerPtrBase > >
showerproductPtrs;
631 std::map<std::string,std::unique_ptr<reco::shower::ShowerUniqueProduerPtrBase > >
showerassnPtrs;
634 std::map<std::string,std::unique_ptr<reco::shower::ShowerPtrMakerBase> >
showerPtrMakers;
std::string GetType() const override
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
std::string GetInstanceName() 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
std::string GetInstanceName() 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)
EResult err(const char *call)
std::unique_ptr< std::vector< T > > showeruniqueptr
virtual void SetPtrMaker(art::Event &evt)=0
virtual std::string GetType() const =0
std::unique_ptr< art::PtrMaker< T > > ptrmaker
int GetVectorPtrSize() const override
int SetShowerUniqueProduerPtr(type< std::vector< T > >, const std::string &Name, const std::string &Instance="")
void SetPtrMaker(art::Event &evt) override
virtual void MoveToEvent(art::Event &evt)=0
ShowerPtrMaker(const std::string &Instancename)
void MoveAllToEvent(art::Event &evt)
void PrintPtr(const std::string &Name) const
bool CheckUniqueProduerPtr(const std::string &Name) const
virtual ~ShowerPtrMakerBase() noexcept=default
std::unique_ptr< T > & GetPtr()
std::unique_ptr< T > showeruniqueptr
bool CheckPtrMaker() const override
void MoveToEvent(art::Event &evt) override
std::map< std::string, std::unique_ptr< reco::shower::ShowerUniqueProduerPtrBase > > showerproductPtrs
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::map< std::string, std::unique_ptr< reco::shower::ShowerUniqueProduerPtrBase > > showerassnPtrs
std::unique_ptr< T > & GetPtr()
virtual bool CheckPtrMaker() const =0
void AddSingle(A &a, B &b, const std::string &Name)
T & GetPtr(const std::string &Name)
bool CheckElement(const std::string &Name) const
BEGIN_PROLOG vertical distance to the surface Name
void SetPtrMakers(art::Event &evt)
int GetElement(const std::string &Name, T &Element) const
std::string GetType() const override
void MoveToEvent(art::Event &evt) override
virtual int GetVectorPtrSize() const
bool CheckAllProducedElements(reco::shower::ShowerElementHolder &selement_holder) const
virtual ~ShowerUniqueProduerPtrBase() noexcept=default
void AddDataProduct(const reco::shower::ShowerElementHolder &selement_holder, const std::string &Name) override
virtual void AddDataProduct(const reco::shower::ShowerElementHolder &selement_holder, const std::string &Name)=0
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
virtual std::string GetInstanceName() const =0
int SetShowerUniqueProduerPtr(type< T >, const std::string &Name, const std::string &Instance="")
bool CheckForMultipleTypes(type< T >, const std::string &Name, const std::string &Instance) const
int GetVectorPtrSize(const std::string &Name) const
BEGIN_PROLOG could also be cout
art::PtrMaker< T > & GetPtrMaker()