All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Gaudi::RootTool Class Reference

Description: More...

#include <src/RootTool.h>

Inheritance diagram for Gaudi::RootTool:
Collaboration diagram for Gaudi::RootTool:

Public Member Functions

 RootTool (RootDataConnection *con)
 Standard constructor. More...
 
virtual TBranch * getBranch (CSTR section, CSTR branch_name)
 Access data branch by name: Get existing branch in read only mode. More...
 
virtual int loadRefs (CSTR section, CSTR cnt, unsigned long entry, RootObjectRefs &refs)
 Load references object from file. More...
 
void addParam (ParamMap &c, char *p)
 Helper function to read params table. More...
 
void addEntry (StringVec &c, char *val)
 Helper function to read string tables. More...
 
template<class C , class F >
StatusCode readBranch (TTree *t, const char *nam, C &v, F pmf)
 Helper function to read internal file tables. More...
 
bool get (const string &dsc, pair< string, ContainerSection > &e)
 Analyze the Sections table entries. More...
 
void analyzeMergeMap (StringVec &tmp)
 Build merge sections from the Sections table entries. More...
 
StatusCode readRefs ()
 Read reference tables. More...
 
string getEntry (const string &c)
 Helper function to convert string vectors to branch entries. More...
 
string getParam (const pair< string, string > &p)
 Helper function to convert parameter vectors to branch entries. More...
 
template<class C , class F >
StatusCode saveBranch (const char *nam, C &v, F pmf)
 Helper function to save internal tables. More...
 
StatusCode saveRefs ()
 Save/update reference tables. More...
 
- Public Member Functions inherited from Gaudi::RootDataConnection::Tool
TTree * refs () const
 
StringVecdbs () const
 
StringVecconts () const
 
StringVeclinks () const
 
ParamMapparams () const
 
MsgStreammsgSvc () const
 
const std::string & name () const
 
Sectionssections () const
 
LinkSectionslinkSections () const
 
MergeSectionsmergeSections () const
 
virtual ~Tool ()=default
 Default destructor. More...
 
virtual TBranch * getBranch (const std::string &section, const std::string &n)=0
 Access data branch by name: Get existing branch in read only mode. More...
 
virtual RootRef poolRef (size_t) const
 Internal overload to facilitate the access to POOL files. More...
 
virtual int loadRefs (const std::string &section, const std::string &cnt, unsigned long entry, RootObjectRefs &refs)=0
 Load references object. More...
 
TTree * refs () const
 
StringVecdbs () const
 
StringVecconts () const
 
StringVeclinks () const
 
ParamMapparams () const
 
MsgStreammsgSvc () const
 
const std::string & name () const
 
Sectionssections () const
 
LinkSectionslinkSections () const
 
MergeSectionsmergeSections () const
 
virtual ~Tool ()=default
 Default destructor. More...
 
virtual TBranch * getBranch (const std::string &section, const std::string &n)=0
 Access data branch by name: Get existing branch in read only mode. More...
 
virtual RootRef poolRef (size_t) const
 Internal overload to facilitate the access to POOL files. More...
 
virtual int loadRefs (const std::string &section, const std::string &cnt, unsigned long entry, RootObjectRefs &refs)=0
 Load references object. More...
 

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
 
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. More...
 

Detailed Description

Description:

Concrete implementation to read objects from POOL files.

Author
M.Frank
Version
1.0

Concrete implementation to read objects from ROOT files.

Author
M.Frank
Version
1.0

Definition at line 16 of file RootTool.h.

Constructor & Destructor Documentation

Gaudi::RootTool::RootTool ( RootDataConnection con)
inline

Standard constructor.

Definition at line 19 of file RootTool.h.

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

Member Function Documentation

void Gaudi::RootTool::addEntry ( StringVec c,
char *  val 
)
inline

Helper function to read string tables.

Definition at line 107 of file RootTool.h.

107 { c.push_back(val); }
RootDataConnection * c
Pointer to containing data connection object.
void Gaudi::RootTool::addParam ( ParamMap c,
char *  p 
)
inline

Helper function to read params table.

Definition at line 99 of file RootTool.h.

99  {
100  char* q = strchr(p,'=');
101  if ( q ) {
102  *q = 0;
103  c.emplace_back(p,++q);
104  }
105  }
RootDataConnection * c
Pointer to containing data connection object.
void Gaudi::RootTool::analyzeMergeMap ( StringVec tmp)
inline

