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