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 #include "boost/type_traits/is_same.hpp"
26 
29 
31 
34 
38 
40 
42 
43 #include "AsgMessaging/Check.h"
46 
48 
49 namespace HLT{
50  class TrigNavStructure;
51 }
52 
53 
54 
55 namespace Trig {
56 
61  namespace FeatureAccessImpl{
62 
64 
65  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);
66 
67 
68  template<typename REQUESTED,typename STORED, typename CONTAINER>
69  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());
70 
71 
73 
74  //do not implement
75  template<typename STORED, typename REQUESTED>
76  void insert_element(std::vector<Trig::Feature<REQUESTED> >&, Trig::TypelessFeature&, const STORED*);
77  //do implement
78  template<typename REQUESTED>
79  void insert_element(std::vector<Trig::Feature<REQUESTED> >& result, Trig::TypelessFeature& feature, const REQUESTED* element){
80  result.push_back(Trig::Feature<REQUESTED>(feature,element));
81  }
82 
83 
84  template<typename STORED>
85  void insert_flatten_if(std::vector<Trig::Feature<STORED> >& result, const Trig::TypelessFeature& feature, const std::shared_ptr<const STORED>& newfeature){
86  result.push_back(Trig::Feature<STORED>(feature,newfeature));
87  }
88 
89  template<typename REQUESTED, typename STORED>
90  void insert_flatten_if(std::vector<Trig::Feature<REQUESTED> >& result, const Trig::TypelessFeature& feature, const std::shared_ptr<const STORED>& newfeature){
91  for(auto element : *newfeature){
92  result.push_back(Trig::Feature<REQUESTED>(feature,element));
93  }
94  }
95 
96 
97  template<typename STORED>
98  std::shared_ptr<const STORED> filter_if(boost::mpl::bool_<true> is_same, std::shared_ptr<const STORED>& original,const TrigPassBits* bits){
99  (void)is_same;
100 
101 
102  if(bits==nullptr){
103  std::cerr << "WARNING: nullptr TrigPassBits" << std::endl;
104  return original;
105  }
106  if(original->size() != bits->size()){
107  std::cerr << "WARNING: bits size and owned size" << std::endl;
108  return original;
109  }
111 
112  for(auto obj : *original){
113  if(HLT::isPassing(bits,obj,original.get())){
114  f->push_back(obj);
115  }
116  }
117  //manage the memory
118  std::shared_ptr<const STORED> filtered(f->asDataVector());
119  return filtered;
120  }
121 
122  template<typename STORED>
123  std::shared_ptr<const STORED> filter_if(boost::mpl::bool_<false> /*is_same*/, std::shared_ptr<const STORED>& original,const TrigPassBits* /*bits*/){
124  //nothing
125  return original;
126  }
127 
128  template<typename REQUESTED,typename STORED, typename CONTAINER>
129  std::vector<Trig::Feature<REQUESTED> > typedGet(const std::vector<TypelessFeature>& features, const HLT::TrigNavStructure* navigation, const asg::EventStoreType* store, const std::string& container_name) {
130  std::vector<Trig::Feature<REQUESTED> > typedvec;
131 
132  for(auto feature : features){
133  auto typelessholder = navigation->getHolder(feature.accessHelper());
134  if(!typelessholder){
135  std::cerr << "ERROR, holder not present" << std::endl;
136  continue;
137  }
138  HLT::TypedHolder<STORED,CONTAINER> typedholder(*typelessholder,store,container_name);
139  const STORED* dest = 0;
140 
141  StatusCode sc = typedholder.get(dest,feature.accessHelper().getIndex());
142  if(sc.isFailure()){
143  std::cerr << "TrigDecisionTool WARNING: Feature access failed for feature: " << feature.accessHelper() << std::endl;
144  continue;
145  }
146 
148  //take ownership because typedholder.get created VIEW container with 'new'
149  std::shared_ptr<const STORED> owned(dest);
150 
151  auto passbitsFeatureAccessHelper = FeatureAccessImpl::getTypelessBits(feature.te(),navigation);
152  if(passbitsFeatureAccessHelper.valid()){
153 #ifndef __CLING__
154  auto passbitsHolder = navigation->getHolder(passbitsFeatureAccessHelper);
156  const TrigPassBits* bits = 0;
157  if(typedBits.get(bits,passbitsFeatureAccessHelper.getIndex()).isFailure()){
158  std::cerr << "WARNING: couldn't get passbits from Holder" << std::endl;
159  }
160  owned = filter_if(boost::is_same<STORED,CONTAINER>(),owned,bits);
161 #endif
162  }
163  //if REQUESTED != STORED we assume REQUESTED is element type
164  //and we flatten the vector
165  insert_flatten_if(typedvec,feature,owned);
166  }
167  else{
169  std::shared_ptr<const STORED> owned(dest);
170  //TrigRoiDescriptor needs deletiong by us.. a bit hacky but oh well...
171  insert_flatten_if(typedvec,feature,owned);
172  }
173  else{
174  //storegate owns the pointer
175  insert_element(typedvec,feature,dest);
176  }
177  }
178  }
179  return typedvec;
180  }
181  } // EOF namespace FeatureAccessImpl
182 
183 } // EOF namespace Trig
184 
185 
186 namespace HLT{
187  template<>
189  public:
190  TypedHolder(const BaseHolder& baseholder, const asg::EventStoreType* store, const std::string& /*container_name*/ = "")
191  : TypelessHolder(baseholder.typeClid(),baseholder.label(),baseholder.subTypeIndex()),
192  asg::AsgMessaging("TypedHolder"),
193  m_store(store){
194  };
195 
197 
198  std::string key = HLTNavDetails::formatSGkey("HLT","xAOD::RoiDescriptorStore",this->label());
199  const xAOD::RoiDescriptorStore* roistore = 0;
200  ASG_CHECK(m_store->retrieve(roistore,key));
201 
202  // so what's happening here is a bit hacky since StoreGate stores (and owns)
203  // the RoiDescriptorStore. But the IRoiDescriptor pointers that get created
204  // by RoiUtil::deserialize are new pointers, so we need to manage them
205  // So we deserialize the entire collection, pick the one pointed to by
206  // the object index and mark it as the return value and the delete the rest again
207  // Later the single remaining element will be deleted by the Feature
208  // (which will have the owning flag set for RoIs). Hopefully the performance
209  // penalty is not too large
210 
211  std::vector<const IRoiDescriptor*> rois;
212  RoiUtil::deserialise( roistore->serialised(), rois );
213  if((idx.objectsEnd() - idx.objectsBegin())!=1){
214  ATH_MSG_ERROR("accessing RoI holder with key: is not single element: ");
215  return StatusCode::FAILURE;
216  }
217 
218  if(rois.size() < idx.objectsBegin()){
219  ATH_MSG_ERROR("deserialized roi collection too small");
220  return StatusCode::FAILURE;
221  };
222  for (unsigned int index = 0; index < rois.size(); ++index){
223  if(index == idx.objectsBegin()){
224  destination = dynamic_cast<const TrigRoiDescriptor*>(rois.at(index));
225  }
226  else{
227  delete rois.at(index);
228  }
229  }
230  return StatusCode::SUCCESS;
231  }
232  private:
234  };
235 }
236 
237 
238 
239 #endif
240 
241 
HLT::TypedHolder< TrigRoiDescriptor, TrigRoiDescriptorCollection >::TypedHolder
TypedHolder(const BaseHolder &baseholder, const asg::EventStoreType *store, const std::string &="")
Definition: FeatureCollectStandalone.h:190
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:69
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
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
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: CaloTowerVecMon.h:44
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:122
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::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:129
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:128
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
HLT::class_id_type
uint32_t class_id_type
Definition: Trigger/TrigEvent/TrigNavStructure/Root/Types.h:11
HLT::TypedHolder::key
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
Trig::FeatureAccessImpl::filter_if
std::shared_ptr< const STORED > filter_if(boost::mpl::bool_< true > is_same, std::shared_ptr< const STORED > &original, const TrigPassBits *bits)
Definition: FeatureCollectStandalone.h:98
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:196
RoiDescriptorStore.h
DeMoScan.index
string index
Definition: DeMoScan.py:362
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
Conditions.h
HLT::TypedHolder< TrigRoiDescriptor, TrigRoiDescriptorCollection >::m_store
const asg::EventStoreType * m_store
Definition: FeatureCollectStandalone.h:233
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:135
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:85
TypedHolder.h