| The Gaudi Framework v32r1 (f65d50dc)

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 <string_view>
13 #include <vector>
14
15 #include "RootCnv/RootRefs.h"
16 #include "TFile.h"
17 #include "TTreePerfStats.h"
18
19 // Forward declarations
20 class TTree;
21 class TClass;
22 class TBranch;
23
24 class MsgStream;
25 class IRegistry;
26 class DataObject;
27 class IIncidentSvc;
28
29 /*
30 * Gaudi namespace declaration
31 */
32 namespace Gaudi {
33
44 class GAUDI_API RootConnectionSetup final {
45 private:
47 std::unique_ptr<MsgStream> m_msgSvc;
49 SmartIF<IIncidentSvc> m_incidentSvc = nullptr;
50
51 public:
53 typedef std::vector<std::string> StringVec;
54
56 StringVec cacheBranches;
58 StringVec vetoBranches;
60 std::string loadSection;
62 int cacheSize;
64 int learnEntries;
65
67 RootConnectionSetup() = default;
68
70 static StatusCode setCompression( std::string_view compression );
72 static int compression();
73
75 void setMessageSvc( MsgStream* m );
77 MsgStream& msgSvc() const { return *m_msgSvc; }
78
80 void setIncidentSvc( IIncidentSvc* m );
82 IIncidentSvc* incidentSvc() const { return m_incidentSvc.get(); }
83 };
84
93 class GAUDI_API RootDataConnection : virtual public Gaudi::IDataConnection {
94 public:
95 enum class Status : StatusCode::code_t { ROOT_READ_ERROR = 0x2, ROOT_OPEN_ERROR = 0x4 };
96
107 struct ContainerSection {
109 ContainerSection() : start( -1 ), length( 0 ) {}
111 ContainerSection( int s, int l ) : start( s ), length( l ) {}
113 ContainerSection( const ContainerSection& s ) : start( s.start ), length( s.length ) {}
115 ContainerSection& operator=( const ContainerSection& s ) {
116 if ( this != &s ) {
117 start = s.start;
118 length = s.length;
119 }
120 return *this;
121 }
123 int start;
125 int length;
126 };
127
129 typedef std::vector<std::string> StringVec;
131 typedef std::vector<std::pair<std::string, std::string>> ParamMap;
133 typedef std::map<std::string, TTree*, std::less<>> Sections;
135 typedef std::vector<ContainerSection> ContainerSections;
137 typedef std::map<std::string, ContainerSections, std::less<>> MergeSections;
139 typedef std::vector<RootRef> LinkSections;
141 typedef std::set<const IInterface*> Clients;
142
144 MsgStream& msgSvc() const { return m_setup->msgSvc(); }
145
146 protected:
148 std::shared_ptr<RootConnectionSetup> m_setup;
150 std::unique_ptr<TTreePerfStats> m_statistics;
152 std::unique_ptr<TFile> m_file;
154 TTree* m_refs = nullptr;
156 Sections m_sections;
158 StringVec m_dbs;
160 StringVec m_conts;
162 StringVec m_links;
164 StringVec m_mergeFIDs;
166 ParamMap m_params;
168 MergeSections m_mergeSects;
170 LinkSections m_linkSects;
172 Clients m_clients;
174 std::string m_empty;
175
177 const std::string& empty() const;
178
180 StatusCode saveRefs();
181
182 public:
192 class Tool {
193 protected:
194 typedef RootDataConnection::StringVec StringVec;
195 typedef RootDataConnection::ParamMap ParamMap;
196 typedef RootDataConnection::Sections Sections;
197 typedef RootDataConnection::MergeSections MergeSections;
198 typedef RootDataConnection::LinkSections LinkSections;
199 typedef RootDataConnection::ContainerSection ContainerSection;
200 typedef RootDataConnection::ContainerSections ContainerSections;
201
203 RootDataConnection* c;
204
205 public:
206 TTree* refs() const { return c->m_refs; }
207 StringVec& dbs() const { return c->m_dbs; }
208 StringVec& conts() const { return c->m_conts; }
209 StringVec& links() const { return c->m_links; }
210 ParamMap& params() const { return c->m_params; }
211 MsgStream& msgSvc() const { return c->msgSvc(); }
212 const std::string& name() const { return c->m_name; }
213 Sections& sections() const { return c->m_sections; }
214 LinkSections& linkSections() const { return c->m_linkSects; }
215 MergeSections& mergeSections() const { return c->m_mergeSects; }
216
218 virtual ~Tool() = default;
220 virtual TBranch* getBranch( std::string_view section, std::string_view n ) = 0;
222 virtual RootRef poolRef( size_t /* which */ ) const { return RootRef(); }
223
225 virtual StatusCode readRefs() = 0;
227 virtual StatusCode saveRefs() = 0;
229 virtual int loadRefs( std::string_view section, std::string_view cnt, unsigned long entry,
230 RootObjectRefs& refs ) = 0;
231 };
232 std::unique_ptr<Tool> m_tool;
233 friend class Tool;
234
236 Tool* makeTool();
237
238 public:
240 RootDataConnection( const IInterface* own, std::string_view nam, std::shared_ptr<RootConnectionSetup> setup );
241
243 TFile* file() const { return m_file.get(); }
245 bool isConnected() const override { return bool( m_file ); }
247 bool isWritable() const { return m_file && m_file->IsWritable(); }
249 Tool* tool() const { return m_tool.get(); }
251 const MergeSections& mergeSections() const { return m_mergeSects; }
253 const StringVec& mergeFIDs() const { return m_mergeFIDs; }
254
256 void addClient( const IInterface* client );
258 size_t removeClient( const IInterface* client );
260 bool lookupClient( const IInterface* client ) const;
261
263 void badWriteError( std::string_view msg ) const;
264
266 std::pair<const RootRef*, const ContainerSection*> getMergeSection( std::string_view container, int entry ) const;
267
269 void enableStatistics( std::string_view section );
271 void saveStatistics( std::string_view statisticsFile );
272
274 int loadObj( std::string_view section, std::string_view cnt, unsigned long entry, DataObject*& pObj );
275
277 int loadRefs( std::string_view section, std::string_view cnt, unsigned long entry, RootObjectRefs& refs );
278
280 std::pair<int, unsigned long> saveObj( std::string_view section, std::string_view cnt, TClass* cl, DataObject* pObj,
281 int buff_siz, int split_lvl, bool fill_missing = false );
283 std::pair<int, unsigned long> save( std::string_view section, std::string_view cnt, TClass* cl, void* pObj,
284 int buff_siz, int split_lvl, bool fill_missing = false );
285
287 StatusCode connectRead() override;
289 StatusCode connectWrite( IoType typ ) override;
291 StatusCode disconnect() override;
293 StatusCode read( void* const, size_t ) override { return StatusCode::FAILURE; }
295 StatusCode write( const void*, int ) override { return StatusCode::FAILURE; }
297 long long int seek( long long int, int ) override { return -1; }
298
300 TTree* getSection( std::string_view sect, bool create = false );
301
303 TBranch* getBranch( std::string_view section, std::string_view branch_name ) {
304 return m_tool->getBranch( section, branch_name );
305 }
307 TBranch* getBranch( std::string_view section, std::string_view branch_name, TClass* cl, void* ptr, int buff_siz,
308 int split_lvl );
309
311 void makeRef( const IRegistry& pA, RootRef& ref );
313 void makeRef( std::string_view name, long clid, int tech, std::string_view db, std::string_view cnt, int entry,
314 RootRef& ref );
315
317 int makeLink( std::string_view p );
318
320 const std::string& getDb( int which ) const;
321
323 const std::string& getCont( int which ) const {
324 return ( which >= 0 ) && ( size_t( which ) < m_conts.size() ) ? *( m_conts.begin() + which ) : empty();
325 }
326
328 const std::string& getLink( int which ) const {
329 return ( which >= 0 ) && ( size_t( which ) < m_links.size() ) ? *( m_links.begin() + which ) : empty();
330 }
331 };
332 } // End namespace Gaudi
333
334 STATUSCODE_ENUM_DECL( Gaudi::RootDataConnection::Status )
335
336 #endif // GAUDIROOT_ROOTDATACONNECTION_H
Gaudi::RootDataConnection::m_mergeSects
MergeSections m_mergeSects
Database section map for merged files.
Definition: RootDataConnection.h:168
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
std::shared_ptr
STL class.
SmartIF< IIncidentSvc >
ClassID.h
Gaudi::RootDataConnection::getBranch
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
Definition: RootDataConnection.h:303
Gaudi::RootDataConnection::mergeSections
const MergeSections & mergeSections() const
Access merged data section inventory.
Definition: RootDataConnection.h:251
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::RootDataConnection::Tool::links
StringVec & links() const
Definition: RootDataConnection.h:209
Gaudi::RootDataConnection::Tool::Sections
RootDataConnection::Sections Sections
Definition: RootDataConnection.h:196
Gaudi::RootDataConnection::ContainerSections
std::vector< ContainerSection > ContainerSections
Definition of container sections to handle merged files.
Definition: RootDataConnection.h:135
Gaudi::RootDataConnection::m_tool
std::unique_ptr< Tool > m_tool
Definition: RootDataConnection.h:232
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::RootDataConnection::tool
Tool * tool() const
Access tool.
Definition: RootDataConnection.h:249
Gaudi::RootDataConnection::Tool::mergeSections
MergeSections & mergeSections() const
Definition: RootDataConnection.h:215
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:297
Gaudi::RootDataConnection::Tool::refs
TTree * refs() const
Definition: RootDataConnection.h:206
Gaudi::RootDataConnection::m_statistics
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
Definition: RootDataConnection.h:150
Gaudi::RootDataConnection::MergeSections
std::map< std::string, ContainerSections, std::less<> > MergeSections
Definition of database section to handle merged files.
Definition: RootDataConnection.h:137
Gaudi::RootDataConnection::Tool::poolRef
virtual RootRef poolRef(size_t) const
Internal overload to facilitate the access to POOL files.
Definition: RootDataConnection.h:222
Gaudi::RootDataConnection::m_clients
Clients m_clients
Client list.
Definition: RootDataConnection.h:172
Gaudi::RootDataConnection::ContainerSection::length
int length
The length of the section.
Definition: RootDataConnection.h:125
Gaudi::RootDataConnection::Tool::StringVec
RootDataConnection::StringVec StringVec
Definition: RootDataConnection.h:194
Gaudi::RootDataConnection::ContainerSection::start
int start
The start entry of the section.
Definition: RootDataConnection.h:123
Gaudi::RootDataConnection::Clients
std::set< const IInterface * > Clients
Client set.
Definition: RootDataConnection.h:141
Gaudi::RootConnectionSetup::incidentSvc
IIncidentSvc * incidentSvc() const
Retrieve incident service.
Definition: RootDataConnection.h:82
Gaudi::RootDataConnection::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:129
Gaudi::RootDataConnection::Tool::linkSections
LinkSections & linkSections() const
Definition: RootDataConnection.h:214
Gaudi::RootDataConnection::mergeFIDs
const StringVec & mergeFIDs() const
Access merged FIDs.
Definition: RootDataConnection.h:253
Gaudi::RootDataConnection::Tool::params
ParamMap & params() const
Definition: RootDataConnection.h:210
Gaudi::RootConnectionSetup::cacheSize
int cacheSize
RootCnvSvc Property: Root data cache size.
Definition: RootDataConnection.h:62
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
IOTest.start
def start
Definition: IOTest.py:97
std::map
STL class.
Gaudi::RootDataConnection::Tool::ContainerSections
RootDataConnection::ContainerSections ContainerSections
Definition: RootDataConnection.h:200
Gaudi::RootDataConnection::Status
Status
Definition: RootDataConnection.h:95
Gaudi::RootObjectRefs
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject.
Definition: extractEvt.C:71
Gaudi::RootDataConnection::m_links
StringVec m_links
Map containing internal links names.
Definition: RootDataConnection.h:162
Gaudi::RootDataConnection::isConnected
bool isConnected() const override
Check if connected to data source.
Definition: RootDataConnection.h:245
Gaudi::RootDataConnection::msgSvc
MsgStream & msgSvc() const
Allow access to printer service.
Definition: RootDataConnection.h:144
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection()
Default constructor.
Definition: RootDataConnection.h:109
IIODataManager.h
Gaudi::RootDataConnection::m_params
ParamMap m_params
Parameter map for file parameters.
Definition: RootDataConnection.h:166
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:60
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:210
Gaudi::RootDataConnection::m_mergeFIDs
StringVec m_mergeFIDs
Map containing merge FIDs.
Definition: RootDataConnection.h:164
Gaudi::RootRef
Persistent reference object.
Definition: extractEvt.C:34
Gaudi::RootDataConnection::write
StatusCode write(const void *, int) override
Write root byte buffer to output stream.
Definition: RootDataConnection.h:295
STATUSCODE_ENUM_DECL
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
Definition: StatusCode.h:239
Gaudi::RootDataConnection::getCont
const std::string & getCont(int which) const
Access container name from saved index.
Definition: RootDataConnection.h:323
RootRefs.h
IIncidentSvc.h
Gaudi::RootDataConnection::Tool
Helper class to facilitate an abstraction layer for reading POOL style files with this package.
Definition: RootDataConnection.h:192
Gaudi::RootConnectionSetup::learnEntries
int learnEntries
RootCnvSvc Property: ROOT cache learn entries.
Definition: RootDataConnection.h:64
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:92
Gaudi::RootConnectionSetup::m_msgSvc
std::unique_ptr< MsgStream > m_msgSvc
Reference to message service.
Definition: RootDataConnection.h:47
IInterface
Definition of the basic interface.
Definition: IInterface.h:244
SmartIF.h
Gaudi::RootDataConnection::Tool::ParamMap
RootDataConnection::ParamMap ParamMap
Definition: RootDataConnection.h:195
Gaudi::RootDataConnection::ParamMap
std::vector< std::pair< std::string, std::string > > ParamMap
Type definition for the parameter map.
Definition: RootDataConnection.h:131
Gaudi::RootDataConnection::getLink
const std::string & getLink(int which) const
Access link name from saved index.
Definition: RootDataConnection.h:328
Gaudi::RootDataConnection::m_conts
StringVec m_conts
Map containing external container names.
Definition: RootDataConnection.h:160
Gaudi::RootDataConnection::m_sections
Sections m_sections
Tree sections in TFile.
Definition: RootDataConnection.h:156
Gaudi::RootConnectionSetup::cacheBranches
StringVec cacheBranches
Vector of strings with branches to be cached for input files.
Definition: RootDataConnection.h:56
Gaudi::RootDataConnection::Tool::dbs
StringVec & dbs() const
Definition: RootDataConnection.h:207
Gaudi::RootConnectionSetup::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:53
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:139
Gaudi::RootDataConnection::Tool::MergeSections
RootDataConnection::MergeSections MergeSections
Definition: RootDataConnection.h:197
Gaudi::RootDataConnection::Tool::conts
StringVec & conts() const
Definition: RootDataConnection.h:208
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection(int s, int l)
Initializing constructor.
Definition: RootDataConnection.h:111
Gaudi::RootConnectionSetup::vetoBranches
StringVec vetoBranches
Vector of strings with branches to NOT be cached for input files.
Definition: RootDataConnection.h:58
Gaudi::RootConnectionSetup::msgSvc
MsgStream & msgSvc() const
Retrieve message service.
Definition: RootDataConnection.h:77
gaudirun.l
dictionary l
Definition: gaudirun.py:521
std::pair
std::unique_ptr::get
T get(T... args)
Gaudi::RootDataConnection::Tool::name
const std::string & name() const
Definition: RootDataConnection.h:212
Gaudi::RootDataConnection::Tool::msgSvc
MsgStream & msgSvc() const
Definition: RootDataConnection.h:211
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:115
std::vector< std::string >
Gaudi::RootDataConnection::Tool::ContainerSection
RootDataConnection::ContainerSection ContainerSection
Definition: RootDataConnection.h:199
std::unique_ptr< MsgStream >
Gaudi::IDataConnection
ABC describing basic data connection.
Definition: IIODataManager.h:24
Gaudi::RootDataConnection::Tool::LinkSections
RootDataConnection::LinkSections LinkSections
Definition: RootDataConnection.h:198
Gaudi::RootDataConnection::m_setup
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
Definition: RootDataConnection.h:148
std::vector::begin
T begin(T... args)
Gaudi::RootDataConnection::m_linkSects
LinkSections m_linkSects
Database link sections.
Definition: RootDataConnection.h:170
GaudiTesting.BaseTest.which
def which(executable)
Definition: BaseTest.py:632
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
gaudirun.s
string s
Definition: gaudirun.py:316
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::RootDataConnection::ContainerSection::ContainerSection
ContainerSection(const ContainerSection &s)
Copy constructor.
Definition: RootDataConnection.h:113
Gaudi::RootDataConnection::Sections
std::map< std::string, TTree *, std::less<> > Sections
Definition of tree sections.
Definition: RootDataConnection.h:133
Gaudi::RootDataConnection::Tool::c
RootDataConnection * c
Pointer to containing data connection object.
Definition: RootDataConnection.h:203
Gaudi::RootDataConnection::file
TFile * file() const
Direct access to TFile structure.
Definition: RootDataConnection.h:243
Gaudi::RootDataConnection::m_file
std::unique_ptr< TFile > m_file
Reference to ROOT file.
Definition: RootDataConnection.h:152
Gaudi::RootDataConnection::isWritable
bool isWritable() const
Is the file writable?
Definition: RootDataConnection.h:247
Gaudi::RootConnectionSetup
Definition: RootDataConnection.h:44
Gaudi::RootDataConnection::m_dbs
StringVec m_dbs
Map containing external database file names (fids)
Definition: RootDataConnection.h:158
Gaudi::RootDataConnection::m_empty
std::string m_empty
Buffer for empty string reference.
Definition: RootDataConnection.h:174
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Gaudi::RootDataConnection
Concrete implementation of the IDataConnection interface to access ROOT files.
Definition: RootDataConnection.h:93
Gaudi::RootDataConnection::read
StatusCode read(void *const, size_t) override
Read root byte buffer from input stream.
Definition: RootDataConnection.h:293
Gaudi::RootDataConnection::Tool::sections
Sections & sections() const
Definition: RootDataConnection.h:213
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::RootDataConnection::ContainerSection
Internal helper class, which described a TBranch section in a ROOT file.
Definition: RootDataConnection.h:107
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
StatusCode::code_t
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:52