| The Gaudi Framework v27r1

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