ATLAS Offline Software
Loading...
Searching...
No Matches
FeatureCollectStandalone.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_FeatureCollectStandalone_H
8#define TRIGGER_DECISION_TOOL_FeatureCollectStandalone_H
9
10
11/**********************************************************************************
12 * @Project:
13 * @Package: TrigDecision
14 *
15 *
16 * @author Nicolas Berger <Nicolas.Berger@cern.ch> - LAPP Annecy
17 * @author Tomasz Bold <tomasz.bold@cern.ch> - UC Irvine, AGH-UST Krakow
18 * @author Lukas Heinrich <lukas.heinrich@cern.ch> - NYU
19 *
20 ***********************************************************************************/
21
22#include <string>
23#include <set>
24#include <type_traits>
25
28
30
33
37
39
41
42#include "AsgMessaging/Check.h"
45
47
48namespace HLT{
49 class TrigNavStructure;
50}
51
52
53
54namespace Trig {
55
59
60 namespace FeatureAccessImpl{
61
62 HLT::TriggerElement::FeatureAccessHelper getTypelessBits(const HLT::TriggerElement* te, const HLT::TrigNavStructure* navigation);
63
64 void typelessCollect(const HLT::TriggerElement* te, HLT::class_id_type clid, std::vector<Trig::TypelessFeature>& data, const std::string& label, unsigned int condition, const HLT::TrigNavStructure* navigation);
65
66
67 template<typename REQUESTED,typename STORED, typename CONTAINER>
68 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());
69
70
72
73 //do not implement
74 template<typename STORED, typename REQUESTED>
75 void insert_element(std::vector<Trig::Feature<REQUESTED> >&, Trig::TypelessFeature&, const STORED*);
76 //do implement
77 template<typename REQUESTED>
78 void insert_element(std::vector<Trig::Feature<REQUESTED> >& result, Trig::TypelessFeature& feature, const REQUESTED* element){
79 result.push_back(Trig::Feature<REQUESTED>(feature,element));
80 }
81
82
83 template<typename STORED>
84 void insert_flatten_if(std::vector<Trig::Feature<STORED> >& result, const Trig::TypelessFeature& feature, const std::shared_ptr<const STORED>& newfeature){
85 result.push_back(Trig::Feature<STORED>(feature,newfeature));
86 }
87
88 template<typename REQUESTED, typename STORED>
89 void insert_flatten_if(std::vector<Trig::Feature<REQUESTED> >& result, const Trig::TypelessFeature& feature, const std::shared_ptr<const STORED>& newfeature){
90 for(auto element : *newfeature){
91 result.push_back(Trig::Feature<REQUESTED>(feature,element));
92 }
93 }
94
95
96 template<typename STORED>
97 std::shared_ptr<const STORED> filter_if(std::true_type is_same, std::shared_ptr<const STORED>& original,const TrigPassBits* bits){
98 (void)is_same;
99
100
101 if(bits==nullptr){
102 std::cerr << "WARNING: nullptr TrigPassBits" << std::endl;
103 return original;
104 }
105 if(original->size() != bits->size()){
106 std::cerr << "WARNING: bits size and owned size" << std::endl;
107 return original;
108 }
110
111 for(auto obj : *original){
112 if(HLT::isPassing(bits,obj,original.get())){
113 f->push_back(obj);
114 }
115 }
116 //manage the memory
117 std::shared_ptr<const STORED> filtered(f->asDataVector());
118 return filtered;
119 }
120
121 template<typename STORED>
122 std::shared_ptr<const STORED> filter_if(std::false_type /*is_same*/, std::shared_ptr<const STORED>& original,const TrigPassBits* /*bits*/){
123 //nothing
124 return original;
125 }
126
127 template<typename REQUESTED,typename STORED, typename CONTAINER>
128 std::vector<Trig::Feature<REQUESTED> > typedGet(const std::vector<TypelessFeature>& features, const HLT::TrigNavStructure* navigation, const asg::EventStoreType* store, const std::string& container_name) {
129 std::vector<Trig::Feature<REQUESTED> > typedvec;
130
131 for(auto feature : features){
132 auto typelessholder = navigation->getHolder(feature.accessHelper());
133 if(!typelessholder){
134 std::cerr << "ERROR, holder not present" << std::endl;
135 continue;
136 }
137 HLT::TypedHolder<STORED,CONTAINER> typedholder(*typelessholder,store,container_name);
138 const STORED* dest = 0;
139
140 StatusCode sc = typedholder.get(dest,feature.accessHelper().getIndex());
141 if(sc.isFailure()){
142 std::cerr << "TrigDecisionTool WARNING: Feature access failed for feature: " << feature.accessHelper() << std::endl;
143 continue;
144 }
145
146 if(std::is_same<STORED, CONTAINER>::value){
147 //take ownership because typedholder.get created VIEW container with 'new'
148 std::shared_ptr<const STORED> owned(dest);
149
150 auto passbitsFeatureAccessHelper = FeatureAccessImpl::getTypelessBits(feature.te(),navigation);
151 if(passbitsFeatureAccessHelper.valid()){
152#ifndef __CLING__
153 auto passbitsHolder = navigation->getHolder(passbitsFeatureAccessHelper);
154 HLT::TypedHolder<TrigPassBits,TrigPassBitsCollection> typedBits(*passbitsHolder,store);
155 const TrigPassBits* bits = 0;
156 if(typedBits.get(bits,passbitsFeatureAccessHelper.getIndex()).isFailure()){
157 std::cerr << "WARNING: couldn't get passbits from Holder" << std::endl;
158 }
159 owned = filter_if(std::is_same<STORED, CONTAINER>(),owned,bits);
160#endif
161 }
162 //if REQUESTED != STORED we assume REQUESTED is element type
163 //and we flatten the vector
164 insert_flatten_if(typedvec,feature,owned);
165 }
166 else{
167 if(std::is_same<STORED,TrigRoiDescriptor>::value){
168 std::shared_ptr<const STORED> owned(dest);
169 //TrigRoiDescriptor needs deletiong by us.. a bit hacky but oh well...
170 insert_flatten_if(typedvec,feature,owned);
171 }
172 else{
173 //storegate owns the pointer
174 insert_element(typedvec,feature,dest);
175 }
176 }
177 }
178 return typedvec;
179 }
180 } // EOF namespace FeatureAccessImpl
181
182} // EOF namespace Trig
183
184
185namespace HLT{
186 template<>
188 public:
189 TypedHolder(const BaseHolder& baseholder, const asg::EventStoreType* store, const std::string& /*container_name*/ = "")
190 : TypelessHolder(baseholder.typeClid(),baseholder.label(),baseholder.subTypeIndex()),
191 asg::AsgMessaging("TypedHolder"),
192 m_store(store){
193 };
194
195 StatusCode get(const TrigRoiDescriptor*& destination, HLT::TriggerElement::ObjectIndex idx){
196
197 std::string key = HLTNavDetails::formatSGkey("HLT","xAOD::RoiDescriptorStore",this->label());
198 const xAOD::RoiDescriptorStore* roistore = 0;
199 ASG_CHECK(m_store->retrieve(roistore,key));
200
201 // so what's happening here is a bit hacky since StoreGate stores (and owns)
202 // the RoiDescriptorStore. But the IRoiDescriptor pointers that get created
203 // by RoiUtil::deserialize are new pointers, so we need to manage them
204 // So we deserialize the entire collection, pick the one pointed to by
205 // the object index and mark it as the return value and the delete the rest again
206 // Later the single remaining element will be deleted by the Feature
207 // (which will have the owning flag set for RoIs). Hopefully the performance
208 // penalty is not too large
209
210 std::vector<const IRoiDescriptor*> rois;
211 RoiUtil::deserialise( roistore->serialised(), rois );
212 if((idx.objectsEnd() - idx.objectsBegin())!=1){
213 ATH_MSG_ERROR("accessing RoI holder with key: is not single element: ");
214 return StatusCode::FAILURE;
215 }
216
217 if(rois.size() < idx.objectsBegin()){
218 ATH_MSG_ERROR("deserialized roi collection too small");
219 return StatusCode::FAILURE;
220 };
221 for (unsigned int index = 0; index < rois.size(); ++index){
222 if(index == idx.objectsBegin()){
223 destination = dynamic_cast<const TrigRoiDescriptor*>(rois.at(index));
224 }
225 else{
226 delete rois.at(index);
227 }
228 }
229 return StatusCode::SUCCESS;
230 }
231 private:
233 };
234}
235
236
237
238#endif
239
240
#define ATH_MSG_ERROR(x)
#define ASG_CHECK(...)
Helper macro for checking the status code returned by a function call.
Definition Check.h:43
DataVector adapter that acts like it holds const pointers.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
DataVector adapter that acts like it holds const pointers.
const BaseHolder * getHolder(const TriggerElement::FeatureAccessHelper &fea) const
Helper class for conversion from/to int stored in TE and pair of ints used in Navigation Object point...
StatusCode get(const TrigRoiDescriptor *&destination, HLT::TriggerElement::ObjectIndex idx)
TypedHolder(const BaseHolder &baseholder, const asg::EventStoreType *store, const std::string &="")
doubly templated class interfacing access to feature containers in StoreGate.
Definition TypedHolder.h:55
StatusCode_if< T, true > get(const T *&destination, HLT::TriggerElement::ObjectIndex idx)
method creates a new VIEW container containing pointers to the elements pointed to by the ObjectIndex...
Definition TypedHolder.h:99
TypelessHolder(class_id_type clid, const std::string &label, sub_index_type sub)
unsigned int size() const
gets size of the bits array
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
is basic vehicle of object access in TDT
Definition Feature.h:112
Feature class, holding information on Feature attached to navigation.
Class mimicking the AthMessaging class from the offline software.
AsgMessaging(const std::string &name)
Constructor with a name.
const std::vector< std::vector< uint32_t > > & serialised() const
expose the navigation information (in serialised form)
std::string label(const std::string &format, int i)
Definition label.h:19
std::string formatSGkey(const std::string &prefix, const std::string &containername, const std::string &label)
declaration of formatting function.
Definition Holder.cxx:122
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
bool isPassing(const TrigPassBits *bits, const T *obj, const CONTAINER *container)
Check the bit for the object in the associated bits object.
void deserialise(const roiserial_type &s, std::vector< const IRoiDescriptor * > &rois)
deserialise uint32_t vector into a full vector of IRoiDescriptors
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
This is the implementation of the Feature collection for Athena.
HLT::TriggerElement::FeatureAccessHelper getTypelessBits(const HLT::TriggerElement *te, const HLT::TrigNavStructure *navigation)
void typelessCollect(const HLT::TriggerElement *te, HLT::class_id_type clid, std::vector< Trig::TypelessFeature > &data, const std::string &label, unsigned int condition, const HLT::TrigNavStructure *navigation)
void insert_flatten_if(std::vector< Trig::Feature< STORED > > &result, const Trig::TypelessFeature &feature, const std::shared_ptr< const STORED > &newfeature)
std::shared_ptr< const STORED > filter_if(std::true_type is_same, std::shared_ptr< const STORED > &original, const TrigPassBits *bits)
void insert_element(std::vector< Trig::Feature< REQUESTED > > &, Trig::TypelessFeature &, const STORED *)
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.
StoreGateSvc EventStoreType
the type returned by AsgTool::evtStore
Definition index.py:1
RoiDescriptorStore_v1 RoiDescriptorStore
Define the latest version of the serialised RoiDescriptor storage.