11 #ifndef ShowerProducedPtrsHolder_HH 12 #define ShowerProducedPtrsHolder_HH 21 #include "cetlib_except/demangle.h" 22 #include "cetlib_except/exception.h" 26 class ShowerUniqueProduerPtrBase;
50 template <
class L,
class R,
class D>
65 virtual void reset() = 0;
68 const std::string& Name) = 0;
72 virtual std::string GetType()
const = 0;
73 virtual std::string GetInstanceName()
const = 0;
88 showeruniqueptr = std::make_unique<std::vector<T>>();
89 InstanceName = Instancename;
95 if (ptr) {
return showeruniqueptr; }
97 throw cet::exception(
"ShowerUniqueProduerPtr") <<
"Element does not exist" << std::endl;
101 void reset()
override { showeruniqueptr.reset(
new std::vector<T>()); }
105 const std::string& Name)
override 110 <<
"Trying to add data product: " << Name
111 <<
". This element does not exist in the element holder" << std::endl;
115 int err = selement_holder.
GetElement(Name, product);
118 <<
"Trying to add data product: " << Name
119 <<
". This element does not exist in the element holder" << std::endl;
122 showeruniqueptr->push_back(product);
132 return cet::demangle_symbol(
typeid(showeruniqueptr.get()).name());
164 showeruniqueptr = std::make_unique<T>();
165 InstanceName = Instancename;
171 if (ptr) {
return showeruniqueptr; }
173 throw cet::exception(
"ShowerUniqueAssnPtr") <<
"Element does not exist" << std::endl;
177 void reset()
override { showeruniqueptr.reset(
new T()); }
184 const std::string& Name)
override 187 <<
"The creator of this code has failed you. Please contact Dominic Bakrer" << std::endl;
193 return cet::demangle_symbol(
typeid(showeruniqueptr.get()).name());
219 virtual bool CheckPtrMaker()
const = 0;
223 virtual void Reset() = 0;
235 InstanceName = Instancename;
241 if (ptr) {
return true; }
249 if (ptrmaker ==
nullptr) {
250 throw cet::exception(
"ShowerPtrMaker") <<
"Ptr maker ptr is null" << std::endl;
255 <<
"Trying to get a ptrmaker that does not exists" << std::endl;
262 if (ptrmaker ==
nullptr) {
263 throw cet::exception(
"ShowerPtrMaker") <<
"Ptr maker ptr is null" << std::endl;
265 return (*ptrmaker)(iter);
268 <<
"Trying to get a ptrmaker that does not exists" << std::endl;
281 throw cet::exception(
"ShowerPtrMaker") <<
"Trying to reset ptr but it has not been set in " 282 "the first place. Please contatc Dom Barker" 285 ptrmaker.reset(
nullptr);
312 if (showerassnPtrs.find(Name) != showerassnPtrs.end()) {
314 <<
"Trying to set Element: " << Name <<
". This element has already been set. Please check." 320 if (!CheckForMultipleTypes(
type<T>(), Name, Instance)) {
322 <<
"Trying to set multiple objects with same type with no instance name or same instance " 327 showerassnPtrs[Name] = std::make_unique<ShowerUniqueAssnPtr<T>>(Instance);
334 const std::string& Name,
335 const std::string& Instance =
"")
339 if (showerproductPtrs.find(Name) != showerproductPtrs.end()) {
341 <<
"Trying to set Element: " << Name <<
". This element has already been set. Please check." 347 if (!CheckForMultipleTypes(
type<std::vector<T>>(), Name, Instance)) {
349 <<
"Trying to set multiple objects with same type with no instance name or same instance " 354 if (showerPtrMakers.find(Name) != showerPtrMakers.end()) {
356 <<
"PtrMaker already exist. It should not be set again" << std::endl;
358 showerPtrMakers[Name] = std::make_unique<ShowerPtrMaker<T>>(Instance);
359 showerproductPtrs[Name] = std::make_unique<ShowerUniqueProductPtr<std::vector<T>>>(Instance);
366 if (showerproductPtrs.find(Name) != showerproductPtrs.end()) {
return true; }
367 if (showerassnPtrs.find(Name) != showerassnPtrs.end()) {
return true; }
374 for (
auto const& showerptr : showerproductPtrs) {
375 (showerptr.second)->reset();
377 for (
auto const& showerptr : showerassnPtrs) {
378 (showerptr.second)->reset();
387 for (
auto const& showerproductPtr : showerproductPtrs) {
388 (showerproductPtr.second)->AddDataProduct(selement_holder, showerproductPtr.first);
395 for (
auto const& showerproductPtr : showerproductPtrs) {
396 (showerproductPtr.second)->MoveToEvent(evt);
398 for (
auto const& showerassnPtr : showerassnPtrs) {
399 (showerassnPtr.second)->MoveToEvent(evt);
406 for (
auto const& showerproductPtr : showerproductPtrs) {
407 if (showerproductPtr.first ==
"shower") {
continue; }
408 checked = checked && selement_holder.
CheckElement(showerproductPtr.first);
417 auto const showerproductPtrsIt = showerproductPtrs.find(Name);
418 if (showerproductPtrsIt != showerproductPtrs.end()) {
421 return prod->GetPtr();
424 auto const showerassnPtrsIt = showerassnPtrs.find(Name);
425 if (showerassnPtrsIt != showerassnPtrs.end()) {
432 <<
"Trying to get Ptr for: " << Name <<
" but Element does not exist" << std::endl;
437 template <
class T,
class A,
class B>
440 auto const showerassnPtrsIt = showerassnPtrs.find(Name);
441 if (showerassnPtrsIt == showerassnPtrs.end()) {
443 <<
"Trying to get the association: " << Name <<
"Element does not exist" << std::endl;
447 <<
"Element type is not an assoication please only use this for assocations" << std::endl;
451 if (assnptr ==
nullptr) {
453 <<
"Failed to cast back. Maybe you got the type wrong or you are accidently accessing a " 454 "differently named product" 458 T* assn =
dynamic_cast<T*
>(assnptr->
GetPtr().get());
459 if (assn ==
nullptr) {
461 <<
"Something went wrong trying to cast tothe assn. Maybe the name: " << Name
462 <<
" exists but its not an assn" << std::endl;
465 assn->addSingle(a, b);
472 for (
auto const& showerPtrMaker : showerPtrMakers) {
473 if (showerPtrMakers.find(showerPtrMaker.first) == showerPtrMakers.end()) {
475 <<
"PtrMaker was empty. This is concerning" << std::endl;
477 showerPtrMakers[showerPtrMaker.first]->SetPtrMaker(evt);
485 auto const showerPtrMakersIt = showerPtrMakers.find(Name);
486 if (showerPtrMakersIt == showerPtrMakers.end()) {
487 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker does not exist" << std::endl;
490 if (!showerPtrMakersIt->second->CheckPtrMaker()) {
491 throw cet::exception(
"ShowerProducedPtrsHolder") <<
"PtrMaker is not set" << std::endl;
503 auto const showerPtrMakersIt = showerPtrMakers.find(Name);
504 if (showerPtrMakersIt == showerPtrMakers.end()) {
506 <<
"PtrMaker does not exist for " << Name <<
" Did you initialise this? " << std::endl;
509 if (!showerPtrMakersIt->second->CheckPtrMaker()) {
511 <<
"PtrMaker is not set. This is an issue for the devlopment team me. Contact Dom Barker" 516 if (ptrmaker ==
nullptr) {
518 <<
"Failed to cast back. Maybe you got the type wrong or you are accidently accessing a " 519 "differently named product" 529 for (
auto const& showerPtrMaker : showerPtrMakers) {
530 (showerPtrMaker.second)->
Reset();
537 auto const showerproductPtrsIt = showerproductPtrs.find(Name);
538 if (showerproductPtrsIt != showerproductPtrs.end()) {
539 return showerproductPtrsIt->second->GetVectorPtrSize();
542 <<
"Product: " << Name <<
" has not been set in the producers map" << std::endl;
548 auto const showerproductPtrsIt = showerproductPtrs.find(Name);
549 if (showerproductPtrsIt != showerproductPtrs.end()) {
550 const std::string Type = showerproductPtrsIt->second->GetType();
551 const std::string InstanceName = showerproductPtrsIt->second->GetInstanceName();
552 std::cout <<
"Element Name: " << Name <<
" Instance Name: " << InstanceName
553 <<
" Type: " << Type << std::endl;
556 auto const showerassnPtrsIt = showerassnPtrs.find(Name);
557 if (showerassnPtrsIt != showerassnPtrs.end()) {
558 const std::string Type = showerassnPtrsIt->second->GetType();
559 const std::string InstanceName = showerassnPtrsIt->second->GetInstanceName();
560 std::cout <<
"Element Name: " << Name <<
" Instance Name: " << InstanceName
561 <<
" Type: " << Type << std::endl;
565 <<
"Trying to print Element: " << Name
566 <<
". This element does not exist in the element holder" << std::endl;
574 unsigned int maxname = 0;
575 for (
auto const& showerprodPtr : showerproductPtrs) {
576 if (showerprodPtr.first.size() > maxname) { maxname = showerprodPtr.first.size(); }
578 for (
auto const& showerassnPtr : showerassnPtrs) {
579 if (showerassnPtr.first.size() > maxname) { maxname = showerassnPtr.first.size(); }
582 std::map<std::string, std::pair<std::string, std::string>> Type_showerprodPtrs;
583 std::map<std::string, std::pair<std::string, std::string>> Type_showerassnPtrs;
584 for (
auto const& showerprodPtr : showerproductPtrs) {
585 const std::string Type = (showerprodPtr.second)->GetType();
586 const std::string InstanceName = (showerprodPtr.second)->GetInstanceName();
587 Type_showerprodPtrs[showerprodPtr.first] = std::make_pair(InstanceName, Type);
589 for (
auto const& showerassnPtr : showerassnPtrs) {
590 const std::string Type = (showerassnPtr.second)->GetType();
591 const std::string InstanceName = (showerassnPtr.second)->GetInstanceName();
592 Type_showerassnPtrs[showerassnPtr.first] = std::make_pair(InstanceName, Type);
595 unsigned int maxtype = 0;
596 unsigned int maxinstname = 0;
597 for (
auto const& Type_showerprodPtr : Type_showerprodPtrs) {
598 if (Type_showerprodPtr.second.second.size() > maxtype) {
599 maxtype = Type_showerprodPtr.second.second.size();
601 if (Type_showerprodPtr.second.first.size() > maxinstname) {
602 maxinstname = Type_showerprodPtr.second.first.size();
605 for (
auto const& Type_showerassnPtr : Type_showerassnPtrs) {
606 if (Type_showerassnPtr.second.second.size() > maxtype) {
607 maxtype = Type_showerassnPtr.second.second.size();
609 if (Type_showerassnPtr.second.first.size() > maxinstname) {
610 maxinstname = Type_showerassnPtr.second.first.size();
614 unsigned int n = maxname + maxtype + maxinstname + 51;
615 std::cout <<
std::left << std::setfill(
'*') << std::setw(n - 1) <<
"**" << std::endl;
616 std::cout <<
"Unique Ptrs that are added to the event" << std::endl;
617 std::cout <<
std::left << std::setfill(
'*') << std::setw(n - 1) <<
"**" << std::endl;
618 for (
auto const& Type_showerprodPtr : Type_showerprodPtrs) {
619 std::cout <<
std::left << std::setfill(
' ') << std::setw(21)
620 <<
"* Data Product Name: " << std::setw(maxname) << Type_showerprodPtr.first;
621 std::cout <<
std::left << std::setfill(
' ') <<
" * Instance Name: " << std::setw(maxinstname)
622 << Type_showerprodPtr.second.first;
623 std::cout <<
std::left << std::setfill(
' ') <<
" * Type: " << std::setw(maxtype)
624 << Type_showerprodPtr.second.second <<
" *" << std::endl;
626 for (
auto const& Type_showerassnPtr : Type_showerassnPtrs) {
627 std::cout <<
std::left << std::setfill(
' ') << std::setw(maxname) << std::setw(21)
628 <<
"* Association Name: " << std::setw(maxname) << Type_showerassnPtr.first;
629 std::cout <<
std::left << std::setfill(
' ') <<
" * Instance Name: " << std::setw(maxinstname)
630 << Type_showerassnPtr.second.first;
631 std::cout <<
std::left << std::setfill(
' ') <<
" * Type: " << std::setw(maxtype)
632 << Type_showerassnPtr.second.second <<
" *" << std::endl;
634 std::cout <<
std::left << std::setfill(
'*') << std::setw(n - 1) <<
"**" << std::endl;
635 std::cout << std::setfill(
' ');
636 std::cout << std::setw(0);
647 for (
auto const& assn : showerassnPtrs) {
650 if (assnptr !=
nullptr) {
660 const std::string& Name,
661 const std::string& Instance)
const 665 for (
auto const& product : showerproductPtrs) {
668 if (prod !=
nullptr) {
669 if (prod->GetInstanceName() == Instance) {
return false; }
676 std::map<std::string, std::unique_ptr<reco::shower::ShowerUniqueProduerPtrBase>>
680 std::map<std::string, std::unique_ptr<reco::shower::ShowerUniqueProduerPtrBase>>
showerassnPtrs;
683 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
void AddDataProducts(const reco::shower::ShowerElementHolder &selement_holder)
std::string GetType() const override
std::unique_ptr< std::vector< T > > showeruniqueptr
std::unique_ptr< art::PtrMaker< T > > ptrmaker
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::map< std::string, std::unique_ptr< reco::shower::ShowerUniqueProduerPtrBase > > showerproductPtrs
std::unique_ptr< T > & GetPtr()
std::unique_ptr< T > showeruniqueptr
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
void MoveToEvent(art::Event &evt) override
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::unique_ptr< T > & GetPtr()
std::string GetInstanceName() const override
void AddSingle(A &a, B &b, const std::string &Name)
ntupleExperimental Reset()
T & GetPtr(const std::string &Name)
bool CheckElement(const std::string &Name) const
void SetPtrMakers(art::Event &evt)
int GetElement(const std::string &Name, T &Element) const
void MoveToEvent(art::Event &evt) override
virtual int GetVectorPtrSize() const
int SetShowerUniqueProduerPtr(type< std::vector< T >>, const std::string &Name, const std::string &Instance="")
bool CheckAllProducedElements(reco::shower::ShowerElementHolder &selement_holder) const
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
std::map< std::string, std::unique_ptr< reco::shower::ShowerUniqueProduerPtrBase > > showerassnPtrs
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
bool CheckForMultipleTypes(type< std::vector< T >>, const std::string &Name, const std::string &Instance) 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="")
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()