Build merge sections from the Sections table entries.

Definition at line 154 of file RootTool.h.

154  {
155  LinkSections& ls = linkSections();
157  pair<string,ContainerSection> e;
158  MsgStream& msg = msgSvc();
159  RootRef r;
160  int cnt = 0;
161  ls.clear();
162  ms.clear();
163  msg << MSG::VERBOSE;
164  r.dbase = r.container = r.link = r.clid = r.svc = r.entry = 0;
165  for(const auto& i:tmp) {
166  if ( get(i,e) ) {
167  msg << "Added Merge Section:" << e.first << endmsg;
168  ms[e.first].push_back(e.second);
169  if ( e.first == "Links" )
170  r.link = e.second.start;
171  else if ( e.first == "Containers" )
172  r.container = e.second.start;
173  else if ( e.first == "Databases" )
174  r.dbase = e.second.start;
175  else if ( e.first == "Params" )
176  r.svc = e.second.start;
177  }
178  else if ( i == "[END-OF-SECTION]" ) {
179  r.entry = cnt;
180  if ( msg.isActive() ) {
181  msg << "Link Section [" << r.entry << "," << ls.size()
182  << "] -> D:" << r.dbase
183  << " C:" << r.container
184  << " L:" << r.link
185  << " P:" << r.svc
186  << endmsg;
187  }
188  ls.push_back(r);
189  cnt++;
190  }
191  }
192  }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:128
MergeSections & mergeSections() const
RootDataConnection::MergeSections MergeSections
RootDataConnection::LinkSections LinkSections
list i
Definition: ana.py:128
constexpr double ms
LinkSections & linkSections() const
bool Gaudi::RootTool::get ( const string &  dsc,
pair< string, ContainerSection > &  e 
)
inline

Analyze the Sections table entries.

Definition at line 135 of file RootTool.h.

135  {
136  if ( dsc != "[END-OF-SECTION]" ) {
137  size_t id1 = dsc.find("[CNT=");
138  size_t id2 = dsc.find("[START=");
139  size_t id3 = dsc.find("[LEN=");
140  if ( id1 != string::npos && id2 != string::npos && id3 != string::npos ) {
141  string cnt = dsc.substr(id1+5, id2-1-5);
142  int section_start = std::stoi(dsc.substr(id2+7,id3-id2-8));
143  int section_length = std::stoi(dsc.substr(id3+5,dsc.find("]",id3+5)-id3-5));
144  e.first = cnt;
145  e.second = ContainerSection(section_start,section_length);
146  return true;
147  }
148  }
149  e.first.clear();
150  e.second = ContainerSection(-1,-1);
151  return false;
152  }
RootDataConnection::ContainerSection ContainerSection
virtual TBranch* Gaudi::RootTool::getBranch ( CSTR  section,
CSTR  branch_name 
)
inlinevirtual

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

Definition at line 21 of file RootTool.h.

21  {
22  std::string n = branch_name+".";
23  for(int i=0, m=n.length()-1; i<m; ++i) if ( !isalnum(n[i]) ) n[i]='_';
24  TTree* t = c->getSection(section);
25  TBranch* b = t ? t->GetBranch(n.c_str()) : 0;
26  if ( !b ) b = t ? t->GetBranch(branch_name.c_str()) : 0;
27  if ( b ) b->SetAutoDelete(kFALSE);
28  return b;
29  }
constexpr double m
Definition: SystemOfUnits.h:93
RootDataConnection * c
Pointer to containing data connection object.
list i
Definition: ana.py:128
TTree * getSection(const std::string &sect, bool create=false)
Access TTree section from section name. The section is created if required.
string Gaudi::RootTool::getEntry ( const string &  c)
inline

Helper function to convert string vectors to branch entries.

Definition at line 215 of file RootTool.h.

215 { return c; }
RootDataConnection * c
Pointer to containing data connection object.
string Gaudi::RootTool::getParam ( const pair< string, string > &  p)
inline

Helper function to convert parameter vectors to branch entries.

Definition at line 217 of file RootTool.h.

217 { return p.first+"="+p.second; }
virtual int Gaudi::RootTool::loadRefs ( CSTR  section,
CSTR  cnt,
unsigned long  entry,
RootObjectRefs refs 
)
inlinevirtual

Load references object from file.

Link manager:

Definition at line 31 of file RootTool.h.

31  {
32  TBranch* b = getBranch(section,cnt+"#R");
33  RootObjectRefs* prefs = &refs;
34  if ( b ) {
35  b->SetAddress(&prefs);
36  int nb = b->GetEntry(entry);
37  if ( nb >= 1 ) {
38  const MergeSections& ms = c->mergeSections();
39  if ( !ms.empty() ) {
40  MsgStream& msg = msgSvc();
41  msgSvc() << MSG::VERBOSE;
42  pair<const RootRef*,const ContainerSection*> ls = c->getMergeSection(cnt,entry);
43  if ( ls.first ) {
44  if ( ls.first->dbase >= 0 ) {
45  // Now patch the references and links 'en block' to be efficient
46  // First the leafs from the TES
47  if ( msg.isActive() ) {
48  msg << "Refs: LS [" << entry << "] -> "
49  << ls.first->dbase << "," << ls.first->container
50  << "," << ls.first->link
51  << "," << ls.first->entry
52  << endmsg;
53  }
54  for(size_t j=0, n=refs.refs.size(); j<n; ++j) {
55  RootRef& r = refs.refs[j];
56  if ( r.entry>= 0 && r.dbase >= 0 ) {
57  int db = r.dbase + ls.first->dbase;
58  if ( c->getDb(db) == c->fid() ) {
59  if ( r.dbase ) r.dbase += ls.first->dbase;
60  if ( r.container ) r.container += ls.first->container;
61  if ( r.link ) r.link += ls.first->link;
62  const string& rc = c->getCont(r.container);
63  auto k = ms.find(rc);
64  if ( k != ms.end() ) {
65  const auto& cs = (*k).second;
66  r.entry = ( ls.first->entry >= 0 && ls.first->entry < (int)cs.size() )
67  ? cs[ls.first->entry].start + r.entry : -1;
68  if ( msg.isActive() ) {
69  msg << "Add link [" << r.entry
70  << "," << ls.first->entry
71  << "," << ls.first->container
72  << "," << r.container
73  << "," << r.entry
74  << "] to -> " << rc << endmsg;
75  }
76  }
77  else {
78  msg << MSG::WARNING << c->fid() << " [" << c->getDb(db)
79  << "] Evt:" << entry << " Invalid link to " << rc << endmsg;
80  msg << MSG::VERBOSE;
81  }
82  }
83  }
84  }
86  std::for_each(std::begin(refs.links),std::end(refs.links),
87  [&](int& i) { i += ls.first->link; } );
88  }
89  return nb;
90  }
91  return -1;
92  }
93  return nb;
94  }
95  }
96  return -1;
97  }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
const MergeSections & mergeSections() const
Access merged data section inventory.
const std::string & fid() const
Access file id.
const std::string & getDb(int which) const
Access database/file name from saved index.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:128
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::pair< const RootRef *, const ContainerSection * > getMergeSection(const std::string &container, int entry) const
Access link section for single container and entry.
RootDataConnection::MergeSections MergeSections
tuple rc
Definition: IOTest.py:92
const std::string & getCont(int which) const
Access container name from saved index.
RootDataConnection * c
Pointer to containing data connection object.
list i
Definition: ana.py:128
constexpr double ms
virtual TBranch * getBranch(CSTR section, CSTR branch_name)
Access data branch by name: Get existing branch in read only mode.
Definition: RootTool.h:21
template<class C , class F >
StatusCode Gaudi::RootTool::readBranch ( TTree *  t,
const char *  nam,
C &  v,
pmf 
)
inline

Helper function to read internal file tables.

Definition at line 109 of file RootTool.h.

109  {
110  char text[2048];
111  TBranch* b = t->GetBranch(nam);
112  if ( b ) {
113  TLeaf* l = b->GetLeaf(nam);
114  if ( l ) {
116  b->SetAddress(text);
117  msgSvc() << MSG::VERBOSE;
118  for(Long64_t i=0, n=b->GetEntries(); i<n; ++i) {
119  if ( b->GetEntry(i)>0 ) {
120  char* p = (char*)l->GetValuePointer();
121  msgSvc() << "Add Value[" << b->GetName() << "]:" << p << endmsg;
122  (this->*pmf)(v,p);
123  }
124  else {
126  }
127  }
128  return sc;
129  }
130  }
131  msgSvc() << MSG::ERROR << "Failed to read '" << nam << "' table." << endmsg;
133  }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
dictionary l
Definition: gaudirun.py:422
list i
Definition: ana.py:128
StatusCode Gaudi::RootTool::readRefs ( )
inlinevirtual

Read reference tables.

Implements Gaudi::RootDataConnection::Tool.

Definition at line 194 of file RootTool.h.

194  {
195  TTree* t = (TTree*)c->file()->Get("Sections");
197  StringVec tmp;
198  if ( t && !(sc=readBranch(t, "Sections", tmp, &RootTool::addEntry)).isSuccess() )
199  return sc;
200  else if ( refs() ) {
201  analyzeMergeMap(tmp);
202  if ( !(sc=readBranch(refs(),"Databases", dbs(), &RootTool::addEntry)).isSuccess() )
203  return sc;
204  if ( !(sc=readBranch(refs(),"Containers",conts(), &RootTool::addEntry)).isSuccess() )
205  return sc;
206  if ( !(sc=readBranch(refs(),"Links", links(), &RootTool::addEntry)).isSuccess() )
207  return sc;
208  if ( !(sc=readBranch(refs(),"Params", params(), &RootTool::addParam)).isSuccess() )
209  return sc;
210  return sc;
211  }
212  return StatusCode::FAILURE;
213  }
TFile * file() const
Direct access to TFile structure.
RootDataConnection::StringVec StringVec
void analyzeMergeMap(StringVec &tmp)
Build merge sections from the Sections table entries.
Definition: RootTool.h:154
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void addParam(ParamMap &c, char *p)
Helper function to read params table.
Definition: RootTool.h:99
void addEntry(StringVec &c, char *val)
Helper function to read string tables.
Definition: RootTool.h:107
StatusCode readBranch(TTree *t, const char *nam, C &v, F pmf)
Helper function to read internal file tables.
Definition: RootTool.h:109
RootDataConnection * c
Pointer to containing data connection object.
template<class C , class F >
StatusCode Gaudi::RootTool::saveBranch ( const char *  nam,
C &  v,
pmf 
)
inline

Helper function to save internal tables.

Definition at line 219 of file RootTool.h.

219  {
220  Long64_t i, n;
221  string val, typ = nam;
223  TDirectory::TContext ctxt(c->file());
224  TBranch* b = refs()->GetBranch(nam);
225  if ( !b ) b = refs()->Branch(nam,0,(typ+"/C").c_str());
226  if ( b ) {
227  for(i=b->GetEntries(), n=Long64_t(v.size()); i<n; ++i) {
228  val = (this->*pmf)(v[size_t(i)]);
229  b->SetAddress((char*)val.c_str());
230  msgSvc() << MSG::VERBOSE << "Save Value[" << b->GetName() << "]:" << val << endmsg;
231  if ( b->Fill() < 0 ) sc = StatusCode::FAILURE;
232  }
233  return sc;
234  }
235  return StatusCode::FAILURE;
236  }
TFile * file() const
Direct access to TFile structure.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
RootDataConnection * c
Pointer to containing data connection object.
list i
Definition: ana.py:128
StatusCode Gaudi::RootTool::saveRefs ( )
inlinevirtual

Save/update reference tables.

Implements Gaudi::RootDataConnection::Tool.

Definition at line 238 of file RootTool.h.

238  {
239  if ( refs() ) {
240  if ( !saveBranch("Databases", dbs(), &RootTool::getEntry).isSuccess() )
241  return StatusCode::FAILURE;
242  if ( !saveBranch("Containers",conts(), &RootTool::getEntry).isSuccess() )
243  return StatusCode::FAILURE;
244  if ( !saveBranch("Links", links(), &RootTool::getEntry).isSuccess() )
245  return StatusCode::FAILURE;
246  if ( !saveBranch("Params", params(),&RootTool::getParam).isSuccess() )
247  return StatusCode::FAILURE;
248  return StatusCode::SUCCESS;
249  }
250  return StatusCode::FAILURE;
251  }
string getEntry(const string &c)
Helper function to convert string vectors to branch entries.
Definition: RootTool.h:215
StatusCode saveBranch(const char *nam, C &v, F pmf)
Helper function to save internal tables.
Definition: RootTool.h:219
string getParam(const pair< string, string > &p)
Helper function to convert parameter vectors to branch entries.
Definition: RootTool.h:217

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