19#define ALLOW_ALL_TYPES
43#define S_OK StatusCode::SUCCESS
44#define S_FAIL StatusCode::FAILURE
51static inline istream& readValue( istream& is, TYP& val ) {
56static inline istream& readValue( istream& is, TYP*& ) {
85 if ( is.fail() && !is.bad() && !is.eof() ) is.clear( is.rdstate() & ~std::ios::failbit );
91 if ( is.fail() && !is.bad() && !is.eof() ) is.clear( is.rdstate() & ~std::ios::failbit );
96static StatusCode createItem( TTree* tree,
INTuple* tuple, istream& is,
const string& name,
bool add,
99 long len, ndim, dim[4], hasIdx, idxLow, idxLen;
100 long dim1 = 1, dim2 = 1;
103 is >> len >>
c >> ndim >>
c >> hasIdx >>
c;
104 if ( hasIdx ) { getline( is, idxName,
';' ) >> idxLow >>
c >> idxLen >>
c; }
105 for (
int i = 0; i < ndim; i++ ) is >> dim[i] >>
c;
107 TYP low = null, high = null;
108 readValue( is, low ) >>
c;
109 readValue( is, high ) >>
c;
116 dim1 = ( hasIdx ) ? idxLen : dim[0];
120 dim1 = ( hasIdx ) ? idxLen : dim[0];
121 dim2 = ( hasIdx ) ? dim[0] : dim[1];
128 TBranch* b = tree->GetBranch( it->
name().c_str() );
130 b->SetAddress(
const_cast<void*
>( it->
buffer() ) );
133 return tuple->add( it );
136 return tuple->add( it );
145static inline string _tr(
string s ) {
146 string local = std::move( s );
147 auto p = std::begin( local );
148 if ( local.compare( 0, 7,
"<local>" ) == 0 ) p += 7;
150 p, std::end( local ), [](
const char& c ) {
return !isalnum( c ); },
'_' );
160 string path =
fileName( pRegistry );
162 string* par =
const_cast<string*
>( pAddr->
par() );
165 string par_val, par_guid;
166 TBranch* b = con->
getBranch(
"##Descriptors",
"GaudiStatisticsDescription" );
170 b->SetAddress( &ptr );
171 for ( Long64_t i = 0, nent = b->GetEntries(); i < nent; ++i ) {
172 int nb = b->GetEntry( i );
181 par[2] = _tr( cntName );
183 if (
nullptr == tree ) {
return makeError(
"Failed to access N-Tuple tree:" + cntName ); }
184 if ( !par_val.empty() ) {
192 istringstream is( par_val );
193 getline( is, title,
';' ) >> clid >> c >> siz >> c;
194 status = ntupleSvc->create( clid, title, nt );
195 for (
int j = 0; j < siz && status.
isSuccess(); j++ ) {
197 getline( is, title,
';' ) >> typ >> c;
200 status = createItem( tree, nt, is, title,
true, (
unsigned char)0 );
203 status = createItem( tree, nt, is, title,
true, (
unsigned short)0 );
206 status = createItem( tree, nt, is, title,
true, 0u );
209 status = createItem( tree, nt, is, title,
true, 0ul );
212 status = createItem( tree, nt, is, title,
true,
char( 0 ) );
215 status = createItem( tree, nt, is, title,
true,
short( 0 ) );
218 status = createItem( tree, nt, is, title,
true, 0 );
221 status = createItem( tree, nt, is, title,
true, 0l );
224 status = createItem( tree, nt, is, title,
true,
false );
227 status = createItem( tree, nt, is, title,
true, 0.f );
230 status = createItem( tree, nt, is, title,
true, 0. );
245 status = createItem( tree, nt, is, title,
false,
static_cast<IOpaqueAddress*
>(
nullptr ) );
248 status = createItem( tree, nt, is, title,
true,
static_cast<void*
>(
nullptr ) );
257 return makeError(
"createObj[NTuple]> Cannot determine column!" );
261 unsigned long* ipar =
const_cast<unsigned long*
>( rpA->
ipar() );
262 log() <<
MSG::DEBUG <<
"Created N-tuple with description:" << par_val << endl;
263 ipar[0] =
reinterpret_cast<uintptr_t
>( con );
268 refpObject =
nullptr;
281 if ( !tupl || !rpA )
return makeError(
"updateObj> Invalid Tuple reference." );
283 if ( !con )
return makeError(
"updateObj> Failed to access data source!" );
285 if ( !tree )
return makeError(
"Failed to access data tree:" + pAddr->
par()[1] );
288#ifdef __POOL_COMPATIBILITY
290 return i__updateObjPool( rpA, tupl, tree, con );
292 return makeError(
"Failed to access reference branch for data tree:" + rpA->
par()[1] );
299 const string* par = rpA->
par();
300 unsigned long* ipar =
const_cast<unsigned long*
>( rpA->
ipar() );
302 if ( Long64_t( ipar[1] ) <= tree->GetEntries() ) {
304 Cont& it = tupl->
items();
305 size_t k, n = it.size();
306 vector<RootRef*> paddr( n );
307 vector<RootRef> addr( n );
308 for ( k = 0; k < n; ++k ) {
309 Cont::value_type j = it[k];
310 switch ( j->type() ) {
313 tree->SetBranchAddress( j->name().c_str(), &paddr[k] );
320 ULong64_t last = tree->GetEntries();
324 if ( !( criteria.length() == 0 || criteria ==
"*" ) ) {
325 if ( rpA->
select ==
nullptr ) {
327 rpA->
select =
new TTreeFormula( tree->GetName(), criteria.c_str(), tree );
329 rpA->
select->SetTree( tree );
330 for ( ; ipar[1] < last; ++ipar[1] ) {
331 tree->LoadTree( ipar[1] );
333 if ( fabs( rpA->
select->EvalInstance( 0 ) ) > std::numeric_limits<double>::epsilon() ) {
break; }
338 if ( ipar[1] < last ) {
339 unsigned long entry = ipar[1];
340 if ( tree->GetEntry( entry ) > 1 ) {
342 string* spar =
nullptr;
343 for ( k = 0; k < n; ++k ) {
344 Cont::value_type j = it[k];
345 switch ( j->type() ) {
350 spar =
const_cast<string*
>( pA->
par() );
351 ipar =
const_cast<unsigned long*
>( pA->
ipar() );
353 pair<const RootRef*, const RootDataConnection::ContainerSection*> ls =
356 if ( ls.first->dbase >= 0 ) {
360 r->
dbase += ls.first->dbase;
362 r->
link += ls.first->link;
364 if (
log().isActive() ) {
365 log() <<
"Refs: LS [" << entry <<
"] -> " << ls.first->dbase <<
"," << ls.first->container <<
","
366 << ls.first->link <<
"," << ls.first->entry <<
" DB:" << con->
getDb( r->
dbase ) <<
endmsg;
400 if ( pAddr )
return S_OK;
403 string path =
fileName( pRegistry );
405 string secName = cntName;
408 if ( !status.
isSuccess() ) {
return makeError(
"Failed to access Tuple file:" + path ); }
409 TTree* tree = con->
getSection( _tr( secName ),
true );
410 if (
nullptr != nt ) {
415 os << nt->
title() <<
';' << pObj->
clID() <<
';' << items.size() <<
';';
416 map<string, TBranch*> branches;
417 TBranch* b =
nullptr;
418 for ( item_no = 0; item_no < items.size(); ++item_no ) {
422 const string& n = itm->
name();
423 switch ( itm->
type() ) {
426 b = tree->Branch( n.c_str(),
const_cast<void*
>( itm->
buffer() ), desc.c_str() );
430 b = tree->Branch( n.c_str(),
const_cast<void*
>( itm->
buffer() ), desc.c_str() );
434 b = tree->Branch( n.c_str(),
const_cast<void*
>( itm->
buffer() ), desc.c_str() );
438 b = tree->Branch( n.c_str(),
const_cast<void*
>( itm->
buffer() ), desc.c_str() );
442 b = tree->Branch( n.c_str(),
const_cast<void*
>( itm->
buffer() ), desc.c_str() );
446 b = tree->Branch( n.c_str(),
const_cast<void*
>( itm->
buffer() ), desc.c_str() );
450 b = tree->Branch( n.c_str(),
const_cast<void*
>( itm->
buffer() ), desc.c_str() );
454 b = tree->Branch( n.c_str(),
const_cast<void*
>( itm->
buffer() ), desc.c_str() );
457 return makeError(
"Column " + it->
index() +
" is not a valid index column!" );
462 for ( item_no = 0; item_no < items.size(); ++item_no ) {
464 const string& n = it->
name();
465 os <<
'{' << n <<
';' << it->
type() <<
';' << it->
length() <<
';' << it->
ndim() <<
';' << it->
hasIndex() <<
';';
467 os << it->
index() <<
';';
469 switch ( itm->
type() ) {
496 " is not a valid index column!" );
499 for (
long k = 0; k < it->
ndim(); k++ ) { os << it->
dim( k ) <<
';'; }
501 TClass* cl =
nullptr;
502 switch ( it->
type() ) {
505 os << 0 <<
';' << 0 <<
';';
509 os << 0 <<
';' << 0 <<
';';
512 if ( it->
length() == 1 ) {
514 os << 0 <<
';' << 0 <<
';';
515 cl = TClass::GetClass( desc.c_str(), kTRUE );
519 if ( it->
length() == 1 ) {
520 os << 0 <<
';' << 0 <<
';';
521 cl = TClass::GetClass( it->
typeID(), kTRUE );
573 if ( branches.find( n ) == branches.end() ) {
576 switch ( it->
ndim() ) {
581 snprintf( text,
sizeof( text ),
"[%ld]", it->
dim( 0 ) );
587 desc = n + tmp +
"[" + itm->
name() +
"]" + desc;
589 snprintf( text,
sizeof( text ),
"[%ld]", it->
dim( 0 ) );
590 desc = n + tmp + text + desc;
594 switch ( it->
type() ) {
596 branches[n] = tree->Branch( n.c_str(), cl->GetName(),
const_cast<void*
>( it->
buffer() ) );
599 branches[n] = tree->Branch( n.c_str(), cl->GetName(),
const_cast<void*
>( it->
buffer() ) );
602 branches[n] = tree->Branch( n.c_str(),
const_cast<void*
>( it->
buffer() ), desc.c_str() );
611 status =
m_dbMgr->commitOutput( path,
true );
613 string spar[] = { path, cntName };
614 unsigned long ipar[] = { (
unsigned long)con, ~0x0u };
619 ( (
unsigned long*)rpA->
ipar() )[0] = (
unsigned long)con;
643 if ( tupl && pReg && rpA ) {
645 unsigned long* ipar =
const_cast<unsigned long*
>( pAddr->
ipar() );
650 Cont& it = tupl->
items();
651 size_t k, n = it.size();
652 vector<RootRef*> paddr( n );
653 vector<RootRef> addr( n );
654 for ( k = 0; k < n; ++k ) {
656 Cont::value_type j = it[k];
657 switch ( j->type() ) {
664 addr[k].entry = pA->
ipar()[1];
666 tree->SetBranchAddress( j->name().c_str(), &paddr[k] );
672 int nb = tree->Fill();
673 if ( nb > 1 ) ++ipar[1];
674 for ( k = 0; k < n; ++k ) it[k]->reset();
677 return makeError(
"fillRepRefs> Failed to access data tree:" + cntName );
679 return makeError(
"fillRepRefs> Failed to access data source!" );
681 return makeError(
"fillRepRefs> Invalid Tuple reference." );
684#ifdef __POOL_COMPATIBILITY
694 IOBuffer() =
default;
695 virtual ~IOBuffer() {
710static inline int load(
int blob, IOBuffer& s,
void* buff ) {
714 s.swapFromBuffer( buff, len *
sizeof( T ) );
721inline int load<string>(
int blob, IOBuffer& s,
void* ptr ) {
723 string* str = (
string*)ptr;
732 const string*
par = rpA->
par();
733 unsigned long* ipar =
const_cast<unsigned long*
>( rpA->
ipar() );
735 if ( Long64_t( ipar[1] ) <= tree->GetEntries() ) {
736 Cont& it = tupl->
items();
737 size_t k,
n = it.size();
738 vector<PoolDbTokenWrap*> paddr( n );
739 vector<PoolDbTokenWrap> addr( n );
740 vector<int> blob_items( n, 0 );
741 for ( k = 0; k <
n; ++k ) {
742 Cont::value_type j = it[k];
743 switch ( j->type() ) {
746 tree->SetBranchAddress( j->name().c_str(), &paddr[k] );
749 if (
nullptr == tree->GetBranch( j->name().c_str() ) ) blob_items[k] = 1;
753 ULong64_t last = (ULong64_t)tree->GetEntries();
757 if ( !( criteria.length() == 0 || criteria ==
"*" ) ) {
758 if ( rpA->
select ==
nullptr ) {
760 rpA->
select =
new TTreeFormula( tree->GetName(), criteria.c_str(), tree );
762 rpA->
select->SetTree( tree );
764 for ( ; ipar[1] < last; ++ipar[1] ) {
765 tree->LoadTree( ipar[1] );
767 if ( fabs( rpA->
select->EvalInstance( 0 ) ) > std::numeric_limits<double>::epsilon() ) {
break; }
772 if ( ipar[1] < last ) {
774 UCharDbArray* pblob = &blob.d;
775 tree->GetBranch(
"BlobData" )->SetAddress( &pblob );
776 if ( tree->GetEntry( ipar[1] ) > 1 ) {
779 for ( k = 0; k <
n; ++k ) {
780 Cont::value_type j = it[k];
781 char* buf = (
char*)j->buffer();
782 switch ( j->type() ) {
784 RootRef r = con->
tool()->
poolRef( addr[k].token.m_oid.first );
785 GenericAddress* pA = *
reinterpret_cast<GenericAddress**
>( buf );
787 string* spar =
const_cast<string*
>( pA->
par() );
788 ipar = (
unsigned long*)pA->
ipar();
793 ipar[1] = addr[k].token.m_oid.second;
806 sc = load<unsigned char>( blob_items[k], blob, buf );
809 sc = load<unsigned short>( blob_items[k], blob, buf );
812 sc = load<unsigned int>( blob_items[k], blob, buf );
815 sc = load<unsigned long>( blob_items[k], blob, buf );
818 sc = load<char>( blob_items[k], blob, buf );
821 sc = load<short>( blob_items[k], blob, buf );
824 sc = load<int>( blob_items[k], blob, buf );
827 sc = load<long>( blob_items[k], blob, buf );
830 sc = load<bool>( blob_items[k], blob, buf );
833 sc = load<float>( blob_items[k], blob, buf );
836 sc = load<double>( blob_items[k], blob, buf );
839 sc = load<string>( blob_items[k], blob, buf );
842 sc = load<char*>( blob_items[k], blob, buf );
856 log() <<
"CANNOT Set Ntuple token: dynamic_cast<GenericAddress*> is NULL";
859 log() <<
"CANNOT Set Ntuple token: invalid address buffer";
const long POOL_ROOTKEY_StorageType
unsigned int CLID
Class ID definition.
const long POOL_ROOT_StorageType
const long POOL_ROOTTREE_StorageType
const long ROOT_StorageType
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
istream & readValue< double >(istream &is, double &val)
istream & readValue< float >(istream &is, float &val)
SmartIF< IDataProviderSvc > & dataProvider() const override
Get Data provider service.
A DataObject is the base class of any identifiable object on any data store.
IRegistry * registry() const
Get pointer to Registry.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
virtual unsigned long release()
release reference to object
void resetAge()
Reset age.
TTreeFormula * select
Pointer to ROOT select statement (filled for N-tuples only)
TTree * section
Pointer to ROOT TTree (filled for N-tuples only)
RootCnvSvc * m_dbMgr
Conversion service needed for proper operation to forward requests.
long repSvcType() const override
Retrieve the class type of the data store the converter uses.
Concrete implementation of the IDataConnection interface to access ROOT files.
const std::string & getLink(int which) const
Access link name from saved index.
Tool * tool() const
Access tool.
TTree * getSection(std::string_view sect, bool create=false)
Access TTree section from section name. The section is created if required.
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
void makeRef(const IRegistry &pA, RootRef &ref)
Create reference object from registry entry.
const std::string & getDb(int which) const
Access database/file name from saved index.
std::pair< const RootRef *, const ContainerSection * > getMergeSection(std::string_view 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.
StatusCode fillRepRefs(IOpaqueAddress *pAdd, DataObject *pObj) override
Resolve the references of the converted object.
StatusCode i__updateObjRoot(RootAddress *rpA, INTuple *tupl, TTree *tree, RootDataConnection *con)
Update the transient object: NTuples end here when reading records.
StatusCode createRep(DataObject *pObj, IOpaqueAddress *&refpAdd) override
Converter overrides: Convert the transient object to the requested representation.
StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject) override
Converter overrides: Update the references of an updated transient object.
StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *pObject) override
Update the transient object: NTuples end here when reading records.
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.
virtual const std::string fileName(IRegistry *pReg) const
Retrieve the name of the file a given object is placed into.
StatusCode makeError(const std::string &msg, bool throw_exception=false) const
Helper method to issue error messages.
MsgStream & log() const
Helper to use mesage logger.
virtual const std::string containerName(IRegistry *pDir) const
Retrieve the name of the container a given object is placed into.
Generic Transient Address.
void setClID(const CLID &clid)
Access : Set class ID of the link.
const std::string * par() const override
Retrieve string parameters.
const unsigned long * ipar() const override
Retrieve integer parameters.
void setSvcType(long typ)
Access : set the storage type of the class id.
NTuple interface class definition.
std::vector< INTupleItem * > ItemContainer
virtual ISelectStatement * selector()=0
Access selector.
virtual ItemContainer & items()=0
Access item container.
virtual const std::string & title() const =0
Object title.
NTuple interface class definition.
virtual long ndim() const =0
Dimension.
virtual const void * buffer() const =0
Access data buffer (CONST)
virtual long dim(long i) const =0
Access individual dimensions.
virtual const std::string & index() const =0
Access the index _Item.
virtual const std::type_info & typeID() const =0
Compiler type ID.
virtual long type() const =0
Type information of the item.
virtual long length() const =0
Access the buffer length.
virtual INTupleItem * indexItem()=0
Pointer to index column (if present, 0 else)
virtual const std::string & name() const =0
Access _Item name.
virtual bool hasIndex() const =0
Is the tuple have an index item?
Opaque address interface definition.
virtual unsigned long release()=0
release reference to object
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
virtual const std::string * par() const =0
Retrieve String parameters.
virtual IRegistry * registry() const =0
Update branch name.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
virtual const name_type & name() const =0
Name of the directory (or key)
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
A select statement can either contain.
static _Array * create(INTuple *tup, const std::string &name, const std::type_info &info, const std::string &index, long len, TYP min, TYP max, TYP def)
Create instance.
Abstract class describing basic data in an Ntuple.
virtual const ItemRange & range() const =0
Access the range if specified.
static _Item * create(INTuple *tup, const std::string &name, const std::type_info &info, TYP min, TYP max, TYP def)
Create instance.
static _Matrix * create(INTuple *tup, const std::string &name, const std::type_info &info, const std::string &index, long ncol, long nrow, TYP min, TYP max, TYP def)
Create instance.
TYP lower() const
Lower boundary of range.
TYP upper() const
Upper boundary of range.
Abstract base class which allows the user to interact with the actual N tuple implementation.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
This class is used for returning status codes from appropriate routines.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
The stream buffer is a small object collecting object data.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
std::string description
Description string.
std::string container
Identifier of description.
Persistent reference object.
int dbase
Data members to define object location in the persistent world.
Shadow class to mimik POOL blobs.
unsigned char * m_buffer
Buffer with object content.
int m_size
Size of buffer.