ATLAS Offline Software
Loading...
Searching...
No Matches
POOL::TEvent Class Reference

#include <TEvent.h>

Collaboration diagram for POOL::TEvent:

Public Types

enum  EReadMode {
  kTreeAccess = -2 , kPOOLAccess = -1 , kBranchAccess = 0 , kClassAccess = 1 ,
  kAthenaAccess = 2 , kUndefinedAccess = 3
}

Public Member Functions

 TEvent (const std::string &name="StoreGateSvc")
 TEvent (EReadMode mode, const std::string &name="StoreGateSvc")
 ~TEvent ()
ServiceHandle< IEventSeek > & evtLoop ()
ServiceHandle< StoreGateSvc > & evtStore ()
ServiceHandle< StoreGateSvc > & inputMetaStore ()
template<typename T>
void setEvtSelProperty (const char *name, const T &val)
template<typename T>
StatusCode retrieve (const T *&obj)
template<typename T>
StatusCode retrieve (T *&obj)
template<typename T>
StatusCode retrieve (const T *&obj, const std::string &key)
template<typename T>
StatusCode retrieve (T *&obj, const std::string &key)
template<typename T>
StatusCode retrieveMetaInput (const T *&obj, const std::string &key)
int getEntry (long entry)
long getEntries ()
StatusCode readFrom (TFile *file)
StatusCode readFrom (const char *file)
StatusCode readFrom (TChain *files)
void setActive ()
 ensure we are the active store, for the purpose of element links etc
PyObjectretrieve (PyObject *tp, PyObject *pykey)
 retrieve and record method for python
PyObjectget_item (PyObject *pykey)
PyObjectcontains (PyObject *tp, PyObject *pykey)
PyObjectretrieveMetaInput (PyObject *tp, PyObject *pykey)
PyObjectrecord (PyObject *obj, PyObject *pykey, bool allowMods=true, bool resetOnly=true, bool noHist=false)

Static Public Member Functions

static IAppMgrUI * Init (const char *options="POOLRootAccess/basic.opts")

Private Attributes

long m_curEntry = -1
long m_size = -1
IEventProcessor * m_evtProcessor
ServiceHandle< IIncidentSvc > m_incSvc
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_joSvc
ServiceHandle< IEventSeekm_evtLoop
ServiceHandle< IEvtSelectorSeekm_evtSelect
ServiceHandle< StoreGateSvcm_evtStore
ServiceHandle< StoreGateSvcm_inputMetaStore

Detailed Description

Member Enumeration Documentation

◆ EReadMode

Enumerator
kTreeAccess 
kPOOLAccess 
kBranchAccess 
kClassAccess 
kAthenaAccess 
kUndefinedAccess 

Definition at line 42 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

Constructor & Destructor Documentation

◆ TEvent() [1/2]

POOL::TEvent::TEvent ( const std::string & name = "StoreGateSvc")

Definition at line 46 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

46: TEvent( kPOOLAccess , name ) { }
TEvent(const std::string &name="StoreGateSvc")

◆ TEvent() [2/2]

POOL::TEvent::TEvent ( EReadMode mode,
const std::string & name = "StoreGateSvc" )

Definition at line 48 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

