Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RootDirectoryCnv.cpp
Go to the documentation of this file.
1 // $Id: RootDirectoryCnv.cpp,v 1.8 2010-09-27 15:43:53 frankb Exp $
2 //------------------------------------------------------------------------------
3 //
4 // Implementation of class : RootDirectoryCnv
5 //
6 // Author : Markus Frank
7 //
8 //------------------------------------------------------------------------------
9 
10 #include <algorithm>
11 #include <memory>
12 
13 // Include files
14 #include "RootCnv/RootCnvSvc.h"
17 #include "GaudiKernel/IRegistry.h"
18 #include "GaudiKernel/NTuple.h"
19 #include "TBranch.h"
20 
21 // Factory declaration
22 using namespace Gaudi;
23 using namespace std;
24 
25 #if 0
28 #endif
29 
30 // Standard Constructor
31 RootDirectoryCnv::RootDirectoryCnv (long typ,
32  const CLID& clid,
33  ISvcLocator* svc, RootCnvSvc* mgr)
34  : RootStatCnv(typ, clid, svc, mgr)
35 {
36 }
37 
38 // Create transient object from persistent data
40 RootDirectoryCnv::createObj(IOpaqueAddress* /* pAddr */,DataObject*& refpObj) {
41  refpObj = new NTuple::Directory();
42  return StatusCode::SUCCESS;
43 }
44 
45 // Converter overrides: Convert the transient object to the requested representation.
47 RootDirectoryCnv::createRep(DataObject* pObj,IOpaqueAddress*& /* refpAddr */) {
48  string dsc;
49  if ( objType() == CLID_StatisticsDirectory ) {
50  dsc = "Directory containing statistics results.";
51  }
52  else if ( objType() == CLID_StatisticsFile ) {
53  dsc = "File containing statistics results.";
54  }
55  else {
56  return StatusCode::FAILURE;
57  }
58  string ident = containerName(pObj->registry());
59  string path = fileName(pObj->registry());
60  return saveDescription(path, ident, dsc, ident, objType());
61 }
62 
63 // Fill transient object references
64 StatusCode RootDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr, DataObject* pObj) {
65  return updateObjRefs(pAddr, pObj);
66 }
67 
68 // Converter overrides: Update the references of an updated transient object.
70 RootDirectoryCnv::updateObjRefs(IOpaqueAddress* pAddr,
71  DataObject* pObject)
72 {
73  typedef vector<RootNTupleDescriptor*> REFS;
74  REFS refs;
76  if ( pAddr ) {
77  IRegistry* pReg = pAddr->registry();
78  if ( pReg ) {
79  typedef vector<IRegistry*> Leaves;
80  string ident = pReg->identifier();
81  string fname = fileName(pReg);
82  string cntName = containerName(pReg);
83  RootDataConnection* con = 0;
84  Leaves leaves;
85  status = m_dbMgr->connectDatabase(fname, IDataConnection::READ, &con);
86  if ( status.isSuccess() ) {
87  TBranch* b = con->getBranch("##Descriptors","GaudiStatisticsDescription");
88  if ( b ) {
89  for(Long64_t n=b->GetEntries(), i=0; i<n; ++i) {
90  RootNTupleDescriptor* ref=0;
91  b->SetAddress(&ref);
92  int nb = b->GetEntry(i);
93  if ( nb > 1 ) {
94  string s = ref->container.substr(0,cntName.length());
95  log() << MSG::VERBOSE << "Read description:" << ref->container
96  << " " << ident << " " << cntName << endmsg;
97  if ( s == cntName ) {
98  if ( ref->container.length() >= cntName.length()+1 ) {
99  if ( ref->container.find('/',cntName.length()+1) == string::npos ) {
100  refs.push_back(ref);
101  continue;
102  }
103  }
104  }
105  }
106  delete ref;
107  }
108  }
109  log() << MSG::DEBUG << "Got " << refs.size() << " tuple connection(s)....." << endmsg;
110  status = m_dataMgr->objectLeaves(pObject, leaves);
111  if ( status.isSuccess() ) {
112  for(REFS::iterator i = refs.begin(); i != refs.end(); ++i) {
113  REFS::value_type& ref = *i;
114  if ( ref ) {
115  bool need_to_add = true;
116  for(Leaves::iterator j=leaves.begin(); j != leaves.end(); ++j ) {
117  string curr_leaf = containerName(*j);
118  if ( curr_leaf == ref->container ) {
119  need_to_add = false;
120  break;
121  }
122  }
123  if ( need_to_add ) {
124  IOpaqueAddress* pA= 0;
125  if ( ref->clid == CLID_StatisticsDirectory ||
126  ref->clid == CLID_StatisticsFile ||
127  ref->clid == CLID_RowWiseTuple ||
128  ref->clid == CLID_ColumnWiseTuple )
129  {
130  string spar[] = { fname, ref->container};
131  unsigned long ipar[] = { ~0x0UL, ~0x0UL };
132  status = m_dbMgr->createAddress(repSvcType(),
133  ref->clid,
134  spar,
135  ipar,
136  pA);
137  }
138  if ( status.isSuccess() ) {
139  string top = topLevel(pReg);
140  string leaf_name = top + ref->container.substr(7);
141  status = m_dataMgr->registerAddress(leaf_name, pA);
142  if ( status.isSuccess() ) {
143  log() << MSG::DEBUG << "Created address for " << leaf_name
144  << " of type " << ref->clid << endmsg;
145  continue;
146  }
147  makeError("Failed to register leaves to directory:"+ident,false).ignore();
148  break;
149  }
150  makeError("Failed to create leave address to directory:"+ident,false).ignore();
151  break;
152  }
153  }
154  makeError("Failed to add leaves to directory:"+ident,false).ignore();
155  break;
156  }
157  }
158  }
159  else {
160  return makeError("Failed to access required tuple data description.",false);
161  }
162  }
163  }
164  for(REFS::iterator k = refs.begin(); k != refs.end(); ++k) {
165  if ( *k ) delete (*k);
166  }
167  return status;
168 }
169 
170 // Converter overrides: Update transient object from persistent data
172 RootDirectoryCnv::updateObj(IOpaqueAddress* /* pAddr */,
173  DataObject* /* pObj */)
174 {
175  return StatusCode::SUCCESS;
176 }
177 
178 // Converter overrides: Update persistent object representation.
180 RootDirectoryCnv::updateRep(IOpaqueAddress* /* pAddr */,
181  DataObject* /* pObj */)
182 {
183  return StatusCode::SUCCESS;
184 }
185 
186 // Converter overrides: Update references of persistent object representation.
188 RootDirectoryCnv::updateRepRefs(IOpaqueAddress* /* pAddr */,
189  DataObject* /* pObj */)
190 {
191  return StatusCode::SUCCESS;
192 }
193 
194 // Converter overrides: Fill references of persistent object representation.
196 RootDirectoryCnv::fillRepRefs(IOpaqueAddress* /* pAddr */,
197  DataObject* /* pObj */)
198 {
199  return StatusCode::SUCCESS;
200 }

Generated at Wed Jun 4 2014 14:48:58 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004