Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 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
26 #include "GaudiKernel/CnvFactory.h"
27 PLUGINSVC_FACTORY_WITH_ID( RootDirectoryCnv,
29  IConverter*(long, CLID, ISvcLocator*) );
30 #endif
31 
32 // Standard Constructor
33 RootDirectoryCnv::RootDirectoryCnv (long typ,
34  const CLID& clid,
35  ISvcLocator* svc, RootCnvSvc* mgr)
36  : RootStatCnv(typ, clid, svc, mgr)
37 {
38 }
39 
40 // Create transient object from persistent data
42 RootDirectoryCnv::createObj(IOpaqueAddress* /* pAddr */,DataObject*& refpObj) {
43  refpObj = new NTuple::Directory();
44  return StatusCode::SUCCESS;
45 }
46 
47 // Converter overrides: Convert the transient object to the requested representation.
49 RootDirectoryCnv::createRep(DataObject* pObj,IOpaqueAddress*& /* refpAddr */) {
50  string dsc;
51  if ( objType() == CLID_StatisticsDirectory ) {
52  dsc = "Directory containing statistics results.";
53  }
54  else if ( objType() == CLID_StatisticsFile ) {
55  dsc = "File containing statistics results.";
56  }
57  else {
58  return StatusCode::FAILURE;
59  }
60  string ident = containerName(pObj->registry());
61  string path = fileName(pObj->registry());
62  return saveDescription(path, ident, dsc, ident, objType());
63 }
64 
65 // Fill transient object references
66 StatusCode RootDirectoryCnv::fillObjRefs(IOpaqueAddress* pAddr, DataObject* pObj) {
67  return updateObjRefs(pAddr, pObj);
68 }
69 
70 // Converter overrides: Update the references of an updated transient object.
72 RootDirectoryCnv::updateObjRefs(IOpaqueAddress* pAddr,
73  DataObject* pObject)
74 {
75  typedef vector<RootNTupleDescriptor*> REFS;
76  REFS refs;
78  if ( pAddr ) {
79  IRegistry* pReg = pAddr->registry();
80  if ( pReg ) {
81  typedef vector<IRegistry*> Leaves;
82  string ident = pReg->identifier();
83  string fname = fileName(pReg);
84  string cntName = containerName(pReg);
85  RootDataConnection* con = 0;
86  Leaves leaves;
87  status = m_dbMgr->connectDatabase(fname, IDataConnection::READ, &con);
88  if ( status.isSuccess() ) {
89  TBranch* b = con->getBranch("##Descriptors","GaudiStatisticsDescription");
90  if ( b ) {
91  for(Long64_t n=b->GetEntries(), i=0; i<n; ++i) {
93  b->SetAddress(&ref);
94  int nb = b->GetEntry(i);
95  if ( nb > 1 ) {
96  string s = ref->container.substr(0,cntName.length());
97  log() << MSG::VERBOSE << "Read description:" << ref->container
98  << " " << ident << " " << cntName << endmsg;
99  if ( s == cntName ) {
100  if ( ref->container.length() >= cntName.length()+1 ) {
101  if ( ref->container.find('/',cntName.length()+1) == string::npos ) {
102  refs.push_back(ref);
103  continue;
104  }
105  }
106  }
107  }
108  delete ref;
109  }
110  }
111  log() << MSG::DEBUG << "Got " << refs.size() << " tuple connection(s)....." << endmsg;
112  status = m_dataMgr->objectLeaves(pObject, leaves);
113  if ( status.isSuccess() ) {
114  for(REFS::iterator i = refs.begin(); i != refs.end(); ++i) {
115  REFS::value_type& ref = *i;
116  if ( ref ) {
117  bool need_to_add = true;
118  for(Leaves::iterator j=leaves.begin(); j != leaves.end(); ++j ) {
119  string curr_leaf = containerName(*j);
120  if ( curr_leaf == ref->container ) {
121  need_to_add = false;
122  break;
123  }
124  }
125  if ( need_to_add ) {
126  IOpaqueAddress* pA= 0;
127  if ( ref->clid == CLID_StatisticsDirectory ||
128  ref->clid == CLID_StatisticsFile ||
129  ref->clid == CLID_RowWiseTuple ||
130  ref->clid == CLID_ColumnWiseTuple )
131  {
132  string spar[] = { fname, ref->container};
133  unsigned long ipar[] = { ~0x0UL, ~0x0UL };
134  status = m_dbMgr->createAddress(repSvcType(),
135  ref->clid,
136  spar,
137  ipar,
138  pA);
139  }
140  if ( status.isSuccess() ) {
141  string top = topLevel(pReg);
142  string leaf_name = top + ref->container.substr(7);
143  status = m_dataMgr->registerAddress(leaf_name, pA);
144  if ( status.isSuccess() ) {
145  log() << MSG::DEBUG << "Created address for " << leaf_name
146  << " of type " << ref->clid << endmsg;
147  continue;
148  }
149  makeError("Failed to register leaves to directory:"+ident,false).ignore();
150  break;
151  }
152  makeError("Failed to create leave address to directory:"+ident,false).ignore();
153  break;
154  }
155  }
156  makeError("Failed to add leaves to directory:"+ident,false).ignore();
157  break;
158  }
159  }
160  }
161  else {
162  return makeError("Failed to access required tuple data description.",false);
163  }
164  }
165  }
166  for(REFS::iterator k = refs.begin(); k != refs.end(); ++k) {
167  if ( *k ) delete (*k);
168  }
169  return status;
170 }
171 
172 // Converter overrides: Update transient object from persistent data
173 StatusCode
174 RootDirectoryCnv::updateObj(IOpaqueAddress* /* pAddr */,
175  DataObject* /* pObj */)
176 {
177  return StatusCode::SUCCESS;
178 }
179 
180 // Converter overrides: Update persistent object representation.
181 StatusCode
182 RootDirectoryCnv::updateRep(IOpaqueAddress* /* pAddr */,
183  DataObject* /* pObj */)
184 {
185  return StatusCode::SUCCESS;
186 }
187 
188 // Converter overrides: Update references of persistent object representation.
189 StatusCode
190 RootDirectoryCnv::updateRepRefs(IOpaqueAddress* /* pAddr */,
191  DataObject* /* pObj */)
192 {
193  return StatusCode::SUCCESS;
194 }
195 
196 // Converter overrides: Fill references of persistent object representation.
197 StatusCode
198 RootDirectoryCnv::fillRepRefs(IOpaqueAddress* /* pAddr */,
199  DataObject* /* pObj */)
200 {
201  return StatusCode::SUCCESS;
202 }

Generated at Wed Nov 28 2012 12:17:19 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004