The Gaudi Framework  v29r0 (ff2e7097)
Gaudi::RootNTupleCnv Class Reference

NTuple converter class definition for NTuples writted/read using ROOT. More...

#include <Root/RootNTupleCnv.h>

Inheritance diagram for Gaudi::RootNTupleCnv:
Collaboration diagram for Gaudi::RootNTupleCnv:

Public Member Functions

 RootNTupleCnv (long typ, const CLID &clid, ISvcLocator *svc, RootCnvSvc *mgr)
 Standard constructor. More...
 
 ~RootNTupleCnv () override=default
 Standard destructor. More...
 
StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAdd) override
 Converter overrides: Convert the transient object to the requested representation. More...
 
StatusCode fillRepRefs (IOpaqueAddress *pAdd, DataObject *pObj) override
 Resolve the references of the converted object. More...
 
StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Converter overrides: Update the references of an updated transient object. More...
 
StatusCode fillObjRefs (IOpaqueAddress *, DataObject *) override
 Converter overrides: Update the references of an updated transient object. More...
 
StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the transient object: NTuples end here when reading records. More...
 
StatusCode updateObjRefs (IOpaqueAddress *, DataObject *) override
 Converter overrides: Update the references of an updated transient object. More...
 
StatusCode updateRep (IOpaqueAddress *, DataObject *) override
 Converter overrides: Update the converted representation of a transient object. More...
 
StatusCode updateRepRefs (IOpaqueAddress *, DataObject *) override
 Converter overrides: Update the converted representation of a transient object. More...
 
- Public Member Functions inherited from Gaudi::RootStatCnv
 RootStatCnv (long typ, const CLID &clid, ISvcLocator *svc, RootCnvSvc *mgr)
 Initializing Constructor. More...
 
 ~RootStatCnv () override=default
 Standard Destructor. More...
 
- Public Member Functions inherited from Gaudi::RootConverter
 RootConverter (long typ, const CLID &clid, ISvcLocator *svc, RootCnvSvc *mgr)
 Initializing Constructor. More...
 
 ~RootConverter () override=default
 Standard Destructor. More...
 
long repSvcType () const override
 Retrieve the class type of the data store the converter uses. More...
 
StatusCode createObj (IOpaqueAddress *pAddr, DataObject *&refpObj) override
 Converter overrides: Create transient object from persistent data. More...
 
StatusCode fillObjRefs (IOpaqueAddress *pAddr, DataObject *pObj) override
 Resolve the references of the created transient object. More...
 
StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAddr) override
 Converter overrides: Convert the transient object to the requested representation. More...
 
StatusCode fillRepRefs (IOpaqueAddress *pAddr, DataObject *pObj) override
 Resolve the references of the created transient object. More...
 
- 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...
 
 ~implements () override=default
 Virtual destructor. 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...
 
- Public Member Functions inherited from extend_interfaces< Interfaces... >
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Protected Member Functions

StatusCode i__updateObjRoot (RootAddress *rpA, INTuple *tupl, TTree *tree, RootDataConnection *con)
 Update the transient object: NTuples end here when reading records. More...
 
- Protected Member Functions inherited from Gaudi::RootStatCnv
MsgStreamlog () const
 Helper to use mesage logger. More...
 
StatusCode initialize () override
 Initialize converter object. More...
 
StatusCode finalize () override
 Finalize converter object. More...
 
virtual const std::string containerName (IRegistry *pDir) const
 Retrieve the name of the container a given object is placed into. More...
 
virtual const std::string fileName (IRegistry *pReg) const
 Retrieve the name of the file a given object is placed into. More...
 
virtual const std::string topLevel (IRegistry *pReg) const
 Retrieve the full path of the file a given object is placed into. More...
 
StatusCode makeError (const std::string &msg, bool throw_exception=false) const
 Helper method to issue error messages. More...
 
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. More...
 
- Protected Member Functions inherited from Converter
 ~Converter () override=default
 Standard Destructor. More...
 
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
typedef Gaudi::PluginService::Factory< IConverter *, ISvcLocator * > Factory
 
- 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 Gaudi::RootStatCnv
SmartIF< IDataManagerSvcm_dataMgr
 Reference to data manager service to manipulate the TES. More...
 
std::unique_ptr< MsgStreamm_log
 Reference to logger object. More...
 
- Protected Attributes inherited from Gaudi::RootConverter
RootCnvSvcm_dbMgr
 Conversion service needed for proper operation to forward requests. More...
 
- Protected Attributes inherited from implements< IConverter >
std::atomic_ulong m_refCount
 Reference counter. More...
 

