ATLAS Offline Software
MultChanContainer.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
25 // $Id: MultChanContainer.h,v 1.8 2009-03-13 10:14:59 dwhittin Exp $
26 
27 #ifndef TRTCONDITIONSDATA_MULTCHANNELCONTAINERDEFAULT_H
28 #define TRTCONDITIONSDATA_MULTCHANNELCONTAINERDEFAULT_H
29 
33 #include "GaudiKernel/MsgStream.h"
34 #include <cxxabi.h>
35 #include <algorithm>
36 
37 namespace TRTCond
38 {
39 
42  template <class DaughterContainer>
43  class MultChanContainer : public CondMultChanCollection<DaughterContainer>
44  {
45  public:
48 
52 
54 
55 
57  size_t channelId( const ExpandedIdentifier& x ) const ;
58 
60  size_t layerwheelindex( size_t channelid ) const ;
61 
63  size_t barrelecindex( size_t channelid ) const ;
64 
66  DaughterContainer* findContainer(const ExpandedIdentifier& id) ;
67  DaughterContainer* findContainer(size_t chanid) ;
68 
70  const DaughterContainer* getContainer(size_t chanid) const ;
71 
73  void set( const ExpandedIdentifier& id, const typename DaughterContainer::value_type& t) ;
74 
76  const typename DaughterContainer::value_type& get( const ExpandedIdentifier& id ) const ;
77 
79  const typename DaughterContainer::value_type& get( const ExpandedIdentifier& id , size_t& resolvelevel ) const ;
80 
82  typedef std::pair< const DaughterContainer*, const typename DaughterContainer::value_type*> ContainerWithValue ;
84 
86  void clear() ;
87 
89  size_t footprint() const ;
90 
92  void crunch() ;
93 
95  void print() const ;
96 
98  size_t numObjects() const ;
99 
101  void getall( typename DaughterContainer::FlatContainer& entries ) const ;
102 
104 
105  private:
107  static const size_t m_defaultschannelid = 0 ;
109  std::vector<const DaughterContainer*> m_channelmap ;
111  const typename DaughterContainer::value_type& dummyVal() const;
112  } ;
113 
114 
116 
117  // Dummy Value for empty DaughterContainer
120  template <class DaughterContainer>
121  inline const typename DaughterContainer::value_type&
123  {
124  static typename DaughterContainer::value_type dummyVal;
125  return dummyVal;
126  }
127 
128  template <class DaughterContainer>
130  {
131  *this = rhs;
132  }
133 
134 template <class DaughterContainer>
137  {
138  clear() ;
141  for( ; rhsit != rhs.end(); ++rhsit, ++ rhschanit) {
142  DaughterContainer* lhscontainer = findContainer( *rhschanit ) ;
143  *lhscontainer = **rhsit ;
144  }
145  return *this ;
146  }
147 
148 
149  template <class DaughterContainer>
150  inline size_t
152  {
153  return x.level() >=ExpandedIdentifier::LAYERWHEEL ?
155  m_defaultschannelid ;
156  }
157 
158 
159  template <class DaughterContainer>
160  inline size_t
162  {
163  return channelid!=m_defaultschannelid ? (channelid-1)/4 : 99 ;
164  }
165 
166 
167  template <class DaughterContainer>
168  inline size_t
170  {
171  return channelid!=m_defaultschannelid ? (channelid-1)%4 : 99 ;
172  }
173 
174 
175  template <class DaughterContainer>
177  {
178  // on the first call, we insert a container for the default. the default is always the first container.
179  if( id.level()==ExpandedIdentifier::BARRELEC ) {
180  MsgStream log(Athena::getMessageSvc(),"TRTCond::MultChanContainer");
181  log << MSG::WARNING << "Sorry: cannot store containers at BARREL_EC granularity" << endmsg ;
182  }
183  return findContainer( channelId( id ) ) ;
184  }
185 
186 
187  template <class DaughterContainer>
188  inline DaughterContainer* MultChanContainer<DaughterContainer>::findContainer(size_t chanid)
189  {
190  // on the first call, we insert a container for the default. the default is always the first container.
191  if(this->size()==0) {
192  this->push_back( new DaughterContainer() ) ;
193  this->add(m_defaultschannelid);
194  }
196  std::find( this->chan_begin(), this->chan_end(), chanid ) ;
197  size_t chanindex = std::distance(this->chan_begin(),chanit) ;
198  if(chanit==this->chan_end()) {
199  // add a new container
200  this->push_back( new DaughterContainer() ) ;
201  this->add(chanid);
202  chanindex = this->size()-1 ; //std::distance(chan_begin(),chan_end())-1 ;
203  // make sure to clear the cache
204  m_channelmap.clear() ;
205  }
206  return this->operator[]( chanindex ) ;
207  }
208 
209 
210  template <class DaughterContainer>
211  inline const DaughterContainer* MultChanContainer<DaughterContainer>::getContainer(size_t chanid) const
212  {
213  //in the const-version to get the container we rely on the m_channelmap per-filled by initialize
214  //(to be thread-seafe)
215  return chanid < m_channelmap.size() ? m_channelmap[chanid] : nullptr ;
216  }
217 
218  template <class DaughterContainer>
219  inline void MultChanContainer<DaughterContainer>::set( const ExpandedIdentifier& id, const typename DaughterContainer::value_type& t )
220  {
221  if( id.level()==ExpandedIdentifier::DETECTOR ) {
222  // set the default value. don't use the id, since it will only confuse the container
223  findContainer(id)->set( t ) ;
224  } else if( id.level()==ExpandedIdentifier::BARRELEC ) {
225  MsgStream log(Athena::getMessageSvc(),"TRTCond::MultChanContainer");
226  log << MSG::WARNING << "Sorry: cannot store containers at BARREL_EC granularity" << endmsg;
227  } else {
228  findContainer(id)->set( id, t ) ;
229  }
230  }
231 
232  template <class DaughterContainer>
233  inline const typename DaughterContainer::value_type&
235  {
236  if( id.level() >= ExpandedIdentifier::LAYERWHEEL ) {
237  const DaughterContainer* container = getContainer( channelId(id) ) ;
238  if( container ) {
239  const typename DaughterContainer::value_type& rc = container->get( id ) ;
240  if( DaughterContainer::trait_type::isvalid(rc) ) return rc ;
241  }
242  }
243  // Throw error if the container is empty.
244  if ( this->size() == 0 ) {
245  size_t len;
246  int s;
247  char* tmp = abi::__cxa_demangle(typeid(this).name(),0,&len,&s);
248  std::string error = std::string(tmp) + std::string(" is empty!!");
249  throw std::runtime_error( error );
250  }
251  return this->front()->get() ;
252  //return operator[]( 0 )->set( t ) ;// m_default ;
253  }
254 
255  template <class DaughterContainer>
256  inline const typename DaughterContainer::value_type&
257  MultChanContainer<DaughterContainer>::get( const ExpandedIdentifier& id , size_t& resolvelevel) const
258  {
259  if( id.level() >= ExpandedIdentifier::LAYERWHEEL ) {
260  const DaughterContainer* container = getContainer( channelId(id) ) ;
261  if( container ) {
262  const typename DaughterContainer::value_type& rc = container->get( id , resolvelevel) ;
263  if( DaughterContainer::trait_type::isvalid(rc) ) return rc ;
264  }
265  }
266  // Throw error if the container is empty.
267  if ( this->size() == 0 ) {
268  size_t len;
269  int s;
270  char* tmp = abi::__cxa_demangle(typeid(this).name(),0,&len,&s);
271  std::string error = std::string(tmp) + std::string(" is empty!!");
272  throw std::runtime_error( error );
273  return dummyVal();
274  }
275  return this->front()->get(id,resolvelevel) ;
276  }
277 
279  template <class DaughterContainer>
282  {
283  if( id.level() >= ExpandedIdentifier::LAYERWHEEL ) {
284  const DaughterContainer* container = getContainer( channelId(id) ) ;
285  if( container ) {
286  const typename DaughterContainer::value_type& value = container->get( id ) ;
287  if( DaughterContainer::trait_type::isvalid(value) ) return ContainerWithValue(container,&value) ;
288  }
289  }
290  // Throw error if the container is empty.
291  if ( this->size() == 0 ) {
292  size_t len;
293  int s;
294  char* tmp = abi::__cxa_demangle(typeid(this).name(),0,&len,&s);
295  std::string error = std::string(tmp) + std::string(" is empty!!");
296  throw std::runtime_error( error );
297  }
298  return ContainerWithValue(this->front(),&(this->front()->get())) ;
299  }
300 
301 
302  template <class DaughterContainer>
304  {
306  it != this->end(); ++it) (*it)->clear() ;
307  }
308 
309 
310  template <class DaughterContainer>
312  size_t total=0; //= Trait::footprint(m_default) ;
314  it != this->end(); ++it) total += (*it)->footprint() ;
315  return total ;
316  }
317 
318 
319  template <class DaughterContainer>
322  it != this->end(); ++it) (*it)->crunch() ;
323  }
324 
325 
326  template <class DaughterContainer>
328  size_t rc(0) ;
330  it != this->end(); ++it) rc += (*it)->numObjects() ;
331  return rc ;
332  }
333 
334 
335  template <class DaughterContainer>
336  inline void MultChanContainer<DaughterContainer>::getall( typename DaughterContainer::FlatContainer& entries ) const {
337  typename CondMultChanCollection<DaughterContainer>::chan_const_iterator chanit = this->chan_begin() ;
339  for( ; dauit != this->end(); ++dauit, ++chanit) {
340  // get the entries in this subcontainer
341  typename DaughterContainer::FlatContainer newentries ;
342  (*dauit)->getall(newentries) ;
343  // update the identifiers
344  if( dauit == this->begin() ) {
345  // deal with the default value
346  for( typename DaughterContainer::FlatContainer::iterator it = newentries.begin() ; it!= newentries.end(); ++it)
348  } else {
349  for( typename DaughterContainer::FlatContainer::iterator it = newentries.begin() ; it!= newentries.end(); ++it) {
350  it->first.index(ExpandedIdentifier::BARRELEC) = barrelecindex( *chanit) ;
351  it->first.index(ExpandedIdentifier::LAYERWHEEL) = layerwheelindex( *chanit) ;
352  }
353  }
354  entries.insert( entries.end(), newentries.begin(), newentries.end() ) ;
355  }
356  }
357 
358 
359  template <class DaughterContainer>
361  typename CondMultChanCollection<DaughterContainer>::chan_const_iterator chanit = this->chan_begin() ;
363  for( ; dauit != this->end(); ++dauit, ++chanit) {
364  std::cout << "Now printing channel " << *chanit << " layer/becindex: " << layerwheelindex(*chanit) << " " << barrelecindex(*chanit) << std::endl ;
365  (*dauit)->print() ;
366  }
367  }
368 
369 
370 
371  template <class DaughterContainer>
373 
374  // sanity check to test we have added a default value
375  if( this->size()>0 && *(this->chan_begin()) != m_defaultschannelid ) {
376  MsgStream log(Athena::getMessageSvc(),"TRTCond::MultChanContainer");
377  log << MSG::ERROR << " first channel id is not defaults channel id!" << endmsg ;
378  }
379 
380  // first get the max channel id
381  auto maxchan=std::max_element(this->chan_begin(),this->chan_end());
382  const size_t maxchanid= maxchan==this->chan_end() ? 0 : *maxchan;
383 
384  // now allocate the map and fill it
385  m_channelmap.clear() ;
386  m_channelmap.resize( maxchanid + 1, nullptr ) ;
387  //typename CondMultChanCollection<DaughterContainer>::const_iterator dauit = this->begin() ;
388  auto dauit = this->begin() ;
389  for( auto chanit = this->chan_begin();chanit != this->chan_end(); ++chanit, ++dauit ) {
390  m_channelmap[*chanit] = *dauit ;
391  }
392  return StatusCode::SUCCESS;
393  }
394 }
395 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TRTCond::MultChanContainer::layerwheelindex
size_t layerwheelindex(size_t channelid) const
calculate layer or wheel index from a channel id
Definition: MultChanContainer.h:161
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CondMultChanCollection< DaughterContainer >::chan_begin
chan_const_iterator chan_begin() const
Access to Channel numbers via iterators.
Definition: CondMultChanCollection.h:128
TRTCond::MultChanContainer::ContainerWithValue
std::pair< const DaughterContainer *, const typename DaughterContainer::value_type * > ContainerWithValue
get a value with the corresponding container.
Definition: MultChanContainer.h:82
TRTCond::MultChanContainer::set
void set(const ExpandedIdentifier &id, const typename DaughterContainer::value_type &t)
set a value
Definition: MultChanContainer.h:219
TRTCond::ExpandedIdentifier::BARRELEC
@ BARRELEC
Definition: InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/ExpandedIdentifier.h:37
CondMultChanCollection
A CondMultChanCollection is a template class which can hold a collection of T* objects which are inte...
Definition: CondMultChanCollection.h:52
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TRTCond::MultChanContainer::clear
void clear()
clear all layercontainers
Definition: MultChanContainer.h:303
athena.value
value
Definition: athena.py:122
TRTCond::MultChanContainer::getContainer
const DaughterContainer * getContainer(size_t chanid) const
get a layercontainer from a channel id.
Definition: MultChanContainer.h:211
TRTCond::MultChanContainer::MultChanContainer
MultChanContainer()
constructor.
Definition: MultChanContainer.h:47
TRTCond::MultChanContainer::m_channelmap
std::vector< const DaughterContainer * > m_channelmap
cached table for fast access from channel to layercontainer
Definition: MultChanContainer.h:109
TRTCond::MultChanContainer::getWithContainer
ContainerWithValue getWithContainer(const ExpandedIdentifier &id) const
for retrieving t0 values, we need also the container to 'unpack' the t0
Definition: MultChanContainer.h:281
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TRTCond::MultChanContainer::m_defaultschannelid
static const size_t m_defaultschannelid
now need various forwarding calls for CondMultChanCollection functionality
Definition: MultChanContainer.h:107
TRTCond::MultChanContainer::findContainer
DaughterContainer * findContainer(size_t chanid)
Definition: MultChanContainer.h:188
x
#define x
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TRTCond::MultChanContainer::findContainer
DaughterContainer * findContainer(const ExpandedIdentifier &id)
find a layercontainer from an identifier.
Definition: MultChanContainer.h:176
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TRTCond::MultChanContainer
Definition: MultChanContainer.h:44
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TRTCond::MultChanContainer::dummyVal
const DaughterContainer::value_type & dummyVal() const
dummy value to return when DaughterContainer is empty
Definition: MultChanContainer.h:122
TRTCond::MultChanContainer::channelId
size_t channelId(const ExpandedIdentifier &x) const
calculate the channel for a given TRT identifier
Definition: MultChanContainer.h:151
TRTCond::MultChanContainer::crunch
void crunch()
crunch the layercontainers.
Definition: MultChanContainer.h:320
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
TRTCond::MultChanContainer::initialize
StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
Definition: MultChanContainer.h:372
TRTCond::ExpandedIdentifier::DETECTOR
@ DETECTOR
Definition: InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/ExpandedIdentifier.h:37
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
TRTCond::MultChanContainer::operator=
MultChanContainer & operator=(const MultChanContainer &rhs)
Definition: MultChanContainer.h:136
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
DataVector< DaughterContainer >::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TRTCond
Definition: BasicRtRelation.cxx:8
TRTCond::MultChanContainer::get
const DaughterContainer::value_type & get(const ExpandedIdentifier &id) const
get a value
Definition: MultChanContainer.h:234
NestedContainer.h
'Nested' template container for storing TRT conditions data.
TRTCond::MultChanContainer::getall
void getall(typename DaughterContainer::FlatContainer &entries) const
get a flat vector with all values.
Definition: MultChanContainer.h:336
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
CondMultChanCollection.h
This file defines the template class used to register the tokens of T* in a COOL multchannel folder.
TRTCond::MultChanContainer::footprint
size_t footprint() const
return the memory allocated by the layercontainers.
Definition: MultChanContainer.h:311
TRTCond::MultChanContainer::MultChanContainer
MultChanContainer(const MultChanContainer &rhs)
copy/assignment.
Definition: MultChanContainer.h:129
TRTCond::MultChanContainer::numObjects
size_t numObjects() const
total number of valid calibration objects
Definition: MultChanContainer.h:327
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
TRTCond::ExpandedIdentifier::LAYERWHEEL
@ LAYERWHEEL
Definition: InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/ExpandedIdentifier.h:37
entries
double entries
Definition: listroot.cxx:49
TRTCond::ExpandedIdentifier
Identifier for TRT detector elements in the conditions code.
Definition: InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/ExpandedIdentifier.h:30
TRTCond::MultChanContainer::get
const DaughterContainer::value_type & get(const ExpandedIdentifier &id, size_t &resolvelevel) const
resolve the nesting level
Definition: MultChanContainer.h:257
error
Definition: IImpactPoint3dEstimator.h:70
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
TRTCond::MultChanContainer::print
void print() const
dump to standard output
Definition: MultChanContainer.h:360
DataVector< DaughterContainer >::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TRTCond::MultChanContainer::barrelecindex
size_t barrelecindex(size_t channelid) const
calculate the barrel-ec index from a channel id.
Definition: MultChanContainer.h:169