Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RDirectoryCnv.cpp
Go to the documentation of this file.
1 // Id: $
2 #define ROOTHISTCNV_RDIRECTORYCNV_CPP
3 
4 // Include files
6 #include "GaudiKernel/xtoa.h"
10 #include "GaudiKernel/IRegistry.h"
11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/NTuple.h"
13 
14 #include "RDirectoryCnv.h"
15 
16 // Root files
17 #include "TObject.h"
18 #include "TDirectory.h"
19 #include "TFile.h"
20 #include "TKey.h"
21 #include "TTree.h"
22 #include "TProfile.h"
23 #include "TProfile2D.h"
24 #include "TH1.h"
25 #include "TH2.h"
26 #include "TH3.h"
27 
28 DECLARE_NAMESPACE_CONVERTER_FACTORY(RootHistCnv,RDirectoryCnv)
29 
30 
31 //-----------------------------------------------------------------------------
32 StatusCode RootHistCnv::RDirectoryCnv::createObj(IOpaqueAddress* /* pAddress */,
33  DataObject*& refpObject)
34 //-----------------------------------------------------------------------------
35 {
36  refpObject = new NTuple::Directory();
37  return StatusCode::SUCCESS;
38 }
39 
40 
41 //-----------------------------------------------------------------------------
43  IOpaqueAddress*& refpAddress)
44 //-----------------------------------------------------------------------------
45 {
46  const std::string& loc = pObject->registry()->identifier();
47  if ( createDirectory(loc).isSuccess() ) {
48  setDirectory(loc);
49  setDiskDirectory(loc);
50 // return createAddress(pObject, pObject->registry()->name(), refpAddress);
51  return createAddress(pObject, gDirectory, 0, refpAddress);
52  }
53  refpAddress = 0;
54  return StatusCode::FAILURE;
55 }
56 
57 
58 //-----------------------------------------------------------------------------
60  DataObject* pObject)
61 //-----------------------------------------------------------------------------
62 {
63  const std::string& loc = pObject->registry()->identifier();
64  if ( createDirectory(loc).isSuccess() ) {
65  setDirectory(loc);
66  return StatusCode::SUCCESS;
67  }
68  return StatusCode::FAILURE;
69 }
70 
71 
72 //-----------------------------------------------------------------------------
75  MsgStream log(msgSvc(), "RDirectoryCnv");
76  IRegistry* pReg = pObj->registry();
77  std::string full = pReg->identifier();
78  const std::string& fname = pAddr->par()[0];
79 
80  TFile *tf;
81  findTFile(full,tf).ignore();
82 
83  // cd to TFile:
84  setDirectory(full);
85  TIter nextkey(gDirectory->GetListOfKeys());
86  while (TKey *key = (TKey*)nextkey()) {
87  IOpaqueAddress* pA = 0;
88  TObject *obj = key->ReadObj();
89  std::string title = obj->GetTitle();
90  std::string sid = obj->GetName();
91  std::string f2 = full + "/" + sid;
92  int idh = ::strtol(sid.c_str(),NULL,10);
93  // introduced by Grigori Rybkine
94  std::string clname = key->GetClassName();
95  std::string clnm = clname.substr(0,3);
96  TClass* isa = obj->IsA();
97  if (isa->InheritsFrom("TTree")) {
98  createAddress(full, CLID_ColumnWiseTuple, idh, obj, pA).ignore();
99  TTree* tree = (TTree*) obj;
100  tree->Print();
101  log << MSG::DEBUG << "Reg CWNT \"" << obj->GetTitle()
102  << "\" as " << f2 << endmsg;
103  title = "/" + sid;
104  } else if (isa->InheritsFrom("TDirectory")) {
105  createAddress(full,CLID_NTupleDirectory, title, obj, pA).ignore();
106  } else if ( isa == TProfile::Class() ) {
107  createAddress(full,CLID_ProfileH,idh,obj,pA).ignore();
108  title = sid;
109  } else if ( isa == TProfile2D::Class() ) {
110  createAddress(full,CLID_ProfileH2,idh,obj,pA).ignore();
111  title = sid;
112  } else if ( isa == TH1C::Class() ) {
113  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
114  title = sid;
115  } else if ( isa == TH1S::Class() ) {
116  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
117  title = sid;
118  } else if ( isa == TH1I::Class() ) {
119  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
120  title = sid;
121  } else if ( isa == TH1F::Class() ) {
122  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
123  title = sid;
124  } else if ( isa == TH1D::Class() ) {
125  createAddress(full,CLID_H1D,idh,obj,pA).ignore();
126  title = sid;
127  } else if ( isa == TH2C::Class() ) {
128  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
129  title = sid;
130  } else if ( isa == TH2S::Class() ) {
131  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
132  title = sid;
133  } else if ( isa == TH2I::Class() ) {
134  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
135  title = sid;
136  } else if ( isa == TH2F::Class() ) {
137  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
138  title = sid;
139  } else if ( isa == TH2D::Class() ) {
140  createAddress(full,CLID_H2D,idh,obj,pA).ignore();
141  title = sid;
142  } else if ( isa == TH3C::Class() ) {
143  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
144  title = sid;
145  } else if ( isa == TH3S::Class() ) {
146  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
147  title = sid;
148  } else if ( isa == TH3I::Class() ) {
149  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
150  title = sid;
151  } else if ( isa == TH3F::Class() ) {
152  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
153  title = sid;
154  } else if ( isa == TH3D::Class() ) {
155  createAddress(full,CLID_H3D,idh,obj,pA).ignore();
156  title = sid;
157  } else {
158  log << MSG::ERROR << "Encountered an unknown object with key: "
159  << obj->GetName() << " in ROOT file " << fname << endmsg;
160  return StatusCode::FAILURE;
161  }
162  if ( 0 != pA ) {
163  StatusCode sc = dataManager()->registerAddress(pReg, title, pA);
164  if ( !sc.isSuccess() ) {
165  log << MSG::ERROR << "Failed to register address for " << full << endmsg;
166  return sc;
167  }
168  log << MSG::VERBOSE << "Created address for " << clnm
169  << "'" << title << "' in " << full << endmsg;
170  }
171  }
172  return StatusCode::SUCCESS;
173 }

Generated at Wed Jan 30 2013 17:13:42 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004