ATLAS Offline Software
TypedHolder.h
Go to the documentation of this file.
1 // Emacs -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef TRIGNAVSTRUCTURE_TYPEDHOLDER_H
8 #define TRIGNAVSTRUCTURE_TYPEDHOLDER_H
9 
10 //#include <stdexcept>
11 #include <type_traits>
12 
15 
17 
18 #ifdef XAOD_STANDALONE
19 #include "xAODCore/ClassID_traits.h" //guarded b/c athena includes its own
20 #include "AsgTools/SgTEvent.h"
21 #else
22 #include "StoreGate/StoreGateSvc.h"
23 #endif
24 
27 
28 //forward declarations
29 class TrigRoiDescriptor;
31 
32 namespace HLTNavDetails{
36  std::string formatSGkey(const std::string& prefix, const std::string& containername, const std::string& label);
37 }
38 
39 namespace HLT{
40 
41 
42  template<typename FEATURE, typename CONTAINER> class TypedHolder;
43 
44 
48  template<>
50 
54  template<typename FEATURE, typename CONTAINER>
55  class TypedHolder : public TypelessHolder, public asg::AsgMessaging {
56  public:
60  template<typename T,bool value> using StatusCode_if = typename std::enable_if<std::is_same<T,CONTAINER>::value == value,StatusCode>::type;
61 
66  TypedHolder(const BaseHolder& baseholder, const asg::EventStoreType* store, const std::string& container_name = ClassID_traits<CONTAINER>::typeName())
67  : TypelessHolder(baseholder.typeClid(),baseholder.label(),baseholder.subTypeIndex()),
68  asg::AsgMessaging("TypedHolder"),
69  m_store(store),
70  m_cont(0) {
71  // if(!clidCheck<FEATURE>())
72  //throw std::runtime_error("attempted construction with CLID mismatch! Check template parameter and passed typeless holder");
73  m_key = HLTNavDetails::formatSGkey("HLT",container_name,this->label());
74  }
75 
79  TypedHolder(const TypelessHolder& typeless, const asg::EventStoreType* store, const std::string& container_name = ClassID_traits<CONTAINER>::typeName())
80  : TypelessHolder(typeless),
81  asg::AsgMessaging("TypedHolder"),
82  m_store(store),
83  m_cont(0) {
84  //if(!clidCheck<FEATURE>())
85  // throw std::runtime_error("attempted construction with CLID mismatch! Check template parameter and passed typeless holder");
86  m_key = HLTNavDetails::formatSGkey("HLT",container_name,this->label());
87  }
88 
92  std::string key() const {return m_key;}
93 
99  template<typename T> StatusCode_if<T,true> get(const T*& destination, HLT::TriggerElement::ObjectIndex idx){
100  if(syncWithStore().isFailure()){
101  ATH_MSG_ERROR("accessing holder with key: " << key() << " sync with store failed ");
102  return StatusCode::FAILURE;
103  }
104  if(m_cont->size() < idx.objectsEnd()){
105  ATH_MSG_ERROR("accessing holder with key: " << key() << " index past range " << "idx range is: " << idx.objectsBegin() << ":" << idx.objectsEnd() << " container size: " << m_cont->size());
106  return StatusCode::FAILURE;
107  };
108 
109  // make sure we get a fresh pointer as were about to set it to a newly created one
110  if(destination){
111  //ATH_MSG_ERROR("reference pointe provided is already set");
112  return StatusCode::FAILURE;
113  }
114 
115  CONTAINER* nonConstDestination = new CONTAINER(SG::VIEW_ELEMENTS);
116 
117  // need to cast to be able to use non const iterators
118  CONTAINER* src = const_cast<CONTAINER*>(m_cont);
119  typename CONTAINER::iterator beg = src->begin();
120  typename CONTAINER::iterator end = src->begin();
121 
122  std::advance(beg, idx.objectsBegin());
123  std::advance(end, idx.objectsEnd());
124  nonConstDestination->insert(nonConstDestination->end(), beg, end);
125 
126  // from now own we don't want anybody modifying the container
127  destination = nonConstDestination;
128  return StatusCode::SUCCESS;
129  }
130 
135  template<typename T> StatusCode_if<T,false> get(const T*& destination, HLT::TriggerElement::ObjectIndex idx){
136  if((idx.objectsEnd() - idx.objectsBegin())!=1){
137  //ATH_MSG_ERROR("accessing holder with key: " << key() << "index is not single element: " << idx.objectsBegin() << ":" << idx.objectsEnd());
138  return StatusCode::FAILURE;
139  }
140  if(syncWithStore().isFailure()){
141  //ATH_MSG_ERROR("accessing holder with key: " << key() << " sync with store failed ");
142  return StatusCode::FAILURE;
143  }
144  if(m_cont->size() < idx.objectsBegin()){
145  //ATH_MSG_ERROR("accessing holder with key: " << key() << " index past range " << "indexBegin is: " << idx.objectsBegin() << " container size: " << m_cont->size() << std::endl;
146  return StatusCode::FAILURE;
147  };
148 
149  //everything went fine
150  destination = m_cont->at(idx.objectsBegin());
151  return StatusCode::SUCCESS;
152  }
153 
154  private:
155 
160  if(m_cont) return StatusCode::SUCCESS;
161 
163 
164  //sanity checks
165  if(sc.isFailure()) return StatusCode::FAILURE;
166  if(!m_cont) return StatusCode::FAILURE;
167 
168  return StatusCode::SUCCESS;
169  }
170 
172  const asg::EventStoreType* m_store = nullptr;
173  const CONTAINER* m_cont = nullptr;
174  std::string m_key;
175  };
176 
177 }//namespace HLT
178 
179 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
HLT::TypedHolder::StatusCode_if
typename std::enable_if< std::is_same< T, CONTAINER >::value==value, StatusCode >::type StatusCode_if
shorthand for enable_if with returning StatusCode base on comparison with CONTAINER type
Definition: TypedHolder.h:60
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
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
HLT::TypedHolder::TypedHolder
TypedHolder(const TypelessHolder &typeless, const asg::EventStoreType *store, const std::string &container_name=ClassID_traits< CONTAINER >::typeName())
constructor from BaseHolder.
Definition: TypedHolder.h:79
HLTNavDetails
Definition: Holder.cxx:118
HLT::TypedHolder::get
StatusCode_if< T, false > get(const T *&destination, HLT::TriggerElement::ObjectIndex idx)
method retrieves container from storegated and returns pointer at passed ObjectIndex Only enabled for...
Definition: TypedHolder.h:135
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
HLT::TypedHolder::TypedHolder
TypedHolder(const BaseHolder &baseholder, const asg::EventStoreType *store, const std::string &container_name=ClassID_traits< CONTAINER >::typeName())
constructor from BaseHolder.
Definition: TypedHolder.h:66
EventStoreType.h
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
HLT::TypedHolder::m_key
std::string m_key
Definition: TypedHolder.h:174
asg
Definition: DataHandleTestTool.h:28
athena.value
value
Definition: athena.py:122
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
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::TypedHolder::m_cont
const CONTAINER * m_cont
Definition: TypedHolder.h:173
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
AsgMessaging.h
HLT::TypedHolder::syncWithStore
StatusCode syncWithStore()
cache container retrieved from StoreGate
Definition: TypedHolder.h:159
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
ClassID_traits.h
File providing the ClassID_traits traits class.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TriggerElement.h
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
HLT::TypelessHolder
Definition: TypelessHolder.h:11
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
HLT::BaseHolder
Definition: BaseHolder.h:14
OwnershipPolicy.h
HLT::TypedHolder::key
std::string key() const
key used to access EventStore
Definition: TypedHolder.h:92
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
TypelessHolder.h
TrigRoiDescriptorCollection
Definition: TrigRoiDescriptorCollection.h:21
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
HLT::TypedHolder
doubly templated class interfacing access to feature containers in StoreGate.
Definition: TypedHolder.h:42
StoreGateSvc.h
HLT::TypedHolder::TypedHolder
TypedHolder()
Definition: TypedHolder.h:171
SgTEvent.h