The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
RootHistCnv::RNTupleCnv Class Referenceabstract

NTuple converter class definition. More...

#include </builds/gaudi/Gaudi/RootHistCnv/src/RNTupleCnv.h>

Inheritance diagram for RootHistCnv::RNTupleCnv:
Collaboration diagram for RootHistCnv::RNTupleCnv:

Public Member Functions

StatusCode initialize () override
 Initialize the converter.
 
StatusCode finalize () override
 Finalize the converter.
 
StatusCode createObj (IOpaqueAddress *pAddr, DataObject *&refpObj) override
 Create the transient representation of an object.
 
StatusCode updateObj (IOpaqueAddress *pAddr, DataObject *refpObj) override
 Update the transient object from the other representation.
 
StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAddr) override
 Convert the transient object to the requested representation.
 
StatusCode updateRep (IOpaqueAddress *pAddr, DataObject *pObj) override
 Update the converted representation of a transient object.
 
- Public Member Functions inherited from RootHistCnv::RConverter
StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAddr) override
 Convert the transient object to the requested representation.
 
long repSvcType () const override
 
StatusCode error (const std::string &msg)
 
StatusCode regTFile (const std::string &, const TFile *)
 
StatusCode findTFile (const std::string &, TFile *&)
 
std::string diskDirectory (const std::string &loc)
 
std::string directory (const std::string &loc)
 
void setDirectory (const std::string &loc)
 
void setDiskDirectory (const std::string &loc)
 
StatusCode createDirectory (const std::string &loc)
 
StatusCode createDiskDirectory (const std::string &loc)
 
std::string getDirectory ()
 
std::string convertId (const std::string &) const
 
- Public Member Functions inherited from Converter
StatusCode initialize () override
 Initialize the converter.
 
StatusCode finalize () override
 Initialize the converter.
 
StatusCode setDataProvider (IDataProviderSvc *svc) override
 Set Data provider service.
 
SmartIF< IDataProviderSvc > & dataProvider () const override
 Get Data provider service.
 
StatusCode setConversionSvc (IConversionSvc *svc) override
 Set conversion service the converter is connected to.
 
SmartIF< IConversionSvc > & conversionSvc () const override
 Get conversion service the converter is connected to.
 
StatusCode setAddressCreator (IAddressCreator *creator) override
 Set address creator facility.
 
SmartIF< IAddressCreator > & addressCreator () const override
 Retrieve address creator facility.
 
const CLIDobjType () const override
 Retrieve the class type of objects the converter produces.
 
virtual long i_repSvcType () const
 Retrieve the class type of the data store the converter uses.
 
StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Create the transient representation of an object.
 
StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the created transient object.
 
StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *refpObject) override
 Update the transient object from the other representation.
 
StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an updated transient object.
 
StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress) override
 Convert the transient object to the requested representation.
 
StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the converted object.
 
StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the converted representation of a transient object.
 
StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an already converted object.
 
 Converter (long storage_type, const CLID &class_type, ISvcLocator *svc=0)
 Standard Constructor.
 
SmartIF< IServiceservice (const std::string &name, const bool createIf=true) const
 Return a pointer to the service identified by name (or "type/name")
 
- Public Member Functions inherited from implements< IConverter >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
 implements ()=default
 Default constructor.
 
 implements (const implements &)
 Copy constructor (zero the reference count)
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count).
 
unsigned long addRef () const override
 Reference Interface instance.
 
unsigned long release () const override
 Release Interface instance.
 
unsigned long refCount () const override
 Current reference count.
 

Protected Member Functions

 RNTupleCnv (ISvcLocator *svc, const CLID &clid)
 Standard constructor.
 
virtual StatusCode load (TTree *tree, INTuple *&refpObj)=0
 Create the transient representation of an object.
 
virtual StatusCode book (const std::string &desc, INTuple *pObj, TTree *&tree)=0
 Book a new N tuple.
 
virtual StatusCode writeData (TTree *rtree, INTuple *pObj)=0
 Write N tuple data.
 
virtual StatusCode readData (TTree *rtree, INTuple *pObj, long ievt)=0
 Read N tuple data.
 
virtual std::string rootVarType (int)
 Return ROOT type info:
 
- Protected Member Functions inherited from RootHistCnv::RConverter
 RConverter (const CLID &clid, ISvcLocator *svc)
 Standard constructor.
 
