The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
RootHistCnv::RConverter Class Reference

Root Converter. More...

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

Inheritance diagram for RootHistCnv::RConverter:
Collaboration diagram for RootHistCnv::RConverter:

Public Member Functions

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.
 

Static Public Member Functions

static long storageType ()
 Inquire storage type.
 

Protected Member Functions

 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
 

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...
 
- Protected Attributes inherited from implements< IConverter >
std::atomic_ulong m_refCount
 Reference counter.
 

Detailed Description

Root Converter.

Author
Charles Leggett

Constructor & Destructor Documentation

◆ RConverter()

RootHistCnv::RConverter::RConverter ( const CLID & clid,
ISvcLocator * svc )
inlineprotected

Standard constructor.

Definition at line 64 of file RConverter.h.

64: Converter( storageType(), clid, svc ) {}
Converter(long storage_type, const CLID &class_type, ISvcLocator *svc=0)
Standard Constructor.
static long storageType()
Inquire storage type.
Definition RConverter.h:45

Member Function Documentation

◆ changeDirectory()

TDirectory * RootHistCnv::RConverter::changeDirectory ( DataObject * pObject)
protected

Switch to object directory (=Parent directory)

Definition at line 210 of file RConverter.cpp.

212{
213 if ( pObject ) {
214 IRegistry* pReg = pObject->registry();
215 if ( pReg ) {
216 auto dataMgr = dataProvider().as<IDataManagerSvc>();
217 if ( dataMgr ) {
218 IRegistry* pParentReg = nullptr;
219 StatusCode status = dataMgr->objectParent( pReg, pParentReg );
220 if ( status.isSuccess() ) {
221 IOpaqueAddress* pParAddr = pParentReg->address();
222 if ( pParAddr ) {
223 TDirectory* pParentDir = (TDirectory*)pParAddr->ipar()[0];
224 if ( pParentDir ) {
225 gDirectory->cd( pParentDir->GetPath() );
226 return pParentDir;
227 }
228 }
229 }
230 }
231 }
232 }
233 return nullptr;
234}
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
Definition Converter.cpp:77
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition SmartIF.h:110
bool isSuccess() const
Definition StatusCode.h:314

◆ convertId()

std::string RootHistCnv::RConverter::convertId ( const std::string & id) const

Definition at line 322 of file RConverter.cpp.

324{
325 bool forced = false;
326 if ( id.size() > 0 && isdigit( id[0] ) ) {
327 try {
328 Gaudi::Property<bool> tmp;
329 tmp.assign( conversionSvc().as<IProperty>()->getProperty( "ForceAlphaIds" ) );
330 forced = tmp.value();
331 } catch ( ... ) {}
332 }
333 if ( forced )
334 return "h" + id;
335 else
336 return id;
337}
const char *PyHelper getProperty(IInterface *p, char *name)
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
Definition Converter.cpp:89
const ValueType & value() const
Definition Property.h:229
bool assign(const Details::PropertyBase &source) override
get the value from another property
Definition Property.h:361
constexpr auto size(const T &, Args &&...) noexcept

◆ createAddress() [1/3]

StatusCode RootHistCnv::RConverter::createAddress ( const std::string & rzdir,
const CLID & clid,
const std::string & title,
TObject * pTobj,
IOpaqueAddress *& refpAddress )
protected

Definition at line 184 of file RConverter.cpp.

187{
188 auto pA = new RootObjAddress( repSvcType(), clid, rzdir, title, 0, 0, pTObj );
189
190 refpAddress = pA;
191 return StatusCode::SUCCESS;
192}
long repSvcType() const override
Definition RConverter.h:46
constexpr static const auto SUCCESS
Definition StatusCode.h:99

◆ createAddress() [2/3]

StatusCode RootHistCnv::RConverter::createAddress ( const std::string & rzdir,
const CLID & clid,
long id,
TObject * pTobj,
IOpaqueAddress *& refpAddress )
protected

Definition at line 195 of file RConverter.cpp.

