The Gaudi Framework  master (e98cfcff)
Loading...
Searching...
No Matches
RootDirectoryCnv.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11//------------------------------------------------------------------------------
12//
13// Implementation of class : RootDirectoryCnv
14//
15// Author : Markus Frank
16//
17//------------------------------------------------------------------------------
18
19#include <algorithm>
20#include <memory>
21
22// Include files
24#include <GaudiKernel/NTuple.h>
25#include <RootCnv/RootCnvSvc.h>
28#include <TBranch.h>
29
30// Factory declaration
31using namespace Gaudi;
32using namespace std;
33
34// Standard Constructor
36 : RootStatCnv( typ, clid, svc, mgr ) {}
37
38// Create transient object from persistent data
40 refpObj = new NTuple::Directory();
42}
43
44// Converter overrides: Convert the transient object to the requested representation.
46 string dsc;
47 if ( objType() == CLID_StatisticsDirectory ) {
48 dsc = "Directory containing statistics results.";
49 } else if ( objType() == CLID_StatisticsFile ) {
50 dsc = "File containing statistics results.";
51 } else {
53 }
54 string ident = containerName( pObj->registry() );
55 string path = fileName( pObj->registry() );
56 return saveDescription( path, ident, dsc, ident, objType() );
57}
58
59// Fill transient object references
61 return updateObjRefs( pAddr, pObj );
62}
63
64// Converter overrides: Update the references of an updated transient object.
66 typedef vector<RootNTupleDescriptor*> REFS;
67 REFS refs;
69 if ( pAddr ) {
70 IRegistry* pReg = pAddr->registry();
71 if ( pReg ) {
72 typedef vector<IRegistry*> Leaves;
73 string ident = pReg->identifier();
74 string fname = fileName( pReg );
75 string cntName = containerName( pReg );
76 RootDataConnection* con = nullptr;
77 Leaves leaves;
78 status = m_dbMgr->connectDatabase( fname, IDataConnection::READ, &con );
79 if ( status.isSuccess() ) {
80 TBranch* b = con->getBranch( "##Descriptors", "GaudiStatisticsDescription" );
81 if ( b ) {
82 for ( Long64_t n = b->GetEntries(), i = 0; i < n; ++i ) {
83 RootNTupleDescriptor* ref = nullptr;
84 b->SetAddress( &ref );
85 int nb = b->GetEntry( i );
86 if ( nb > 1 ) {
87 string s = ref->container.substr( 0, cntName.length() );
88 log() << MSG::VERBOSE << "Read description:" << ref->container << " " << ident << " " << cntName
89 << endmsg;
90 if ( s == cntName ) {
91 if ( ref->container.length() >= cntName.length() + 1 ) {
92 if ( ref->container.find( '/', cntName.length() + 1 ) == string::npos ) {
93 refs.push_back( ref );
94 continue;
95 }
96 }
97 }
98 }
99 delete ref;
100 }
101 }
102 log() << MSG::DEBUG << "Got " << refs.size() << " tuple connection(s)....." << endmsg;
103 status = m_dataMgr->objectLeaves( pObject, leaves );
104 if ( status.isSuccess() ) {
105 for ( auto& ref : refs ) {
106 if ( ref ) {
107 bool need_to_add =
108 std::none_of( std::begin( leaves ), std::end( leaves ),
109 [&]( Leaves::const_reference j ) { return containerName( j ) == ref->container; } );
110 if ( need_to_add ) {
111 IOpaqueAddress* pA = nullptr;
112 if ( ref->clid == CLID_StatisticsDirectory || ref->clid == CLID_StatisticsFile ||
113 ref->clid == CLID_RowWiseTuple || ref->clid == CLID_ColumnWiseTuple ) {
114 string spar[] = { fname, ref->container };
115 unsigned long ipar[] = { ~0x0UL, ~0x0UL };
116 status = m_dbMgr->createAddress( repSvcType(), ref->clid, spar, ipar, pA );
117 }
118 if ( status.isSuccess() ) {
119 string top = topLevel( pReg );
120 string leaf_name = top + ref->container.substr( 7 );
121 status = m_dataMgr->registerAddress( leaf_name, pA );
122 if ( status.isSuccess() ) {
123 log() << MSG::DEBUG << "Created address for " << leaf_name << " of type " << ref->clid << endmsg;
124 continue;
125 }
126 makeError( "Failed to register leaves to directory:" + ident, false ).ignore();
127 break;
128 }
129 makeError( "Failed to create leave address to directory:" + ident, false ).ignore();
130 break;
131 }
132 }
133 makeError( "Failed to add leaves to directory:" + ident, false ).ignore();
134 break;
135 }
136 }
137 } else {
138 return makeError( "Failed to access required tuple data description.", false );
139 }
140 }
141 }
142 for ( auto& ref : refs ) delete ref;
143 return status;
144}
145
146// Converter overrides: Update transient object from persistent data
150
151// Converter overrides: Update persistent object representation.
155
156// Converter overrides: Update references of persistent object representation.
160
161// Converter overrides: Fill references of persistent object representation.
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition Converter.cpp:22
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
Description:
Definition RootCnvSvc.h:61
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
long repSvcType() const override
Retrieve the class type of the data store the converter uses.
Concrete implementation of the IDataConnection interface to access ROOT files.
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
StatusCode updateRepRefs(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Update references of persistent object representation.
StatusCode createRep(DataObject *pObj, IOpaqueAddress *&refpAddr) override
Converter overrides: Convert the transient object to the requested representation.
StatusCode fillObjRefs(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Resolve the references of the transient object.
StatusCode updateObj(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Update transient object from persistent data.
RootDirectoryCnv(long typ, const CLID &clid, ISvcLocator *svc, RootCnvSvc *mgr)
Initializing Constructor.
StatusCode updateRep(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Update persistent object representation.
StatusCode updateObjRefs(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Update the references of an updated transient object.
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Converter overrides: Create transient object from persistent data.
StatusCode fillRepRefs(IOpaqueAddress *pAddr, DataObject *pObj) override
Converter overrides: Fill references of persistent object representation.
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 const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
MsgStream & log() const
Helper to use mesage logger.
Definition RootStatCnv.h:47
SmartIF< IDataManagerSvc > m_dataMgr
Reference to data manager service to manipulate the TES.
Definition RootStatCnv.h:42
RootStatCnv(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.
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Opaque address interface definition.
virtual IRegistry * registry() const =0
Update branch name.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
virtual const id_type & identifier() const =0
Full identifier (or key)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
@ DEBUG
Definition IMessageSvc.h:22
@ VERBOSE
Definition IMessageSvc.h:22
STL namespace.
Small class representing an N tuple directory in the transient store.
Definition NTuple.h:907