Detailed Description

NTuple converter class definition for NTuples writted/read using ROOT.

Description: Definition of the generic converter for row wise and column wise Ntuples.

Author
M.Frank
Version
1.0

Definition at line 36 of file RootNTupleCnv.h.

Constructor & Destructor Documentation

Gaudi::RootNTupleCnv::RootNTupleCnv ( long  typ,
const CLID clid,
ISvcLocator svc,
RootCnvSvc mgr 
)
inline

Standard constructor.

Parameters
clid[IN] Class ID of the object type to be converted.
db[IN] Pointer to POOL database interface
svc[IN] Pointer to Gaudi service locator
Returns
Reference to RootNTupleCnv object

Definition at line 56 of file RootNTupleCnv.h.

56  : RootStatCnv( typ, clid, svc, mgr )
57  {
58  }
RootStatCnv(long typ, const CLID &clid, ISvcLocator *svc, RootCnvSvc *mgr)
Initializing Constructor.
Definition: RootStatCnv.cpp:24
Gaudi::RootNTupleCnv::~RootNTupleCnv ( )
overridedefault

Standard destructor.

Member Function Documentation

StatusCode RootNTupleCnv::createObj ( IOpaqueAddress pAddress,
DataObject *&  refpObject 
)
override

Converter overrides: Update the references of an updated transient object.

Parameters
pAddress[IN] Valid pointer to the object's opaque address
refpObject[OUT] Location to store pointer to DataObject
Returns
Status code indicating success or failure

Definition at line 118 of file RootNTupleCnv.cpp.

