10 #define ALLOW_ALL_TYPES
30 #include "Reflex/Reflex.h"
35 #define S_OK StatusCode::SUCCESS
36 #define S_FAIL StatusCode::FAILURE
38 using namespace Gaudi;
58 template<
class TYP>
static
61 long len, ndim, dim[4], hasIdx, idxLow, idxLen;
62 long dim1 = 1, dim2 = 1;
69 getline(is, idxName,
';') >> idxLow >> c >> idxLen >>
c;
71 for (
int i = 0;
i < ndim;
i++ )
74 TYP low = null, high = null;
75 is >> low >> c >> high >>
c;
83 dim1 = (hasIdx) ? idxLen : dim[0];
94 dim1 = (hasIdx) ? idxLen : dim[0];
95 dim2 = (hasIdx) ? dim[0] : dim[1];
110 TBranch* b = tree->GetBranch(it->
name().c_str());
112 b->SetAddress((
void*)it->
buffer());
116 return tuple->
add(it);
119 return tuple->
add(it);
127 static inline string _tr(
const string&
s) {
129 char* p = (
char*)local.c_str();
130 if ( strncmp(p,
"<local>",7)==0 ) p += 7;
143 string path = fileName(pRegistry);
144 string cntName = containerName(pRegistry);
145 string*
par =
const_cast<string*
>(pAddr->
par());
146 status = m_dbMgr->connectDatabase(path,IDataConnection::READ,&con);
148 string par_val, par_guid;
149 TBranch* b = con->
getBranch(
"##Descriptors",
"GaudiStatisticsDescription");
154 for(Long64_t
i=0, nent = b->GetEntries();
i<nent; ++
i) {
155 int nb = b->GetEntry(
i);
164 par[2] =
_tr(cntName);
167 return makeError(
"Failed to access N-Tuple tree:"+cntName);
169 if ( !par_val.empty() ) {
178 getline(is, title,
';') >> clid >> c >> siz >>
c;
179 status = ntupleSvc->create(clid, title, nt);
180 for (
int j = 0; j < siz && status.
isSuccess(); j++ ) {
182 getline(is, title,
';') >> typ >>
c;
186 status =
createItem(tree, nt, is, title,
true, (
unsigned char)0);
189 status =
createItem(tree, nt, is, title,
true, (
unsigned short)0);
192 status =
createItem(tree, nt, is, title,
true, (
unsigned int)0);
195 status =
createItem(tree, nt, is, title,
true, (
unsigned long)0);
198 status =
createItem(tree, nt, is, title,
true,
char(0));
201 status =
createItem(tree, nt, is, title,
true,
short(0));
204 status =
createItem(tree, nt, is, title,
true,
int(0));
207 status =
createItem(tree, nt, is, title,
true,
long(0));
210 status =
createItem(tree, nt, is, title,
true,
false);
213 status =
createItem(tree, nt, is, title,
true,
float(0.0));
216 status =
createItem(tree, nt, is, title,
true,
double(0.0));
234 status =
createItem(tree, nt, is, title,
true, (
void*)0);
243 <<
"Error connecting (Unknown) column:" << j <<
endmsg
245 return makeError(
"createObj[NTuple]> Cannot determine column!");
249 unsigned long* ipar =
const_cast<unsigned long*
>(rpA->
ipar());
252 ipar[0] = (
unsigned long)con;
271 if ( 0 != tupl && 0 != rpA ) {
278 return i__updateObjRoot(rpA,tupl,tree,con);
279 #ifdef __POOL_COMPATIBILITY
281 return i__updateObjPool(rpA,tupl,tree,con);
283 return makeError(
"Failed to access reference branch for data tree:"+rpA->
par()[1]);
286 return makeError(
"Failed to access data tree:"+pAddr->
par()[1]);
288 return makeError(
"updateObj> Failed to access data source!");
290 return makeError(
"updateObj> Invalid Tuple reference.");
296 const string*
par = rpA->
par();
297 unsigned long* ipar =
const_cast<unsigned long*
>(rpA->
ipar());
299 if ( Long64_t(ipar[1]) <= tree->GetEntries() ) {
301 Cont& it = tupl->
items();
302 size_t k, n = it.
size();
305 for(k = 0; k < n; ++k) {
306 Cont::value_type j = it[k];
311 tree->SetBranchAddress(j->name().c_str(),&paddr[k]);
318 ULong64_t last = (ULong64_t)tree->GetEntries();
323 if ( !(criteria.length() == 0 || criteria ==
"*") ) {
326 rpA->
select =
new TTreeFormula(tree->GetName(),criteria.c_str(), tree);
328 rpA->
select->SetTree(tree);
329 for( ; ipar[1] < last; ++ipar[1]) {
330 tree->LoadTree(ipar[1]);
339 if ( ipar[1] < last ) {
340 unsigned long entry = ipar[1];
341 if ( tree->GetEntry(entry) > 1 ) {
344 for(k = 0; k < n; ++k) {
345 Cont::value_type j = it[k];
352 spar = (
string*)pA->
par();
353 ipar = (
unsigned long*)pA->
ipar();
365 if (
log().isActive() ) {
366 log() <<
"Refs: LS [" << entry <<
"] -> "
403 if ( 0 != pRegistry ) {
410 string path = fileName(pRegistry);
411 string cntName = containerName(pRegistry);
412 string secName = cntName.c_str();
414 StatusCode status = m_dbMgr->connectDatabase(path, IDataConnection::UPDATE, &con);
416 return makeError(
"Failed to access Tuple file:"+path);
424 os << nt->
title()<<
';'<<pObj->
clID()<<
';'<<items.
size()<<
';';
427 for(item_no = 0; item_no < items.
size(); ++item_no ) {
431 const string& n = itm->
name();
432 switch( itm->
type() )
436 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
440 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
444 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
448 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
452 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
456 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
460 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
464 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
467 return makeError(
"Column "+it->
index()+
" is not a valid index column!");
472 for(item_no = 0; item_no < items.
size(); ++item_no ) {
474 const string& n = it->
name();
482 os << it->
index() <<
';';
484 switch( itm->
type() )
511 return makeError(
"NTuple:"+pRegistry->
name()+
" Column "+it->
index()+
512 " is not a valid index column!");
515 for (
long k = 0; k < it->
ndim(); k++ ) {
516 os << it->
dim(k) <<
';';
524 os << 0 <<
';' << 0 <<
';';
528 os << 0 <<
';' << 0 <<
';';
531 if ( it->
length() == 1 ) {
533 os << 0 <<
';' << 0 <<
';';
534 cl = gROOT->GetClass(desc.c_str(),kTRUE);
538 if ( it->
length() == 1 ) {
540 desc = typ.Name(ROOT::Reflex::SCOPED);
541 os << 0 <<
';' << 0 <<
';';
542 cl = gROOT->GetClass(desc.c_str(),kTRUE);
591 return makeError(
"Create item[FAIL]: "+it->
name());
594 if ( branches.
find(n) == branches.
end() ) {
603 sprintf(text,
"[%ld]",it->
dim(0));
608 desc = n + tmp +
"[" + itm->
name() +
"]" + desc;
611 sprintf(text,
"[%ld]",it->
dim(0));
612 desc = n + tmp + text + desc;
615 log() <<
MSG::DEBUG <<
"Create branch:" << n <<
" Desc:" << desc
620 branches[n] = tree->Branch(n.c_str(),cl->GetName(),(
void*)it->
buffer());
623 branches[n] = tree->Branch(n.c_str(),cl->GetName(),(
void*)it->
buffer());
626 branches[n] = tree->Branch(n.c_str(),(
void*)it->
buffer(),desc.c_str());
634 status = saveDescription(path,cntName,os.str(),
"",pObj->
clID());
636 status = m_dbMgr->commitOutput(path,
true);
638 string spar[] = {
path, cntName};
639 unsigned long ipar[] = { (
unsigned long)con, ~0x0 };
640 status = m_dbMgr->createAddress(repSvcType(),pObj->
clID(),spar,ipar,pAddr);
643 ((
unsigned long*)rpA->
ipar())[0] = (
unsigned long)con;
664 if ( tupl && pReg && rpA ) {
665 string cntName = containerName(pReg);
666 unsigned long* ipar =
const_cast<unsigned long*
>(pAddr->
ipar());
671 Cont& it = tupl->
items();
672 size_t k, n = it.
size();
675 for(k = 0; k < n; ++k) {
677 Cont::value_type j = it[k];
686 addr[k].entry = pA->
ipar()[1];
688 tree->SetBranchAddress(j->name().c_str(),&paddr[k]);
694 int nb = tree->Fill();
695 if ( nb>1 ) ++ipar[1];
696 for(k = 0; k < n; ++k) it[k]->reset();
699 return makeError(
"fillRepRefs> Failed to access data tree:"+cntName);
701 return makeError(
"fillRepRefs> Failed to access data source!");
703 return makeError(
"fillRepRefs> Invalid Tuple reference.");
706 #ifdef __POOL_COMPATIBILITY
717 virtual ~IOBuffer() { m_pointer=0; m_length=0; m_buffer=0;}
718 void start() {m_pointer=0; m_buffer=(
char*)d.m_buffer; m_length=d.m_size;}
723 template <
class T>
static inline int load(
int blob, IOBuffer&
s,
void* buff) {
727 s.swapFromBuffer(buff, len*
sizeof(T));
733 template <>
inline int load<string>(
int blob, IOBuffer&
s,
void* ptr) {
735 string* str = (
string*)ptr;
744 const string*
par = rpA->
par();
745 unsigned long* ipar =
const_cast<unsigned long*
>(rpA->
ipar());
747 if ( Long64_t(ipar[1]) <= tree->GetEntries() ) {
748 Cont& it = tupl->
items();
749 size_t k, n = it.
size();
753 for(k = 0; k < n; ++k) {
754 Cont::value_type j = it[k];
759 tree->SetBranchAddress(j->name().c_str(),&paddr[k]);
762 if ( 0 == tree->GetBranch(j->name().c_str()) ) blob_items[k] = 1;
766 ULong64_t last = (ULong64_t)tree->GetEntries();
771 if ( !(criteria.length() == 0 || criteria ==
"*") ) {
774 rpA->
select =
new TTreeFormula(tree->GetName(),criteria.c_str(), tree);
776 rpA->
select->SetTree(tree);
778 for( ; ipar[1] < last; ++ipar[1]) {
779 tree->LoadTree(ipar[1]);
788 if ( ipar[1] < last ) {
791 tree->GetBranch(
"BlobData")->SetAddress(&pblob);
792 if ( tree->GetEntry(ipar[1]) > 1 ) {
795 for(k = 0; k < n; ++k) {
796 Cont::value_type j = it[k];
797 char* buf = (
char*)j->buffer();
804 string *spar = (
string*)pA->
par();
805 ipar = (
unsigned long*)pA->
ipar();
810 ipar[1] = addr[k].token.m_oid.second;
845 log() <<
"CANNOT Set Ntuple token: dynamic_cast<GenericAddress*> is NULL";
848 log() <<
"CANNOT Set Ntuple token: invalid address buffer";