ATLAS Offline Software
PyDataHeader.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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"
19 #include "GaudiKernel/ServiceHandle.h"
20 #include "GaudiKernel/SmartIF.h"
22 
23 #include <vector>
24 
26 {
27 public:
29  {
30  MsgStream log(Athena::getMessageSvc(), "PyDataHeader");
31 
32  // get StoreGate
33  SmartIF<StoreGateSvc> pSvc{ Gaudi::svcLocator()->service("StoreGateSvc") };
34  if (!pSvc)
35  log << MSG::ERROR << "could not get StoreGateSvc" << endmsg;
36  else
37  {
38  // retrieve DataHeader
41  StatusCode sc = pSvc->retrieve(beg,ending);
42  if (sc.isFailure() || beg==ending)
43  log << MSG::ERROR << "could not get DataHeader" << endmsg;
44  else
45  {
46  // cache DataHeaderElement
47  for (; beg != ending; ++beg)
48  {
49  const DataHeader &dh = *beg;
50  std::vector<DataHeaderElement>::const_iterator it = dh.begin();
51  for (; it != dh.end(); ++it)
52  m_DataHeaderElementV.push_back(&*it);
53  }
54  }
55  }
56 
57  if (m_classIDSvc.retrieve().isFailure())
58  log << MSG::ERROR << "could not get ClassIDSvc" << endmsg;
59  }
60 
61  virtual ~PyDataHeader () {}
62 
64  int size() { return m_DataHeaderElementV.size(); }
65 
67  std::string getName (int index)
68  {
69  if (index >= size()) return "";
71  it += index;
72 
73  // look for non-symlink name
74  std::string name="";
75  for (CLID clid : (*it)->getClassIDs())
76  {
77  // convert CLID to class name
78  std::string localName;
79  StatusCode sc = m_classIDSvc->getTypeNameOfID (clid, localName);
80  if (sc.isFailure())
81  {
82  MsgStream log(Athena::getMessageSvc(), "PyDataHeader");
83  log << MSG::ERROR << "could not get TypeName for " << clid << endmsg;
84  return "";
85  }
86  // select non-symlink
87  if ((name == "") ||
88  ((localName != "ParticleBaseContainer") &&
89  (localName != "IParticleContainer") &&
90  (localName != "INavigable4MomentumCollection")))
91  name = localName;
92  }
93  return name;
94  }
95 
97  std::string getKey (int index)
98  {
99  if (index >= size()) return "";
101  it += index;
102  return (*it)->getKey();
103  }
104 
105 private:
107  std::vector<const DataHeaderElement *> m_DataHeaderElementV;
108 
110  ServiceHandle<IClassIDSvc> m_classIDSvc{"ClassIDSvc", "PyDataHeader"};
111 };
112 
113 #endif
114 
115 
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:28
skel.it
it
Definition: skel.GENtoEVGEN.py:396
PyDataHeader
A wrapper for DataHeader.
Definition: PyDataHeader.h:26
PyPoolBrowser.dh
dh
Definition: PyPoolBrowser.py:102
PyDataHeader::size
int size()
get number of elements
Definition: PyDataHeader.h:64
PyDataHeader::m_DataHeaderElementV
std::vector< const DataHeaderElement * > m_DataHeaderElementV
cash for DataHeaderElements
Definition: PyDataHeader.h:107
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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:228
DeMoScan.index
string index
Definition: DeMoScan.py:364
PyDataHeader::getName
std::string getName(int index)
get class name of Nth element
Definition: PyDataHeader.h:67
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
PyDataHeader::m_classIDSvc
ServiceHandle< IClassIDSvc > m_classIDSvc
class ID service
Definition: PyDataHeader.h:110
PyDataHeader::~PyDataHeader
virtual ~PyDataHeader()
Definition: PyDataHeader.h:61
PyDataHeader::getKey
std::string getKey(int index)
get key of Nth element
Definition: PyDataHeader.h:97
StoreGateSvc.h
SG::ConstIterator
Definition: SGIterator.h:163
ServiceHandle< IClassIDSvc >