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
27  ConverterID(POOL_StorageType,CLID_StatisticsDirectory))
28 #endif
29 
30 // Standard Constructor
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
41  refpObj = new NTuple::Directory();
42  return StatusCode::SUCCESS;
43 }
44 
45 // Converter overrides: Convert the transient object to the requested representation.
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
65  return updateObjRefs(pAddr, pObj);
66 }
67 
68 // Converter overrides: Update the references of an updated transient object.
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
173  DataObject* /* pObj */)
174 {
175  return StatusCode::SUCCESS;
176 }
177 
178 // Converter overrides: Update persistent object representation.
181  DataObject* /* pObj */)
182 {
183  return StatusCode::SUCCESS;
184 }
185 
186 // Converter overrides: Update references of persistent object representation.
189  DataObject* /* pObj */)
190 {
191  return StatusCode::SUCCESS;
192 }
193 
194 // Converter overrides: Fill references of persistent object representation.
197  DataObject* /* pObj */)
198 {
199  return StatusCode::SUCCESS;
200 }
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&refpAddr)
Converter overrides: Convert the transient object to the requested representation.
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:39
#define DECLARE_COMPONENT_WITH_ID(type, id)
Definition: PluginService.h:39
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
RootDirectoryCnv(long typ, const CLID &clid, ISvcLocator *svc, RootCnvSvc *mgr)
Initializing Constructor.
virtual const std::string topLevel(IRegistry *pReg) const
Retrieve the full path of the file a given object is placed into.
Definition: RootStatCnv.cpp:89
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
IAddressCreator implementation: Address creation.
Definition: RootCnvSvc.cpp:391
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:37
Description:
Definition: RootCnvSvc.h:54
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
StatusCode connectDatabase(const std::string &dataset, int mode, RootDataConnection **con)
Connect the output file to the service with open mode.
Definition: RootCnvSvc.cpp:224
virtual StatusCode updateRep(IOpaqueAddress *pAddr, DataObject *pObj)
Converter overrides: Update persistent object representation.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:69
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Converter overrides: Fill references of persistent object representation.
virtual const CLID & objType() const
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:16
virtual IRegistry * registry() const =0
Update branch name.
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Converter overrides: Resolve the references of the transient object.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
Definition: RootStatCnv.cpp:75
virtual StatusCode updateObjRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Converter overrides: Update the references of an updated transient object.
TBranch * getBranch(const std::string &section, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
StatusCode saveDescription(const std::string &path, const std::string &ident, const std::string &desc, const std::string &opt, const CLID &clid)
Save statistics object description.
virtual long repSvcType() const
Retrieve the class type of the data store the converter uses.
Definition: RootConverter.h:55
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
unsigned int CLID
Class ID definition.
Definition: ClassID.h:9
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
virtual StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves)=0
Explore the object store: retrieve all leaves attached to the object The object is identified by its ...
const long POOL_StorageType
Definition: ClassID.h:68
Description: NTuple directory converter class definition Definition of the converter to manage the di...
virtual StatusCode updateRepRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Converter overrides: Update references of persistent object representation.
std::string container
Identifier of description.
Definition: RootRefs.h:105
virtual StatusCode updateObj(IOpaqueAddress *pAddr, DataObject *pObj)
Converter overrides: Update transient object from persistent data.
string s
Definition: gaudirun.py:210
virtual const id_type & identifier() const =0
Full identifier (or key)
virtual StatusCode registerAddress(const std::string &fullPath, IOpaqueAddress *pAddress)=0
Register object address with the data store.
Opaque address interface definition.
void ignore() const
Definition: StatusCode.h:94
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Definition: RootStatCnv.cpp:58
Description: Base class converter for N-tuples and related classes.
Definition: RootStatCnv.h:31
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
list i
Definition: ana.py:128
Concrete implementation of the IDataConnection interface to access ROOT files.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
IDataManagerSvc * m_dataMgr
Reference to data manager service to manipulate the TES.
Definition: RootStatCnv.h:34
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj)
Converter overrides: Create transient object from persistent data.