The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
Gaudi::PoolTool Class Reference

#include </builds/gaudi/Gaudi/RootCnv/src/PoolTool.h>

Inheritance diagram for Gaudi::PoolTool:
Collaboration diagram for Gaudi::PoolTool:

Public Member Functions

 PoolTool (RootDataConnection *con)
 Standard constructor.
 
string _treeName (std::string_view sr)
 Convert TES object identifier to ROOT tree name.
 
RootRef poolRef (size_t i) const override
 Internal overload to facilitate the access to POOL files.
 
int loadRefs (std::string_view, std::string_view cnt, unsigned long entry, RootObjectRefs &refs) override
 Load references object from file.
 
TBranch * getBranch (std::string_view, std::string_view branch_name) override
 Access data branch by name: Get existing branch in read only mode.
 
StatusCode saveRefs () override
 Save references section when closing data file (NOT SUPPORTED)
 
StatusCode readRefs () override
 Internal helper to read reference tables ##Params and ##Links.
 
- Public Member Functions inherited from Gaudi::RootDataConnection::Tool
TTree * refs () const
 
StringVecdbs () const
 
StringVecconts () const
 
StringVeclinks () const
 
ParamMapparams () const
 
MsgStreammsgSvc () const
 
IIncidentSvcincidentSvc () const
 
const std::string & name () const
 
Sectionssections () const
 
LinkSectionslinkSections () const
 
MergeSectionsmergeSections () const
 
virtual ~Tool ()=default
 Default destructor.
 

Private Attributes

std::vector< Gaudi::RootRefm_poolLinks
 Image of the POOL ##Links table.
 

Additional Inherited Members

- Protected Types inherited from Gaudi::RootDataConnection::Tool
typedef RootDataConnection::StringVec StringVec
 
typedef RootDataConnection::ParamMap ParamMap
 
typedef RootDataConnection::Sections Sections
 
typedef RootDataConnection::MergeSections MergeSections
 
typedef RootDataConnection::LinkSections LinkSections
 
typedef RootDataConnection::ContainerSection ContainerSection
 
typedef RootDataConnection::ContainerSections ContainerSections
 
- Protected Attributes inherited from Gaudi::RootDataConnection::Tool
RootDataConnectionc
 Pointer to containing data connection object.
 

Detailed Description

Definition at line 30 of file PoolTool.h.

Constructor & Destructor Documentation

◆ PoolTool()

Gaudi::PoolTool::PoolTool ( RootDataConnection * con)
inline

Standard constructor.

Definition at line 36 of file PoolTool.h.

36{ c = con; }
RootDataConnection * c
Pointer to containing data connection object.

Member Function Documentation

◆ _treeName()

string Gaudi::PoolTool::_treeName ( std::string_view sr)
inline

Convert TES object identifier to ROOT tree name.

Definition at line 39 of file PoolTool.h.

39 {
40 std::string t{ sr };
41 std::replace( begin( t ), end( t ), '/', '_' );
42 return t;
43 }
constexpr double sr
AttribStringParser::Iterator begin(const AttribStringParser &parser)

◆ getBranch()

TBranch * Gaudi::PoolTool::getBranch ( std::string_view ,
std::string_view branch_name )
inlineoverridevirtual

Access data branch by name: Get existing branch in read only mode.

Implements Gaudi::RootDataConnection::Tool.

Definition at line 100 of file PoolTool.h.

