ATLAS Offline Software
TrigHolderStructure.h
Go to the documentation of this file.
1 // Emacs -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef TRIGNAVSTRUCTURE_TRIGHOLDERSTRUCTURE
8 #define TRIGNAVSTRUCTURE_TRIGHOLDERSTRUCTURE
9 #include <map>
10 #include <memory>
11 #include <string>
12 
13 #include <variant>
14 
16 #include "TrigNavStructure/Types.h"
19 
20 namespace HLT{
22  public:
24 
25  void reset();
26 
27  bool registerHolder(const std::shared_ptr<BaseHolder>& holder);
28 
29  template<typename HolderType = BaseHolder>
30  HolderType* getHolder(class_id_type clid, const std::variant<sub_index_type,std::string>& stiOrLabel) const {
31  return getCastHolder<HolderType>(getBaseHolder(clid,getSubTypeIndex(clid,stiOrLabel)));
32  }
33 
34  template<typename HolderType = BaseHolder>
36  return getCastHolder<HolderType>(getBaseHolder(fea.getCLID(),fea.getIndex().subTypeIndex()));
37  }
38 
39  template<typename HolderType = BaseHolder>
40  std::vector<HolderType*> getAllHolders() const {
41  std::vector<HolderType*> result;
42  for(auto& clid_indexmap : m_holderByClidAndIndex){
43  for(auto& index_holder : clid_indexmap.second){
44  result.push_back(getCastHolder<HolderType>(index_holder.second.get()));
45  }
46  }
47  return result;
48  }
49 
50  template<typename HolderType = BaseHolder>
51  std::vector<HolderType*> getHoldersOfClid(class_id_type clid) const {
52  std::vector<HolderType*> result;
53  auto lookup_it = m_holderByClidAndIndex.find(clid);
54  if(lookup_it == m_holderByClidAndIndex.end()) return result;
55 
56  for(auto& index_holder : lookup_it->second){
57  result.push_back(getCastHolder<HolderType>(index_holder.second.get()));
58  }
59  return result;
60  }
61 
62 
64  //short circuit for sub_index_type because that case is valid whether we have a map or not. (visitor only works with map)
65  if (stiOrLabel.index() == 0){
66  return std::get<sub_index_type>(stiOrLabel);
67  }
68 
69  auto lookup_it = m_lookupSubIndex.find(clid);
70  if(lookup_it == m_lookupSubIndex.end()) return invalid_sub_index;
71 
72  auto it = lookup_it->second.find(std::get<std::string>(stiOrLabel));
73  if(it==lookup_it->second.end()) return invalid_sub_index;
74 
75  return it->second;
76  }
77 
78  std::string getLabel(class_id_type clid, const index_or_label_type& stiOrLabel) const {
79  //short circuit for sub_index_type because that case is valid whether we have a map or not. (visitor only works with map)
80  if (stiOrLabel.index() == 1){
81  return std::get<std::string>(stiOrLabel);
82  }
83 
84  std::string invalid_label = "inavalid_label";
85 
86  auto lookup_it = m_lookupLabels.find(clid);
87  if(lookup_it == m_lookupLabels.end()) return invalid_label;
88 
89  auto it = lookup_it->second.find(std::get<sub_index_type>(stiOrLabel));
90  if(it==lookup_it->second.end()) return invalid_label;
91 
92  return it->second;
93  }
94 
95 
96  private:
97 
99 
100  template<typename T>
101  T* getCastHolder(BaseHolder* holder) const {
102  if(!holder){
103  return 0;
104  }
105  auto cast_holder = dynamic_cast<T*>(holder);
106  if(!cast_holder){
107  ATH_MSG_ERROR("cast failed");
108  }
109  return cast_holder;
110  }
111 
112  typedef std::map<sub_index_type, std::shared_ptr<BaseHolder> > IndexToHolderMap;
113  typedef std::map<std::string,sub_index_type> LabelToSubIndexMap;
114  typedef std::map<sub_index_type,std::string> SubIndexToLabelMap;
115 
116  std::map<class_id_type, IndexToHolderMap> m_holderByClidAndIndex;
117 
118  std::map<class_id_type, SubIndexToLabelMap > m_lookupLabels;
119  std::map<class_id_type, LabelToSubIndexMap > m_lookupSubIndex;
120 
121  };
122 }//end namespace HLT
123 #endif
get_generator_info.result
result
Definition: get_generator_info.py:21
HLT::TrigHolderStructure
Definition: TrigHolderStructure.h:21
skel.it
it
Definition: skel.GENtoEVGEN.py:423
HLT::TriggerElement::FeatureAccessHelper::getCLID
class_id_type getCLID() const
Class ID of object.
Definition: TrigNavStructure/TrigNavStructure/TriggerElement.h:208
HLT::TrigHolderStructure::getHoldersOfClid
std::vector< HolderType * > getHoldersOfClid(class_id_type clid) const
Definition: TrigHolderStructure.h:51
HLT::TrigHolderStructure::IndexToHolderMap
std::map< sub_index_type, std::shared_ptr< BaseHolder > > IndexToHolderMap
Definition: TrigHolderStructure.h:112
HLT::TrigHolderStructure::registerHolder
bool registerHolder(const std::shared_ptr< BaseHolder > &holder)
Definition: TrigHolderStructure.cxx:34
HLT::TrigHolderStructure::reset
void reset()
Definition: TrigHolderStructure.cxx:10
AsgMessaging.h
HLT::TriggerElement::ObjectIndex::subTypeIndex
sub_index_type subTypeIndex() const
to get collection index
Definition: TrigNavStructure/Root/TriggerElement.cxx:247
HLT::TrigHolderStructure::TrigHolderStructure
TrigHolderStructure()
Definition: TrigHolderStructure.cxx:7
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLT::index_or_label_type
std::variant< sub_index_type, std::string > index_or_label_type
Definition: Trigger/TrigEvent/TrigNavStructure/TrigNavStructure/Types.h:16
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
HLT::TrigHolderStructure::getHolderForFeature
HolderType * getHolderForFeature(const TriggerElement::FeatureAccessHelper &fea) const
Definition: TrigHolderStructure.h:35
Types.h
TriggerElement.h
HLT::BaseHolder
Definition: BaseHolder.h:14
HLT::class_id_type
uint32_t class_id_type
Definition: Trigger/TrigEvent/TrigNavStructure/Root/Types.h:11
HLT::sub_index_type
uint16_t sub_index_type
Definition: Trigger/TrigEvent/TrigNavStructure/Root/Types.h:9
BaseHolder.h
HLT::TrigHolderStructure::m_lookupSubIndex
std::map< class_id_type, LabelToSubIndexMap > m_lookupSubIndex
Definition: TrigHolderStructure.h:119
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
HLT::TrigHolderStructure::LabelToSubIndexMap
std::map< std::string, sub_index_type > LabelToSubIndexMap
Definition: TrigHolderStructure.h:113
HLT::TriggerElement::FeatureAccessHelper::getIndex
const ObjectIndex & getIndex() const
index in the external ojects array
Definition: TrigNavStructure/TrigNavStructure/TriggerElement.h:209
HLT::TriggerElement::FeatureAccessHelper
the FeatureAccessHelper is a class used to keep track of features attached to this TE.
Definition: TrigNavStructure/TrigNavStructure/TriggerElement.h:192
HLT::TrigHolderStructure::SubIndexToLabelMap
std::map< sub_index_type, std::string > SubIndexToLabelMap
Definition: TrigHolderStructure.h:114
HLT::TrigHolderStructure::getSubTypeIndex
sub_index_type getSubTypeIndex(class_id_type clid, const index_or_label_type &stiOrLabel) const
Definition: TrigHolderStructure.h:63
HLT::TrigHolderStructure::m_lookupLabels
std::map< class_id_type, SubIndexToLabelMap > m_lookupLabels
Definition: TrigHolderStructure.h:118
HLT::TrigHolderStructure::getAllHolders
std::vector< HolderType * > getAllHolders() const
Definition: TrigHolderStructure.h:40
HLT::TrigHolderStructure::getHolder
HolderType * getHolder(class_id_type clid, const std::variant< sub_index_type, std::string > &stiOrLabel) const
Definition: TrigHolderStructure.h:30
HLT::TrigHolderStructure::m_holderByClidAndIndex
std::map< class_id_type, IndexToHolderMap > m_holderByClidAndIndex
Definition: TrigHolderStructure.h:116
HLT::TrigHolderStructure::getCastHolder
T * getCastHolder(BaseHolder *holder) const
Definition: TrigHolderStructure.h:101
HLT::TrigHolderStructure::getBaseHolder
BaseHolder * getBaseHolder(class_id_type clid, sub_index_type sti) const
Definition: TrigHolderStructure.cxx:16
HLT::TrigHolderStructure::getLabel
std::string getLabel(class_id_type clid, const index_or_label_type &stiOrLabel) const
Definition: TrigHolderStructure.h:78