| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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"
3 #include "GaudiKernel/IDataProviderSvc.h"
4 #include "GaudiKernel/IDataManagerSvc.h"
5 #include "GaudiKernel/IOpaqueAddress.h"
6 #include "GaudiKernel/IRegistry.h"
7 #include "GaudiKernel/MsgStream.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 //-----------------------------------------------------------------------------
38 StatusCode RootHistCnv::RDirectoryCnv::createRep(DataObject* pObject,
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 //-----------------------------------------------------------------------------
55 StatusCode RootHistCnv::RDirectoryCnv::updateRep(IOpaqueAddress* /* pAddress */,
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 //-----------------------------------------------------------------------------
69 StatusCode
70 RootHistCnv::RDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr,DataObject* pObj) {
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 }