100 {
101 auto ti = sections().find( branch_name );
102 TTree* t = ( ti != sections().end() ? ti->second : nullptr );
103 if ( t ) { return (TBranch*)t->GetListOfBranches()->At( 0 ); }
104 string tname = _treeName( branch_name );
105 t = (TTree*)c->file()->Get( tname.c_str() ); // c->getSection(tname);
106 if ( t ) {
107 TBranch* b = (TBranch*)t->GetListOfBranches()->At( 0 );
108 if ( b ) {
109 sections()[std::string{ branch_name }] = t;
110 return b;
111 }
112 incidentSvc()->fireIncident( Incident( c->pfn(), IncidentType::CorruptedInputFile ) );
113 msgSvc() << MSG::ERROR << "Failed to access POOL branch:" << branch_name << " [" << tname << "]" << endmsg;
114 t->Print();
115 }
116 return nullptr;
117 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
string _treeName(std::string_view sr)
Convert TES object identifier to ROOT tree name.
Definition PoolTool.h:39
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
@ ERROR
Definition IMessageSvc.h:22

◆ loadRefs()

int Gaudi::PoolTool::loadRefs ( std::string_view ,
std::string_view cnt,
unsigned long entry,
RootObjectRefs & refs )
inlineoverridevirtual

Load references object from file.

Implements Gaudi::RootDataConnection::Tool.

Definition at line 48 of file PoolTool.h.

49 {
50 auto ti = sections().find( cnt );
51 TTree* t = ( ti != sections().end() ? ti->second : nullptr );
52 if ( !t ) { t = (TTree*)c->file()->Get( _treeName( cnt ).c_str() ); }
53 if ( t ) {
54 TBranch* b1 = t->GetBranch( "Links" );
55 TBranch* b2 = t->GetBranch( "Refs" );
56 MsgStream& msg = msgSvc();
57 if ( b1 && b2 ) {
58 LinkManager lm, *plm = &lm;
59 PoolDbLinkManager mgr, *pmgr = &mgr;
60 b1->SetAutoDelete( kFALSE );
61 b2->SetAutoDelete( kFALSE );
62 b1->SetAddress( &plm );
63 b2->SetAddress( &pmgr );
64 int nb1 = b1->GetEvent( entry );
65 int nb2 = b2->GetEvent( entry );
66 if ( nb1 > 1 && nb2 > 1 ) {
67 size_t ref_size = mgr.references().size();
68 refs.refs.resize( ref_size );
70 for ( size_t j = 0; j < ref_size; ++j ) {
71 const pair<int, int>& oid = mgr.references()[j]->m_oid;
72 string loc = mgr.links()[j].substr( 1 );
73 RootRef& r = refs.refs[j];
74 if ( oid.first >= 0 ) {
75 r = m_poolLinks[oid.first];
76 r.entry = oid.second;
77 r.link = c->makeLink( loc );
78 msg << "Add leaf:" << oid.first << "->" << loc << " from " << c->getDb( r.dbase ) << "#"
79 << c->getCont( r.container ) << " Link:" << c->getLink( r.link ) << " CLID:" << hex << r.clid
80 << " Typ:" << hex << int( r.svc ) << " Ent:" << dec << r.entry << endl;
81 }
82 }
83 for ( int i = 0, n = lm.size(); i < n; ++i ) {
84 const LinkManager::Link* lnk = lm.link( i );
85 int link_id = c->makeLink( lnk->path() );
86 msg << "Add Link:" << lnk->path() << endl;
87 refs.links.push_back( link_id );
88 }
89 return nb1 + nb2;
90 }
91 }
92 msg << MSG::ERROR << "Failed to access POOL Ref/Link branches:" << cnt << " [" << _treeName( cnt ) << "]"
93 << endmsg;
94 t->Print();
95 }
96 return -1;
97 }
std::vector< Gaudi::RootRef > m_poolLinks
Image of the POOL ##Links table.
Definition PoolTool.h:32
MsgStream & dec(MsgStream &log)
Definition MsgStream.h:254
@ VERBOSE
Definition IMessageSvc.h:22
MsgStream & hex(MsgStream &log)
Definition MsgStream.h:258

◆ poolRef()

RootRef Gaudi::PoolTool::poolRef ( size_t ) const
inlineoverridevirtual

Internal overload to facilitate the access to POOL files.

Reimplemented from Gaudi::RootDataConnection::Tool.

Definition at line 45 of file PoolTool.h.

45{ return m_poolLinks[i]; }

◆ readRefs()

StatusCode Gaudi::PoolTool::readRefs ( )
inlineoverridevirtual

Internal helper to read reference tables ##Params and ##Links.

Implements Gaudi::RootDataConnection::Tool.

Definition at line 123 of file PoolTool.h.

123 {
124 int i;
125 char text[2048];
126 msgSvc() << MSG::VERBOSE;
127
128 // First read ##Params
129 TTree* t = (TTree*)c->file()->Get( "##Params" );
130 if ( !t ) return StatusCode::FAILURE;
131 TBranch* b = t->GetBranch( "db_string" );
132 if ( !b ) return StatusCode::FAILURE;
133 for ( i = 0, b->SetAddress( text ); i < b->GetEntries(); ++i ) {
134 b->GetEvent( i );
135 char* id1 = strstr( text, "[NAME=" );
136 char* id2 = strstr( text, "[VALUE=" );
137 if ( id1 && id2 ) {
138 id1 += 6;
139 id2 += 7;
140 char* id11 = strstr( id1, "]" );
141 char* id22 = strstr( id2, "]" );
142 if ( id11 && id22 ) {
143 *id11 = 0;
144 *id22 = 0;
145 params().emplace_back( id1, id2 );
146 msgSvc() << "Param:" << id1 << "=" << id2 << "." << endmsg;
147 }
148 }
149 }
150
151 // Read ##Links
152 t = (TTree*)c->file()->Get( "##Links" );
153 if ( !t ) return StatusCode::FAILURE;
154 b = t->GetBranch( "db_string" );
155 if ( !b ) return StatusCode::FAILURE;
156 m_poolLinks.resize( (size_t)b->GetEntries() + 2 ); // Take into account the ##Links and ##Shapes entry of POOL!
157 for ( i = 0, b->SetAddress( text ); i < b->GetEntries(); ++i ) {
158 b->GetEvent( i );
159 std::string db, container;
160 int clid = 1, technology = 0, ipar[2] = { -1, -1 };
161 for ( char* p1 = (char*)text; p1; p1 = ::strchr( ++p1, '[' ) ) {
162 char* p2 = ::strchr( p1, '=' );
163 char* p3 = ::strchr( p1, ']' );
164 if ( p2 && p3 ) {
165 if ( ::strncmp( "[DB=", p1, 4 ) == 0 ) {
166 *p3 = 0;
167 db = p1 + 4;
168 } else if ( ::strncmp( "[CNT=", p1, 5 ) == 0 ) {
169 *p3 = 0;
170 container = p1 + 5;
171 } else if ( ::strncmp( "[OID=", p1, 5 ) == 0 ) {
172 *p3 = 0;
173 ::sscanf( p1 + 5, "%08X,%08X", (unsigned int*)&ipar[0], (unsigned int*)&ipar[1] );
174 } else if ( ::strncmp( "[CLID=", p1, 6 ) == 0 ) {
175 *p3 = 0;
176 ::sscanf( p1 + 6, "%08X", (unsigned int*)&clid );
177 } else if ( ::strncmp( "[TECH=", p1, 6 ) == 0 ) {
178 *p3 = 0;
179 ::sscanf( p1 + 6, "%08X", (unsigned int*)&technology );
180 } else {
181 *p3 = *p2 = 0;
182 }
183 *p3 = ']';
184 *p2 = '=';
185 }
186 }
187 c->makeRef( "", clid, technology, db, container, -1, m_poolLinks[i + 2] );
188 RootRef& r = m_poolLinks[i];
189 msgSvc() << "Add link[" << i << "]:" << db << container << " [" << r.dbase << "," << r.container << "] "
190 << " tech:" << hex << setw( 8 ) << r.svc << " CLID:" << setw( 8 ) << r.clid << dec << endmsg;
191 }
192 return StatusCode::SUCCESS;
193 }
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ saveRefs()

StatusCode Gaudi::PoolTool::saveRefs ( )
inlineoverridevirtual

Save references section when closing data file (NOT SUPPORTED)

Implements Gaudi::RootDataConnection::Tool.

Definition at line 120 of file PoolTool.h.

120{ return StatusCode::FAILURE; }

Member Data Documentation

◆ m_poolLinks

std::vector<Gaudi::RootRef> Gaudi::PoolTool::m_poolLinks
private

Image of the POOL ##Links table.

Definition at line 32 of file PoolTool.h.


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