198{
199 auto obj = std::to_string( id );
200 StatusCode status = createAddress( rzdir, clid, obj, pTobj, refpAddress );
201 if ( status.isSuccess() ) {
202 unsigned long* ipar = (unsigned long*)refpAddress->ipar();
203 ipar[0] = id;
204 }
205 return status;
206}
StatusCode createAddress(DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
Create address of the transient object according to the requested representation.

◆ createAddress() [3/3]

StatusCode RootHistCnv::RConverter::createAddress ( DataObject * pObject,
TDirectory * pDir,
TObject * pTObject,
IOpaqueAddress *& refpAddr )
protected

Create address of the transient object according to the requested representation.

Definition at line 165 of file RConverter.cpp.

168{
169 // Get address again....it does not change
170 IRegistry* pReg = pObj->registry();
171 if ( pReg ) {
172 refpAddr = pReg->address();
173 if ( !refpAddr ) {
174 refpAddr = new RootObjAddress( repSvcType(), objType(), pReg->name(), "", (unsigned long)( pDir ),
175 (unsigned long)( pTObj ), pTObj );
176
177 return StatusCode::SUCCESS;
178 }
179 }
180 return StatusCode::FAILURE;
181}
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition Converter.cpp:22
virtual const name_type & name() const =0
Name of the directory (or key)
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ createDirectory()

StatusCode RootHistCnv::RConverter::createDirectory ( const std::string & loc)

Definition at line 34 of file RConverter.cpp.

36{
37 MsgStream log( msgSvc(), "RConverter::createDir" );
38
39 // Get rid of leading /NTUPLES
40 std::string full = diskDirectory( loc );
41
42 std::string fil, cur, s;
43 TDirectory* gDir = gDirectory;
44
45 TFile* tf = nullptr;
46 if ( findTFile( loc, tf ).isSuccess() ) { tf->cd(); }
47
48 std::vector<std::string> lpath;
49 int i = 1;
50
51 auto p = full.find( ":", 0 );
52 if ( p != std::string::npos ) {
53 fil = full.substr( 0, p );
54 i = p + 1;
55 fil += ":/";
56 gDirectory->cd( fil.c_str() );
57 }
58
59 while ( ( p = full.find( "/", i ) ) != std::string::npos ) {
60 s = full.substr( i, p - i );
61 lpath.push_back( s );
62 i = p + 1;
63 }
64 lpath.push_back( full.substr( i ) );
65
66 if ( full.compare( 0, 1, "/" ) == 0 ) gDirectory->cd( "/" );
67
68 for ( const auto& litr : lpath ) {
69 cur = litr;
70 if ( !gDirectory->GetKey( litr.c_str() ) ) { gDirectory->mkdir( litr.c_str() ); }
71 gDirectory->cd( litr.c_str() );
72 }
73
74 gDirectory = gDir;
75
77}
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
std::string diskDirectory(const std::string &loc)
StatusCode findTFile(const std::string &, TFile *&)

◆ createDiskDirectory()

StatusCode RootHistCnv::RConverter::createDiskDirectory ( const std::string & loc)

◆ createPersistent()

◆ createRep()

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

Convert the transient object to the requested representation.

Definition at line 238 of file RConverter.cpp.

240{
241 GlobalDirectoryRestore restore;
242 pAddr = nullptr;
243 try {
244 TDirectory* pParentDir = changeDirectory( pObject );
245 if ( pParentDir ) {
246 TObject* pTObj = createPersistent( pObject );
247 if ( pTObj ) {
248 pTObj->Write();
249 delete pTObj;
250 return createAddress( pObject, pParentDir, nullptr, pAddr );
251 }
252 }
253 } catch ( ... ) {}
254 MsgStream log( msgSvc(), "RConverter" );
255 log << MSG::ERROR << "Failed to create persistent Object!" << endmsg;
256 return StatusCode::FAILURE;
257}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
TDirectory * changeDirectory(DataObject *pObject)
Switch to object directory (=Parent directory)
virtual TObject * createPersistent(DataObject *pObj)
Create the persistent representation of an object.
@ ERROR
Definition IMessageSvc.h:22

◆ directory()

std::string RootHistCnv::RConverter::directory ( const std::string & loc)

Definition at line 111 of file RConverter.cpp.

113{
114 return diskDirectory( loc );
115}

◆ diskDirectory()

std::string RootHistCnv::RConverter::diskDirectory ( const std::string & loc)

Definition at line 79 of file RConverter.cpp.

81{
82 // Get rid of leading /NTUPLES/{INPUT_STREAM} or /stat/{INPUT_STREAM}
83 std::string dir;
84 long lf1 = loc.find( "/NTUPLES/" );
85 long lf2 = loc.find( "/stat/" );
86 long ll;
87 if ( lf1 != -1 ) {
88 ll = loc.find( "/", lf1 + 9 );
89
90 } else if ( lf2 != -1 ) {
91 ll = loc.find( "/", lf2 + 6 );
92
93 } else {
94 MsgStream log( msgSvc(), "RConverter" );
95 log << MSG::ERROR << "diskDirectory(" << loc << ")"
96 << " --> no leading /NTUPLES/ or /stat/" << endmsg;
97 return loc;
98 }
99 // dir = loc.substr(ll+8);
100
101 if ( ll == -1 ) {
102 dir = "/";
103 } else {
104 dir = loc.substr( ll );
105 }
106
107 return dir;
108}

◆ error()

StatusCode RootHistCnv::RConverter::error ( const std::string & msg)

Definition at line 339 of file RConverter.cpp.

341{
342 MsgStream log( msgSvc(), "RootHistCnv" );
343 log << MSG::ERROR << msg << endmsg;
344 return StatusCode::FAILURE;
345}

◆ findTFile()

StatusCode RootHistCnv::RConverter::findTFile ( const std::string & id,
TFile *& tfile )

Definition at line 289 of file RConverter.cpp.

291{
292 MsgStream log( msgSvc(), "RConverter" );
293 tfile = nullptr;
294
295 std::string idm;
296
297 // make sure we only get first two parts of id
298 int i1, i2, i3;
299 i1 = id.find( "/", 0 );
300 if ( i1 != 0 ) {
301 log << MSG::ERROR << "Directory name does not start with \"/\": " << id << endmsg;
302 return StatusCode::FAILURE;
303 }
304 i2 = id.find( "/", i1 + 1 );
305 if ( i2 == -1 ) {
306 log << MSG::ERROR << "Directory name has only one part: " << id << endmsg;
307 return StatusCode::FAILURE;
308 }
309 i3 = id.find( "/", i2 + 1 );
310 if ( i3 == -1 ) {
311 idm = id;
312 } else {
313 idm = id.substr( 0, i3 );
314 }
315
316 auto imap = s_fileMap.find( idm );
317 if ( imap == s_fileMap.end() ) return StatusCode::FAILURE;
318 tfile = imap->second;
319 return StatusCode::SUCCESS;
320}

◆ getDirectory()

std::string RootHistCnv::RConverter::getDirectory ( )

Definition at line 158 of file RConverter.cpp.

160{
161 return gDirectory->GetPath();
162}

◆ readObject()

StatusCode RootHistCnv::RConverter::readObject ( IOpaqueAddress * pAddr,
DataObject *& refpObj )
protectedvirtual

Create the transient representation of an object.

Definition at line 260 of file RConverter.cpp.

260 {
261 // MsgStream log(msgSvc(), "RConverter::readObject");
262 // log << MSG::WARNING << pAddr->par()[0] << " <> " << pAddr->par()[1]
263 // << " <> "
264 // << pAddr->ipar()[0] << " <> " << pAddr->ipar()[1] << " <> "
265 // << pAddr->registry()->identifier() << endmsg;
266
267 return StatusCode::SUCCESS;
268}

◆ regTFile()

StatusCode RootHistCnv::RConverter::regTFile ( const std::string & id,
const TFile * tfile )

Definition at line 274 of file RConverter.cpp.

276{
277 auto imap = s_fileMap.find( id );
278 if ( imap != s_fileMap.end() ) {
279 MsgStream log( msgSvc(), "RConverter" );
280 log << MSG::ERROR << "cannot register TTree " << id << ": already exists" << endmsg;
281 return StatusCode::FAILURE;
282 }
283 s_fileMap[id] = const_cast<TFile*>( tfile );
284
285 return StatusCode::SUCCESS;
286}

◆ repSvcType()

long RootHistCnv::RConverter::repSvcType ( ) const
inlineoverride

Definition at line 46 of file RConverter.h.

46{ return i_repSvcType(); }
virtual long i_repSvcType() const
Retrieve the class type of the data store the converter uses.
Definition Converter.cpp:25

◆ setDirectory()

void RootHistCnv::RConverter::setDirectory ( const std::string & loc)

Definition at line 118 of file RConverter.cpp.

120{
121 MsgStream log( msgSvc(), "RConverter" );
122 TFile* tf = nullptr;
123
124 std::string full = diskDirectory( loc );
125
126 // get associated TFile
127 if ( findTFile( loc, tf ).isSuccess() ) {
128 tf->cd();
129 } else {
130 log << MSG::ERROR << "error getting TFile name " << loc << endmsg;
131 }
132
133 int p, i = 1;
134 std::string cur, sdir;
135
136 gDirectory->cd( "/" );
137 while ( ( p = full.find( "/", i ) ) != -1 ) {
138 sdir = full.substr( i, p - i );
139 if ( !gDirectory->GetKey( sdir.c_str() ) ) {
140 log << MSG::ERROR << "cannot cd to " << full << " from " << gDirectory->GetPath() << endmsg;
141 return;
142 }
143 gDirectory->cd( sdir.c_str() );
144
145 i = p + 1;
146 }
147 gDirectory->cd( full.substr( i ).c_str() );
148}

◆ setDiskDirectory()

void RootHistCnv::RConverter::setDiskDirectory ( const std::string & loc)

Definition at line 151 of file RConverter.cpp.

153{
154 setDirectory( loc );
155}
void setDirectory(const std::string &loc)

◆ storageType()

static long RootHistCnv::RConverter::storageType ( )
inlinestatic

Inquire storage type.

Definition at line 45 of file RConverter.h.

45{ return ROOT_StorageType; }
const long ROOT_StorageType
Definition ClassID.h:60

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