119 {
120  StatusCode status = S_FAIL;
121  RootDataConnection* con = nullptr;
122  IRegistry* pRegistry = pAddr->registry();
123  RootAddress* rpA = dynamic_cast<RootAddress*>( pAddr );
124  string path = fileName( pRegistry );
125  string cntName = containerName( pRegistry );
126  string* par = const_cast<string*>( pAddr->par() );
127  status = m_dbMgr->connectDatabase( path, IDataConnection::READ, &con );
128  if ( status.isSuccess() ) {
129  string par_val, par_guid;
130  TBranch* b = con->getBranch( "##Descriptors", "GaudiStatisticsDescription" );
131  if ( b ) {
134  b->SetAddress( &ptr );
135  for ( Long64_t i = 0, nent = b->GetEntries(); i < nent; ++i ) {
136  int nb = b->GetEntry( i );
137  if ( nb > 1 ) {
138  if ( ptr->container == cntName ) {
139  par_val = ptr->description;
140  break;
141  }
142  }
143  }
144  }
145  par[2] = _tr( cntName );
146  TTree* tree = con->getSection( par[2] );
147  if ( nullptr == tree ) {
148  return makeError( "Failed to access N-Tuple tree:" + cntName );
149  }
150  if ( !par_val.empty() ) {
151  auto ntupleSvc = dataProvider().as<INTupleSvc>();
152  if ( ntupleSvc ) {
153  char c;
154  CLID clid;
155  int siz, typ;
156  string title;
157  NTuple::Tuple* nt = nullptr;
158  istringstream is( par_val );
159  getline( is, title, ';' ) >> clid >> c >> siz >> c;
160  status = ntupleSvc->create( clid, title, nt );
161  for ( int j = 0; j < siz && status.isSuccess(); j++ ) {
162  is >> c;
163  getline( is, title, ';' ) >> typ >> c;
164  switch ( typ ) {
165  case DataTypeInfo::UCHAR:
166  status = createItem( tree, nt, is, title, true, (unsigned char)0 );
167  break;
169  status = createItem( tree, nt, is, title, true, (unsigned short)0 );
170  break;
171  case DataTypeInfo::UINT:
172  status = createItem( tree, nt, is, title, true, (unsigned int)0 );
173  break;
174  case DataTypeInfo::ULONG:
175  status = createItem( tree, nt, is, title, true, (unsigned long)0 );
176  break;
177  case DataTypeInfo::CHAR:
178  status = createItem( tree, nt, is, title, true, char( 0 ) );
179  break;
180  case DataTypeInfo::SHORT:
181  status = createItem( tree, nt, is, title, true, short( 0 ) );
182  break;
183  case DataTypeInfo::INT:
184  status = createItem( tree, nt, is, title, true, int( 0 ) );
185  break;
186  case DataTypeInfo::LONG:
187  status = createItem( tree, nt, is, title, true, long( 0 ) );
188  break;
189  case DataTypeInfo::BOOL:
190  status = createItem( tree, nt, is, title, true, false );
191  break;
192  case DataTypeInfo::FLOAT:
193  status = createItem( tree, nt, is, title, true, float( 0.0 ) );
194  break;
196  status = createItem( tree, nt, is, title, true, double( 0.0 ) );
197  break;
198  /*
199  case DataTypeInfo::NTCHAR:
200  case DataTypeInfo::LONG_NTCHAR:
201  status =
202  createItem(tree, nt, is, title, true, (char*)0);
203  break;
204  case DataTypeInfo::STRING:
205  case DataTypeInfo::LONG_STRING:
206  status =
207  createItem(tree, nt, is, title, true, string(""));
208  break;
209  */
211  status = createItem( tree, nt, is, title, false, (IOpaqueAddress*)nullptr );
212  break;
214  status = createItem( tree, nt, is, title, true, (void*)nullptr );
215  break;
217  default:
218  status = S_FAIL;
219  break;
220  }
221  if ( !status.isSuccess() ) {
222  log() << MSG::FATAL << "Error connecting (Unknown) column:" << j << endmsg << par_val << endmsg;
223  return makeError( "createObj[NTuple]> Cannot determine column!" );
224  }
225  }
226  if ( status.isSuccess() ) {
227  unsigned long* ipar = const_cast<unsigned long*>( rpA->ipar() );
228  log() << MSG::DEBUG << "Created N-tuple with description:" << par_val << endl;
229  ipar[0] = (unsigned long)con;
230  ipar[1] = ~0x0UL;
231  rpA->section = tree;
232  refpObject = nt;
233  } else {
234  refpObject = nullptr;
235  if ( nt ) nt->release();
236  }
237  }
238  }
239  }
240  return status;
241 }
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:40
T empty(T...args)
Description:
Definition: RootAddress.h:37
TTree * section
Pointer to ROOT TTree (filled for N-tuples only)
Definition: RootAddress.h:43
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:37
T getline(T...args)
TTree * getSection(const std::string &sect, bool create=false)
Access TTree section from section name. The section is created if required.
T endl(T...args)
#define S_FAIL
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
StatusCode connectDatabase(const std::string &dataset, int mode, RootDataConnection **con)
Connect the output file to the service with open mode.
Definition: RootCnvSvc.cpp:211
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:115
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
virtual const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
Definition: RootStatCnv.cpp:70
const unsigned long * ipar() const override
Retrieve integer parameters.
TBranch * getBranch(const std::string &section, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
std::string description
Description string.
Definition: RootRefs.h:81
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:412
virtual unsigned long release()
release reference to object
Definition: DataObject.cpp:51
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
Definition: Converter.cpp:74
STL class.
std::string container
Identifier of description.
Definition: RootRefs.h:85
Opaque address interface definition.
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Definition: RootStatCnv.cpp:52
Concrete implementation of the IDataConnection interface to access ROOT files.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode RootNTupleCnv::createRep ( DataObject pObj,
IOpaqueAddress *&  refpAdd 
)
override

Converter overrides: Convert the transient object to the requested representation.

Convert the transient object to the requested representation.

Parameters
pObj[IN] Valid pointer to DataObject
refpAdd[OUT] Location to store pointer to the object's opaque address
Returns
Status code indicating success or failure

Definition at line 372 of file RootNTupleCnv.cpp.

373 {
374  IRegistry* pRegistry = pObj->registry();
375  if ( nullptr != pRegistry ) {
376  pAddr = pRegistry->address();
377  if ( nullptr != pAddr ) {
378  return S_OK;
379  }
380 
381  RootDataConnection* con = nullptr;
382  string path = fileName( pRegistry );
383  string cntName = containerName( pRegistry );
384  string secName = cntName.c_str();
385  const INTuple* nt = dynamic_cast<const INTuple*>( pObj );
387  if ( !status.isSuccess() ) {
388  return makeError( "Failed to access Tuple file:" + path );
389  }
390  TTree* tree = con->getSection( _tr( secName ), true );
391  if ( nullptr != nt ) {
392  const INTuple::ItemContainer& items = nt->items();
393  ostringstream os;
394  size_t item_no;
395  string desc;
396  os << nt->title() << ';' << pObj->clID() << ';' << items.size() << ';';
397  map<string, TBranch*> branches;
398  TBranch* b = nullptr;
399  for ( item_no = 0; item_no < items.size(); ++item_no ) {
400  INTupleItem* it = items[item_no];
401  if ( it->hasIndex() ) {
402  INTupleItem* itm = it->indexItem();
403  const string& n = itm->name();
404  switch ( itm->type() ) {
405  case DataTypeInfo::UCHAR:
406  desc = n + "/b";
407  b = tree->Branch( n.c_str(), (void*)itm->buffer(), desc.c_str() );
408  break;
410  desc = n + "/s";
411  b = tree->Branch( n.c_str(), (void*)itm->buffer(), desc.c_str() );
412  break;
413  case DataTypeInfo::UINT:
414  desc = n + "/i";
415  b = tree->Branch( n.c_str(), (void*)itm->buffer(), desc.c_str() );
416  break;
417  case DataTypeInfo::ULONG:
418  desc = n + "/l";
419  b = tree->Branch( n.c_str(), (void*)itm->buffer(), desc.c_str() );
420  break;
421  case DataTypeInfo::CHAR:
422  desc = n + "/B";
423  b = tree->Branch( n.c_str(), (void*)itm->buffer(), desc.c_str() );
424  break;
425  case DataTypeInfo::SHORT:
426  desc = n + "/S";
427  b = tree->Branch( n.c_str(), (void*)itm->buffer(), desc.c_str() );
428  break;
429  case DataTypeInfo::INT:
430  desc = n + "/I";
431  b = tree->Branch( n.c_str(), (void*)itm->buffer(), desc.c_str() );
432  break;
433  case DataTypeInfo::LONG:
434  desc = n + "/L";
435  b = tree->Branch( n.c_str(), (void*)itm->buffer(), desc.c_str() );
436  break;
437  default:
438  return makeError( "Column " + it->index() + " is not a valid index column!" );
439  }
440  branches[n] = b;
441  }
442  }
443  for ( item_no = 0; item_no < items.size(); ++item_no ) {
444  INTupleItem* it = items[item_no];
445  const string& n = it->name();
446  os << '{' << n << ';' << it->type() << ';' << it->length() << ';' << it->ndim() << ';' << it->hasIndex() << ';';
447  if ( it->hasIndex() ) {
448  os << it->index() << ';';
449  INTupleItem* itm = it->indexItem();
450  switch ( itm->type() ) {
451  case DataTypeInfo::UCHAR:
452  putRange( os, dynamic_cast<NTuple::_Data<unsigned char>*>( itm ) );
453  break;
455  putRange( os, dynamic_cast<NTuple::_Data<unsigned short>*>( itm ) );
456  break;
457  case DataTypeInfo::UINT:
458  putRange( os, dynamic_cast<NTuple::_Data<unsigned int>*>( itm ) );
459  break;
460  case DataTypeInfo::ULONG:
461  putRange( os, dynamic_cast<NTuple::_Data<unsigned long>*>( itm ) );
462  break;
463  case DataTypeInfo::CHAR:
464  putRange( os, dynamic_cast<NTuple::_Data<char>*>( itm ) );
465  break;
466  case DataTypeInfo::SHORT:
467  putRange( os, dynamic_cast<NTuple::_Data<short>*>( itm ) );
468  break;
469  case DataTypeInfo::INT:
470  putRange( os, dynamic_cast<NTuple::_Data<int>*>( itm ) );
471  break;
472  case DataTypeInfo::LONG:
473  putRange( os, dynamic_cast<NTuple::_Data<long>*>( itm ) );
474  break;
475  default:
476  return makeError( "NTuple:" + pRegistry->name() + " Column " + it->index() +
477  " is not a valid index column!" );
478  }
479  }
480  for ( long k = 0; k < it->ndim(); k++ ) {
481  os << it->dim( k ) << ';';
482  }
483  desc = n;
484  TClass* cl = nullptr;
485  switch ( it->type() ) {
487  desc = "/C";
488  os << 0 << ';' << 0 << ';';
489  break;
491  desc = "/C";
492  os << 0 << ';' << 0 << ';';
493  break;
495  if ( it->length() == 1 ) {
496  desc = System::typeinfoName( typeid( RootRef ) );
497  os << 0 << ';' << 0 << ';';
498  cl = TClass::GetClass( desc.c_str(), kTRUE );
499  }
500  break;
502  if ( it->length() == 1 ) {
503  os << 0 << ';' << 0 << ';';
504  cl = TClass::GetClass( it->typeID(), kTRUE );
505  }
506  break;
507  case DataTypeInfo::UCHAR:
508  desc = "/b";
509  putRange( os, dynamic_cast<NTuple::_Data<unsigned char>*>( it ) );
510  break;
512  desc = "/s";
513  putRange( os, dynamic_cast<NTuple::_Data<unsigned short>*>( it ) );
514  break;
515  case DataTypeInfo::UINT:
516  desc = "/i";
517  putRange( os, dynamic_cast<NTuple::_Data<unsigned int>*>( it ) );
518  break;
519  case DataTypeInfo::ULONG:
520  desc = "/l";
521  putRange( os, dynamic_cast<NTuple::_Data<unsigned long>*>( it ) );
522  break;
523  case DataTypeInfo::CHAR:
524  desc = "/B";
525  putRange( os, dynamic_cast<NTuple::_Data<char>*>( it ) );
526  break;
527  case DataTypeInfo::SHORT:
528  desc = "/S";
529  putRange( os, dynamic_cast<NTuple::_Data<short>*>( it ) );
530  break;
531  case DataTypeInfo::INT:
532  desc = "/I";
533  putRange( os, dynamic_cast<NTuple::_Data<int>*>( it ) );
534  break;
535  case DataTypeInfo::LONG:
536  desc = "/L";
537  putRange( os, dynamic_cast<NTuple::_Data<long>*>( it ) );
538  break;
539  case DataTypeInfo::BOOL:
540  desc = "/b";
541  putRange( os, dynamic_cast<NTuple::_Data<bool>*>( it ) );
542  break;
543  case DataTypeInfo::FLOAT:
544  desc = "/F";
545  putRange( os, dynamic_cast<NTuple::_Data<float>*>( it ) );
546  break;
548  desc = "/D";
549  putRange( os, dynamic_cast<NTuple::_Data<double>*>( it ) );
550  break;
552  default:
553  return makeError( "Create item[FAIL]: " + it->name() );
554  }
555  os << '}';
556  if ( branches.find( n ) == branches.end() ) {
557  string tmp;
558  char text[32];
559  switch ( it->ndim() ) {
560  case 0:
561  desc = n + desc;
562  break;
563  case 2:
564  sprintf( text, "[%ld]", it->dim( 0 ) );
565  tmp = text;
566  /* FALLTHROUGH */
567  case 1:
568  if ( it->hasIndex() ) {
569  INTupleItem* itm = it->indexItem();
570  desc = n + tmp + "[" + itm->name() + "]" + desc;
571  } else {
572  sprintf( text, "[%ld]", it->dim( 0 ) );
573  desc = n + tmp + text + desc;
574  }
575  }
576  log() << MSG::DEBUG << "Create branch:" << n << " Desc:" << desc << " of type:" << it->type() << endmsg;
577  switch ( it->type() ) {
579  branches[n] = tree->Branch( n.c_str(), cl->GetName(), (void*)it->buffer() );
580  break;
582  branches[n] = tree->Branch( n.c_str(), cl->GetName(), (void*)it->buffer() );
583  break;
584  default:
585  branches[n] = tree->Branch( n.c_str(), (void*)it->buffer(), desc.c_str() );
586  break;
587  }
588  }
589  }
590 
591  log() << MSG::DEBUG << "Save description:" << path << " -> " << cntName << endmsg << os.str() << endmsg;
592  status = saveDescription( path, cntName, os.str(), "", pObj->clID() );
593  if ( status.isSuccess() ) {
594  status = m_dbMgr->commitOutput( path, true );
595  if ( status.isSuccess() ) {
596  string spar[] = {path, cntName};
597  unsigned long ipar[] = {(unsigned long)con, ~0x0u};
598  status = m_dbMgr->createAddress( repSvcType(), pObj->clID(), spar, ipar, pAddr );
599  if ( status.isSuccess() ) {
600  RootAddress* rpA = dynamic_cast<RootAddress*>( pAddr );
601  ( (unsigned long*)rpA->ipar() )[0] = (unsigned long)con;
602  rpA->section = tree;
603  } else {
604  pAddr->release();
605  pAddr = nullptr;
606  }
607  }
608  }
609  return status;
610  }
611  }
612  return S_FAIL;
613 }
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:40
virtual const std::string & name() const =0
Access _Item name.
Description:
Definition: RootAddress.h:37
TTree * section
Pointer to ROOT TTree (filled for N-tuples only)
Definition: RootAddress.h:43
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:329
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:371
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
Definition: RootConverter.h:37
TTree * getSection(const std::string &sect, bool create=false)
Access TTree section from section name. The section is created if required.
virtual const name_type & name() const =0
Name of the directory (or key)
#define S_FAIL
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
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:211
long repSvcType() const override
Retrieve the class type of the data store the converter uses.
Definition: RootConverter.h:56
STL class.
StatusCode commitOutput(const std::string &outputFile, bool do_commit) override
Commit pending output.
Definition: RootCnvSvc.cpp:312
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
NTuple interface class definition.
Definition: INTuple.h:82
Persistent reference object.
Definition: RootRefs.h:31
virtual long ndim() const =0
Dimension.
NTuple interface class definition.
Definition: INTuple.h:27
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:62
virtual INTupleItem * indexItem()=0
Pointer to index column (if present, 0 else)
virtual long length() const =0
Access the buffer length.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
virtual const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
Definition: RootStatCnv.cpp:70
const unsigned long * ipar() const override
Retrieve integer parameters.
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:22
Abstract class describing basic data in an Ntuple.
Definition: NTuple.h:39
virtual long type() const =0
Type information of the item.
virtual const void * buffer() const =0
Access data buffer (CONST)
T find(T...args)
T size(T...args)
STL class.
virtual const std::string & index() const =0
Access the index _Item.
T c_str(T...args)
virtual long dim(long i) const =0
Access individual dimensions.
#define S_OK
virtual ItemContainer & items()=0
Access item container.
virtual bool hasIndex() const =0
Is the tuple have an index item?
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Definition: RootStatCnv.cpp:52
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
virtual const std::type_info & typeID() const =0
Compiler type ID.
Concrete implementation of the IDataConnection interface to access ROOT files.
T sprintf(T...args)
virtual const std::string & title() const =0
Object title.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode Gaudi::RootNTupleCnv::fillObjRefs ( IOpaqueAddress ,
DataObject  
)
inlineoverride

Converter overrides: Update the references of an updated transient object.

Parameters
pAddress[IN] Valid pointer to the object's opaque address
pObject[IN] Valid pointer to DataObject
Returns
Status code indicating success or failure

Definition at line 101 of file RootNTupleCnv.h.

102  {
103  return StatusCode::SUCCESS;
104  }
StatusCode RootNTupleCnv::fillRepRefs ( IOpaqueAddress pAdd,
DataObject pObj 
)
override

Resolve the references of the converted object.

Parameters
pAdd[IN] Valid pointer to the object's opaque address
pObj[IN] Valid pointer to DataObject
Returns
Status code indicating success or failure

Definition at line 616 of file RootNTupleCnv.cpp.

617 {
618  typedef INTuple::ItemContainer Cont;
619  INTuple* tupl = dynamic_cast<INTuple*>( pObj );
620  IRegistry* pReg = pObj->registry();
621  RootAddress* rpA = dynamic_cast<RootAddress*>( pAddr );
622  if ( tupl && pReg && rpA ) {
623  string cntName = containerName( pReg );
624  unsigned long* ipar = const_cast<unsigned long*>( pAddr->ipar() );
625  RootDataConnection* con = (RootDataConnection*)rpA->ipar()[0];
626  if ( con ) {
627  TTree* tree = rpA->section;
628  if ( tree ) {
629  Cont& it = tupl->items();
630  size_t k, n = it.size();
631  vector<RootRef*> paddr( n );
632  vector<RootRef> addr( n );
633  for ( k = 0; k < n; ++k ) {
634  IOpaqueAddress* pA = nullptr;
635  Cont::value_type j = it[k];
636  switch ( j->type() ) {
638  pA = ( *(IOpaqueAddress**)j->buffer() );
639  paddr[k] = &addr[k];
640  addr[k].reset();
641  if ( pA ) {
642  con->makeRef( pA->registry(), addr[k] );
643  addr[k].entry = pA->ipar()[1];
644  }
645  tree->SetBranchAddress( j->name().c_str(), &paddr[k] );
646  break;
647  default:
648  break;
649  }
650  }
651  int nb = tree->Fill();
652  if ( nb > 1 ) ++ipar[1];
653  for ( k = 0; k < n; ++k ) it[k]->reset();
654  return nb > 1 ? StatusCode::SUCCESS : StatusCode::FAILURE;
655  }
656  return makeError( "fillRepRefs> Failed to access data tree:" + cntName );
657  }
658  return makeError( "fillRepRefs> Failed to access data source!" );
659  }
660  return makeError( "fillRepRefs> Invalid Tuple reference." );
661 }
Description:
Definition: RootAddress.h:37
TTree * section
Pointer to ROOT TTree (filled for N-tuples only)
Definition: RootAddress.h:43
virtual IRegistry * registry() const =0
Update branch name.
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
NTuple interface class definition.
Definition: INTuple.h:82
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
const unsigned long * ipar() const override
Retrieve integer parameters.
void makeRef(IRegistry *pA, RootRef &ref)
Create reference object from registry entry.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
STL class.
virtual ItemContainer & items()=0
Access item container.
Opaque address interface definition.
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Definition: RootStatCnv.cpp:52
Concrete implementation of the IDataConnection interface to access ROOT files.
StatusCode RootNTupleCnv::i__updateObjRoot ( RootAddress rpA,
INTuple tupl,
TTree *  tree,
RootDataConnection con 
)
protected

Update the transient object: NTuples end here when reading records.

Definition at line 270 of file RootNTupleCnv.cpp.

271 {
272  typedef INTuple::ItemContainer Cont;
273  const string* par = rpA->par();
274  unsigned long* ipar = const_cast<unsigned long*>( rpA->ipar() );
275  ++ipar[1];
276  if ( Long64_t( ipar[1] ) <= tree->GetEntries() ) {
277  GenericAddress* pA = nullptr;
278  Cont& it = tupl->items();
279  size_t k, n = it.size();
280  vector<RootRef*> paddr( n );
281  vector<RootRef> addr( n );
282  for ( k = 0; k < n; ++k ) {
283  Cont::value_type j = it[k];
284  switch ( j->type() ) {
286  paddr[k] = &addr[k];
287  tree->SetBranchAddress( j->name().c_str(), &paddr[k] );
288  break;
289  default:
290  break;
291  }
292  }
293 
294  ULong64_t last = (ULong64_t)tree->GetEntries();
295  ISelectStatement* sel = tupl->selector();
296  if ( sel ) {
297  string criteria = ( sel && ( sel->type() & ISelectStatement::STRING ) ) ? sel->criteria() : string( "" );
298  if ( !( criteria.length() == 0 || criteria == "*" ) ) {
299  if ( rpA->select == nullptr ) {
300  log() << MSG::DEBUG << "Selection criteria: " << criteria << " " << ipar[1] << endmsg;
301  rpA->select = new TTreeFormula( tree->GetName(), criteria.c_str(), tree );
302  }
303  rpA->select->SetTree( tree );
304  for ( ; ipar[1] < last; ++ipar[1] ) { // loop on all selected entries
305  tree->LoadTree( ipar[1] );
306  rpA->select->GetNdata();
307  if ( fabs( rpA->select->EvalInstance( 0 ) ) > std::numeric_limits<float>::epsilon() ) {
308  break;
309  }
310  log() << MSG::DEBUG << par[0] << "/" << par[1] << " SKIP Entry: " << ipar[1] << endmsg;
311  }
312  }
313  }
314  if ( ipar[1] < last ) {
315  unsigned long entry = ipar[1];
316  if ( tree->GetEntry( entry ) > 1 ) {
317  RootRef* r = nullptr;
318  string* spar = nullptr;
319  for ( k = 0; k < n; ++k ) {
320  Cont::value_type j = it[k];
321  switch ( j->type() ) {
323  r = paddr[k];
324  pA = ( *(GenericAddress**)j->buffer() );
325  if ( pA ) { // Fill only if item is connected!
326  spar = (string*)pA->par();
327  ipar = (unsigned long*)pA->ipar();
328  log() << MSG::DEBUG;
330  con->getMergeSection( tree->GetName(), entry );
331  if ( ls.first ) {
332  if ( ls.first->dbase >= 0 ) {
333  // Now patch the references and links 'en block' to be efficient
334  // First the leafs from the TES
335 
336  r->dbase += ls.first->dbase;
337  r->container += ls.first->container;
338  r->link += ls.first->link;
339 
340  if ( log().isActive() ) {
341  log() << "Refs: LS [" << entry << "] -> " << ls.first->dbase << "," << ls.first->container << ","
342  << ls.first->link << "," << ls.first->entry << " DB:" << con->getDb( r->dbase ) << endmsg;
343  }
344  }
345  }
346  spar[0] = con->getDb( r->dbase );
347  spar[1] = con->getCont( r->container );
348  spar[2] = con->getLink( r->link );
349  ipar[0] = 0;
350  ipar[1] = r->entry;
351  pA->setClID( r->clid );
352  pA->setSvcType( r->svc );
353  break;
354  }
355  break;
356  default:
357  break;
358  }
359  }
360  return StatusCode::SUCCESS;
361  }
362  log() << MSG::ERROR << "Failed to read data from NTuple tree." << endmsg;
363  return StatusCode::FAILURE;
364  }
365  log() << MSG::INFO << "End of input Ntuple." << endmsg;
366  return StatusCode::FAILURE;
367  }
368  return StatusCode::FAILURE;
369 }
MsgStream & log() const
Helper to use mesage logger.
Definition: RootStatCnv.h:40
A select statement can either contain.
const std::string & getDb(int which) const
Access database/file name from saved index.
void setSvcType(long typ)
Access : set the storage type of the class id.
sel
Definition: IOTest.py:95
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:116
const std::string & getLink(int which) const
Access link name from saved index.
Generic Transient Address.
virtual ISelectStatement * selector()=0
Access selector.
STL class.
virtual const std::string & criteria() const =0
Access the selection string.
int dbase
Data members to define object location in the persistent world.
Definition: RootRefs.h:33
Persistent reference object.
Definition: RootRefs.h:31
void setClID(const CLID &clid)
Access : Set class ID of the link.
const unsigned long * ipar() const override
Retrieve integer parameters.
const std::string * par() const override
Retrieve string parameters.
std::pair< const RootRef *, const ContainerSection * > getMergeSection(const std::string &container, int entry) const
Access link section for single container and entry.
const std::string & getCont(int which) const
Access container name from saved index.
T fabs(T...args)
T length(T...args)
STL class.
T c_str(T...args)
virtual ItemContainer & items()=0
Access item container.
TTreeFormula * select
Pointer to ROOT select statement (filled for N-tuples only)
Definition: RootAddress.h:41
virtual long type() const =0
Access the type of the object.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode RootNTupleCnv::updateObj ( IOpaqueAddress pAddress,
DataObject pObject 
)
override

Update the transient object: NTuples end here when reading records.

Parameters
pAddress[IN] Valid pointer to the object's opaque address
pObject[IN] Valid pointer to DataObject
Returns
Status code indicating success or failure

Definition at line 244 of file RootNTupleCnv.cpp.

245 {
246  INTuple* tupl = dynamic_cast<INTuple*>( pObj );
247  RootAddress* rpA = dynamic_cast<RootAddress*>( pAddr );
248  if ( nullptr != tupl && nullptr != rpA ) {
249  RootDataConnection* con = (RootDataConnection*)rpA->ipar()[0];
250  if ( con ) {
251  TTree* tree = rpA->section;
252  if ( tree ) {
253  con->resetAge();
254  if ( con->tool()->refs() ) return i__updateObjRoot( rpA, tupl, tree, con );
255 #ifdef __POOL_COMPATIBILITY
256  // POOL compatibility mode:
257  return i__updateObjPool( rpA, tupl, tree, con );
258 #else
259  return makeError( "Failed to access reference branch for data tree:" + rpA->par()[1] );
260 #endif
261  }
262  return makeError( "Failed to access data tree:" + pAddr->par()[1] );
263  }
264  return makeError( "updateObj> Failed to access data source!" );
265  }
266  return makeError( "updateObj> Invalid Tuple reference." );
267 }
Description:
Definition: RootAddress.h:37
TTree * section
Pointer to ROOT TTree (filled for N-tuples only)
Definition: RootAddress.h:43
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
NTuple interface class definition.
Definition: INTuple.h:82
const unsigned long * ipar() const override
Retrieve integer parameters.
const std::string * par() const override
Retrieve string parameters.
Tool * tool() const
Access tool.
void resetAge()
Reset age.
StatusCode i__updateObjRoot(RootAddress *rpA, INTuple *tupl, TTree *tree, RootDataConnection *con)
Update the transient object: NTuples end here when reading records.
Concrete implementation of the IDataConnection interface to access ROOT files.
StatusCode Gaudi::RootNTupleCnv::updateObjRefs ( IOpaqueAddress ,
DataObject  
)
inlineoverride

Converter overrides: Update the references of an updated transient object.

Parameters
pAddress[IN] Valid pointer to the object's opaque address
pObject[IN] Valid pointer to DataObject
Returns
Status code indicating success or failure

Definition at line 123 of file RootNTupleCnv.h.

124  {
125  return StatusCode::SUCCESS;
126  }
StatusCode Gaudi::RootNTupleCnv::updateRep ( IOpaqueAddress ,
DataObject  
)
inlineoverride

Converter overrides: Update the converted representation of a transient object.

Parameters
pAddress[IN] Valid pointer to the object's opaque address
pObject[IN] Valid pointer to DataObject
Returns
Status code indicating success or failure

Definition at line 136 of file RootNTupleCnv.h.

137  {
138  return StatusCode::SUCCESS;
139  }
StatusCode Gaudi::RootNTupleCnv::updateRepRefs ( IOpaqueAddress ,
DataObject  
)
inlineoverride

Converter overrides: Update the converted representation of a transient object.

Parameters
pAddress[IN] Valid pointer to the object's opaque address
pObject[IN] Valid pointer to DataObject
Returns
Status code indicating success or failure

Definition at line 149 of file RootNTupleCnv.h.

150  {
151  return StatusCode::SUCCESS;
152  }

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