10 #ifndef ShowerElementHolder_HH 11 #define ShowerElementHolder_HH 17 #include "cetlib_except/demangle.h" 18 #include "cetlib_except/exception.h" 29 class ShowerElementBase;
36 template <
class T,
class T2>
49 <<
"Trying to check an element that is not a product" << std::endl;
54 <<
"Trying to set an element that is not a product" << std::endl;
57 virtual std::string
GetType()
const = 0;
111 <<
"The element that is being accessed is not set" << std::endl;
120 <<
"The element that is being accessed is not set" << std::endl;
126 std::string
GetType()
const override {
return cet::demangle_symbol(
typeid(element).name()); }
173 template <
class T,
class T2>
179 propertyErr = ElementErr;
186 ElementErr = propertyErr;
197 this->element = Element;
199 propertyErr = ElementErr;
221 auto const showerPropertiesIt = showerproperties.find(Name);
222 if (showerPropertiesIt != showerproperties.end()) {
223 if (showerPropertiesIt->second->CheckShowerElement()) {
226 if (showerprop ==
nullptr) {
228 <<
"Trying to get Element: " << Name
229 <<
". This element you are filling is not the correct type" << std::endl;
236 <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
241 auto const showerDataProductsIt = showerdataproducts.find(Name);
242 if (showerDataProductsIt != showerdataproducts.end()) {
243 if (showerDataProductsIt->second->CheckShowerElement()) {
246 if (showerprop ==
nullptr) {
248 <<
"Trying to get Element: " << Name
249 <<
". This element you are filling is not the correct type" << std::endl;
256 <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
261 auto const eventDataProductsIt = eventdataproducts.find(Name);
262 if (eventDataProductsIt != eventdataproducts.end()) {
263 if (eventDataProductsIt->second->CheckShowerElement()) {
266 if (eventprop ==
nullptr) {
268 <<
"Trying to get Element: " << Name
269 <<
". This element you are filling is not the correct type" << std::endl;
276 <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
281 <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder" 288 auto const eventDataProductsIt = eventdataproducts.find(Name);
289 if (eventDataProductsIt != eventdataproducts.end()) {
290 if (eventDataProductsIt->second->CheckShowerElement()) {
293 if (eventprop ==
nullptr) {
295 <<
"Trying to get Element: " << Name
296 <<
". This element you are filling is not the correct type" << std::endl;
303 <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
308 <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder" 316 auto const eventDataProductsIt = eventdataproducts.find(Name);
317 if (eventDataProductsIt != eventdataproducts.end()) {
318 if (eventDataProductsIt->second->CheckShowerElement()) {
321 if (eventprop ==
nullptr) {
323 <<
"Trying to get Element: " << Name
324 <<
". This element you are filling is not the correct type" << std::endl;
330 <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder" 338 auto const showerPropertiesIt = showerproperties.find(Name);
339 if (showerPropertiesIt != showerproperties.end()) {
340 if (showerPropertiesIt->second->CheckShowerElement()) {
343 if (showerprop ==
nullptr) {
345 <<
"Trying to get Element: " << Name
346 <<
". This element you are filling is not the correct type" << std::endl;
352 auto const showerDataProductsIt = showerdataproducts.find(Name);
353 if (showerDataProductsIt != showerdataproducts.end()) {
354 if (showerDataProductsIt->second->CheckShowerElement()) {
357 if (showerprop ==
nullptr) {
359 <<
"Trying to get Element: " << Name
360 <<
". This element you are filling is not the correct type" << std::endl;
366 auto const eventDataProductsIt = eventdataproducts.find(Name);
367 if (eventDataProductsIt != eventdataproducts.end()) {
368 if (eventDataProductsIt->second->CheckShowerElement()) {
371 if (eventprop ==
nullptr) {
373 <<
"Trying to get Element: " << Name
374 <<
". This element you are filling is not the correct type" << std::endl;
380 <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder" 385 template <
class T,
class T2>
388 auto const showerPropertiesIt = showerproperties.find(Name);
389 if (showerPropertiesIt == showerproperties.end()) {
391 <<
"Trying to get Element Error: " << Name
392 <<
". This elment does not exist in the element holder" << std::endl;
405 void SetElement(T& dataproduct,
const std::string& Name,
bool checktag =
false)
408 auto const showerDataProductsIt = showerdataproducts.find(Name);
409 if (showerDataProductsIt != showerdataproducts.end()) {
417 showerdataproducts[Name] = std::make_unique<ShowerDataProduct<T>>(dataproduct, checktag);
424 template <
class T,
class T2>
425 void SetElement(T& propertyval, T2& propertyvalerror,
const std::string& Name)
428 auto const showerPropertiesIt = showerproperties.find(Name);
429 if (showerPropertiesIt != showerproperties.end()) {
436 showerproperties[Name] =
437 std::make_unique<ShowerProperty<T, T2>>(propertyval, propertyvalerror);
448 auto const eventDataProductsIt = eventdataproducts.find(Name);
449 if (eventDataProductsIt != eventdataproducts.end()) {
456 eventdataproducts[Name] = std::make_unique<EventDataProduct<T>>(dataproduct);
463 auto const eventDataProductsIt = eventdataproducts.find(Name);
464 return eventDataProductsIt == eventdataproducts.end() ?
466 eventDataProductsIt->second->CheckShowerElement();
472 auto const showerPropertiesIt = showerproperties.find(Name);
473 if (showerPropertiesIt != showerproperties.end()) {
474 return showerPropertiesIt->second->CheckShowerElement();
476 auto const showerDataProductsIt = showerdataproducts.find(Name);
477 if (showerDataProductsIt != showerdataproducts.end()) {
478 return showerDataProductsIt->second->CheckShowerElement();
480 auto const eventDataProductsIt = eventdataproducts.find(Name);
481 if (eventDataProductsIt != eventdataproducts.end()) {
482 return eventDataProductsIt->second->CheckShowerElement();
491 for (
auto const& showerprop : showerproperties) {
492 checked = checked && showerprop.second->CheckShowerElement();
494 for (
auto const& showerdataprod : showerdataproducts) {
495 checked = checked && showerdataprod.second->CheckShowerElement();
503 auto const showerPropertiesIt = showerproperties.find(Name);
504 if (showerPropertiesIt != showerproperties.end()) {
505 return showerPropertiesIt->second->Clear();
507 auto const showerDataProductsIt = showerdataproducts.find(Name);
508 if (showerDataProductsIt != showerdataproducts.end()) {
509 return showerDataProductsIt->second->Clear();
512 <<
"Trying to clear Element: " << Name
513 <<
". This element does not exist in the element holder" << std::endl;
520 for (
auto const& showerprop : showerproperties) {
521 (showerprop.second)->
Clear();
523 for (
auto const& showerdataproduct : showerdataproducts) {
524 (showerdataproduct.second)->
Clear();
530 for (
auto const& eventdataproduct : eventdataproducts) {
531 (eventdataproduct.second)->
Clear();
544 auto const showerDataProductsIt = showerdataproducts.find(Name);
545 if (showerDataProductsIt != showerdataproducts.end()) {
546 return showerDataProductsIt->second->CheckTag();
554 auto const showerPropertiesIt = showerproperties.find(Name);
555 if (showerPropertiesIt != showerproperties.end()) {
556 return showerPropertiesIt->second.reset(
nullptr);
558 auto const showerDataProductsIt = showerdataproducts.find(Name);
559 if (showerDataProductsIt != showerdataproducts.end()) {
560 return showerDataProductsIt->second.reset(
nullptr);
563 <<
"Trying to delete Element: " << Name
564 <<
". This element does not exist in the element holder" << std::endl;
571 auto const showerDataProductsIt = showerdataproducts.find(Name);
572 if (showerDataProductsIt != showerdataproducts.end()) {
573 return showerDataProductsIt->second->SetCheckTag(checkelement);
576 <<
"Trying set the checking of the data product: " << Name
577 <<
". This data product does not exist in the element holder" << std::endl;
584 for (
auto const& showerdataproduct : showerdataproducts) {
585 bool check = showerdataproduct.second->CheckTag();
587 bool elementset = showerdataproduct.second->CheckShowerElement();
590 <<
"The following element is not set and was asked to be checked: " 591 << showerdataproduct.first << std::endl;
609 unsigned int maxname = 0;
610 for (
auto const& showerprop : showerproperties) {
611 if (showerprop.first.size() > maxname) { maxname = showerprop.first.size(); }
613 for (
auto const& showerdataprod : showerdataproducts) {
614 if (showerdataprod.first.size() > maxname) { maxname = showerdataprod.first.size(); }
617 std::map<std::string, std::string> Type_showerprops;
618 std::map<std::string, std::string> Type_showerdataprods;
619 for (
auto const& showerprop : showerproperties) {
620 std::string Type = (showerprop.second)->
GetType();
621 Type_showerprops[showerprop.first] = Type;
623 for (
auto const& showerdataprod : showerdataproducts) {
624 std::string Type = (showerdataprod.second)->
GetType();
625 Type_showerdataprods[showerdataprod.first] = Type;
628 unsigned int maxtype = 0;
629 for (
auto const& Type_showerprop : Type_showerprops) {
630 if (Type_showerprop.second.size() > maxtype) { maxtype = Type_showerprop.second.size(); }
632 for (
auto const& Type_showerdataprod : Type_showerdataprods) {
633 if (Type_showerdataprod.second.size() > maxtype) {
634 maxtype = Type_showerdataprod.second.size();
638 unsigned int n = maxname + maxtype + 33;
639 std::cout <<
std::left << std::setfill(
'*') << std::setw(n - 1) <<
"*" << std::endl;
640 std::cout <<
"Elements in the element holder" << std::endl;
641 std::cout <<
std::left << std::setfill(
'*') << std::setw(n - 1) <<
"*" << std::endl;
642 for (
auto const& Type_showerprop : Type_showerprops) {
643 std::cout <<
std::left << std::setfill(
' ') << std::setw(21)
644 <<
"* Property Name: " << std::setw(maxname) << Type_showerprop.first;
645 std::cout <<
std::left << std::setfill(
' ') <<
" * Type: " << std::setw(maxtype)
646 << Type_showerprop.second <<
" * " << std::endl;
648 for (
auto const& Type_showerdataprod : Type_showerdataprods) {
649 std::cout <<
std::left << std::setfill(
' ') << std::setw(maxname) << std::setw(21)
650 <<
"* Data Product Name: " << std::setw(maxname) << Type_showerdataprod.first;
651 std::cout <<
std::left << std::setfill(
' ') <<
" * Type: " << std::setw(maxtype)
652 << Type_showerdataprod.second <<
" *" << std::endl;
654 std::cout <<
std::left << std::setfill(
'*') << std::setw(n - 1) <<
"*" << std::endl;
655 std::cout << std::setfill(
' ');
656 std::cout << std::setw(0);
663 return cet::demangle_symbol(
typeid(
object).name());
669 return cet::demangle_symbol(
typeid(T).name());
672 template <
class T1,
class T2>
678 const std::string name(
"FMP_" + moduleTag.
label() +
"_" + getType<T1>() +
"_" + getType<T2>());
680 if (CheckEventElement(name)) {
return GetEventElement<art::FindManyP<T1>>(name); }
683 if (findManyP.isValid()) {
684 SetEventElement(findManyP, name);
685 return GetEventElement<art::FindManyP<T1>>(name);
689 <<
"FindManyP is not valid: " << name << std::endl;
694 template <
class T1,
class T2>
700 const std::string name(
"FOP_" + moduleTag.
label() +
"_" + getType<T1>() +
"_" + getType<T2>());
702 if (CheckEventElement(name)) {
return GetEventElement<art::FindOneP<T1>>(name); }
705 if (findOneP.isValid()) {
706 SetEventElement(findOneP, name);
707 return GetEventElement<art::FindOneP<T1>>(name);
711 <<
"FindOneP is not valid: " << name << std::endl;
void DeleteElement(const std::string &Name)
bool CheckShowerElement() const
virtual ~ShowerElementBase() noexcept=default
int GetShowerNumber() const
int GetShowerElement(T &Element) const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
virtual void SetCheckTag(bool &check)
void SetElementTag(const std::string &Name, bool checkelement)
virtual bool CheckTag() const
void SetEventElement(T &dataproduct, const std::string &Name)
std::string GetType() const override
EventDataProduct(T &Element)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > eventdataproducts
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > showerdataproducts
const T & GetEventElement(std::string const &Name)
void SetElement(T &propertyval, T2 &propertyvalerror, const std::string &Name)
void SetCheckTag(bool &Checktag)
void PrintElements() const
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > showerproperties
ShowerProperty(T &Element, T2 &ElementErr)
bool CheckElement(const std::string &Name) const
bool CheckElementTag(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
void SetShowerElement(T &Element)
bool CheckEventElement(const std::string &Name) const
T GetElement(const std::string &Name) const
ShowerDataProduct(T &Element, bool Checktag)
void SetShowerProperty(T &Element, T2 &ElementErr)
void SetShowerNumber(int &shower_iter)
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
T GetShowerElement() const
int GetEventElement(const std::string &Name, T &Element) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
int GetShowerPropertyError(T2 &ElementErr) const
bool CheckAllElements() const
void ClearElement(const std::string &Name)
int GetElementAndError(const std::string &Name, T &Element, T2 &ElementErr) const
std::string getType(T object) const
T & GetShowerElementRef()
virtual std::string GetType() const =0
const art::FindOneP< T1 > & GetFindOneP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)
std::string getType() const
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)
bool CheckAllElementTags() const
cet::coded_exception< error, detail::translate > exception
ShowerElementAccessor(T &Element)