ATLAS Offline Software
Loading...
Searching...
No Matches
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 <ranges>
25
31
33
35
36#include <unordered_set>
37#include <vector>
38
39namespace Trig {
40
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);
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{
74 auto features = typelessGet(ClassID_traits<ELEMENT_OF<CONTAINER> >::ID(),label,condition,teName);
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{
80 auto features = typelessGet(ClassID_traits<CONTAINER>::ID(),label,condition,teName);
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{
86 auto features = typelessGet(ClassID_traits<CONTAINER>::ID(),label,condition,teName);
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
129
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
144template<class T>
145bool
147 return weakOrder(a.te(), b.te(), a.cptr(), b.cptr());
148}
149
150template<class T> const std::vector<Trig::Feature<T> >
151Trig::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 : std::views::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
195template<class T> TrigPassFlags
196Trig::FeatureContainer::getFlags(const Trig::Feature<T> & f, const std::string & flagsLabel) const {
197
198 TrigPassFlags pf;
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
std::vector< Identifier > ID
static Double_t a
The NavigationCore class, adds on top of the TrigNavStructure the EDM read-only handling.
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
TriggerElement is the basic ingreedient of the interface between HLT algorithms and the navigation It...
A Flag is an ordered collection of bits (vector<bool>) that can hold additional (boolean) information...
is a connector between chains and object It store single combination of trigger elements.
helper class to support ordered set of features
bool weakOrder(const HLT::TriggerElement *te_a, const HLT::TriggerElement *te_b, const void *obj_a, const void *obj_b) const
bool operator()(const Feature< T > &a, const Feature< T > &b) const
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.
std::vector< Feature< ELEMENT_OF< CONTAINER > > > elementFeature(const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
std::vector< Trig::Combination > m_combinations
container preserving insertion order
std::vector< Feature< ELEMENT_OF< CONTAINER > > > flattenedContainerFeature(const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
std::vector< Feature< CONTAINER > > containerFeature(const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
const std::vector< Trig::Combination > & getCombinations() const
gives back reference to combinations collected through append
TrigPassFlags getFlags(const Trig::Feature< T > &f, const std::string &flagsLabel="") const
access to TrigPassFlags for given trigger object or container in given TE
typename CONTAINER::base_value_type ELEMENT_OF
void append(const FeatureContainer &other)
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
FeatureContainer(const CacheGlobalMemory *cgm=0)
constructors, destructor
std::unordered_set< Trig::Combination > m_combinations_unique
set for ensuring uniqueness in the above container
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
std::vector< Combination >::const_iterator combination_const_iterator
const Trig::CacheGlobalMemory * m_cgm
const HLT::TrigNavStructure * navigation() const
void addWithChecking(const Combination &newComb)
add new combination to the container checking for overlap
is basic vehicle of object access in TDT
Definition Feature.h:112
std::string label(const std::string &format, int i)
Definition label.h:19
const TrigPassFlags * getFlags(size_t size, const HLT::TriggerElement *te, const std::string &label, const HLT::NavigationCore *navigation)
std::vector< Trig::Feature< REQUESTED > > typedGet(const std::vector< TypelessFeature > &features, const HLT::TrigNavStructure *navigation, const asg::EventStoreType *store, const std::string &container_name=ClassID_traits< CONTAINER >::typeName())
The common trigger namespace for trigger analysis tools.
Default, invalid implementation of ClassID_traits.