10 #ifndef ShowerElementHolder_HH
11 #define ShowerElementHolder_HH
14 #include "art/Framework/Principal/Handle.h"
15 #include "canvas/Persistency/Common/FindOneP.h"
16 #include "canvas/Persistency/Common/FindManyP.h"
17 #include "messagefacility/MessageLogger/MessageLogger.h"
18 #include "cetlib_except/demangle.h"
19 #include "cetlib_except/exception.h"
29 class ShowerElementBase;
44 throw cet::exception(
"ShowerElementHolder") <<
"Trying to check an element that is not a product" << std::endl;
47 throw cet::exception(
"ShowerElementHolder") <<
"Trying to set an element that is not a product" << std::endl;
50 virtual std::string
GetType()
const = 0;
103 throw cet::exception(
"ShowerElementHolder") <<
"The element that is being accessed is not set" << std::endl;
110 throw cet::exception(
"ShowerElementHolder") <<
"The element that is being accessed is not set" << std::endl;
117 return cet::demangle_symbol(
typeid(
element).
name());
174 template <
class T,
class T2>
224 if(showerPropertiesIt->second->CheckShowerElement()){
226 if(showerprop ==
nullptr){
227 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element you are filling is not the correct type" << std::endl;
233 mf::LogWarning(
"ShowerElementHolder") <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
240 if(showerDataProductsIt->second->CheckShowerElement()){
242 if(showerprop ==
nullptr){
243 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element you are filling is not the correct type" << std::endl;
249 mf::LogWarning(
"ShowerElementHolder") <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
256 if(eventDataProductsIt->second->CheckShowerElement()){
258 if(eventprop ==
nullptr){
259 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element you are filling is not the correct type" << std::endl;
264 mf::LogWarning(
"ShowerElementHolder") <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
268 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder" << std::endl;
275 if(eventDataProductsIt->second->CheckShowerElement()){
277 if(eventprop ==
nullptr){
278 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element you are filling is not the correct type" << std::endl;
283 mf::LogWarning(
"ShowerElementHolder") <<
"Trying to get Element " << Name <<
". This elment has not been filled" << std::endl;
287 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder" << std::endl;
295 if(eventDataProductsIt->second->CheckShowerElement()){
297 if(eventprop ==
nullptr){
298 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element you are filling is not the correct type" << std::endl;
303 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder" << std::endl;
311 if(showerPropertiesIt->second->CheckShowerElement()){
313 if(showerprop ==
nullptr){
314 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element you are filling is not the correct type" << std::endl;
322 if(showerDataProductsIt->second->CheckShowerElement()){
324 if(showerprop ==
nullptr){
325 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element you are filling is not the correct type" << std::endl;
333 if(eventDataProductsIt->second->CheckShowerElement()){
335 if(eventprop ==
nullptr){
336 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element you are filling is not the correct type" << std::endl;
341 throw cet::exception(
"ShowerElementHolder") <<
"Trying to get Element: " << Name <<
". This element does not exist in the element holder" << std::endl;
345 template <
class T,
class T2>
349 mf::LogError(
"ShowerElementHolder") <<
"Trying to get Element Error: " << Name <<
". This elment does not exist in the element holder" << std::endl;
379 template <
class T,
class T2>
413 return eventDataProductsIt ==
eventdataproducts.end() ?
false : eventDataProductsIt->second->CheckShowerElement();
420 return showerPropertiesIt->second->CheckShowerElement();
424 return showerDataProductsIt->second->CheckShowerElement();
428 return eventDataProductsIt->second->CheckShowerElement();
437 checked *= showerprop.second->CheckShowerElement();
440 checked *= showerdataprod.second->CheckShowerElement();
450 return showerPropertiesIt->second->Clear();
454 return showerDataProductsIt->second->Clear();
456 mf::LogError(
"ShowerElementHolder") <<
"Trying to clear Element: " << Name <<
". This element does not exist in the element holder" << std::endl;
463 (showerprop.second)->Clear();
466 (showerdataproduct.second)->Clear();
472 (eventdataproduct.second)->Clear();
485 return showerDataProductsIt->second->CheckTag();
494 return showerPropertiesIt->second.reset(
nullptr);
498 return showerDataProductsIt->second.reset(
nullptr);
500 mf::LogError(
"ShowerElementHolder") <<
"Trying to delete Element: " << Name <<
". This element does not exist in the element holder" << std::endl;
508 return showerDataProductsIt->second->SetCheckTag(checkelement);
510 mf::LogError(
"ShowerElementHolder") <<
"Trying set the checking of the data product: " << Name <<
". This data product does not exist in the element holder" << std::endl;
517 bool check = showerdataproduct.second->CheckTag();
519 bool elementset = showerdataproduct.second->CheckShowerElement();
521 mf::LogError(
"ShowerElementHolder") <<
"The following element is not set and was asked to be checked: " << showerdataproduct.first << std::endl;
542 unsigned int maxname = 0;
544 if(showerprop.first.size() > maxname){
545 maxname = showerprop.first.size();
549 if(showerdataprod.first.size() > maxname){
550 maxname = showerdataprod.first.size();
554 std::map<std::string,std::string> Type_showerprops;
555 std::map<std::string,std::string> Type_showerdataprods;
556 for(
auto const& showerprop: showerproperties){
557 std::string
Type = (showerprop.second)->GetType();
558 Type_showerprops[showerprop.first] =
Type;
560 for(
auto const& showerdataprod: showerdataproducts){
561 std::string
Type = (showerdataprod.second)->GetType();
562 Type_showerdataprods[showerdataprod.first] =
Type;
565 unsigned int maxtype = 0;
566 for(
auto const& Type_showerprop: Type_showerprops){
567 if(Type_showerprop.second.size() > maxtype){
568 maxtype = Type_showerprop.second.size();
571 for(
auto const& Type_showerdataprod: Type_showerdataprods){
572 if(Type_showerdataprod.second.size() > maxtype){
573 maxtype = Type_showerdataprod.second.size();
577 unsigned int n = maxname + maxtype + 33;
579 std::cout <<
"Elements in the element holder" << std::endl;
581 for(
auto const& Type_showerprop: Type_showerprops){
582 std::cout <<
std::left << std::setfill(
' ') << std::setw(21) <<
"* Property Name: " << std::setw(maxname) << Type_showerprop.first;
583 std::cout <<
std::left << std::setfill(
' ') <<
" * Type: " << std::setw(maxtype) << Type_showerprop.second <<
" * " << std::endl;
585 for(
auto const& Type_showerdataprod: Type_showerdataprods){
586 std::cout <<
std::left << std::setfill(
' ') << std::setw(maxname) << std::setw(21) <<
"* Data Product Name: " << std::setw(maxname) << Type_showerdataprod.first;
587 std::cout <<
std::left << std::setfill(
' ') <<
" * Type: " << std::setw(maxtype) << Type_showerdataprod.second <<
" *" << std::endl;
597 return cet::demangle_symbol(
typeid(
object).
name());
602 return cet::demangle_symbol(
typeid(T).
name());
605 template <
class T1,
class T2>
606 const art::FindManyP<T1>&
GetFindManyP(
const art::ValidHandle<std::vector<T2> >& handle,
607 const art::Event &
evt,
const art::InputTag &moduleTag){
609 const std::string
name(
"FMP_" + moduleTag.label() +
"_" + getType<T1>() +
"_" + getType<T2>());
612 return GetEventElement<art::FindManyP<T1> >(
name);
614 art::FindManyP<T1> findManyP(handle, evt, moduleTag);
615 if (findManyP.isValid()){
617 return GetEventElement<art::FindManyP<T1> >(
name);
619 throw cet::exception(
"ShowerElementHolder") <<
"FindManyP is not valid: " <<
name << std::endl;
624 template <
class T1,
class T2>
625 const art::FindOneP<T1>&
GetFindOneP(
const art::ValidHandle<std::vector<T2> >& handle,
626 const art::Event&
evt,
const art::InputTag& moduleTag){
628 const std::string
name(
"FOP_" + moduleTag.label() +
"_" + getType<T1>() +
"_" + getType<T2>());
631 return GetEventElement<art::FindOneP<T1> >(
name);
633 art::FindOneP<T1> findOneP(handle, evt, moduleTag);
634 if (findOneP.isValid()){
636 return GetEventElement<art::FindOneP<T1> >(
name);
638 throw cet::exception(
"ShowerElementHolder") <<
"FindOneP is not valid: " <<
name << std::endl;
virtual std::string GetType() const =0
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > showerdataproducts
void DeleteElement(const std::string &Name)
bool CheckShowerElement() const
virtual ~ShowerElementBase() noexcept=default
int GetShowerNumber() const
int GetShowerElement(T &Element) const
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > showerproperties
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)
const art::FindOneP< T1 > & GetFindOneP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
EventDataProduct(T &Element)
const T & GetEventElement(std::string const &Name)
void SetElement(T &propertyval, T2 &propertyvalerror, const std::string &Name)
void SetCheckTag(bool &Checktag)
void PrintElements() const
process_name standard_reco_uboone reco
ShowerProperty(T &Element, T2 &ElementErr)
bool CheckElement(const std::string &Name) const
BEGIN_PROLOG vertical distance to the surface Name
process_name tightIsolTest check
std::map< std::string, std::unique_ptr< reco::shower::ShowerElementBase > > eventdataproducts
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)
T GetShowerElement() const
int GetEventElement(const std::string &Name, T &Element) const
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()
std::string getType() const
bool CheckAllElementTags() const
BEGIN_PROLOG could also be cout
std::string GetType() const override
ShowerElementAccessor(T &Element)