virtual StatusCode readObject (IOpaqueAddress *pAddr, DataObject *&refpObj)
 Create the transient representation of an object.
 
virtual TObject * createPersistent (DataObject *pObj)
 Create the persistent representation of an object.
 
StatusCode createAddress (DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
 Create address of the transient object according to the requested representation.
 
StatusCode createAddress (const std::string &rzdir, const CLID &clid, long id, TObject *pTobj, IOpaqueAddress *&refpAddress)
 
StatusCode createAddress (const std::string &rzdir, const CLID &clid, const std::string &title, TObject *pTobj, IOpaqueAddress *&refpAddress)
 
TDirectory * changeDirectory (DataObject *pObject)
 Switch to object directory (=Parent directory)
 
- Protected Member Functions inherited from Converter
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator.
 
SmartIF< IMessageSvc > & msgSvc () const
 Retrieve pointer to message service.
 
SmartIF< IDataManagerSvc > & dataManager () const
 Get Data Manager service.
 
- Protected Member Functions inherited from implements< IConverter >
unsigned long decRef () const override
 

Protected Attributes

SmartIF< INTupleSvcm_ntupleSvc
 Reference to N tuple service.
 
- Protected Attributes inherited from implements< IConverter >
std::atomic_ulong m_refCount
 Reference counter.
 

Additional Inherited Members

- Public Types inherited from Converter
using Factory = Gaudi::PluginService::Factory<IConverter*( ISvcLocator* )>
 
- Public Types inherited from implements< IConverter >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
using iids
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 
- Static Public Member Functions inherited from RootHistCnv::RConverter
static long storageType ()
 Inquire storage type.
 

Detailed Description

NTuple converter class definition.

Package : RootHistCnv Author : Charles Leggett

Constructor & Destructor Documentation

◆ RNTupleCnv()

RootHistCnv::RNTupleCnv::RNTupleCnv ( ISvcLocator * svc,
const CLID & clid )
protected

Standard constructor.

Definition at line 38 of file RNTupleCnv.cpp.

38: RConverter( clid, svc ) {}
RConverter(const CLID &clid, ISvcLocator *svc)
Standard constructor.
Definition RConverter.h:64

Member Function Documentation

◆ book()

virtual StatusCode RootHistCnv::RNTupleCnv::book ( const std::string & desc,
INTuple * pObj,
TTree *& tree )
protectedpure virtual

Book a new N tuple.

Implemented in RootHistCnv::RCWNTupleCnv, and RootHistCnv::RRWNTupleCnv.

◆ createObj()

StatusCode RootHistCnv::RNTupleCnv::createObj ( IOpaqueAddress * pAddr,
DataObject *& refpObj )
override

Create the transient representation of an object.

Definition at line 89 of file RNTupleCnv.cpp.

91{
92 MsgStream log( msgSvc(), "RNTupleCnv" );
93
94 IRegistry* pReg = pAddress->registry();
95
96 // log << MSG::WARNING << "adr: " << pAddress->par()[0] << " <> "
97 // << pAddress->par()[1] << " <> " << pAddress->ipar()[0] << " <> "
98 // << pAddress->ipar()[1] << " <> " << hex << rAddr->tObj()
99 // << dec << " <> " << pReg->identifier() << endmsg;
100
101 std::string ident = pReg->identifier();
102
103 StatusCode status = readObject( pAddress, refpObject ); // Doesn't do anything
104 if ( status.isSuccess() ) {
105 RootObjAddress* rAddr = dynamic_cast<RootObjAddress*>( pAddress );
106 if ( !rAddr ) {
107 log << MSG::ERROR << "Could not cast to RootObjAddress" << endmsg;
108 return StatusCode::FAILURE;
109 }
110 INTuple* nt = nullptr;
111 TTree* tobj = (TTree*)rAddr->tObj();
112 status = load( tobj, nt );
113 if ( status.isSuccess() ) {
114 refpObject = dynamic_cast<DataObject*>( nt );
115 } else {
116 log << MSG::ERROR << "Problems loading ntuple id: " << pReg->identifier() << endmsg;
117 }
118 }
119 return status;
120}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
virtual const id_type & identifier() const =0
Full identifier (or key)
virtual StatusCode readObject(IOpaqueAddress *pAddr, DataObject *&refpObj)
Create the transient representation of an object.
virtual StatusCode load(TTree *tree, INTuple *&refpObj)=0
Create the transient representation of an object.
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto FAILURE
Definition StatusCode.h:100
@ ERROR
Definition IMessageSvc.h:22

◆ createRep()

StatusCode RootHistCnv::RNTupleCnv::createRep ( DataObject * pObj,
IOpaqueAddress *& refpAddr )
override

Convert the transient object to the requested representation.

Definition at line 124 of file RNTupleCnv.cpp.

126{
127 GlobalDirectoryRestore restore;
128 pAddr = nullptr;
129 try {
130 IRegistry* pReg = pObject->registry();
131 if ( pReg ) {
132 pAddr = pReg->address();
133 if ( !pAddr ) {
134 auto dataMgr = dataProvider().as<IDataManagerSvc>();
135 if ( dataMgr ) {
136 IRegistry* pParentReg = nullptr;
137 StatusCode status = dataMgr->objectParent( pReg, pParentReg );
138 if ( status.isSuccess() ) {
139 IOpaqueAddress* pParAddr = pParentReg->address();
140 if ( pParAddr ) {
141 TDirectory* pParentDir = (TDirectory*)pParAddr->ipar()[0];
142 if ( pParentDir ) {
143 TTree* pTree = nullptr;
144 auto dsc = pReg->name().substr( 1 );
145 gDirectory = pParentDir;
146 status = book( dsc, dynamic_cast<INTuple*>( pObject ), pTree );
147 if ( !status.isSuccess() ) { return status; }
148 status = createAddress( pObject, gDirectory, pTree, pAddr );
149 if ( !status.isSuccess() ) { return status; }
150 return writeData( pTree, dynamic_cast<INTuple*>( pObject ) );
151 }
152 }
153 }
154 }
155 } else {
156 TDirectory* pDir = (TDirectory*)pAddr->ipar()[0];
157 RootObjAddress* rAddr = dynamic_cast<RootObjAddress*>( pAddr );
158 if ( !rAddr ) {
159 MsgStream log( msgSvc(), "RNTupleCnv" );
160 log << MSG::ERROR << "Could not cast to RootObjAddress" << endmsg;
161 return StatusCode::FAILURE;
162 }
163 TTree* pTree = (TTree*)rAddr->tObj();
164 gDirectory = pDir;
165 return writeData( pTree, dynamic_cast<INTuple*>( pObject ) );
166 }
167 }
168 } catch ( ... ) {}
169 MsgStream log( msgSvc(), "RNTupleCnv" );
170 log << MSG::ERROR << "Failed to create persistent N-tuple!" << endmsg;
171 return StatusCode::FAILURE;
172}
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
Definition Converter.cpp:77
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
virtual const name_type & name() const =0
Name of the directory (or key)
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
StatusCode createAddress(DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
Create address of the transient object according to the requested representation.
virtual StatusCode writeData(TTree *rtree, INTuple *pObj)=0
Write N tuple data.
virtual StatusCode book(const std::string &desc, INTuple *pObj, TTree *&tree)=0
Book a new N tuple.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition SmartIF.h:110

◆ finalize()

StatusCode RootHistCnv::RNTupleCnv::finalize ( )
override

Finalize the converter.

Definition at line 55 of file RNTupleCnv.cpp.

55 {
56 //-----------------------------------------------------------------------------
57 m_ntupleSvc.reset();
58 return Converter::finalize();
59}
StatusCode finalize() override
Initialize the converter.
Definition Converter.cpp:59
SmartIF< INTupleSvc > m_ntupleSvc
Reference to N tuple service.
Definition RNTupleCnv.h:63

◆ initialize()

StatusCode RootHistCnv::RNTupleCnv::initialize ( )
override

Initialize the converter.

Definition at line 43 of file RNTupleCnv.cpp.

43 {
44 //-----------------------------------------------------------------------------
45 StatusCode status = Converter::initialize();
46 if ( status.isSuccess() ) {
47 m_ntupleSvc = serviceLocator()->service( "NTupleSvc" );
48 if ( !m_ntupleSvc ) status = StatusCode::FAILURE;
49 }
50 return status;
51}
StatusCode initialize() override
Initialize the converter.
Definition Converter.cpp:52
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.

◆ load()

virtual StatusCode RootHistCnv::RNTupleCnv::load ( TTree * tree,
INTuple *& refpObj )
protectedpure virtual

Create the transient representation of an object.

Implemented in RootHistCnv::RCWNTupleCnv, and RootHistCnv::RRWNTupleCnv.

◆ readData()

virtual StatusCode RootHistCnv::RNTupleCnv::readData ( TTree * rtree,
INTuple * pObj,
long ievt )
protectedpure virtual

Read N tuple data.

Implemented in RootHistCnv::RCWNTupleCnv, and RootHistCnv::RRWNTupleCnv.

◆ rootVarType()

std::string RootHistCnv::RNTupleCnv::rootVarType ( int type)
protectedvirtual

Return ROOT type info:

Definition at line 204 of file RNTupleCnv.cpp.

204 {
205 //-----------------------------------------------------------------------------
206 switch ( type ) {
208 return "/O"; // bool
210 return "/S"; // short
212 return "/I"; // int
214 return "/I"; // long
216 return "/L"; // long long
218 return "/s"; // ushort
220 return "/i"; // uint
222 return "/i"; // ulong
224 return "/l"; // unsigned long long
226 return "/F"; // float
228 return "/D"; // double
230 return "/B"; // char
232 return "/b"; // char
233 default:
234 return "";
235 }
236 // cannot reach this point
237}

◆ updateObj()

StatusCode RootHistCnv::RNTupleCnv::updateObj ( IOpaqueAddress * pAddr,
DataObject * refpObj )
override

Update the transient object from the other representation.

Definition at line 63 of file RNTupleCnv.cpp.

65{
66 MsgStream log( msgSvc(), "RNTupleCnv" );
67
68 StatusCode status = StatusCode::FAILURE;
69
70 RootObjAddress* rAddr = dynamic_cast<RootObjAddress*>( pAddress );
71
72 if ( !rAddr ) {
73 log << MSG::ERROR << "Could not dynamic cast to RootObjAddress" << endmsg;
75 }
76
77 TTree* rtree = (TTree*)rAddr->tObj();
78
79 try {
80 unsigned long* info = (unsigned long*)pAddress->ipar();
81 setDirectory( pAddress->par()[0] );
82 status = readData( rtree, dynamic_cast<INTuple*>( pObject ), info[1]++ );
83 } catch ( ... ) {}
84 return status;
85}
void setDirectory(const std::string &loc)
virtual StatusCode readData(TTree *rtree, INTuple *pObj, long ievt)=0
Read N tuple data.

◆ updateRep()

StatusCode RootHistCnv::RNTupleCnv::updateRep ( IOpaqueAddress * pAddr,
DataObject * pObj )
override

Update the converted representation of a transient object.

Definition at line 176 of file RNTupleCnv.cpp.

178{
179 MsgStream log( msgSvc(), "RNTupleCnv" );
180 if ( pAddr ) {
181 GlobalDirectoryRestore restore;
182 TDirectory* pDir = (TDirectory*)pAddr->ipar()[0];
183 RootObjAddress* rAddr = dynamic_cast<RootObjAddress*>( pAddr );
184 if ( !rAddr ) {
185 log << MSG::ERROR << "Could not cast to RootObjAddress" << endmsg;
186 return StatusCode::FAILURE;
187 }
188 TTree* pTree = (TTree*)rAddr->tObj();
189 if ( pDir && pTree ) {
190 gDirectory->cd( pDir->GetPath() );
191 pTree->Write( "", TObject::kOverwrite );
192 return StatusCode::SUCCESS;
193 }
194 } else {
195 log << MSG::WARNING << "empty ntuple: " << pObj->registry()->identifier() << endmsg;
196 return createRep( pObj, pAddr );
197 }
198 return StatusCode::FAILURE;
199}
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
StatusCode createRep(DataObject *pObj, IOpaqueAddress *&refpAddr) override
Convert the transient object to the requested representation.
constexpr static const auto SUCCESS
Definition StatusCode.h:99
@ WARNING
Definition IMessageSvc.h:22

◆ writeData()

virtual StatusCode RootHistCnv::RNTupleCnv::writeData ( TTree * rtree,
INTuple * pObj )
protectedpure virtual

Write N tuple data.

Implemented in RootHistCnv::RCWNTupleCnv, and RootHistCnv::RRWNTupleCnv.

Member Data Documentation

◆ m_ntupleSvc

SmartIF<INTupleSvc> RootHistCnv::RNTupleCnv::m_ntupleSvc
protected

Reference to N tuple service.

Definition at line 63 of file RNTupleCnv.h.


The documentation for this class was generated from the following files: