All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 destructor. More...
 
virtual void release ()
 Use releasePtr() helper to delete object. 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
 
- 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 15 of file RootTool.h.

Constructor & Destructor Documentation

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

Standard constructor.

Definition at line 18 of file RootTool.h.

18 { 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.push_back(make_pair(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 155 of file RootTool.h.

155  {
156  StringVec::const_iterator i;
157  LinkSections& ls = linkSections();
159  pair<string,ContainerSection> e;
160  MsgStream& msg = msgSvc();
161  RootRef r;
162  int cnt = 0;
163  ls.clear();
164  ms.clear();
165  msg << MSG::VERBOSE;
166  r.dbase = r.container = r.link = r.clid = r.svc = r.entry = 0;
167  for(i=tmp.begin(); i!=tmp.end();++i) {
168  if ( get(*i,e) ) {
169  msg << "Added Merge Section:" << e.first << endmsg;
170  ms[e.first].push_back(e.second);
171  if ( e.first == "Links" )
172  r.link = e.second.start;
173  else if ( e.first == "Containers" )
174  r.container = e.second.start;
175  else if ( e.first == "Databases" )
176  r.dbase = e.second.start;
177  else if ( e.first == "Params" )
178  r.svc = e.second.start;
179  }
180  else if ( (*i) == "[END-OF-SECTION]" ) {
181  r.entry = cnt;
182  if ( msg.isActive() ) {
183  msg << "Link Section [" << r.entry << "," << ls.size()
184  << "] -> D:" << r.dbase
185  << " C:" << r.container
186  << " L:" << r.link
187  << " P:" << r.svc
188  << endmsg;
189  }
190  ls.push_back(r);
191  cnt++;
192  }
193  }
194  }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:127
MergeSections & mergeSections() const
RootDataConnection::MergeSections MergeSections
RootDataConnection::LinkSections LinkSections
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
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 tmp;
142  string cnt = dsc.substr(id1+5, id2-1-5);
143  int section_start = ::atoi((tmp=dsc.substr(id2+7,id3-id2-8)).c_str());
144  int section_length = ::atoi((tmp=dsc.substr(id3+5,dsc.find("]",id3+5)-id3-5)).c_str());
145  e.first = cnt;
146  e.second = ContainerSection(section_start,section_length);
147  return true;
148  }
149  }
150  e.first = "";
151  e.second = ContainerSection(-1,-1);
152  return false;
153  }
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 20 of file RootTool.h.

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

Helper function to convert string vectors to branch entries.

Definition at line 217 of file RootTool.h.

217 { 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 219 of file RootTool.h.

219 { 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 30 of file RootTool.h.

30  {
31  TBranch* b = getBranch(section,cnt+"#R");
32  RootObjectRefs* prefs = &refs;
33  if ( b ) {
34  b->SetAddress(&prefs);
35  int nb = b->GetEntry(entry);
36  if ( nb >= 1 ) {
37  const MergeSections& ms = c->mergeSections();
38  if ( !ms.empty() ) {
39  MsgStream& msg = msgSvc();
40  msgSvc() << MSG::VERBOSE;
41  pair<const RootRef*,const ContainerSection*> ls = c->getMergeSection(cnt,entry);
42  if ( ls.first ) {
43  if ( ls.first->dbase >= 0 ) {
44  // Now patch the references and links 'en block' to be efficient
45  // First the leafs from the TES
46  if ( msg.isActive() ) {
47  msg << "Refs: LS [" << entry << "] -> "
48  << ls.first->dbase << "," << ls.first->container
49  << "," << ls.first->link
50  << "," << ls.first->entry
51  << endmsg;
52  }
53  for(size_t j=0, n=refs.refs.size(); j<n; ++j) {
54  RootRef& r = refs.refs[j];
55  if ( r.entry>= 0 && r.dbase >= 0 ) {
56  int db = r.dbase + ls.first->dbase;
57  if ( c->getDb(db) == c->fid() ) {
58  if ( r.dbase ) r.dbase += ls.first->dbase;
59  if ( r.container ) r.container += ls.first->container;
60  if ( r.link ) r.link += ls.first->link;
61  const string& rc = c->getCont(r.container);
62  MergeSections::const_iterator k = ms.find(rc);
63  if ( k != ms.end() ) {
64  const ContainerSections& cs = (*k).second;
65  r.entry = ( ls.first->entry >= 0 && ls.first->entry < (int)cs.size() )
66  ? cs[ls.first->entry].start + r.entry : -1;
67  if ( msg.isActive() ) {
68  msg << "Add link [" << r.entry
69  << "," << ls.first->entry
70  << "," << ls.first->container
71  << "," << r.container
72  << "," << r.entry
73  << "] to -> " << rc << endmsg;
74  }
75  }
76  else {
77  msg << MSG::WARNING << c->fid() << " [" << c->getDb(db)
78  << "] Evt:" << entry << " Invalid link to " << rc << endmsg;
79  msg << MSG::VERBOSE;
80  }
81  }
82  }
83  }
85  for(vector<int>::iterator i=refs.links.begin(); i!=refs.links.end();++i) {
86  (*i) += ls.first->link;
87  }
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.
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:127
RootDataConnection::ContainerSections ContainerSections
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
virtual TBranch * getBranch(CSTR section, CSTR branch_name)
Access data branch by name: Get existing branch in read only mode.
Definition: RootTool.h:20
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
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  }
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
dictionary l
Definition: gaudirun.py:365
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
StatusCode Gaudi::RootTool::readRefs ( )
inlinevirtual

Read reference tables.

Implements Gaudi::RootDataConnection::Tool.

Definition at line 196 of file RootTool.h.

196  {
197  TTree* t = (TTree*)c->file()->Get("Sections");
199  StringVec tmp;
200  if ( t && !(sc=readBranch(t, "Sections", tmp, &RootTool::addEntry)).isSuccess() )
201  return sc;
202  else if ( refs() ) {
203  analyzeMergeMap(tmp);
204  if ( !(sc=readBranch(refs(),"Databases", dbs(), &RootTool::addEntry)).isSuccess() )
205  return sc;
206  if ( !(sc=readBranch(refs(),"Containers",conts(), &RootTool::addEntry)).isSuccess() )
207  return sc;
208  if ( !(sc=readBranch(refs(),"Links", links(), &RootTool::addEntry)).isSuccess() )
209  return sc;
210  if ( !(sc=readBranch(refs(),"Params", params(), &RootTool::addParam)).isSuccess() )
211  return sc;
212  return sc;
213  }
214  return StatusCode::FAILURE;
215  }
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:155
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
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 221 of file RootTool.h.

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

Save/update reference tables.

Implements Gaudi::RootDataConnection::Tool.

Definition at line 240 of file RootTool.h.

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

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