48 :
49 m_evtProcessor (nullptr),
50 m_incSvc("IncidentSvc","TEvent"+name),
51 m_joSvc("JobOptionsSvc","TEvent"+name),
52 m_evtLoop("AthenaEventLoopMgr/"+name+"_EventLoopMgr","TEvent"+name),
53 m_evtSelect("EventSelectorAthenaPool/"+name+"_EventSelector","TEvent"+name),
54 m_evtStore("StoreGateSvc/"+name,"TEvent"+name),
55 m_inputMetaStore("InputMetaDataStore","TEvent"+name) /*fixme, when reading multiple files at once?*/ {
56
58
59 //SEEMS TO CAUSE INITIALIZE LOOP if(name=="StoreGateSvc") m_evtSelect.setName("EventSelector"); //use default selector name if we use default storegate
60
61 //FIXME: Should protect against attempt to mix POOL with nonPOOL
62 if(mode==kPOOLAccess) {
63 //add AthenaPoolCnvSvc to the EventPersistencySvc (ideally the selector should add this itself!!)
64 ServiceHandle<IService> epSvc("EventPersistencySvc","TEvent"+name);
65 AAH::setProperty( epSvc , "CnvServices" , "['AthenaPoolCnvSvc']" ).ignore(); //FIXME: perhaps should append rather than overwrite
66 //add the AthenaPoolAddressProviderSvc to ProxyProviderSvc
67 ServiceHandle<IService> ppSvc("ProxyProviderSvc","TEvent"+name);
68 AAH::setProperty( ppSvc , "ProviderNames", "['MetaDataSvc', 'AthenaPoolAddressProviderSvc']" ).ignore();
69 } else if(mode==kTreeAccess) {
70 //switch selector type to Athena::RootNtupleEventSelector
71 m_evtSelect.setTypeAndName("Athena::RootNtupleEventSelector/"+m_evtSelect.name());
72 //also default to 'CollectionTree' as the tree to read
73 this->setEvtSelProperty("TupleName","CollectionTree");
74 } else {
75 //switch selector type to xAODEventSelector:
76 m_evtSelect.setTypeAndName("Athena::xAODEventSelector/"+m_evtSelect.name());
77 }
78
79 //check if a SelectorType has been specified in the joSvc
80 //should retire this code at some point (hangover from basicxAOD.opts)
81 if (m_joSvc->has("TEvent.EventSelectorType")) {
82 m_evtSelect.setTypeAndName(m_joSvc->get("TEvent.EventSelectorType") + "/" + m_evtSelect.name());
83 }
84
85 AAH::setProperty( m_evtLoop , "ClearStorePolicy", "BeginEvent" ).ignore(); //for interactive use of storegate
86 AAH::setProperty( m_evtLoop , "EvtSel", m_evtSelect.typeAndName() ).ignore(); //connect loop to selector
87 AAH::setProperty( m_evtLoop , "EvtStore", m_evtStore.typeAndName() ).ignore();//connect loop to store
88 AAH::setProperty( m_evtLoop , "EventPrintoutInterval", 0 ).ignore(); //disable printout (speeds up loop)
89
90 if(m_evtSelect.type()=="Athena::xAODEventSelector") {
91 AAH::setProperty( m_evtSelect , "ReadMetaDataWithPool" , true).ignore(); //uses hybrid xAOD reading by default
92 AAH::setProperty( m_evtSelect , "AccessMode" , int(mode) ).ignore(); //sets the mode
93 AAH::setProperty( m_evtSelect , "EvtStore" , m_evtStore.typeAndName() ).ignore();
94 //FIXME ... cant get dual event stores working :-(
95 //AAH::setProperty( m_evtSelect , "ProxyProviderSvc" , "ProxyProviderSvc/" + name + "_ProxyProviderSvc" );
96 //AAH::setProperty( m_evtStore , "ProxyProviderSvc", "ProxyProviderSvc/" + name + "_ProxyProviderSvc" );
97 }
98
99 //set outputlevels to WARNING
100 AAH::setProperty( m_evtLoop, "OutputLevel", 4 ).ignore();
101 AAH::setProperty( m_evtSelect, "OutputLevel", 4 ).ignore();
102 //AAH::setProperty( m_evtStore, "OutputLevel", 4 ).ignore();
103
104 //suppress messages below WARNING too
105 //do this here to stop some pre initialize INFO messages from showing
106 ServiceHandle<IProperty> messageSvc("MessageSvc","");
107 std::vector<std::string> p;
108 Gaudi::Parsers::parse(p,messageSvc->getProperty("setWarning").toString()).ignore();
109 p.push_back( m_evtLoop.name() );
110 p.push_back( m_evtSelect.name() );
111 p.push_back( m_evtStore.name() );
112 messageSvc->setProperty( StringArrayProperty( "setWarning" , p ) ).ignore();
113
114 //also push this into the joboptionsvc so that if a reinit happens then these settings are remembered
115 //m_joSvc->addPropertyToCatalogue( "MessageSvc", StringArrayProperty( "setWarning", p ) );
116
117}
static StatusCode setProperty(const GaudiHandleBase &toolHandle, const std::string &property, const int &value, bool override=true)
ServiceHandle< IEvtSelectorSeek > m_evtSelect
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_joSvc
void setEvtSelProperty(const char *name, const T &val)
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)

◆ ~TEvent()

POOL::TEvent::~TEvent ( )

Definition at line 33 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

33 {
34 //need to destroy my storegate, selector, and loop
35 if(m_evtLoop.isSet()) {
36 m_evtLoop.release().ignore();
37 }
38 if(m_evtSelect.isSet()) {
39 m_evtSelect.release().ignore();
40 }
41 if(m_evtStore.isSet()) {
42 m_evtStore.release().ignore();
43 }
44}

Member Function Documentation

◆ contains()

PyObject * POOL::TEvent::contains ( PyObject * tp,
PyObject * pykey )

Definition at line 212 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

212 {
213 return AthenaInternal::py_sg_contains( &*evtStore() , tp, pykey );
214 }
ServiceHandle< StoreGateSvc > & evtStore()
PyObject * py_sg_contains(PyObject *storeGateSvc, PyObject *tp, PyObject *key)

