1 #define ROOTHISTCNV_RCWNTUPLECNV_CPP 3 #define ALLOW_ALL_TYPES 26 #pragma warning( disable : 1572 ) 32 std::string& var_name,
long& lowerRange,
long& upperRange,
long& size )
39 long item_size =
sizeof( T );
40 long dimension = it->
length();
41 long ndim = it->
ndim() - 1;
49 if ( ind_blk != block_name ) {
50 std::cerr <<
"ERROR: Index for CWNT variable " << ind_var <<
" is in a different block: " << ind_blk <<
std::endl;
53 }
else if ( it->
dim( ndim ) > 1 ) {
57 for (
int i = ndim - 1; i >= 0; i-- ) {
66 lowerRange = it->
range().lower();
67 upperRange = it->
range().upper();
73 size += item_size * dimension;
82 log <<
MSG::VERBOSE <<
"created tree id: " << rtree->GetName() <<
" title: " << nt->
title() <<
" desc: " << desc
88 long lowerRange, upperRange;
90 long cursize, oldsize = 0;
97 for (
const auto& i : nt->
items() ) {
100 switch ( i->type() ) {
103 lowerRange, upperRange, size );
107 lowerRange, upperRange, size );
111 lowerRange, upperRange, size );
115 lowerRange, upperRange, size );
119 var_name, lowerRange, upperRange, size );
123 var_name, lowerRange, upperRange, size );
127 var_name, lowerRange, upperRange, size );
131 var_name, lowerRange, upperRange, size );
135 var_name, lowerRange, upperRange, size );
139 block_name, var_name, lowerRange, upperRange, size );
143 var_name, lowerRange, upperRange, size );
147 lowerRange, upperRange, size );
151 lowerRange, upperRange, size );
158 cursize = size - oldsize;
160 log <<
MSG::VERBOSE <<
"item: " << item <<
" type " << i->type() <<
" blk: " << block_name <<
" var: " << var_name
161 <<
" rng: " << lowerRange <<
" " << upperRange <<
" sz: " << size <<
" " << cursize
162 <<
" buf_pos: " << size - cursize <<
endmsg;
165 item_buf_pos.
push_back( size - cursize );
168 item_range_lower.
push_back( lowerRange );
169 item_range_upper.
push_back( upperRange );
175 char* buff = nt->
setBuffer(
new char[size] );
177 log <<
MSG::VERBOSE <<
"Created buffer size: " << size <<
" at " << (
void*)buff << endmsg;
182 char* buf_pos = buff;
187 unsigned int i_item = 0;
188 for (
auto itr = item_name.
cbegin(); itr !=
end; ++itr, ++i_item ) {
190 buf_pos = buff + item_buf_pos[i_item];
199 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 15, 0 ) 200 auto br =
new TBranch( rtree,
202 TBranch* br =
new TBranch(
204 item_fullname[i_item].c_str(), buf_pos, itr->second.c_str() );
206 if ( itr->first !=
"AUTO_BLK" ) {
208 tit = itr->first +
"::" + br->GetTitle();
209 br->SetTitle( tit.
c_str() );
212 log <<
MSG::DEBUG <<
"adding TBranch " << br->GetTitle() <<
" at " << (
void*)buf_pos << endmsg;
215 if ( item_range_lower[i_item] < item_range_upper[i_item] ) {
219 TLeafI* index =
nullptr;
220 TObject* tobj = br->GetListOfLeaves()->FindObject( item_fullname[i_item].c_str() );
221 if ( tobj->IsA()->InheritsFrom(
"TLeafI" ) ) {
222 index =
dynamic_cast<TLeafI*
>( tobj );
225 index->SetMaximum( item_range_upper[i_item] );
229 log <<
MSG::ERROR <<
"Could dynamic cast to TLeafI: " << item_fullname[i_item] <<
endmsg;
234 rtree->GetListOfBranches()->Add( br );
251 for (
const auto& i : nt->
items() ) {
252 switch ( i->type() ) {
254 tar +=
saveItem( tar, (
bool*)i->buffer(), i->length() );
257 tar +=
saveItem( tar, (
char*)i->buffer(), i->length() );
260 tar +=
saveItem( tar, (
short*)i->buffer(), i->length() );
263 tar +=
saveItem( tar, (
int*)i->buffer(), i->length() );
266 tar +=
saveItem( tar, (
long*)i->buffer(), i->length() );
269 tar +=
saveItem( tar, (
long long*)i->buffer(), i->length() );
272 tar +=
saveItem( tar, (
unsigned char*)i->buffer(), i->length() );
275 tar +=
saveItem( tar, (
unsigned short*)i->buffer(), i->length() );
278 tar +=
saveItem( tar, (
unsigned int*)i->buffer(), i->length() );
281 tar +=
saveItem( tar, (
unsigned long*)i->buffer(), i->length() );
284 tar +=
saveItem( tar, (
unsigned long long*)i->buffer(), i->length() );
287 tar +=
saveItem( tar, (
float*)i->buffer(), i->length() );
290 tar +=
saveItem( tar, (
double*)i->buffer(), i->length() );
308 if ( ievt >= rtree->GetEntries() ) {
309 log <<
MSG::ERROR <<
"no more entries in tree to read. max: " << rtree->GetEntries() <<
" current: " << ievt
314 rtree->GetEvent( ievt );
320 char* src = ntup->
buffer();
321 for (
auto& i : ntup->
items() ) {
323 switch ( i->type() ) {
325 src +=
loadItem( src, (
bool*)i->buffer(), i->length() );
328 src +=
loadItem( src, (
char*)i->buffer(), i->length() );
331 src +=
loadItem( src, (
short*)i->buffer(), i->length() );
334 src +=
loadItem( src, (
int*)i->buffer(), i->length() );
337 src +=
loadItem( src, (
long*)i->buffer(), i->length() );
340 src +=
loadItem( src, (
long long*)i->buffer(), i->length() );
343 src +=
loadItem( src, (
unsigned char*)i->buffer(), i->length() );
346 src +=
loadItem( src, (
unsigned short*)i->buffer(), i->length() );
349 src +=
loadItem( src, (
unsigned int*)i->buffer(), i->length() );
352 src +=
loadItem( src, (
unsigned long*)i->buffer(), i->length() );
355 src +=
loadItem( src, (
unsigned long long*)i->buffer(), i->length() );
358 src +=
loadItem( src, (
float*)i->buffer(), i->length() );
361 src +=
loadItem( src, (
double*)i->buffer(), i->length() );
389 std::string itemName, indexName, item_type, itemTitle, blockName;
391 long size, totsize = 0;
398 TObjArray* lbr = tree->GetListOfBranches();
400 while ( TObject* tobjb = bitr() ) {
402 TBranch* br = (TBranch*)tobjb;
403 itemTitle = br->GetTitle();
405 int ipos = itemTitle.
find(
"::" );
407 blockName = itemTitle.
substr( 0, ipos );
412 TObjArray* lf = br->GetListOfLeaves();
415 while ( TObject* tobj = litr() ) {
417 bool hasRange =
false;
423 TLeaf* tl =
dynamic_cast<TLeaf*
>( tobj );
424 itemName = tl->GetName();
430 if ( blockName !=
"" ) {
431 log <<
MSG::DEBUG <<
"loading NTuple item " << blockName <<
"/" << itemName;
433 log <<
MSG::DEBUG <<
"loading NTuple item " << itemName;
437 TLeaf* indexLeaf = tl->GetLeafCounter( arraySize );
439 if ( arraySize == 0 ) {
440 log <<
MSG::ERROR <<
"TLeaf counter size = 0. This should not happen!" <<
endmsg;
446 indexName = indexLeaf->GetName();
448 indexRange = indexLeaf->GetMaximum();
449 itemSize = indexRange * tl->GetLenType() * arraySize;
451 log <<
"[" << indexName;
454 if ( arraySize != 1 ) {
455 log <<
"][" << arraySize;
460 itemSize = tl->GetLenType() * arraySize;
464 if ( arraySize == 1 ) {
468 log <<
"[" << arraySize <<
"]";
480 hasRange = tl->IsRange();
485 if ( tobj->IsA()->InheritsFrom(
"TLeafI" ) ) {
487 TLeafI* tli =
dynamic_cast<TLeafI*
>( tobj );
488 if ( tli->IsUnsigned() ) {
489 unsigned long min = 0, max = 0;
491 min = tli->GetMinimum();
492 max = tli->GetMaximum();
495 item =
createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup );
497 long min = 0, max = 0;
499 min = tli->GetMinimum();
500 max = tli->GetMaximum();
503 item =
createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup );
507 }
else if ( tobj->IsA()->InheritsFrom(
"TLeafF" ) ) {
508 float min = 0., max = 0.;
510 TLeafF* tlf =
dynamic_cast<TLeafF*
>( tobj );
512 min = float( tlf->GetMinimum() );
513 max = float( tlf->GetMaximum() );
516 item =
createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup );
519 }
else if ( tobj->IsA()->InheritsFrom(
"TLeafD" ) ) {
520 double min = 0., max = 0.;
522 TLeafD* tld =
dynamic_cast<TLeafD*
>( tobj );
524 min = tld->GetMinimum();
525 max = tld->GetMaximum();
528 item =
createNTupleItem( itemName, blockName, indexName, indexRange, arraySize, min, max, ntup );
537 log <<
MSG::ERROR <<
"Unable to create ntuple item \"" << itemName <<
"\"" <<
endmsg;
543 log <<
MSG::DEBUG <<
"Total buffer size of NTuple: " << totsize <<
" Bytes." <<
endmsg;
545 char* buf = ntup->
setBuffer(
new char[totsize] );
549 for (
const auto& iitr : itemList ) {
550 TLeaf* leaf = iitr.first;
551 int isize = iitr.second;
553 log <<
MSG::VERBOSE <<
"setting TBranch " << leaf->GetBranch()->GetName() <<
" buffer at " << (
void*)bufpos
556 leaf->GetBranch()->SetAddress( (
void*)bufpos );
574 if ( totsize != ts ) {
575 log <<
MSG::ERROR <<
"buffer size mismatch: " << ts <<
" " << totsize <<
endmsg;
std::string getDirectory()
virtual const std::string & name() const =0
Access _Item name.
Definition of the MsgStream class used to transmit messages.
virtual const ItemRange & range() const =0
Access the range if specified.
bool parseName(const std::string &full, std::string &blk, std::string &var)
virtual StatusCode add(INTupleItem *item)=0
Add an item row to the N tuple.
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Converter of Column-wise NTuple into ROOT format.
StatusCode book(const std::string &desc, INTuple *pObject, TTree *&tree) override
Book the N tuple.
NTuple interface class definition.
virtual void reset()=0
Reset all entries to their default values.
virtual long ndim() const =0
Dimension.
NTuple interface class definition.
virtual long length() const =0
Access the buffer length.
virtual const char * buffer() const =0
Access data buffer (CONST)
virtual StatusCode create(const CLID &typ, const std::string &title, NTuple::Tuple *&refpTuple)=0
Create requested N tuple (Hide constructor)
This class is used for returning status codes from appropriate routines.
StatusCode load(TTree *tree, INTuple *&refpObject) override
Create the transient representation of an object.
auto end(reverse_wrapper< T > &w)
Abstract class describing basic data in an Ntuple.
Abstract base class which allows the user to interact with the actual N tuple implementation.
StatusCode readData(TTree *rtree, INTuple *pObject, long ievt) override
Read N tuple data.
size_t saveItem(char *target, const T *src, size_t len)
#define DECLARE_NAMESPACE_CONVERTER_FACTORY(n, x)
size_t loadItem(char *src, T *tar, size_t len)
virtual char * setBuffer(char *buff)=0
Attach data buffer.
virtual const std::string & index() const =0
Access the index _Item.
virtual long dim(long i) const =0
Access individual dimensions.
virtual ItemContainer & items()=0
Access item container.
virtual bool hasIndex() const =0
Is the tuple have an index item?
SmartIF< INTupleSvc > m_ntupleSvc
Reference to N tuple service.
virtual const std::string & title() const =0
Object title.
void analyzeItem(std::string typ, const NTuple::_Data< T > *it, std::string &desc, std::string &block_name, std::string &var_name, long &lowerRange, long &upperRange, long &size)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
INTupleItem * createNTupleItem(std::string itemName, std::string blockName, std::string indexName, int indexRange, int arraySize, TYP min, TYP max, INTuple *ntup)
virtual std::string rootVarType(int)
Return ROOT type info:
StatusCode writeData(TTree *rtree, INTuple *pObject) override
Write N tuple data.