| The Gaudi Framework v29r1 (5cd95fa2)

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

- File List
- File Members

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