◆ evtLoop()

ServiceHandle< IEventSeek > & POOL::TEvent::evtLoop ( )
inline

Definition at line 59 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

59{ return m_evtLoop; }

◆ evtStore()

ServiceHandle< StoreGateSvc > & POOL::TEvent::evtStore ( )
inline

Definition at line 60 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

60{ return m_evtStore; }

◆ get_item()

PyObject * POOL::TEvent::get_item ( PyObject * pykey)

Definition at line 209 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

209 {
210 return AthenaInternal::py_sg_getitem( &*evtStore() , pykey );
211 }
PyObject * py_sg_getitem(PyObject *storeGateSvc, PyObject *key)

◆ getEntries()

long POOL::TEvent::getEntries ( )

Definition at line 124 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

124 {
125 if(m_size>=0) return m_size;
126 if(!m_evtLoop.isSet()) { if(m_evtLoop.retrieve().isFailure()) return 0; }
127 if (ICollectionSize* isize = dynamic_cast<ICollectionSize*>(&*m_evtLoop)) {
128 return isize->size();
129 }
130 return 0;
131}

◆ getEntry()

int POOL::TEvent::getEntry ( long entry)

Definition at line 185 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

185 {
186 if(!m_evtLoop.isSet()) { if(m_evtLoop.retrieve().isFailure()) return -1; }
187 if(entry==0 || entry != m_curEntry+1) {
188 //need to seek on first read or if not reading next event
189 if (m_evtLoop->seek(entry).isFailure()) return -1;
190 }
191 //ensure our storegate is the active store
192 setActive();
193 if (m_evtProcessor == nullptr) {
194 m_evtProcessor = dynamic_cast<IEventProcessor*>(&*m_evtLoop);
195 }
196 StatusCode out = m_evtProcessor->nextEvent(entry+1);
198 m_incSvc->fireIncident(Incident("BeginEvent",IncidentType::BeginEvent));
199 return (out.isSuccess()) ? 0 : -1;
200}
void setActive()
ensure we are the active store, for the purpose of element links etc
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ Init()

IAppMgrUI * POOL::TEvent::Init ( const char * options = "POOLRootAccess/basic.opts")
inlinestatic

Definition at line 51 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

51{ return POOL::Init(options); }
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.

◆ inputMetaStore()

ServiceHandle< StoreGateSvc > & POOL::TEvent::inputMetaStore ( )
inline

◆ readFrom() [1/3]

StatusCode POOL::TEvent::readFrom ( const char * file)

Definition at line 138 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

138 {
139 if(m_curEntry >= 0) {
140 std::cout << "Unable to change file after already reading" << std::endl;
141 return StatusCode::FAILURE;
142 }
143 std::vector<std::string> myFiles;
144 //see if contains wildcard
145 //separate by comma
146 TString sFileIn(file);
147 std::unique_ptr<TObjArray> sFiles(sFileIn.Tokenize(","));
148 std::unique_ptr<TIterator> itr(sFiles->MakeIterator());
149 TObject* obj;
150 while( (obj = itr->Next()) ) {
151 TString sFile(static_cast<TObjString*>(obj)->String());
152 if(sFile.Contains('*')) {
153 std::unique_ptr<TObjArray> theFiles(gSystem->GetFromPipe(("ls " + std::string(file)).c_str()).Tokenize("\n"));
154 for(int i=0;i<theFiles->GetEntries();i++) {
155 //std::cout << "Adding " << dynamic_cast<TObjString*>(theFiles->At(i))->String().Data() << std::endl;
156 if (TObjString* objstr = dynamic_cast<TObjString*>(theFiles->At(i))) {
157 myFiles.push_back(gSystem->ExpandPathName(objstr->String().Data()));
158 }
159 }
160 } else {
161 myFiles.push_back( gSystem->ExpandPathName(sFile.Data()) );
162 }
163 }
164
165 return AAH::setProperty( m_evtSelect , "InputCollections" , myFiles );
166}
TFile * file

◆ readFrom() [2/3]

StatusCode POOL::TEvent::readFrom ( TChain * files)

Definition at line 168 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

168 {
169
170 //add all files to the property list by giving a comma separated list of files
171 std::string sfiles;
172 std::unique_ptr<TIterator> itr(files->GetListOfFiles()->MakeIterator());
173 TObject* obj;
174 bool hasFile(false);
175 while( (obj = itr->Next()) ) {
176 if(hasFile) sfiles += ",";
177 sfiles += obj->GetTitle();
178 hasFile=true;
179 }
180 //std::cout << sfiles << std::endl;
181 return readFrom(sfiles.c_str());
182
183}
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:50

