ATLAS Offline Software
Loading...
Searching...
No Matches
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
19
20namespace 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>
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
#define ATH_MSG_ERROR(x)
BaseHolder * getBaseHolder(class_id_type clid, sub_index_type sti) const
std::map< sub_index_type, std::string > SubIndexToLabelMap
std::string getLabel(class_id_type clid, const index_or_label_type &stiOrLabel) const
std::vector< HolderType * > getAllHolders() const
HolderType * getHolderForFeature(const TriggerElement::FeatureAccessHelper &fea) const
sub_index_type getSubTypeIndex(class_id_type clid, const index_or_label_type &stiOrLabel) const
std::map< class_id_type, SubIndexToLabelMap > m_lookupLabels
T * getCastHolder(BaseHolder *holder) const
std::vector< HolderType * > getHoldersOfClid(class_id_type clid) const
HolderType * getHolder(class_id_type clid, const std::variant< sub_index_type, std::string > &stiOrLabel) const
std::map< class_id_type, LabelToSubIndexMap > m_lookupSubIndex
std::map< std::string, sub_index_type > LabelToSubIndexMap
bool registerHolder(const std::shared_ptr< BaseHolder > &holder)
std::map< sub_index_type, std::shared_ptr< BaseHolder > > IndexToHolderMap
std::map< class_id_type, IndexToHolderMap > m_holderByClidAndIndex
the FeatureAccessHelper is a class used to keep track of features attached to this TE.
const ObjectIndex & getIndex() const
index in the external ojects array
sub_index_type subTypeIndex() const
to get collection index
Class mimicking the AthMessaging class from the offline software.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
std::variant< sub_index_type, std::string > index_or_label_type
static const index_type invalid_sub_index