10#ifndef ShowerElementHolder_HH
11#define ShowerElementHolder_HH
14#include "art/Framework/Principal/Handle.h"
15#include "canvas/Persistency/Common/FindManyP.h"
16#include "canvas/Persistency/Common/FindOneP.h"
17#include "cetlib_except/demangle.h"
18#include "cetlib_except/exception.h"
19#include "messagefacility/MessageLogger/MessageLogger.h"
29 class ShowerElementBase;
31 class ShowerElementAccessor;
33 class ShowerDataProduct;
35 class EventDataProduct;
36 template <
class T,
class T2>
38 class ShowerElementHolder;
48 throw cet::exception(
"ShowerElementHolder")
49 <<
"Trying to check an element that is not a product" << std::endl;
53 throw cet::exception(
"ShowerElementHolder")
54 <<
"Trying to set an element that is not a product" << std::endl;
110 throw cet::exception(
"ShowerElementHolder")
111 <<
"The element that is being accessed is not set" << std::endl;
119 throw cet::exception(
"ShowerElementHolder")
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()); }
173template <
class T,
class T2>
223 if (showerPropertiesIt->second->CheckShowerElement()) {
226 if (showerprop ==
nullptr) {
227 throw cet::exception(
"ShowerElementHolder")
228 <<
"Trying to get Element: " << Name
229 <<
". This element you are filling is not the correct type" << std::endl;
235 mf::LogWarning(
"ShowerElementHolder")
236 <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
243 if (showerDataProductsIt->second->CheckShowerElement()) {
246 if (showerprop ==
nullptr) {
247 throw cet::exception(
"ShowerElementHolder")
248 <<
"Trying to get Element: " << Name
249 <<
". This element you are filling is not the correct type" << std::endl;
255 mf::LogWarning(
"ShowerElementHolder")
256 <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
263 if (eventDataProductsIt->second->CheckShowerElement()) {
266 if (eventprop ==
nullptr) {
267 throw cet::exception(
"ShowerElementHolder")
268 <<
"Trying to get Element: " << Name
269 <<
". This element you are filling is not the correct type" << std::endl;
275 mf::LogWarning(
"ShowerElementHolder")
276 <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
280 throw cet::exception(
"ShowerElementHolder")
281 <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder"
290 if (eventDataProductsIt->second->CheckShowerElement()) {
293 if (eventprop ==
nullptr) {
294 throw cet::exception(
"ShowerElementHolder")
295 <<
"Trying to get Element: " << Name
296 <<
". This element you are filling is not the correct type" << std::endl;
302 mf::LogWarning(
"ShowerElementHolder")
303 <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
307 throw cet::exception(
"ShowerElementHolder")
308 <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder"
318 if (eventDataProductsIt->second->CheckShowerElement()) {
321 if (eventprop ==
nullptr) {
322 throw cet::exception(
"ShowerElementHolder")
323 <<
"Trying to get Element: " << Name
324 <<
". This element you are filling is not the correct type" << std::endl;
329 throw cet::exception(
"ShowerElementHolder")
330 <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder"
340 if (showerPropertiesIt->second->CheckShowerElement()) {
343 if (showerprop ==
nullptr) {
344 throw cet::exception(
"ShowerElementHolder")
345 <<
"Trying to get Element: " << Name
346 <<
". This element you are filling is not the correct type" << std::endl;
354 if (showerDataProductsIt->second->CheckShowerElement()) {
357 if (showerprop ==
nullptr) {
358 throw cet::exception(
"ShowerElementHolder")
359 <<
"Trying to get Element: " << Name
360 <<
". This element you are filling is not the correct type" << std::endl;
368 if (eventDataProductsIt->second->CheckShowerElement()) {
371 if (eventprop ==
nullptr) {
372 throw cet::exception(
"ShowerElementHolder")
373 <<
"Trying to get Element: " << Name
374 <<
". This element you are filling is not the correct type" << std::endl;
379 throw cet::exception(
"ShowerElementHolder")
380 <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder"
385 template <
class T,
class T2>
390 mf::LogError(
"ShowerElementHolder")
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)
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)
437 std::make_unique<ShowerProperty<T, T2>>(propertyval, propertyvalerror);
466 eventDataProductsIt->second->CheckShowerElement();
474 return showerPropertiesIt->second->CheckShowerElement();
478 return showerDataProductsIt->second->CheckShowerElement();
482 return eventDataProductsIt->second->CheckShowerElement();
492 checked = checked && showerprop.second->CheckShowerElement();
495 checked = checked && showerdataprod.second->CheckShowerElement();
505 return showerPropertiesIt->second->Clear();
509 return showerDataProductsIt->second->Clear();
511 mf::LogError(
"ShowerElementHolder")
512 <<
"Trying to clear Element: " << Name
513 <<
". This element does not exist in the element holder" << std::endl;
521 (showerprop.second)->Clear();
524 (showerdataproduct.second)->Clear();
531 (eventdataproduct.second)->Clear();
546 return showerDataProductsIt->second->CheckTag();
556 return showerPropertiesIt->second.reset(
nullptr);
560 return showerDataProductsIt->second.reset(
nullptr);
562 mf::LogError(
"ShowerElementHolder")
563 <<
"Trying to delete Element: " << Name
564 <<
". This element does not exist in the element holder" << std::endl;
573 return showerDataProductsIt->second->SetCheckTag(checkelement);
575 mf::LogError(
"ShowerElementHolder")
576 <<
"Trying set the checking of the data product: " << Name
577 <<
". This data product does not exist in the element holder" << std::endl;
585 bool check = showerdataproduct.second->CheckTag();
587 bool elementset = showerdataproduct.second->CheckShowerElement();
589 mf::LogError(
"ShowerElementHolder")
590 <<
"The following element is not set and was asked to be checked: "
591 << showerdataproduct.first << std::endl;
609 unsigned int maxname = 0;
611 if (showerprop.first.size() > maxname) { maxname = showerprop.first.size(); }
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;
620 std::string Type = (showerprop.second)->GetType();
621 Type_showerprops[showerprop.first] = Type;
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>
673 const art::FindManyP<T1>&
GetFindManyP(
const art::ValidHandle<std::vector<T2>>& handle,
674 const art::Event& evt,
675 const art::InputTag& moduleTag)
678 const std::string name(
"FMP_" + moduleTag.label() +
"_" + getType<T1>() +
"_" + getType<T2>());
680 if (
CheckEventElement(name)) {
return GetEventElement<art::FindManyP<T1>>(name); }
682 art::FindManyP<T1> findManyP(handle, evt, moduleTag);
683 if (findManyP.isValid()) {
685 return GetEventElement<art::FindManyP<T1>>(name);
688 throw cet::exception(
"ShowerElementHolder")
689 <<
"FindManyP is not valid: " << name << std::endl;
694 template <
class T1,
class T2>
695 const art::FindOneP<T1>&
GetFindOneP(
const art::ValidHandle<std::vector<T2>>& handle,
696 const art::Event& evt,
697 const art::InputTag& moduleTag)
700 const std::string name(
"FOP_" + moduleTag.label() +
"_" + getType<T1>() +
"_" + getType<T2>());
702 if (
CheckEventElement(name)) {
return GetEventElement<art::FindOneP<T1>>(name); }
704 art::FindOneP<T1> findOneP(handle, evt, moduleTag);
705 if (findOneP.isValid()) {
707 return GetEventElement<art::FindOneP<T1>>(name);
710 throw cet::exception(
"ShowerElementHolder")
711 <<
"FindOneP is not valid: " << name << std::endl;
EventDataProduct(T &Element)
ShowerDataProduct(T &Element, bool Checktag)
void SetCheckTag(bool &Checktag)
T GetShowerElement() const
std::string GetType() const override
T & GetShowerElementRef()
void SetShowerElement(T &Element)
int GetShowerElement(T &Element) const
ShowerElementAccessor(T &Element)
bool CheckShowerElement() const
virtual void SetCheckTag(bool &check)
virtual bool CheckTag() const
virtual ~ShowerElementBase() noexcept=default
virtual std::string GetType() const =0
bool CheckEventElement(const std::string &Name) const
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > showerproperties
void SetEventElement(T &dataproduct, const std::string &Name)
bool CheckAllElements() const
int GetShowerNumber() const
int GetElement(const std::string &Name, T &Element) const
void SetElementTag(const std::string &Name, bool checkelement)
const T & GetEventElement(std::string const &Name)
void DeleteElement(const std::string &Name)
std::string getType() const
void SetShowerNumber(int &shower_iter)
bool CheckElementTag(const std::string &Name) const
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > showerdataproducts
void ClearElement(const std::string &Name)
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > eventdataproducts
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
void SetElement(T &propertyval, T2 &propertyvalerror, const std::string &Name)
void PrintElements() const
T GetElement(const std::string &Name) const
int GetEventElement(const std::string &Name, T &Element) const
int GetElementAndError(const std::string &Name, T &Element, T2 &ElementErr) const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
std::string getType(T object) const
bool CheckElement(const std::string &Name) const
const art::FindOneP< T1 > & GetFindOneP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
bool CheckAllElementTags() const
int GetShowerPropertyError(T2 &ElementErr) const
ShowerProperty(T &Element, T2 &ElementErr)
void SetShowerProperty(T &Element, T2 &ElementErr)