◆ readFrom() [3/3]

StatusCode POOL::TEvent::readFrom ( TFile * file)

Definition at line 133 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

133 {
134 if(file==0 || file->IsZombie()) return StatusCode::FAILURE;
135 return readFrom( file->GetName() );
136}

◆ record()

PyObject * POOL::TEvent::record ( PyObject * obj,
PyObject * pykey,
bool allowMods = true,
bool resetOnly = true,
bool noHist = false )

Definition at line 219 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

219 {
220 return AthenaInternal::recordObjectToStore( &*evtStore() , obj, pykey,allowMods,resetOnly,noHist );
221 }
PyObject * recordObjectToStore(StoreGateSvc *, PyObject *, PyObject *, bool, bool, bool)
record object to storegate

◆ retrieve() [1/5]

template<typename T>
StatusCode POOL::TEvent::retrieve ( const T *& obj)
inline

Definition at line 74 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

74 {
75 return evtStore()->retrieve( obj );
76 }

◆ retrieve() [2/5]

template<typename T>
StatusCode POOL::TEvent::retrieve ( const T *& obj,
const std::string & key )
inline

Definition at line 82 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

82 {
83 return evtStore()->retrieve( obj, key );
84 }

◆ retrieve() [3/5]

PyObject * POOL::TEvent::retrieve ( PyObject * tp,
PyObject * pykey )

retrieve and record method for python

Definition at line 204 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

205 {
206 return AthenaInternal::retrieveObjectFromStore( &*evtStore() , tp, pykey );
207 }
PyObject * retrieveObjectFromStore(PyObject *storeGateSvc, PyObject *tp, PyObject *key)

◆ retrieve() [4/5]

template<typename T>
StatusCode POOL::TEvent::retrieve ( T *& obj)
inline

Definition at line 78 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

78 {
79 return evtStore()->retrieve( obj );
80 }

◆ retrieve() [5/5]

template<typename T>
StatusCode POOL::TEvent::retrieve ( T *& obj,
const std::string & key )
inline

Definition at line 85 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

85 {
86 return evtStore()->retrieve( obj, key );
87 }

◆ retrieveMetaInput() [1/2]

template<typename T>
StatusCode POOL::TEvent::retrieveMetaInput ( const T *& obj,
const std::string & key )
inline

Definition at line 90 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

90 {
91 return inputMetaStore()->retrieve( obj, key );
92 }
ServiceHandle< StoreGateSvc > & inputMetaStore()

◆ retrieveMetaInput() [2/2]

PyObject * POOL::TEvent::retrieveMetaInput ( PyObject * tp,
PyObject * pykey )

Definition at line 215 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

215 {
216 if(!m_evtLoop.isSet()) { if(m_evtLoop.retrieve().isFailure()) return 0; }
218 }

◆ setActive()

void POOL::TEvent::setActive ( )

ensure we are the active store, for the purpose of element links etc

Definition at line 120 of file PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx.

120 {
121 m_evtStore->makeCurrent();
122}

◆ setEvtSelProperty()

template<typename T>
void POOL::TEvent::setEvtSelProperty ( const char * name,
const T & val )
inline

Definition at line 63 of file PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h.

63 {
64 if constexpr (std::is_convertible_v<T, std::string>) {
65 // Gaudi::Utils::toString adds extra quotes, don't do this for strings:
66 m_joSvc->set(m_evtSelect.name() + "." + name, std::string(val));
67 }
68 else {
69 m_joSvc->set(m_evtSelect.name() + "." + name, Gaudi::Utils::toString(val));
70 }
71 }

Member Data Documentation

◆ m_curEntry

long POOL::TEvent::m_curEntry = -1
private

◆ m_evtLoop

ServiceHandle<IEventSeek> POOL::TEvent::m_evtLoop
private

◆ m_evtProcessor

IEventProcessor* POOL::TEvent::m_evtProcessor
private

◆ m_evtSelect

ServiceHandle<IEvtSelectorSeek> POOL::TEvent::m_evtSelect
private

◆ m_evtStore

ServiceHandle<StoreGateSvc> POOL::TEvent::m_evtStore
private

◆ m_incSvc

ServiceHandle<IIncidentSvc> POOL::TEvent::m_incSvc
private

◆ m_inputMetaStore

ServiceHandle<StoreGateSvc> POOL::TEvent::m_inputMetaStore
private

◆ m_joSvc

ServiceHandle<Gaudi::Interfaces::IOptionsSvc> POOL::TEvent::m_joSvc
private

◆ m_size

long POOL::TEvent::m_size = -1
private

The documentation for this class was generated from the following files: