ATLAS Offline Software
PyDataHeader.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef PYANALYSISCORE_PYDATAHEADER_H
6 #define PYANALYSISCORE_PYDATAHEADER_H
7 
15 #include "StoreGate/StoreGateSvc.h"
16 #include "GaudiKernel/Bootstrap.h"
17 #include "GaudiKernel/ISvcLocator.h"
18 #include "GaudiKernel/MsgStream.h"
20 
21 #include <vector>
22 
24 {
25 public:
27  {
28  MsgStream log(Athena::getMessageSvc(), "PyDataHeader");
29 
30  // get StoreGate
31  StoreGateSvc *pSvc = 0;
32  StatusCode sc = Gaudi::svcLocator()->service("StoreGateSvc", pSvc);
33  if (sc.isFailure())
34  log << MSG::ERROR << "could not get StoreGateSvc" << endmsg;
35  else
36  {
37  // retrieve DataHeader
40  sc = pSvc->retrieve(beg,ending);
41  if (sc.isFailure() || beg==ending)
42  log << MSG::ERROR << "could not get DataHeader" << endmsg;
43  else
44  {
45  // cache DataHeaderElement
46  for (; beg != ending; ++beg)
47  {
48  const DataHeader &dh = *beg;
49  std::vector<DataHeaderElement>::const_iterator it = dh.begin();
50  for (; it != dh.end(); ++it)
51  m_DataHeaderElementV.push_back(&*it);
52  }
53  }
54  }
55 
56  m_classIDSvc = 0;
57  sc = Gaudi::svcLocator()->service("ClassIDSvc", m_classIDSvc);
58  if (sc.isFailure())
59  log << MSG::ERROR << "could not get ClassIDSvc" << endmsg;
60  }
61 
62  virtual ~PyDataHeader () {}
63 
65  int size() { return m_DataHeaderElementV.size(); }
66 
68  std::string getName (int index)
69  {
70  if (index >= size()) return "";
72  it += index;
73 
74  // look for non-symlink name
75  std::string name="";
76  for (CLID clid : (*it)->getClassIDs())
77  {
78  // convert CLID to class name
79  std::string localName;
80  StatusCode sc = m_classIDSvc->getTypeNameOfID (clid, localName);
81  if (sc.isFailure())
82  {
83  MsgStream log(Athena::getMessageSvc(), "PyDataHeader");
84  log << MSG::ERROR << "could not get TypeName for " << clid << endmsg;
85  return "";
86  }
87  // select non-symlink
88  if ((name == "") ||
89  ((localName != "ParticleBaseContainer") &&
90  (localName != "IParticleContainer") &&
91  (localName != "INavigable4MomentumCollection")))
92  name = localName;
93  }
94  return name;
95  }
96 
98  std::string getKey (int index)
99  {
100  if (index >= size()) return "";
102  it += index;
103  return (*it)->getKey();
104  }
105 
106 private:
108  std::vector<const DataHeaderElement *> m_DataHeaderElementV;
109 
111  IClassIDSvc *m_classIDSvc;
112 };
113 
114 #endif
115 
116 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
index
Definition: index.py:1
PyDataHeader::PyDataHeader
PyDataHeader()
Definition: PyDataHeader.h:26
skel.it
it
Definition: skel.GENtoEVGEN.py:423
PyDataHeader
A wrapper for DataHeader.
Definition: PyDataHeader.h:24
PyPoolBrowser.dh
dh
Definition: PyPoolBrowser.py:102
PyDataHeader::size
int size()
get number of elements
Definition: PyDataHeader.h:65
PyDataHeader::m_DataHeaderElementV
std::vector< const DataHeaderElement * > m_DataHeaderElementV
cash for DataHeaderElements
Definition: PyDataHeader.h:108
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
PyDataHeader::m_classIDSvc
IClassIDSvc * m_classIDSvc
class ID service
Definition: PyDataHeader.h:111
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
DataHeader
This class provides the layout for summary information stored for data written to POOL.
Definition: DataHeader.h:124
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
DataHeader.h
This file contains the class definition for the DataHeader and DataHeaderElement classes.
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DeMoScan.index
string index
Definition: DeMoScan.py:362
PyDataHeader::getName
std::string getName(int index)
get class name of Nth element
Definition: PyDataHeader.h:68
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
PyDataHeader::~PyDataHeader
virtual ~PyDataHeader()
Definition: PyDataHeader.h:62
PyDataHeader::getKey
std::string getKey(int index)
get key of Nth element
Definition: PyDataHeader.h:98
StoreGateSvc.h
SG::ConstIterator
Definition: SGIterator.h:163