The Gaudi Framework  v31r0 (aeb156f0)
RootDirectoryCnv.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 //
3 // Implementation of class : RootDirectoryCnv
4 //
5 // Author : Markus Frank
6 //
7 //------------------------------------------------------------------------------
8 
9 #include <algorithm>
10 #include <memory>
11 
12 // Include files
13 #include "GaudiKernel/IRegistry.h"
14 #include "GaudiKernel/NTuple.h"
15 #include "RootCnv/RootCnvSvc.h"
18 #include "TBranch.h"
19 
20 // Factory declaration
21 using namespace Gaudi;
22 using namespace std;
23 
24 #if 0
26  ConverterID(POOL_StorageType,CLID_StatisticsDirectory))
27 #endif
28 
29 // Standard Constructor
30 RootDirectoryCnv::RootDirectoryCnv( long typ, const CLID& clid, ISvcLocator* svc, RootCnvSvc* mgr )
31  : RootStatCnv( typ, clid, svc, mgr ) {}
32 
33 // Create transient object from persistent data
35  refpObj = new NTuple::Directory();
36  return StatusCode::SUCCESS;
37 }
38 
39 // Converter overrides: Convert the transient object to the requested representation.
41  string dsc;
42  if ( objType() == CLID_StatisticsDirectory ) {
43  dsc = "Directory containing statistics results.";
44  } else if ( objType() == CLID_StatisticsFile ) {
45  dsc = "File containing statistics results.";
46  } else {
47  return StatusCode::FAILURE;
48  }
49  string ident = containerName( pObj->registry() );
50  string path = fileName( pObj->registry() );
51  return saveDescription( path, ident, dsc, ident, objType() );
52 }
53 
54 // Fill transient object references
56  return updateObjRefs( pAddr, pObj );
57 }
58 
59 // Converter overrides: Update the references of an updated transient object.
61  typedef vector<RootNTupleDescriptor*> REFS;
62  REFS refs;
63  StatusCode status = StatusCode( StatusCode::FAILURE, true );
64  if ( pAddr ) {
65  IRegistry* pReg = pAddr->registry();
66  if ( pReg ) {
67  typedef vector<IRegistry*> Leaves;
68  string ident = pReg->identifier();
69  string fname = fileName( pReg );
70  string cntName = containerName( pReg );
71  RootDataConnection* con = nullptr;
72  Leaves leaves;
73  status = m_dbMgr->connectDatabase( fname, IDataConnection::READ, &con );
74  if ( status.isSuccess() ) {
75  TBranch* b = con->getBranch( "##Descriptors", "GaudiStatisticsDescription" );
76  if ( b ) {
77  for ( Long64_t n = b->GetEntries(), i = 0; i < n; ++i ) {
78  RootNTupleDescriptor* ref = nullptr;
79  b->SetAddress( &ref );
80  int nb = b->GetEntry( i );
81  if ( nb > 1 ) {
82  string s = ref->container.substr( 0, cntName.length() );
83  log() << MSG::VERBOSE << "Read description:" << ref->container << " " << ident << " " << cntName
84  << endmsg;
85  if ( s == cntName ) {
86  if ( ref->container.length() >= cntName.length() + 1 ) {
87  if ( ref->container.find( '/', cntName.length() + 1 ) == string::npos ) {
88  refs.push_back( ref );
89  continue;
90  }
91  }
92  }
93  }
94  delete ref;
95  }
96  }
97  log() << MSG::DEBUG << "Got " << refs.size() << " tuple connection(s)....." << endmsg;
98  status = m_dataMgr->objectLeaves( pObject, leaves );
99  if ( status.isSuccess() ) {
100  for ( auto& ref : refs ) {
101  if ( ref ) {
102  bool need_to_add =
103  std::none_of( std::begin( leaves ), std::end( leaves ),
104  [&]( Leaves::const_reference j ) { return containerName( j ) == ref->container; } );
105  if ( need_to_add ) {
106  IOpaqueAddress* pA = nullptr;
107  if ( ref->clid == CLID_StatisticsDirectory || ref->clid == CLID_StatisticsFile ||
108  ref->clid == CLID_RowWiseTuple || ref->clid == CLID_ColumnWiseTuple ) {
109  string spar[] = {fname, ref->container};
110  unsigned long ipar[] = {~0x0UL, ~0x0UL};
111  status = m_dbMgr->createAddress( repSvcType(), ref->clid, spar, ipar, pA );
112  }
113  if ( status.isSuccess() ) {
114  string top = topLevel( pReg );
115  string leaf_name = top + ref->container.substr( 7 );
116  status = m_dataMgr->registerAddress( leaf_name, pA );
117  if ( status.isSuccess() ) {
118  log() << MSG::DEBUG << "Created address for " << leaf_name << " of type " << ref->clid << endmsg;
119  continue;
120  }
121  makeError( "Failed to register leaves to directory:" + ident, false ).ignore();
122  break;
123  }
124  makeError( "Failed to create leave address to directory:" + ident, false ).ignore();
125  break;
126  }
127  }
128  makeError( "Failed to add leaves to directory:" + ident, false ).ignore();
129  break;
130  }
131  }
132  } else {
133  return makeError( "Failed to access required tuple data description.", false );
134  }
135  }
136  }
137  for ( auto& ref : refs ) delete ref;
138  return status;
139 }
140 
141 // Converter overrides: Update transient object from persistent data
143  return StatusCode::SUCCESS;
144 }
145 
146 // Converter overrides: Update persistent object representation.
148  return StatusCode::SUCCESS;
149 }
150 
151 // Converter overrides: Update references of persistent object representation.
153  return StatusCode::SUCCESS;
154 }
155 
156 // Converter overrides: Fill references of persistent object representation.
158  return StatusCode::SUCCESS;
159 }
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:38
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 ...
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
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:73
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:13
StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress) override
IAddressCreator implementation: Address creation.
Definition: RootCnvSvc.cpp:347
bool isSuccess() const
Definition: StatusCode.h:267
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:35
StatusCode updateRepRefs(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Update references of persistent object representation.
virtual IRegistry * registry() const =0
Update branch name.
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Description:
Definition: RootCnvSvc.h:52
STL namespace.
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
Definition: RootStatCnv.cpp:87
T end(T...args)
StatusCode connectDatabase(const std::string &dataset, int mode, RootDataConnection **con)
Connect the output file to the service with open mode.
Definition: RootCnvSvc.cpp:194
StatusCode fillObjRefs(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Resolve the references of the transient object.
SmartIF< IDataManagerSvc > m_dataMgr
Reference to data manager service to manipulate the TES.
Definition: RootStatCnv.h:33
long repSvcType() const override
Retrieve the class type of the data store the converter uses.
Definition: RootConverter.h:49
StatusCode createRep(DataObject *pObj, IOpaqueAddress *&refpAddr) override
Converter overrides: Convert the transient object to the requested representation.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Converter overrides: Create transient object from persistent data.
virtual const id_type & identifier() const =0
Full identifier (or key)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
virtual const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
Definition: RootStatCnv.cpp:61
StatusCode updateObj(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Update transient object from persistent data.
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.
Definition: RootStatCnv.cpp:99
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:8
StatusCode fillRepRefs(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Fill references of persistent object representation.
const long POOL_StorageType
Definition: ClassID.h:67
TBranch * getBranch(boost::string_ref section, boost::string_ref branch_name)
Access data branch by name: Get existing branch in read only mode.
Description: NTuple directory converter class definition Definition of the converter to manage the di...
T find(T...args)
T length(T...args)
STL class.
T begin(T...args)
T none_of(T...args)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
std::string container
Identifier of description.
Definition: RootRefs.h:83
StatusCode updateObjRefs(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Update the references of an updated transient object.
virtual StatusCode registerAddress(boost::string_ref fullPath, IOpaqueAddress *pAddress)=0
Register object address with the data store.
string s
Definition: gaudirun.py:312
constexpr static const auto FAILURE
Definition: StatusCode.h:86
T substr(T...args)
Small class representing an N tuple directory in the transient store.
Definition: NTuple.h:901
#define DECLARE_COMPONENT_WITH_ID(type, id)
StatusCode updateRep(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Update persistent object representation.
Opaque address interface definition.
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Definition: RootStatCnv.cpp:46
Description: Base class converter for N-tuples and related classes.
Definition: RootStatCnv.h:30
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Concrete implementation of the IDataConnection interface to access ROOT files.
Helper functions to set/get the application return code.
Definition: __init__.py:1
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192