All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RDirectoryCnv.cpp
Go to the documentation of this file.
1 // Include files
2 #include "GaudiKernel/xtoa.h"
8 #include "GaudiKernel/NTuple.h"
9 
10 #include "RDirectoryCnv.h"
11 
12 // Root files
13 #include "TObject.h"
14 #include "TDirectory.h"
15 #include "TFile.h"
16 #include "TKey.h"
17 #include "TTree.h"
18 #include "TProfile.h"
19 #include "TProfile2D.h"
20 #include "TH1.h"
21 #include "TH2.h"
22 #include "TH3.h"
23 
24 DECLARE_NAMESPACE_CONVERTER_FACTORY(RootHistCnv,RDirectoryCnv)
25 
26 
27 //-----------------------------------------------------------------------------
28 StatusCode RootHistCnv::RDirectoryCnv::createObj(IOpaqueAddress* /* pAddress */,
29  DataObject*& refpObject)
30 //-----------------------------------------------------------------------------
31 {
32  refpObject = new NTuple::Directory();
33  return StatusCode::SUCCESS;
34 }
35 
36 
37 //-----------------------------------------------------------------------------
39  IOpaqueAddress*& refpAddress)
40 //-----------------------------------------------------------------------------
41 {
42  const std::string& loc = pObject->registry()->identifier();
43  if ( createDirectory(loc).isSuccess() ) {
44  setDirectory(loc);
45  setDiskDirectory(loc);
46 // return createAddress(pObject, pObject->registry()->name(), refpAddress);
47  return createAddress(pObject, gDirectory, 0, refpAddress);
48  }
49  refpAddress = 0;
50  return StatusCode::FAILURE;
51 }
52 
53 
54 //-----------------------------------------------------------------------------
56  DataObject* pObject)
57 //-----------------------------------------------------------------------------
58 {
59  const std::string& loc = pObject->registry()->identifier();
60  if ( createDirectory(loc).isSuccess() ) {
61  setDirectory(loc);
62  return StatusCode::SUCCESS;
63  }
64  return StatusCode::FAILURE;
65 }
66 
67 
68 //-----------------------------------------------------------------------------
71  MsgStream log(msgSvc(), "RDirectoryCnv");
72  IRegistry* pReg = pObj->registry();
73  std::string full = pReg->identifier();
74  const std::string& fname = pAddr->par()[0];
75 
76  TFile *tf;
77  findTFile(full,tf).ignore();
78 
79  // cd to TFile:
80  setDirectory(full);
81  TIter nextkey(gDirectory->GetListOfKeys());
82  while (TKey *key = (TKey*)nextkey()) {
83  IOpaqueAddress* pA = 0;
84  TObject *obj = key->ReadObj();
85  std::string title = obj->GetTitle();
86  std::string sid = obj->GetName();
87  std::string f2 = full + "/" + sid;
88  int idh = ::strtol(sid.c_str(),NULL,10);
89  // introduced by Grigori Rybkine
90  std::string clname = key->GetClassName();
91  std::string clnm = clname.substr(0,3);
92  TClass* isa = obj->IsA();
93  if (isa->InheritsFrom("TTree")) {
94  createAddress(full, CLID_ColumnWiseTuple, idh, obj, pA).ignore();
95  TTree* tree = (TTree*) obj;
96  tree->Print();
97  log << MSG::DEBUG << "Reg CWNT \"" << obj->GetTitle()
98  << "\" as " << f2 << endmsg;
99  title = "/" + sid;
100  } else if (isa->InheritsFrom("TDirectory")) {
101  createAddress(full,CLID_NTupleDirectory, title, obj, pA).ignore();
102  } else if ( isa == TProfile::Class() ) {
103  createAddress(full,CLID_ProfileH,idh,obj,pA).ignore();
104  title = sid;
105  } else if ( isa == TProfile2D::Class() ) {
106  createAddress(full,CLID_ProfileH2,idh,obj,pA).ignore();
107  title = sid;
108  } else if ( isa == TH1C::Class() ) {
109  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
110  title = sid;
111  } else if ( isa == TH1S::Class() ) {
112  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
113  title = sid;
114  } else if ( isa == TH1I::Class() ) {
115  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
116  title = sid;
117  } else if ( isa == TH1F::Class() ) {
118  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
119  title = sid;
120  } else if ( isa == TH1D::Class() ) {
121  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
122  title = sid;
123  } else if ( isa == TH2C::Class() ) {
124  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
125  title = sid;
126  } else if ( isa == TH2S::Class() ) {
127  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
128  title = sid;
129  } else if ( isa == TH2I::Class() ) {
130  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
131  title = sid;
132  } else if ( isa == TH2F::Class() ) {
133  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
134  title = sid;
135  } else if ( isa == TH2D::Class() ) {
136  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
137  title = sid;
138  } else if ( isa == TH3C::Class() ) {
139  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
140  title = sid;
141  } else if ( isa == TH3S::Class() ) {
142  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
143  title = sid;
144  } else if ( isa == TH3I::Class() ) {
145  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
146  title = sid;
147  } else if ( isa == TH3F::Class() ) {
148  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
149  title = sid;
150  } else if ( isa == TH3D::Class() ) {
151  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
152  title = sid;
153  } else {
154  log << MSG::ERROR << "Encountered an unknown object with key: "
155  << obj->GetName() << " in ROOT file " << fname << endmsg;
156  return StatusCode::FAILURE;
157  }
158  if ( 0 != pA ) {
159  StatusCode sc = dataManager()->registerAddress(pReg, title, pA);
160  if ( !sc.isSuccess() ) {
161  log << MSG::ERROR << "Failed to register address for " << full << endmsg;
162  return sc;
163  }
164  log << MSG::VERBOSE << "Created address for " << clnm
165  << "'" << title << "' in " << full << endmsg;
166  }
167  }
168  return StatusCode::SUCCESS;
169 }
virtual const std::string * par() const =0
Retrieve String parameters.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
void setDirectory(const std::string &loc)
Definition: RConverter.cpp:120
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
StatusCode createDirectory(const std::string &loc)
Definition: RConverter.cpp:26
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:69
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&refpAddr)
Convert the transient object to the requested representation.
Create persistent and transient representations of data store directories.
Definition: RDirectoryCnv.h:17
virtual StatusCode updateRep(IOpaqueAddress *pAddr, DataObject *pObject)
Convert the transient object to the requested representation.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddr, DataObject *refpObj)
Update the transient object from the other representation.
#define DECLARE_NAMESPACE_CONVERTER_FACTORY(n, x)
Definition: Converter.h:180
virtual const id_type & identifier() const =0
Full identifier (or key)
Opaque address interface definition.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
Small class representing an N tuple directory in the transient store.
Definition: NTuple.h:1065
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
StatusCode createAddress(DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
Create address of the transient object according to the requested representation. ...
Definition: RConverter.cpp:171
void setDiskDirectory(const std::string &loc)
Definition: RConverter.cpp:155