ATLAS Offline Software
FeatureContainer.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef TRIGGER_DECISION_TOOL_FeatureContainer_H
8 #define TRIGGER_DECISION_TOOL_FeatureContainer_H
9 
10 
11 /**********************************************************************************
12  * @Project:
13  * @Package: TrigDecision
14  * @class : TrigDecision
15  *
16  * @brief objects of this type hold "synchronized" lists of features
17  *
18  * @author Nicolas Berger <Nicolas.Berger@cern.ch> - LAPP Annecy
19  * @author Michael Begel <Michael.Begel@cern.ch> - BNL
20  * @author Tomasz Bold <Tomasz.Bold@cern.ch> - UC Irvine - AGH-UST Krakow
21  * @author Joerg Stelzer <Joerg.Stelzer@cern.ch> - DESY
22  *
23  ***********************************************************************************/
24 #include "boost/range/adaptor/reversed.hpp"
25 
31 
33 
35 
36 #include <unordered_set>
37 #include <vector>
38 
39 namespace Trig {
40 
41  class FeatureContainer
42  {
43  public:
44 
45  typedef std::vector<Combination>::const_iterator combination_const_iterator;
46 
48  FeatureContainer(const CacheGlobalMemory* cgm = 0): m_cgm(cgm) {}
49 
58  template<class T> const std::vector<Trig::Feature<T> > get(const std::string& label = "", unsigned int condition = TrigDefs::Physics,
59  const std::string& teName = "") const;
60 
61 
62  std::vector<Trig::Feature<xAOD::IParticle> > getIParticle(HLT::class_id_type clid, const std::string& container_name, const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string & teName = "" ) const{
63  auto features = typelessGet(clid,label,condition,teName);
64  return FeatureAccessImpl::typedGet<xAOD::IParticle,xAOD::IParticleContainer,xAOD::IParticleContainer>(features,
65  navigation(),
66  m_cgm->store(),
67  container_name);
68  }
69 
70  template<typename CONTAINER> using ELEMENT_OF = typename CONTAINER::base_value_type;
71 
72  template<typename CONTAINER>
73  std::vector<Feature<ELEMENT_OF<CONTAINER> > > elementFeature(const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string& teName = "") const{
75  return FeatureAccessImpl::typedGet<ELEMENT_OF<CONTAINER>,ELEMENT_OF<CONTAINER>,CONTAINER>(features,navigation(),m_cgm->store());
76  }
77 
78  template<typename CONTAINER>
79  std::vector<Feature<CONTAINER> > containerFeature(const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string& teName = "") const{
81  return FeatureAccessImpl::typedGet<CONTAINER,CONTAINER,CONTAINER>(features,navigation(),m_cgm->store());
82  }
83 
84  template<typename CONTAINER>
85  std::vector<Feature<ELEMENT_OF<CONTAINER> > > flattenedContainerFeature(const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string& teName = "") const{
87  return FeatureAccessImpl::typedGet<ELEMENT_OF<CONTAINER>,CONTAINER,CONTAINER>(features,navigation(),m_cgm->store());
88  }
89 
90 
95  const std::vector<Trig::TypelessFeature> typelessGet(HLT::class_id_type clid, const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string& teName = "") const;
96 
97 
104 #if !defined(XAOD_STANDALONE) && !defined(XAOD_ANALYSIS) // Full Athena only
105  template<class T> TrigPassFlags getFlags(const Trig::Feature<T> & f, const std::string & flagsLabel = "") const;
106 #endif
107 
111  const std::vector<Trig::Combination>& getCombinations() const { return m_combinations; }
112 
116  void addWithChecking(const Combination& newComb);
117  void append(const FeatureContainer& other);
118 
119  private:
120 
121  const HLT::TrigNavStructure* navigation() const;
122 
124  std::vector<Trig::Combination> m_combinations;
126  std::unordered_set<Trig::Combination> m_combinations_unique;
127 
128  const Trig::CacheGlobalMemory* m_cgm{nullptr};
129 
131  class ordering_by_objects_attached {
132  public:
133  template<class T>
134  bool operator()(const Feature<T>& a, const Feature<T>& b) const;
135  bool weakOrder(const HLT::TriggerElement* te_a, const HLT::TriggerElement* te_b,
136  const void* obj_a, const void* obj_b) const;
137  };
138 
139  };
140 
141 } // End of namespace
142 
143 
144 template<class T>
145 bool
147  return weakOrder(a.te(), b.te(), a.cptr(), b.cptr());
148 }
149 
150 template<class T> const std::vector<Trig::Feature<T> >
151 Trig::FeatureContainer::get(const std::string& label, unsigned int condition, const std::string& teName) const
152 {
153  if ( condition != TrigDefs::Physics && condition != TrigDefs::alsoDeactivateTEs ) {
154  throw std::runtime_error("Only two flags can be supplied to features");
155  }
156 
157  //std::cout << " in FC::get, after call to getCombinations(), now looping over them" << std::endl;
158 
159  std::set<Trig::Feature<T>, Trig::FeatureContainer::ordering_by_objects_attached > uniqnessHelper;
160 
161 
162  for(const Trig::Combination& comb : m_combinations ) {
163  //std::cout << " ---- combination has size " << comb.tes().size() << " tes[0] " << comb.tes()[0] << std::endl;
164  // for (std::vector<Trig::Combination>::const_iterator it = m_combinations.begin(); it != m_combinations.end(); ++it){
165  if (condition == TrigDefs::Physics) {
166  if (!comb.active()) continue;
167  }
168  std::vector<Trig::Feature<T> > features = comb.get<T>(label, condition, teName);
169 
170  //typedef std::vector< Trig::Feature<T> > FTV;
171  //typename FTV::const_iterator fIt;
172  //for (fIt = features.begin(); fIt != features.end(); ++fIt ) {
173  for(const Trig::Feature<T>& f : boost::adaptors::reverse(features)) {
174  //std::cout << "in FC::get, insertion of feature " << std::endl;
175  uniqnessHelper.insert(f);
176 
177  }
178  }
179 
180  //std::cout << " in FC::get, at the end: uniqnessHelper size = " << uniqnessHelper.size() << std::endl;
181 
182  return std::vector<Trig::Feature<T> >(uniqnessHelper.begin(), uniqnessHelper.end());
183 
184 }
185 
186 
187 
194 #if !defined(XAOD_STANDALONE) && !defined(XAOD_ANALYSIS) // Full Athena only
195 template<class T> TrigPassFlags
196 Trig::FeatureContainer::getFlags(const Trig::Feature<T> & f, const std::string & flagsLabel) const {
197 
199 
200  // get the trigPassFlag (only works if the flags are created in the same TE as the objects
201  const TrigPassFlags* flags(0);
202  const HLT::TriggerElement* sourceTE(0);
203  std::string sourceLabel;
204 
205  auto fullnavi = dynamic_cast<const HLT::NavigationCore*>(navigation());
206 
207  bool success = fullnavi->getRecentFeature(f.te(), flags, flagsLabel, sourceTE, sourceLabel);
208 
209  if(!success || !flags) // navigation failed or did not return a flags
210  return pf;
211 
212 
213  return FeatureAccessImpl::getFlags(f, flags, fullnavi);
214 
215 }
216 #endif
217 
218 #endif
Trig::FeatureContainer::combination_const_iterator
std::vector< Combination >::const_iterator combination_const_iterator
Definition: FeatureContainer.h:69
Trig::Feature
Definition: Feature.h:112
Combination.h
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
Trig
The common trigger namespace for trigger analysis tools.
Definition: LArCellMonAlg.h:33
TrigNavStructure.h
Trig::FeatureContainer::getIParticle
std::vector< Trig::Feature< xAOD::IParticle > > getIParticle(HLT::class_id_type clid, const std::string &container_name, const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
Definition: FeatureContainer.h:86
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
Trig::FeatureContainer::ordering_by_objects_attached::weakOrder
bool weakOrder(const HLT::TriggerElement *te_a, const HLT::TriggerElement *te_b, const void *obj_a, const void *obj_b) const
Definition: FeatureContainer.cxx:44
Trig::FeatureContainer::m_combinations_unique
std::unordered_set< Trig::Combination > m_combinations_unique
set for ensuring uniqueness in the above container
Definition: FeatureContainer.h:150
Trig::FeatureContainer::ordering_by_objects_attached
helper class to support ordered set of features
Definition: FeatureContainer.h:155
Trig::FeatureContainer::containerFeature
std::vector< Feature< CONTAINER > > containerFeature(const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
Definition: FeatureContainer.h:103
Trig::FeatureContainer::elementFeature
std::vector< Feature< ELEMENT_OF< CONTAINER > > > elementFeature(const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
Definition: FeatureContainer.h:97
Feature.h
navigation2dot.teName
def teName(teid)
Definition: navigation2dot.py:59
FeatureCollectStandalone.h
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
Trig::CacheGlobalMemory
Definition: CacheGlobalMemory.h:67
HLT::TrigNavStructure
Definition: TrigNavStructure.h:40
Trig::FeatureAccessImpl::getFlags
const TrigPassFlags * getFlags(size_t size, const HLT::TriggerElement *te, const std::string &label, const HLT::NavigationCore *navigation)
Definition: FeatureCollectAthena.cxx:39
DeMoUpdate.reverse
reverse
Definition: DeMoUpdate.py:563
Trig::FeatureContainer
Definition: FeatureContainer.h:54
Trig::FeatureContainer::typelessGet
const std::vector< Trig::TypelessFeature > typelessGet(HLT::class_id_type clid, const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
typeless version of get
Definition: FeatureContainer.cxx:92
HLT::NavigationCore
The NavigationCore class, adds on top of the TrigNavStructure the EDM read-only handling.
Definition: NavigationCore.h:96
Trig::CacheGlobalMemory::store
const asg::EventStoreType * store() const
Get the event store that the object is using.
Definition: CacheGlobalMemory.h:139
Trig::Combination
Definition: Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/Combination.h:55
HLT::TriggerElement
TriggerElement is the basic ingreedient of the interface between HLT algorithms and the navigation It...
Definition: TrigNavStructure/TrigNavStructure/TriggerElement.h:27
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
Trig::FeatureContainer::navigation
const HLT::TrigNavStructure * navigation() const
Definition: FeatureContainer.cxx:37
hist_file_dump.f
f
Definition: hist_file_dump.py:135
HLT::class_id_type
uint32_t class_id_type
Definition: Trigger/TrigEvent/TrigNavStructure/Root/Types.h:11
Trig::FeatureContainer::ELEMENT_OF
typename CONTAINER::base_value_type ELEMENT_OF
Definition: FeatureContainer.h:94
Trig::FeatureContainer::m_combinations
std::vector< Trig::Combination > m_combinations
container preserving insertion order
Definition: FeatureContainer.h:148
Trig::FeatureContainer::m_cgm
const Trig::CacheGlobalMemory * m_cgm
Definition: FeatureContainer.h:152
HLT::NavigationCore::getRecentFeature
bool getRecentFeature(const TriggerElement *te, const T *&feature, const std::string &label="", const TriggerElement *&source=::HLT::TrigNavStructure::m_unspecifiedTE, std::string &sourcelabel=::HLT::TrigNavStructure::m_unspecifiedLabel) const
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Trig::FeatureContainer::get
const std::vector< Trig::Feature< T > > get(const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
returns flattened vector of Features of given type This method is in fact sullied by 3 arguments.
Definition: FeatureContainer.h:151
Trig::FeatureContainer::getFlags
TrigPassFlags getFlags(const Trig::Feature< T > &f, const std::string &flagsLabel="") const
access to TrigPassFlags for given trigger object or container in given TE
Definition: FeatureContainer.h:196
Conditions.h
Trig::FeatureContainer::ordering_by_objects_attached::operator()
bool operator()(const Feature< T > &a, const Feature< T > &b) const
Definition: FeatureContainer.h:146
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
python.output.AtlRunQueryRoot.pf
pf
Definition: AtlRunQueryRoot.py:988
Trig::FeatureContainer::addWithChecking
void addWithChecking(const Combination &newComb)
add new combination to the container checking for overlap
Definition: FeatureContainer.cxx:19
TrigPassFlags
A Flag is an ordered collection of bits (vector<bool>) that can hold additional (boolean) information...
Definition: TrigPassFlags.h:29
Trig::FeatureContainer::flattenedContainerFeature
std::vector< Feature< ELEMENT_OF< CONTAINER > > > flattenedContainerFeature(const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
Definition: FeatureContainer.h:109
TypelessFeature.h
Trig::FeatureContainer::getCombinations
const std::vector< Trig::Combination > & getCombinations() const
gives back reference to combinations collected through append
Definition: FeatureContainer.h:135
Trig::FeatureContainer::FeatureContainer
FeatureContainer(const CacheGlobalMemory *cgm=0)
constructors, destructor
Definition: FeatureContainer.h:72
Trig::FeatureContainer::append
void append(const FeatureContainer &other)
Definition: FeatureContainer.cxx:29
TrigPassFlags.h