ATLAS Offline Software
PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef POOLROOTACCESS_TEVENT_H
6 #define POOLROOTACCESS_TEVENT_H
7 
9 
10 #include "GaudiKernel/Bootstrap.h"
11 
12 #include "GaudiKernel/IIncidentSvc.h"
13 #include "Gaudi/Interfaces/IOptionsSvc.h"
16 
17 #include "GaudiKernel/IAppMgrUI.h"
18 
19 //include the CLIDs of simple types so that we don't need to do this ourselves from ROOT prompt
20 //when reading in kTreeAccess
21 #include "SGTools/BuiltinsClids.h"
22 #include "SGTools/StlVectorClids.h"
23 #include "SGTools/StlMapClids.h"
24 
25 class TFile;
26 class TChain;
27 class IEventProcessor;
28 
29 //Bootstraps the minimal gaudi environment + a few extra defaults (see basic.opts)
30 namespace Gaudi {
31  IAppMgrUI* Init();
32 }
33 
34 namespace POOL {
35 
37  IAppMgrUI* Init( const char* options = "POOLRootAccess/basic.opts" );
38 
39 
40  class TEvent {
41  public:
42  enum EReadMode {
43  kTreeAccess = -2, //read the TTree directly
44  kPOOLAccess = -1, //cannot be used in the same session as the other access modes
49  };
50 
51  static IAppMgrUI* Init( const char* options = "POOLRootAccess/basic.opts" ) { return POOL::Init(options); }
52 
53 
54  TEvent( const std::string& name = "StoreGateSvc" );
55  TEvent( EReadMode mode, const std::string& name = "StoreGateSvc" );
56 
57  ~TEvent();
58 
62 
63  template<typename T> void setEvtSelProperty( const char* name, const T& val ) {
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  }
72 
73  //forward retrieve calls to the evtStore
74  template<typename T> StatusCode retrieve( const T*& obj ) {
75  return evtStore()->retrieve( obj );
76  }
77 
78  template<typename T> StatusCode retrieve( T*& obj ) {
79  return evtStore()->retrieve( obj );
80  }
81 
82  template<typename T> StatusCode retrieve( const T*& obj , const std::string& key ){
83  return evtStore()->retrieve( obj, key );
84  }
85  template<typename T> StatusCode retrieve( T*& obj , const std::string& key ){
86  return evtStore()->retrieve( obj, key );
87  }
88 
89  //forward calls to metadata store
90  template<typename T> StatusCode retrieveMetaInput( const T*& obj, const std::string& key ) {
91  return inputMetaStore()->retrieve( obj, key );
92  }
93 
94  int getEntry( long entry ); //return -1 if failure. otherwise 0
95  long getEntries();
96 
97  StatusCode readFrom( TFile* file );
98  StatusCode readFrom( const char* file ); //also takes a comma-separated list and can take wild cards
99  StatusCode readFrom( TChain* files ); //multi-file input
100 
102  void setActive();
103 
104 
106  PyObject* retrieve( PyObject* tp, PyObject* pykey );
107  PyObject* get_item( PyObject* pykey ); //typess retrieve, which is slower than retrieve above
108  PyObject* contains( PyObject* tp, PyObject* pykey );
110  PyObject* record (PyObject* obj, PyObject* pykey,bool allowMods = true,bool resetOnly = true,bool noHist = false);
111 
112  private:
113  long m_curEntry = -1; //if this becomes >=0 then the TEvent is considered 'initialized'
114  long m_size = -1; //cache of the event size, filled on first call to getEntries
115 
116  IEventProcessor* m_evtProcessor;
117 
120 
121  ServiceHandle<IEventSeek> m_evtLoop; //the AthenaEventLoopMgr
122  ServiceHandle<IEvtSelectorSeek> m_evtSelect; //the EventSelectorAthenaPool
124 
125  ServiceHandle<StoreGateSvc> m_inputMetaStore; //input metadata storegate
126 
127  };
128 
129 }
130 
131 
132 #endif
POOL::TEvent::m_joSvc
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_joSvc
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:119
POOL::TEvent::retrieveMetaInput
StatusCode retrieveMetaInput(const T *&obj, const std::string &key)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:90
POOL::TEvent::evtLoop
ServiceHandle< IEventSeek > & evtLoop()
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:59
POOL::TEvent::m_curEntry
long m_curEntry
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:113
POOL::TEvent::m_inputMetaStore
ServiceHandle< StoreGateSvc > m_inputMetaStore
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:125
IEventSeek.h
Abstract interface for seeking within an event stream.
POOL::TEvent::setActive
void setActive()
ensure we are the active store, for the purpose of element links etc
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:120
Gaudi::Init
IAppMgrUI * Init()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:22
ParticleTest.tp
tp
Definition: ParticleTest.py:25
BuiltinsClids.h
POOL::TEvent::get_item
PyObject * get_item(PyObject *pykey)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:209
POOL::TEvent::kTreeAccess
@ kTreeAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:43
POOL::Init
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:29
POOL::TEvent::kClassAccess
@ kClassAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:46
POOL::TEvent::contains
PyObject * contains(PyObject *tp, PyObject *pykey)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:212
POOL::TEvent::kAthenaAccess
@ kAthenaAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:47
StlVectorClids.h
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
POOL::TEvent::EReadMode
EReadMode
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:42
POOL::TEvent::getEntry
int getEntry(long entry)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:185
POOL::TEvent::kUndefinedAccess
@ kUndefinedAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:48
POOL::TEvent::m_size
long m_size
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:114
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:124
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
POOL::TEvent::m_evtSelect
ServiceHandle< IEvtSelectorSeek > m_evtSelect
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:122
generateReferenceFile.files
files
Definition: generateReferenceFile.py:12
file
TFile * file
Definition: tile_monitor.h:29
Preparation.mode
mode
Definition: Preparation.py:94
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
POOL::TEvent::m_incSvc
ServiceHandle< IIncidentSvc > m_incSvc
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:118
POOL::TEvent::m_evtProcessor
IEventProcessor * m_evtProcessor
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:116
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
POOL::TEvent
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
StlMapClids.h
POOL::TEvent::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:60
POOL::TEvent::Init
static IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:51
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj, const std::string &key)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:82
POOL::TEvent::kBranchAccess
@ kBranchAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:45
POOL
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:34
POOL::TEvent::setEvtSelProperty
void setEvtSelProperty(const char *name, const T &val)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:63
POOL::TEvent::retrieve
StatusCode retrieve(T *&obj, const std::string &key)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:85
POOL::TEvent::retrieve
StatusCode retrieve(T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:78
POOL::TEvent::~TEvent
~TEvent()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:33
POOL::TEvent::kPOOLAccess
@ kPOOLAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:44
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
POOL::TEvent::m_evtLoop
ServiceHandle< IEventSeek > m_evtLoop
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:121
POOL::TEvent::record
PyObject * record(PyObject *obj, PyObject *pykey, bool allowMods=true, bool resetOnly=true, bool noHist=false)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:219
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
POOL::TEvent::inputMetaStore
ServiceHandle< StoreGateSvc > & inputMetaStore()
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:61
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
POOL::TEvent::m_evtStore
ServiceHandle< StoreGateSvc > m_evtStore
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:123
IEvtSelectorSeek.h
Extension to IEvtSelector to allow for seeking.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
PyObject
_object PyObject
Definition: IPyComponent.h:26
StoreGateSvc.h
POOL::TEvent::TEvent
TEvent(const std::string &name="StoreGateSvc")
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:46
ServiceHandle< IEventSeek >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37