1 #define ROOTHISTCNV_RCWNTUPLECNV_CPP 3 #define ALLOW_ALL_TYPES 26 #pragma warning(disable:1572) 44 long item_size =
sizeof(T);
45 long dimension = it->
length();
46 long ndim = it->
ndim()-1;
55 if (ind_blk != block_name) {
56 std::cerr <<
"ERROR: Index for CWNT variable " << ind_var
57 <<
" is in a different block: " << ind_blk <<
std::endl;
61 else if ( it->
dim(ndim) > 1 ) {
65 for (
int i = ndim-1; i>=0; i-- ){
73 if (it->
range().lower() != it->
range().min() &&
75 lowerRange = it->
range().lower();
76 upperRange = it->
range().upper();
82 size += item_size * dimension;
93 log <<
MSG::VERBOSE <<
"created tree id: " << rtree->GetName()
94 <<
" title: "<< nt->
title() <<
" desc: " << desc <<
endmsg;
99 long lowerRange, upperRange;
101 long cursize, oldsize = 0;
108 for (
const auto& i : nt->
items() ) {
111 switch( i->type() ) {
115 block_name,var_name,lowerRange,upperRange,size);
120 item, block_name,var_name,lowerRange,upperRange,size);
125 block_name,var_name,lowerRange,upperRange,size);
130 block_name,var_name,lowerRange,upperRange,size);
135 block_name,var_name,lowerRange,upperRange,size);
140 item, block_name,var_name,lowerRange,upperRange,size);
145 item, block_name,var_name,lowerRange,upperRange,size);
150 item, block_name,var_name,lowerRange,upperRange,size);
155 item, block_name,var_name,lowerRange,upperRange,size);
160 item, block_name,var_name,lowerRange,upperRange,size);
165 block_name,var_name,lowerRange,upperRange,size);
170 block_name,var_name,lowerRange,upperRange,size);
175 block_name,var_name,lowerRange,upperRange,size);
182 cursize = size - oldsize;
184 log <<
MSG::VERBOSE <<
"item: " << item <<
" type " << i->type()
185 <<
" blk: " << block_name
186 <<
" var: " << var_name <<
" rng: " << lowerRange <<
" " 187 << upperRange <<
" sz: " << size <<
" " << cursize
188 <<
" buf_pos: " << size-cursize <<
endmsg;
201 char* buff = nt->
setBuffer(
new char[size]);
203 log <<
MSG::VERBOSE <<
"Created buffer size: " << size <<
" at " 204 << (
void*)buff << endmsg;
209 char *buf_pos = buff;
214 unsigned int i_item = 0;
215 for (
auto itr=item_name.
cbegin(); itr!=
end; ++itr, ++i_item) {
217 buf_pos = buff + item_buf_pos[i_item];
226 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0) 227 auto br =
new TBranch(rtree,
229 TBranch *br =
new TBranch(
231 item_fullname[i_item].c_str(),
236 if (itr->first !=
"AUTO_BLK") {
238 tit = itr->first +
"::" + br->GetTitle();
239 br->SetTitle(tit.
c_str());
242 log <<
MSG::DEBUG <<
"adding TBranch " << br->GetTitle() <<
" at " 243 << (
void*) buf_pos << endmsg;
247 if ( item_range_lower[i_item] < item_range_upper[i_item] ) {
251 TLeafI *index =
nullptr;
252 TObject *tobj = br->GetListOfLeaves()->FindObject( item_fullname[i_item].c_str() );
253 if (tobj->IsA()->InheritsFrom(
"TLeafI")) {
254 index =
dynamic_cast<TLeafI*
>(tobj);
257 index->SetMaximum( item_range_upper[i_item] );
261 log <<
MSG::ERROR <<
"Could dynamic cast to TLeafI: " 262 << item_fullname[i_item] <<
endmsg;
267 rtree->GetListOfBranches()->Add(br);
272 log <<
MSG::INFO <<
"Booked TTree with ID: " << desc
273 <<
" \"" << nt->
title() <<
"\" in directory " 287 char * tar = nt->
buffer();
288 for (
const auto& i : nt->
items() ) {
289 switch( i->type() ) {
291 tar +=
saveItem(tar, (
bool*)i->buffer(), i->length());
294 tar +=
saveItem(tar, (
char*)i->buffer(), i->length());
297 tar +=
saveItem(tar, (
short*)i->buffer(), i->length());
300 tar +=
saveItem(tar, (
int*)i->buffer(), i->length());
303 tar +=
saveItem(tar, (
long*)i->buffer(), i->length());
306 tar +=
saveItem(tar, (
long long*)i->buffer(), i->length());
309 tar +=
saveItem(tar, (
unsigned char*)i->buffer(), i->length());
312 tar +=
saveItem(tar, (
unsigned short*)i->buffer(), i->length());
315 tar +=
saveItem(tar, (
unsigned int*)i->buffer(), i->length());
318 tar +=
saveItem(tar, (
unsigned long*)i->buffer(), i->length());
321 tar +=
saveItem(tar, (
unsigned long long*)i->buffer(), i->length());
324 tar +=
saveItem(tar, (
float*)i->buffer(), i->length());
327 tar +=
saveItem(tar, (
double*)i->buffer(), i->length());
348 if (ievt >= rtree->GetEntries()) {
349 log <<
MSG::ERROR <<
"no more entries in tree to read. max: " 350 << rtree->GetEntries() <<
" current: " << ievt
355 rtree->GetEvent(ievt);
361 char *src = ntup->
buffer();
362 for (
auto &i : ntup->
items() ) {
364 switch( i->type() ) {
366 src +=
loadItem(src, (
bool*)i->buffer(), i->length());
369 src +=
loadItem(src, (
char*)i->buffer(), i->length());
372 src +=
loadItem(src, (
short*)i->buffer(), i->length());
375 src +=
loadItem(src, (
int*)i->buffer(), i->length());
378 src +=
loadItem(src, (
long*)i->buffer(), i->length());
381 src +=
loadItem(src, (
long long*)i->buffer(), i->length());
384 src +=
loadItem(src, (
unsigned char*)i->buffer(), i->length());
387 src +=
loadItem(src, (
unsigned short*)i->buffer(), i->length());
390 src +=
loadItem(src, (
unsigned int*)i->buffer(), i->length());
393 src +=
loadItem(src, (
unsigned long*)i->buffer(), i->length());
396 src +=
loadItem(src, (
unsigned long long*)i->buffer(), i->length());
399 src +=
loadItem(src, (
float*)i->buffer(), i->length());
402 src +=
loadItem(src, (
double*)i->buffer(), i->length());
425 log <<
MSG::VERBOSE <<
"loading CWNT " << title <<
" at: " 433 std::string itemName, indexName, item_type, itemTitle, blockName;
435 long size, totsize=0;
442 TObjArray* lbr = tree->GetListOfBranches();
444 while ( TObject *tobjb = bitr() ) {
446 TBranch* br = (TBranch*)tobjb;
447 itemTitle = br->GetTitle();
449 int ipos = itemTitle.
find(
"::");
451 blockName = itemTitle.
substr(0,ipos);
456 TObjArray* lf = br->GetListOfLeaves();
459 while ( TObject *tobj = litr() ) {
467 TLeaf* tl =
dynamic_cast<TLeaf*
> (tobj);
468 itemName = tl->GetName();
475 if (blockName !=
"") {
476 log <<
MSG::DEBUG <<
"loading NTuple item " << blockName <<
"/" 479 log <<
MSG::DEBUG <<
"loading NTuple item " << itemName;
483 TLeaf* indexLeaf = tl->GetLeafCounter(arraySize);
485 if (arraySize == 0) {
486 log <<
MSG::ERROR <<
"TLeaf counter size = 0. This should not happen!" 493 indexName = indexLeaf->GetName();
495 indexRange = indexLeaf->GetMaximum();
496 itemSize = indexRange * tl->GetLenType() * arraySize;
498 log <<
"[" << indexName;
501 if (arraySize != 1) {
502 log <<
"][" << arraySize;
507 itemSize = tl->GetLenType() * arraySize;
511 if (arraySize == 1) {
515 log <<
"[" << arraySize <<
"]";
527 hasRange = tl->IsRange();
533 if (tobj->IsA()->InheritsFrom(
"TLeafI")) {
535 TLeafI *tli =
dynamic_cast<TLeafI*
>(tobj);
536 if (tli->IsUnsigned()) {
537 unsigned long min=0, max=0;
539 min = tli->GetMinimum();
540 max = tli->GetMaximum();
549 min = tli->GetMinimum();
550 max = tli->GetMaximum();
559 }
else if (tobj->IsA()->InheritsFrom(
"TLeafF")) {
560 float min=0., max=0.;
562 TLeafF *tlf =
dynamic_cast<TLeafF*
>(tobj);
564 min = float(tlf->GetMinimum());
565 max = float(tlf->GetMaximum());
573 }
else if (tobj->IsA()->InheritsFrom(
"TLeafD")) {
574 double min=0., max=0.;
576 TLeafD *tld =
dynamic_cast<TLeafD*
>(tobj);
578 min = tld->GetMinimum();
579 max = tld->GetMaximum();
596 <<
"Unable to create ntuple item \"" 597 << itemName <<
"\"" <<
endmsg;
603 log <<
MSG::DEBUG <<
"Total buffer size of NTuple: " << totsize
606 char* buf = ntup->
setBuffer(
new char[totsize] );
610 for (
const auto& iitr : itemList) {
611 TLeaf* leaf = iitr.first;
612 int isize = iitr.second;
614 log <<
MSG::VERBOSE <<
"setting TBranch " << leaf->GetBranch()->GetName()
615 <<
" buffer at " << (
void*) bufpos << endmsg;
617 leaf->GetBranch()->SetAddress((
void*)bufpos);
635 if (totsize != ts ) {
636 log <<
MSG::ERROR <<
"buffer size mismatch: " << ts <<
" " << totsize
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.