The Gaudi Framework  master (37c0b60a)
RootHistCnv::RConverter Class Reference

#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. More...
 
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. More...
 
StatusCode finalize () override
 Initialize the converter. More...
 
StatusCode setDataProvider (IDataProviderSvc *svc) override
 Set Data provider service. More...
 
SmartIF< IDataProviderSvc > & dataProvider () const override
 Get Data provider service. More...
 
StatusCode setConversionSvc (IConversionSvc *svc) override
 Set conversion service the converter is connected to. More...
 
SmartIF< IConversionSvc > & conversionSvc () const override
 Get conversion service the converter is connected to. More...
 
StatusCode setAddressCreator (IAddressCreator *creator) override
 Set address creator facility. More...
 
SmartIF< IAddressCreator > & addressCreator () const override
 Retrieve address creator facility. More...
 
const CLIDobjType () const override
 Retrieve the class type of objects the converter produces. More...
 
virtual long i_repSvcType () const
 Retrieve the class type of the data store the converter uses. More...
 
StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Create the transient representation of an object. More...
 
StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the created transient object. More...
 
StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *refpObject) override
 Update the transient object from the other representation. More...
 
StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an updated transient object. More...
 
StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress) override
 Convert the transient object to the requested representation. More...
 
StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the converted object. More...
 
StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the converted representation of a transient object. More...
 
StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an already converted object. More...
 
 Converter (long storage_type, const CLID &class_type, ISvcLocator *svc=0)
 Standard Constructor. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=false) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &type, const std::string &name, T *&psvc) const
 Access a service by name, type creating it if it doesn't already exist. More...
 
SmartIF< IServiceservice (const std::string &name, const bool createIf=true) const
 Return a pointer to the service identified by name (or "type/name") More...
 
- Public Member Functions inherited from implements< IConverter >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 implements ()=default
 Default constructor. More...
 
 implements (const implements &)
 Copy constructor (zero the reference count) More...
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count). More...
 
unsigned long addRef () override
 Reference Interface instance
More...
 
unsigned long release () override
 Release Interface instance
More...
 
unsigned long refCount () const override
 Current reference count
More...
 

Static Public Member Functions

static long storageType ()
 Inquire storage type. More...
 

Protected Member Functions

 RConverter (const CLID &clid, ISvcLocator *svc)
 Standard constructor. More...
 
virtual StatusCode readObject (IOpaqueAddress *pAddr, DataObject *&refpObj)
 Create the transient representation of an object. More...
 
virtual TObject * createPersistent (DataObject *pObj)
 Create the persistent representation of an object. More...
 
StatusCode createAddress (DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
 Create address of the transient object according to the requested representation. More...
 
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) More...
 
- Protected Member Functions inherited from Converter
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 Retrieve pointer to message service. More...
 
SmartIF< IDataManagerSvc > & dataManager () const
 Get Data Manager service. More...
 

Additional Inherited Members

- Public Types inherited from Converter
using Factory = Gaudi::PluginService::Factory< IConverter *(ISvcLocator *)>
 
- Public Types inherited from implements< IConverter >
using base_class = implements< Interfaces... >
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
using iids = typename extend_interfaces_base::ext_iids
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Attributes inherited from implements< IConverter >
std::atomic_ulong m_refCount
 Reference counter
More...
 

Detailed Description

Root Converter

Author
Charles Leggett

Definition at line 41 of file RConverter.h.

Constructor & Destructor Documentation

◆ RConverter()

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

Standard constructor.

Definition at line 65 of file RConverter.h.

65 : Converter( storageType(), clid, svc ) {}

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 }

◆ 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 {
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 }

◆ 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 }

◆ 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 }

◆ 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 }

◆ 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
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 
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 
76  return StatusCode::SUCCESS;
77 }

◆ createDiskDirectory()

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

◆ createPersistent()

TObject * RootHistCnv::RConverter::createPersistent ( DataObject pObj)
protectedvirtual

Create the persistent representation of an object.

Reimplemented in RootHistCnv::RHistogramCnv< T, S, Q >.

Definition at line 271 of file RConverter.cpp.

271 { return nullptr; }

◆ 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 }

◆ 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 47 of file RConverter.h.

47 { return i_repSvcType(); }

◆ 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 }

◆ storageType()

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

Inquire storage type.

Definition at line 46 of file RConverter.h.

46 { return ROOT_StorageType; }

The documentation for this class was generated from the following files:
Converter::dataProvider
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
Definition: Converter.cpp:78
std::isdigit
T isdigit(T... args)
RootHistCnv::RConverter::createPersistent
virtual TObject * createPersistent(DataObject *pObj)
Create the persistent representation of an object.
Definition: RConverter.cpp:271
std::string
STL class.
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:23
Gaudi.Configuration.log
log
Definition: Configuration.py:28
IDataManagerSvc
Definition: IDataManagerSvc.h:55
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
Gaudi::Accumulators::atomicity::full
@ full
gaudirun.s
string s
Definition: gaudirun.py:346
IOpaqueAddress
Definition: IOpaqueAddress.h:33
std::vector< std::string >
std::string::find
T find(T... args)
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
RootHistCnv::RConverter::findTFile
StatusCode findTFile(const std::string &, TFile *&)
Definition: RConverter.cpp:289
IRegistry
Definition: IRegistry.h:32
Gaudi::Property::assign
bool assign(const Details::PropertyBase &source) override
get the value from another property
Definition: Property.h:370
GaudiPartProp.tests.id
id
Definition: tests.py:111
RootHistCnv::RConverter::setDirectory
void setDirectory(const std::string &loc)
Definition: RConverter.cpp:118
std::vector::push_back
T push_back(T... args)
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key)
StatusCode
Definition: StatusCode.h:65
RootHistCnv::RConverter::diskDirectory
std::string diskDirectory(const std::string &loc)
Definition: RConverter.cpp:79
RootHistCnv::RConverter::storageType
static long storageType()
Inquire storage type.
Definition: RConverter.h:46
std::string::c_str
T c_str(T... args)
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
Converter::conversionSvc
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
Definition: Converter.cpp:90
std::to_string
T to_string(T... args)
RootHistCnv::RConverter::createAddress
StatusCode createAddress(DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
Create address of the transient object according to the requested representation.
Definition: RConverter.cpp:165
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Converter::i_repSvcType
virtual long i_repSvcType() const
Retrieve the class type of the data store the converter uses.
Definition: Converter.cpp:26
ROOT_StorageType
const long ROOT_StorageType
Definition: ClassID.h:62
Converter::objType
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:23
Converter::Converter
Converter(long storage_type, const CLID &class_type, ISvcLocator *svc=0)
Standard Constructor.
Definition: Converter.cpp:114
MsgStream
Definition: MsgStream.h:33
GlobalDirectoryRestore
Definition: RConverter.h:26
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:117
std::string::substr
T substr(T... args)
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
RootHistCnv::RConverter::repSvcType
long repSvcType() const override
Definition: RConverter.h:47
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
RootHistCnv::RConverter::changeDirectory
TDirectory * changeDirectory(DataObject *pObject)
Switch to object directory (=Parent directory)
Definition: RConverter.cpp:210
Converter::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:105
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
getProperty
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:251
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:78
Gaudi::Property< bool >
IOpaqueAddress::ipar
virtual const unsigned long * ipar() const =0
Access to generic link parameters.