ATLAS Offline Software
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 
48 namespace HLT{
49  class TrigNavStructure;
50 }
51 
52 
53 
54 namespace Trig {
55 
60  namespace FeatureAccessImpl{
61 
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 
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);
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{
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 
185 namespace 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 
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 
HLT::TypedHolder< TrigRoiDescriptor, TrigRoiDescriptorCollection >::TypedHolder
TypedHolder(const BaseHolder &baseholder, const asg::EventStoreType *store, const std::string &="")
Definition: FeatureCollectStandalone.h:189
HLT::TriggerElement::ObjectIndex
Helper class for conversion from/to int stored in TE and pair of ints used in Navigation Object point...
Definition: TrigNavStructure/TrigNavStructure/TriggerElement.h:75
TrigPassBitsCollection.h
Trig::FeatureAccessImpl::getTypelessBits
HLT::TriggerElement::FeatureAccessHelper getTypelessBits(const HLT::TriggerElement *te, const HLT::TrigNavStructure *navigation)
Definition: FeatureCollectStandalone.cxx:26
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Trig::Feature< REQUESTED >
ASG_CHECK
#define ASG_CHECK(...)
Helper macro for checking the status code returned by a function call.
Definition: Check.h:39
Check.h
get_generator_info.result
result
Definition: get_generator_info.py:21
Trig::FeatureAccessImpl::insert_element
void insert_element(std::vector< Trig::Feature< REQUESTED > > &, Trig::TypelessFeature &, const STORED *)
Trig
The common trigger namespace for trigger analysis tools.
Definition: LArCellMonAlg.h:33
TrigNavStructure.h
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
EventStoreType.h
index
Definition: index.py:1
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
TrigPassBits::size
unsigned int size() const
gets size of the bits array
Definition: Trigger/TrigEvent/TrigSteeringEvent/TrigSteeringEvent/TrigPassBits.h:44
asg
Definition: DataHandleTestTool.h:28
Feature.h
athena.value
value
Definition: athena.py:124
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
perfmonmt-printer.dest
dest
Definition: perfmonmt-printer.py:189
HLTNavDetails::formatSGkey
std::string formatSGkey(const std::string &prefix, const std::string &containername, const std::string &label)
declaration of formatting function.
Definition: Holder.cxx:122
HLT::TypedHolder::m_store
const asg::EventStoreType * m_store
Definition: TypedHolder.h:172
HLT::TrigNavStructure
Definition: TrigNavStructure.h:40
TDTUtilities.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trig::FeatureAccessImpl::filter_if
std::shared_ptr< const STORED > filter_if(std::true_type is_same, std::shared_ptr< const STORED > &original, const TrigPassBits *bits)
Definition: FeatureCollectStandalone.h:97
Trig::FeatureAccessImpl::typedGet
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())
Definition: FeatureCollectStandalone.h:128
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
xAOD::RoiDescriptorStore_v1
Definition: RoiDescriptorStore_v1.h:29
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trig::TypelessFeature
Feature class, holding information on Feature attached to navigation.
Definition: TypelessFeature.h:20
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
xAOD::RoiDescriptorStore_v1::serialised
const std::vector< std::vector< uint32_t > > & serialised() const
expose the navigation information (in serialised form)
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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
HLT::TypelessHolder
Definition: TypelessHolder.h:11
RoiUtil::deserialise
void deserialise(const roiserial_type &s, std::vector< const IRoiDescriptor * > &rois)
deserialise uint32_t vector into a full vector of IRoiDescriptors
Definition: RoiSerialise.cxx:62
HLT::BaseHolder
Definition: BaseHolder.h:14
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
HLT::TypedHolder::key
const std::string & key() const
key used to access EventStore
Definition: TypedHolder.h:92
HLT::isPassing
bool isPassing(const TrigPassBits *bits, const T *obj, const CONTAINER *container)
Check the bit for the object in the associated bits object.
Definition: Trigger/TrigEvent/TrigSteeringEvent/TrigSteeringEvent/TrigPassBits.h:82
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
TrigPassBits
Definition: Trigger/TrigEvent/TrigSteeringEvent/TrigSteeringEvent/TrigPassBits.h:17
HLT::TypedHolder< TrigRoiDescriptor, TrigRoiDescriptorCollection >::get
StatusCode get(const TrigRoiDescriptor *&destination, HLT::TriggerElement::ObjectIndex idx)
Definition: FeatureCollectStandalone.h:195
RoiDescriptorStore.h
Conditions.h
DeMoScan.index
string index
Definition: DeMoScan.py:364
HLT::TriggerElement::FeatureAccessHelper
the FeatureAccessHelper is a class used to keep track of features attached to this TE.
Definition: TrigNavStructure/TrigNavStructure/TriggerElement.h:192
TrigRoiDescriptorCollection
Definition: TrigRoiDescriptorCollection.h:21
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
HLT::TypedHolder::get
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
TriggerTest.rois
rois
Definition: TriggerTest.py:23
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
RoiSerialise.h
TypelessFeature.h
HLT::TypedHolder< TrigRoiDescriptor, TrigRoiDescriptorCollection >::m_store
const asg::EventStoreType * m_store
Definition: FeatureCollectStandalone.h:232
TrigRoiDescriptor.h
TrigPassBits.h
HLT::TypedHolder
doubly templated class interfacing access to feature containers in StoreGate.
Definition: TypedHolder.h:42
python.PyAthena.obj
obj
Definition: PyAthena.py:132
HLT::TrigNavStructure::getHolder
const BaseHolder * getHolder(const TriggerElement::FeatureAccessHelper &fea) const
Definition: TrigNavStructure.cxx:923
Trig::FeatureAccessImpl::typelessCollect
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)
Definition: FeatureCollectStandalone.cxx:65
Trig::FeatureAccessImpl::insert_flatten_if
void insert_flatten_if(std::vector< Trig::Feature< STORED > > &result, const Trig::TypelessFeature &feature, const std::shared_ptr< const STORED > &newfeature)
Definition: FeatureCollectStandalone.h:84
TypedHolder.h