ATLAS Offline Software
Loading...
Searching...
No Matches
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
13
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{
27public:
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 "";
70 std::vector<const DataHeaderElement *>::iterator it = m_DataHeaderElementV.begin();
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 "";
100 std::vector<const DataHeaderElement *>::iterator it = m_DataHeaderElementV.begin();
101 it += index;
102 return (*it)->getKey();
103 }
104
105private:
107 std::vector<const DataHeaderElement *> m_DataHeaderElementV;
108
110 ServiceHandle<IClassIDSvc> m_classIDSvc{"ClassIDSvc", "PyDataHeader"};
111};
112
113#endif
114
115
#define endmsg
This file contains the class definition for the DataHeader and DataHeaderElement classes.
uint32_t CLID
The Class ID type.
static Double_t sc
This class provides the layout for summary information stored for data written to POOL.
Definition DataHeader.h:123
std::string getKey(int index)
get key of Nth element
std::vector< const DataHeaderElement * > m_DataHeaderElementV
cash for DataHeaderElements
virtual ~PyDataHeader()
int size()
get number of elements
ServiceHandle< IClassIDSvc > m_classIDSvc
class ID service
std::string getName(int index)
get class name of Nth element
a const_iterator facade to DataHandle.
Definition SGIterator.h:164
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
Definition index.py:1