| The Gaudi Framework v32r1 (f65d50dc)

PoolTool.h
Go to the documentation of this file.
1 #include "RootCnv/PoolClasses.h"
2 #include <algorithm>
3 /*
4 * Gaudi namespace declaration
5 */
6 namespace Gaudi {
7
17 class PoolTool : virtual public RootDataConnection::Tool {
19 std::vector<Gaudi::RootRef> m_poolLinks;
20
21 public:
23 PoolTool( RootDataConnection* con ) { c = con; }
24
26 string _treeName( std::string_view sr ) {
27 std::string t{sr};
28 std::replace( begin( t ), end( t ), '/', '_' );
29 return t;
30 }
31
32 RootRef poolRef( size_t i ) const override { return m_poolLinks[i]; }
33
35 int loadRefs( std::string_view /* section */, std::string_view cnt, unsigned long entry,
36 RootObjectRefs& refs ) override {
37 auto ti = sections().find( cnt );
38 TTree* t = ( ti != sections().end() ? ti->second : nullptr );
39 if ( !t ) { t = (TTree*)c->file()->Get( _treeName( cnt ).c_str() ); }
40 if ( t ) {
41 TBranch* b1 = t->GetBranch( "Links" );
42 TBranch* b2 = t->GetBranch( "Refs" );
43 MsgStream& msg = msgSvc();
44 if ( b1 && b2 ) {
45 LinkManager lm, *plm = &lm;
46 PoolDbLinkManager mgr, *pmgr = &mgr;
47 b1->SetAutoDelete( kFALSE );
48 b2->SetAutoDelete( kFALSE );
49 b1->SetAddress( &plm );
50 b2->SetAddress( &pmgr );
51 int nb1 = b1->GetEvent( entry );
52 int nb2 = b2->GetEvent( entry );
53 if ( nb1 > 1 && nb2 > 1 ) {
54 size_t ref_size = mgr.references().size();
55 refs.refs.resize( ref_size );
56 msg << MSG::VERBOSE;
57 for ( size_t j = 0; j < ref_size; ++j ) {
58 const pair<int, int>& oid = mgr.references()[j]->m_oid;
59 string loc = mgr.links()[j].substr( 1 );
60 RootRef& r = refs.refs[j];
61 if ( oid.first >= 0 ) {
62 r = m_poolLinks[oid.first];
63 r.entry = oid.second;
64 r.link = c->makeLink( loc );
65 msg << "Add leaf:" << oid.first << "->" << loc << " from " << c->getDb( r.dbase ) << "#"
66 << c->getCont( r.container ) << " Link:" << c->getLink( r.link ) << " CLID:" << hex << r.clid
67 << " Typ:" << hex << int( r.svc ) << " Ent:" << dec << r.entry << endl;
68 }
69 }
70 for ( int i = 0, n = lm.size(); i < n; ++i ) {
71 LinkManager::Link* lnk = lm.link( i );
72 int link_id = c->makeLink( lnk->path() );
73 msg << "Add Link:" << lnk->path() << endl;
74 refs.links.push_back( link_id );
75 }
76 return nb1 + nb2;
77 }
78 }
79 msg << MSG::ERROR << "Failed to access POOL Ref/Link branches:" << cnt << " [" << _treeName( cnt ) << "]"
80 << endmsg;
81 t->Print();
82 }
83 return -1;
84 }
85
87 TBranch* getBranch( std::string_view /* section */, std::string_view branch_name ) override {
88 auto ti = sections().find( branch_name );
89 TTree* t = ( ti != sections().end() ? ti->second : nullptr );
90 if ( t ) { return (TBranch*)t->GetListOfBranches()->At( 0 ); }
91 string tname = _treeName( branch_name );
92 t = (TTree*)c->file()->Get( tname.c_str() ); // c->getSection(tname);
93 if ( t ) {
94 TBranch* b = (TBranch*)t->GetListOfBranches()->At( 0 );
95 if ( b ) {
96 sections()[std::string{branch_name}] = t;
97 return b;
98 }
99 msgSvc() << MSG::ERROR << "Failed to access POOL branch:" << branch_name << " [" << tname << "]" << endmsg;
100 t->Print();
101 }
102 return nullptr;
103 }
104
106 StatusCode saveRefs() override { return StatusCode::FAILURE; }
107
109 StatusCode readRefs() override {
110 int i;
111 char text[2048];
112 msgSvc() << MSG::VERBOSE;
113
114 // First read ##Params
115 TTree* t = (TTree*)c->file()->Get( "##Params" );
116 if ( !t ) return StatusCode::FAILURE;
117 TBranch* b = t->GetBranch( "db_string" );
118 if ( !b ) return StatusCode::FAILURE;
119 for ( i = 0, b->SetAddress( text ); i < b->GetEntries(); ++i ) {
120 b->GetEvent( i );
121 char* id1 = strstr( text, "[NAME=" );
122 char* id2 = strstr( text, "[VALUE=" );
123 if ( id1 && id2 ) {
124 id1 += 6;
125 id2 += 7;
126 char* id11 = strstr( id1, "]" );
127 char* id22 = strstr( id2, "]" );
128 if ( id11 && id22 ) {
129 *id11 = 0;
130 *id22 = 0;
131 params().emplace_back( id1, id2 );
132 msgSvc() << "Param:" << id1 << "=" << id2 << "." << endmsg;
133 }
134 }
135 }
136
137 // Read ##Links
138 t = (TTree*)c->file()->Get( "##Links" );
139 if ( !t ) return StatusCode::FAILURE;
140 b = t->GetBranch( "db_string" );
141 if ( !b ) return StatusCode::FAILURE;
142 m_poolLinks.resize( (size_t)b->GetEntries() + 2 ); // Take into account the ##Links and ##Shapes entry of POOL!
143 for ( i = 0, b->SetAddress( text ); i < b->GetEntries(); ++i ) {
144 b->GetEvent( i );
145 std::string db, container;
146 int clid = 1, technology = 0, ipar[2] = {-1, -1};
147 for ( char* p1 = (char*)text; p1; p1 = ::strchr( ++p1, '[' ) ) {
148 char* p2 = ::strchr( p1, '=' );
149 char* p3 = ::strchr( p1, ']' );
150 if ( p2 && p3 ) {
151 if ( ::strncmp( "[DB=", p1, 4 ) == 0 ) {
152 *p3 = 0;
153 db = p1 + 4;
154 } else if ( ::strncmp( "[CNT=", p1, 5 ) == 0 ) {
155 *p3 = 0;
156 container = p1 + 5;
157 } else if ( ::strncmp( "[OID=", p1, 5 ) == 0 ) {
158 *p3 = 0;
159 ::sscanf( p1 + 5, "%08X,%08X", (unsigned int*)&ipar[0], (unsigned int*)&ipar[1] );
160 } else if ( ::strncmp( "[CLID=", p1, 6 ) == 0 ) {
161 *p3 = 0;
162 ::sscanf( p1 + 6, "%08X", (unsigned int*)&clid );
163 } else if ( ::strncmp( "[TECH=", p1, 6 ) == 0 ) {
164 *p3 = 0;
165 ::sscanf( p1 + 6, "%08X", (unsigned int*)&technology );
166 } else {
167 *p3 = *p2 = 0;
168 }
169 *p3 = ']';
170 *p2 = '=';
171 }
172 }
173 c->makeRef( "", clid, technology, db, container, -1, m_poolLinks[i + 2] );
174 RootRef& r = m_poolLinks[i];
175 msgSvc() << "Add link[" << i << "]:" << db << container << " [" << r.dbase << "," << r.container << "] "
176 << " tech:" << hex << setw( 8 ) << r.svc << " CLID:" << setw( 8 ) << r.clid << dec << endmsg;
177 }
178 return StatusCode::SUCCESS;
179 }
180 };
181 } // namespace Gaudi
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Gaudi::Units::sr
constexpr double sr
Definition: SystemOfUnits.h:114
Gaudi::PoolTool::saveRefs
StatusCode saveRefs() override
Save references section when closing data file (NOT SUPPORTED)
Definition: PoolTool.h:106
Gaudi::RootDataConnection::makeLink
int makeLink(std::string_view p)
Convert path string to path index.
Definition: RootDataConnection.cpp:440
Gaudi::RootDataConnection::Tool::refs
TTree * refs() const
Definition: RootDataConnection.h:206
PoolDbLinkManager::references
std::vector< pool::Token * > & references()
Access to token array.
Definition: PoolClasses.h:109
Gaudi::PoolTool::m_poolLinks
std::vector< Gaudi::RootRef > m_poolLinks
Image of the POOL ##Links table.
Definition: PoolTool.h:19
MSG::dec
MsgStream & dec(MsgStream &log)
Definition: MsgStream.h:267
PoolClasses.h
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Gaudi::RootRef::container
int container
Definition: extractEvt.C:36
std::map::end
T end(T... args)
Gaudi::RootRef::entry
int entry
Definition: extractEvt.C:36
Gaudi::RootDataConnection::Tool::params
ParamMap & params() const
Definition: RootDataConnection.h:210
Gaudi::RootDataConnection::getDb
const std::string & getDb(int which) const
Access database/file name from saved index.
Definition: RootDataConnection.cpp:448
MSG::hex
MsgStream & hex(MsgStream &log)
Definition: MsgStream.h:271
MSG::VERBOSE
Definition: IMessageSvc.h:15
Gaudi::RootObjectRefs
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject.
Definition: extractEvt.C:71
std::vector::resize
T resize(T... args)
std::string
STL class.
Gaudi::PoolTool::loadRefs
int loadRefs(std::string_view, std::string_view cnt, unsigned long entry, RootObjectRefs &refs) override
Load references object from file.
Definition: PoolTool.h:35
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:210
Gaudi::RootRef::dbase
int dbase
Data members to define object location in the persistent world.
Definition: extractEvt.C:36
PoolDbLinkManager::links
std::vector< std::string > & links()
Access to link array.
Definition: PoolClasses.h:111
Gaudi::RootRef
Persistent reference object.
Definition: extractEvt.C:34
CFinViewTest.b1
b1
Definition: CFinViewTest.py:79
Gaudi::RootDataConnection::getCont
const std::string & getCont(int which) const
Access container name from saved index.
Definition: RootDataConnection.h:323
Gaudi::PoolTool::PoolTool
PoolTool(RootDataConnection *con)
Standard constructor.
Definition: PoolTool.h:23
std::replace
T replace(T... args)
PoolDbLinkManager
Description: PoolDbLinkManager class implementation definition.
Definition: PoolClasses.h:94
Gaudi::RootDataConnection::Tool
Helper class to facilitate an abstraction layer for reading POOL style files with this package.
Definition: RootDataConnection.h:192
CFinViewTest.b2
b2
Definition: CFinViewTest.py:82
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
LinkManager::Link::path
const std::string & path() const
Access to path of object.
Definition: LinkManager.h:61
LinkManager::link
Link * link(long id)
Retrieve symbolic link identified by ID.
Definition: LinkManager.cpp:29
Gaudi::RootDataConnection::getLink
const std::string & getLink(int which) const
Access link name from saved index.
Definition: RootDataConnection.h:328
IOTest.end
def end
Definition: IOTest.py:112
Gaudi::RootRef::clid
int clid
Definition: extractEvt.C:36
Gaudi::RootDataConnection::Tool::msgSvc
MsgStream & msgSvc() const
Definition: RootDataConnection.h:211
std::map::find
T find(T... args)
std::vector::size
T size(T... args)
std::vector< Gaudi::RootRef >
Gaudi::PoolTool::poolRef
RootRef poolRef(size_t i) const override
Internal overload to facilitate the access to POOL files.
Definition: PoolTool.h:32
Gaudi::RootRef::link
int link
Definition: extractEvt.C:36
Gaudi::PoolTool::getBranch
TBranch * getBranch(std::string_view, std::string_view branch_name) override
Access data branch by name: Get existing branch in read only mode.
Definition: PoolTool.h:87
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
LinkManager::size
long size() const
Retrieve number of link present.
Definition: LinkManager.h:100
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MSG::ERROR
Definition: IMessageSvc.h:15
Gaudi::RootDataConnection::Tool::c
RootDataConnection * c
Pointer to containing data connection object.
Definition: RootDataConnection.h:203
Gaudi::RootRef::svc
int svc
Definition: extractEvt.C:36
Gaudi::RootDataConnection::makeRef
void makeRef(const IRegistry &pA, RootRef &ref)
Create reference object from registry entry.
Definition: RootDataConnection.cpp:590
Gaudi::RootDataConnection::file
TFile * file() const
Direct access to TFile structure.
Definition: RootDataConnection.h:243
Gaudi::PoolTool::readRefs
StatusCode readRefs() override
Internal helper to read reference tables ##Params and ##Links.
Definition: PoolTool.h:109
LinkManager::Link
Embedded class defining a symbolic link Note: No copy constructor; bitwise copy (done by the compiler...
Definition: LinkManager.h:31
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:120
Gaudi::RootDataConnection
Concrete implementation of the IDataConnection interface to access ROOT files.
Definition: RootDataConnection.h:93
LinkManager
A LinkManager is the object aggregated into a DataObject, which is responsible for the handling of no...
Definition: LinkManager.h:21
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::PoolTool::_treeName
string _treeName(std::string_view sr)
Convert TES object identifier to ROOT tree name.
Definition: PoolTool.h:26
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi::PoolTool
Definition: PoolTool.h:17
std::vector::emplace_back
T emplace_back(T... args)