| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

RootDataConnection.h
Go to the documentation of this file.
1 #ifndef GAUDIROOT_ROOTDATACONNECTION_H
2 #define GAUDIROOT_ROOTDATACONNECTION_H
3
4 // Framework include files
5 #include "GaudiKernel/ClassID.h"
6 #include "GaudiKernel/IIncidentSvc.h"
7 #include "GaudiKernel/SmartIF.h"
8 #include "GaudiUtils/IIODataManager.h"
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13
14 #include "RootCnv/RootRefs.h"
15 #include "TFile.h"
16 #include "TTreePerfStats.h"
17
18 // Forward declarations
19 class TTree;
20 class TClass;
21 class TBranch;
22
23 class MsgStream;
24 class IRegistry;
25 class DataObject;
26 class IIncidentSvc;
27
28 /*
29 * Gaudi namespace declaration
30 */
31 namespace Gaudi
32 {
33
44 class GAUDI_API RootConnectionSetup final
45 {
46 private:
48 std::unique_ptr<MsgStream> m_msgSvc;
50 SmartIF<IIncidentSvc> m_incidentSvc = nullptr;
51
52 public:
54 typedef std::vector<std::string> StringVec;
55
57 StringVec cacheBranches;
59 StringVec vetoBranches;
61 std::string loadSection;
63 int cacheSize;
65 int learnEntries;
66
68 RootConnectionSetup() = default;
69
71 static long setCompression( const std::string& compression );
73 static int compression();
74
76 void setMessageSvc( MsgStream* m );
78 MsgStream& msgSvc() const { return *m_msgSvc; }
79
81 void setIncidentSvc( IIncidentSvc* m );
83 IIncidentSvc* incidentSvc() const { return m_incidentSvc.get(); }
84 };
85
94 class GAUDI_API RootDataConnection : virtual public Gaudi::IDataConnection
95 {
96 public:
97 enum { ROOT_READ_ERROR = 0x2, ROOT_OPEN_ERROR = 0x4 };
98
109 struct ContainerSection {
111 ContainerSection() : start( -1 ), length( 0 ) {}
113 ContainerSection( int s, int l ) : start( s ), length( l ) {}
115 ContainerSection( const ContainerSection& s ) : start( s.start ), length( s.length ) {}
117 ContainerSection& operator=( const ContainerSection& s )
118 {
119 if ( this != &s ) {
120 start = s.start;
121 length = s.length;
122 }
123 return *this;
124 }
126 int start;
128 int length;
129 };
130
132 typedef std::vector<std::string> StringVec;
134 typedef std::vector<std::pair<std::string, std::string>> ParamMap;
136 typedef std::map<std::string, TTree*> Sections;
138 typedef std::vector<ContainerSection> ContainerSections;
140 typedef std::map<std::string, ContainerSections> MergeSections;
142 typedef std::vector<RootRef> LinkSections;
144 typedef std::set<const IInterface*> Clients;
145
147 MsgStream& msgSvc() const { return m_setup->msgSvc(); }
148
149 protected:
151 std::shared_ptr<RootConnectionSetup> m_setup;
153 std::unique_ptr<TTreePerfStats> m_statistics;
155 std::unique_ptr<TFile> m_file;
157 TTree* m_refs = nullptr;
159 Sections m_sections;
161 StringVec m_dbs;
163 StringVec m_conts;
165 StringVec m_links;
167 StringVec m_mergeFIDs;
169 ParamMap m_params;
171 MergeSections m_mergeSects;
173 LinkSections m_linkSects;
175 Clients m_clients;
177 std::string m_empty;
178
180 const std::string& empty() const;
181
183 StatusCode saveRefs();
184
185 public:
195 class Tool
196 {
197 protected:
198 typedef RootDataConnection::StringVec StringVec;
199 typedef RootDataConnection::ParamMap ParamMap;
200 typedef RootDataConnection::Sections Sections;
201 typedef RootDataConnection::MergeSections MergeSections;
202 typedef RootDataConnection::LinkSections LinkSections;
203 typedef RootDataConnection::ContainerSection ContainerSection;
204 typedef RootDataConnection::ContainerSections ContainerSections;
205
207 RootDataConnection* c;
208
209 public:
210 TTree* refs() const { return c->m_refs; }
211 StringVec& dbs() const { return c->m_dbs; }
212 StringVec& conts() const { return c->m_conts; }
213 StringVec& links() const { return c->m_links; }
214 ParamMap& params() const { return c->m_params; }
215 MsgStream& msgSvc() const { return c->msgSvc(); }
216 const std::string& name() const { return c->m_name; }
217 Sections& sections() const { return c->m_sections; }
218 LinkSections& linkSections() const { return c->m_linkSects; }
219 MergeSections& mergeSections() const { return c->m_mergeSects; }
220
222 virtual ~Tool() = default;
224 virtual TBranch* getBranch( const std::string& section, const std::string& n ) = 0;
226 virtual RootRef poolRef( size_t /* which */ ) const { return RootRef(); }
227
229 virtual StatusCode readRefs() = 0;
231 virtual StatusCode saveRefs() = 0;
233 virtual int loadRefs( const std::string& section, const std::string& cnt, unsigned long entry,
234 RootObjectRefs& refs ) = 0;
235 };
236 std::unique_ptr<Tool> m_tool;
237 friend class Tool;
238
240 Tool* makeTool();
241
242 public:
244 RootDataConnection( const IInterface* own, const std::string& nam, std::shared_ptr<RootConnectionSetup> setup );
246 ~RootDataConnection() override = default;
247
249 TFile* file() const { return m_file.get(); }
251 bool isConnected() const override { return bool( m_file ); }
253 bool isWritable() const { return m_file && m_file->IsWritable(); }
255 Tool* tool() const { return m_tool.get(); }
257 const MergeSections& mergeSections() const { return m_mergeSects; }
259 const StringVec& mergeFIDs() const { return m_mergeFIDs; }
260
262 void addClient( const IInterface* client );
264 size_t removeClient( const IInterface* client );
266 bool lookupClient( const IInterface* client ) const;
267
269 void badWriteError( const std::string& msg ) const;
270
272 std::pair<const RootRef*, const ContainerSection*> getMergeSection( const std::string& container, int entry ) const;
273
275 void enableStatistics( const std::string& section );
277 void saveStatistics( const std::string& statisticsFile );
278
280 int loadObj( const std::string& section, const std::string& cnt, unsigned long entry, DataObject*& pObj );
281
283 int loadRefs( const std::string& section, const std::string& cnt, unsigned long entry, RootObjectRefs& refs );
284
286 std::pair<int, unsigned long> saveObj( const std::string& section, const std::string& cnt, TClass* cl,
287 DataObject* pObj, int buff_siz, int split_lvl, bool fill_missing = false );
289 std::pair<int, unsigned long> save( const std::string& section, const std::string& cnt, TClass* cl, void* pObj,
290 int buff_siz, int split_lvl, bool fill_missing = false );
291
293 StatusCode connectRead() override;
295 StatusCode connectWrite( IoType typ ) override;
297 StatusCode disconnect() override;
299 StatusCode read( void* const, size_t ) override { return StatusCode::FAILURE; }
301 StatusCode write( const void*, int ) override { return StatusCode::FAILURE; }
303 long long int seek( long long int, int ) override { return -1; }
304
306 TTree* getSection( const std::string& sect, bool create = false );
307
309 TBranch* getBranch( const std::string& section, const std::string& branch_name )
310 {
311 return m_tool->getBranch( section, branch_name );
312 }
314 TBranch* getBranch( const std::string& section, const std::string& branch_name, TClass* cl, void* ptr, int buff_siz,
315 int split_lvl );
316
318 void makeRef( IRegistry* pA, RootRef& ref );
320 void makeRef( const std::string& name, long clid, int tech, const std::string& db, const std::string& cnt,
321 int entry, RootRef& ref );
322
324 int makeLink( const std::string& p );
325
327 const std::string& getDb( int which ) const;
328
330 const std::string& getCont( int which ) const
331 {
332 return ( which >= 0 ) && ( size_t( which ) < m_conts.size() ) ? *( m_conts.begin() + which ) : empty();
333 }
334
336 const std::string& getLink( int which ) const
337 {
338 return ( which >= 0 ) && ( size_t( which ) < m_links.size() ) ? *( m_links.begin() + which ) : empty();
339 }
340 };
341 } // End namespace Gaudi
342 #endif // GAUDIROOT_ROOTDATACONNECTION_H
Gaudi::RootDataConnection::Tool::name
const std::string & name() const
Definition: RootDataConnection.h:216
Gaudi::RootDataConnection::m_mergeSects
MergeSections m_mergeSects
Database section map for merged files.
Definition: RootDataConnection.h:171
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Gaudi::RootDataConnection::mergeSections
const MergeSections & mergeSections() const
Access merged data section inventory.
Definition: RootDataConnection.h:257
std::shared_ptr
SmartIF< IIncidentSvc >
ClassID.h
Gaudi::RootDataConnection::Tool::Sections
RootDataConnection::Sections Sections
Definition: RootDataConnection.h:200
Gaudi::RootDataConnection::ContainerSections
std::vector< ContainerSection > ContainerSections
Definition of container sections to handle merged files.
Definition: RootDataConnection.h:138
Gaudi::RootDataConnection::m_tool
std::unique_ptr< Tool > m_tool
Definition: RootDataConnection.h:236
Gaudi::RootDataConnection::Tool::dbs
StringVec & dbs() const
Definition: RootDataConnection.h:211
Gaudi::IDataConnection::m_name
std::string m_name
Connection name/identifier.
Definition: IIODataManager.h:29
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::FAILURE
Definition: StatusCode.h:31
Gaudi::IDataConnection::IoType
IoType
I/O Connection types.
Definition: IIODataManager.h:41
Gaudi::RootDataConnection::file
TFile * file() const
Direct access to TFile structure.
Definition: RootDataConnection.h:249
Gaudi::RootDataConnection::Tool::poolRef
virtual RootRef poolRef(size_t) const
Internal overload to facilitate the access to POOL files.
Definition: RootDataConnection.h:226
Gaudi::RootDataConnection::isConnected
bool isConnected() const override
Check if connected to data source.
Definition: RootDataConnection.h:251
Gaudi::RootDataConnection::MergeSections
std::map< std::string, ContainerSections > MergeSections
Definition of database section to handle merged files.
Definition: RootDataConnection.h:140
Gaudi::RootDataConnection::seek
long long int seek(long long int, int) override
Seek on the file described by ioDesc. Arguments as in ::seek()
Definition: RootDataConnection.h:303
Gaudi::RootDataConnection::m_statistics
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
Definition: RootDataConnection.h:153
Gaudi::RootDataConnection::m_clients
Clients m_clients
Client list.
Definition: RootDataConnection.h:175
Gaudi::RootDataConnection::ContainerSection::length
int length
The length of the section.
Definition: RootDataConnection.h:128
Gaudi::RootDataConnection::Tool::StringVec
RootDataConnection::StringVec StringVec
Definition: RootDataConnection.h:198
Gaudi::RootDataConnection::ContainerSection::start
int start
The start entry of the section.
Definition: RootDataConnection.h:126
Gaudi::RootDataConnection::Clients
std::set< const IInterface * > Clients
Client set.
Definition: RootDataConnection.h:144
Gaudi::RootConnectionSetup::msgSvc
MsgStream & msgSvc() const
Retrieve message service.
Definition: RootDataConnection.h:78
Gaudi::RootDataConnection::getLink
const std::string & getLink(int which) const
Access link name from saved index.
Definition: RootDataConnection.h:336
Gaudi::RootDataConnection::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:132
Gaudi::RootConnectionSetup::cacheSize
int cacheSize
RootCnvSvc Property: Root data cache size.
Definition: RootDataConnection.h:63
std::map< std::string, TTree * >
Gaudi::RootDataConnection::Tool::ContainerSections
RootDataConnection::ContainerSections ContainerSections
Definition: RootDataConnection.h:204
Gaudi::RootObjectRefs
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject...
Definition: RootRefs.h:60
Gaudi::RootDataConnection::m_links
StringVec m_links
Map containing internal links names.
Definition: RootDataConnection.h:165
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection()
Default constructor.
Definition: RootDataConnection.h:111
IIODataManager.h
Gaudi::RootDataConnection::m_params
ParamMap m_params
Parameter map for file parameters.
Definition: RootDataConnection.h:169
std::string
STL class.
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:14
Gaudi::RootConnectionSetup::loadSection
std::string loadSection
RootCnvSvc Property: Root data cache size.
Definition: RootDataConnection.h:61
Gaudi::RootDataConnection::Tool::params
ParamMap & params() const
Definition: RootDataConnection.h:214
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:228
Gaudi::RootDataConnection::m_mergeFIDs
StringVec m_mergeFIDs
Map containing merge FIDs.
Definition: RootDataConnection.h:167
Gaudi::RootDataConnection::Tool::mergeSections
MergeSections & mergeSections() const
Definition: RootDataConnection.h:219
Gaudi::RootRef
Persistent reference object.
Definition: RootRefs.h:31
Gaudi::RootDataConnection::write
StatusCode write(const void *, int) override
Write root byte buffer to output stream.
Definition: RootDataConnection.h:301
RootRefs.h
Gaudi::RootDataConnection::Tool::sections
Sections & sections() const
Definition: RootDataConnection.h:217
IIncidentSvc.h
Gaudi::RootDataConnection::Tool
Helper class to facilitate an abstraction layer for reading POOL style files with this package...
Definition: RootDataConnection.h:195
Gaudi::RootConnectionSetup::learnEntries
int learnEntries
RootCnvSvc Property: ROOT cache learn entries.
Definition: RootDataConnection.h:65
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:94
Gaudi::RootConnectionSetup::m_msgSvc
std::unique_ptr< MsgStream > m_msgSvc
Reference to message service.
Definition: RootDataConnection.h:48
IInterface
Definition of the basic interface.
Definition: IInterface.h:277
SmartIF.h
Gaudi::RootDataConnection::getBranch
TBranch * getBranch(const std::string &section, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
Definition: RootDataConnection.h:309
Gaudi::RootDataConnection::Tool::ParamMap
RootDataConnection::ParamMap ParamMap
Definition: RootDataConnection.h:199
Gaudi::RootDataConnection::ParamMap
std::vector< std::pair< std::string, std::string > > ParamMap
Type definition for the parameter map.
Definition: RootDataConnection.h:134
Gaudi::RootDataConnection::Tool::links
StringVec & links() const
Definition: RootDataConnection.h:213
Gaudi::RootDataConnection::m_conts
StringVec m_conts
Map containing external container names.
Definition: RootDataConnection.h:163
Gaudi::RootDataConnection::m_sections
Sections m_sections
Tree sections in TFile.
Definition: RootDataConnection.h:159
Gaudi::RootConnectionSetup::cacheBranches
StringVec cacheBranches
Vector of strings with branches to be cached for input files.
Definition: RootDataConnection.h:57
IOTest.start
start
Definition: IOTest.py:99
Gaudi::RootConnectionSetup::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:54
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
Gaudi::RootDataConnection::LinkSections
std::vector< RootRef > LinkSections
Link sections definition.
Definition: RootDataConnection.h:142
Gaudi::RootDataConnection::Tool::MergeSections
RootDataConnection::MergeSections MergeSections
Definition: RootDataConnection.h:201
Gaudi::RootDataConnection::Tool::msgSvc
MsgStream & msgSvc() const
Definition: RootDataConnection.h:215
Gaudi::RootDataConnection::getCont
const std::string & getCont(int which) const
Access container name from saved index.
Definition: RootDataConnection.h:330
Gaudi::RootDataConnection::tool
Tool * tool() const
Access tool.
Definition: RootDataConnection.h:255
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection(int s, int l)
Initializing constructor.
Definition: RootDataConnection.h:113
Gaudi::RootConnectionSetup::vetoBranches
StringVec vetoBranches
Vector of strings with branches to NOT be cached for input files.
Definition: RootDataConnection.h:59
gaudirun.l
dictionary l
Definition: gaudirun.py:440
std::pair
Gaudi::RootDataConnection::mergeFIDs
const StringVec & mergeFIDs() const
Access merged FIDs.
Definition: RootDataConnection.h:259
std::unique_ptr::get
T get(T...args)
std::vector::size
T size(T...args)
std::set< const IInterface * >
Gaudi::RootDataConnection::ContainerSection::operator=
ContainerSection & operator=(const ContainerSection &s)
Assignment operator to copy objects.
Definition: RootDataConnection.h:117
std::vector< std::string >
Gaudi::RootDataConnection::Tool::ContainerSection
RootDataConnection::ContainerSection ContainerSection
Definition: RootDataConnection.h:203
Gaudi::RootDataConnection::isWritable
bool isWritable() const
Is the file writable?
Definition: RootDataConnection.h:253
std::unique_ptr< MsgStream >
Gaudi::IDataConnection
ABC describing basic data connection.
Definition: IIODataManager.h:25
Gaudi::RootDataConnection::Tool::LinkSections
RootDataConnection::LinkSections LinkSections
Definition: RootDataConnection.h:202
Gaudi::RootConnectionSetup::incidentSvc
IIncidentSvc * incidentSvc() const
Retrieve incident service.
Definition: RootDataConnection.h:83
Gaudi::RootDataConnection::Tool::conts
StringVec & conts() const
Definition: RootDataConnection.h:212
Gaudi::RootDataConnection::Tool::refs
TTree * refs() const
Definition: RootDataConnection.h:210
Gaudi::RootDataConnection::m_setup
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
Definition: RootDataConnection.h:151
std::vector::begin
T begin(T...args)
Gaudi::RootDataConnection::m_linkSects
LinkSections m_linkSects
Database link sections.
Definition: RootDataConnection.h:173
GaudiTesting.BaseTest.which
def which(executable)
Definition: BaseTest.py:570
Gaudi::RootDataConnection::msgSvc
MsgStream & msgSvc() const
Allow access to printer service.
Definition: RootDataConnection.h:147
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
gaudirun.s
string s
Definition: gaudirun.py:253
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection(const ContainerSection &s)
Copy constructor.
Definition: RootDataConnection.h:115
Gaudi::RootDataConnection::Tool::c
RootDataConnection * c
Pointer to containing data connection object.
Definition: RootDataConnection.h:207
Gaudi::RootDataConnection::m_file
std::unique_ptr< TFile > m_file
Reference to ROOT file.
Definition: RootDataConnection.h:155
Gaudi::RootConnectionSetup
Definition: RootDataConnection.h:44
Gaudi::RootDataConnection::m_dbs
StringVec m_dbs
Map containing external database file names (fids)
Definition: RootDataConnection.h:161
Gaudi::RootDataConnection::m_empty
std::string m_empty
Buffer for empty string reference.
Definition: RootDataConnection.h:177
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
Gaudi::RootDataConnection
Concrete implementation of the IDataConnection interface to access ROOT files.
Definition: RootDataConnection.h:94
Gaudi::RootDataConnection::m_refs
TTree * m_refs
Pointer to the reference tree.
Definition: RootDataConnection.h:157
Gaudi::RootDataConnection::read
StatusCode read(void *const, size_t) override
Read root byte buffer from input stream.
Definition: RootDataConnection.h:299
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::RootDataConnection::ContainerSection
Internal helper class, which described a TBranch section in a ROOT file.
Definition: RootDataConnection.h:109
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
Gaudi::RootDataConnection::Tool::linkSections
LinkSections & linkSections() const
Definition: RootDataConnection.h:218
Gaudi::RootDataConnection::Sections
std::map< std::string, TTree * > Sections
Definition of tree sections.
Definition: RootDataConnection.h:136