10 #define ALLOW_ALL_TYPES
34 #define S_OK StatusCode::SUCCESS
35 #define S_FAIL StatusCode::FAILURE
37 using namespace Gaudi;
57 template<
class TYP>
static
60 long len, ndim, dim[4], hasIdx, idxLow, idxLen;
61 long dim1 = 1, dim2 = 1;
68 getline(is, idxName,
';') >> idxLow >> c >> idxLen >>
c;
70 for (
int i = 0;
i < ndim;
i++ )
73 TYP low = null, high = null;
74 is >> low >> c >> high >>
c;
82 dim1 = (hasIdx) ? idxLen : dim[0];
93 dim1 = (hasIdx) ? idxLen : dim[0];
94 dim2 = (hasIdx) ? dim[0] : dim[1];
109 TBranch* b = tree->GetBranch(it->
name().c_str());
111 b->SetAddress((
void*)it->
buffer());
115 return tuple->
add(it);
118 return tuple->
add(it);
126 static inline string _tr(
const string&
s) {
128 char* p = (
char*)local.c_str();
129 if ( strncmp(p,
"<local>",7)==0 ) p += 7;
142 string path = fileName(pRegistry);
143 string cntName = containerName(pRegistry);
144 string*
par =
const_cast<string*
>(pAddr->
par());
147 string par_val, par_guid;
148 TBranch* b = con->
getBranch(
"##Descriptors",
"GaudiStatisticsDescription");
153 for(Long64_t
i=0, nent = b->GetEntries();
i<nent; ++
i) {
154 int nb = b->GetEntry(
i);
163 par[2] =
_tr(cntName);
166 return makeError(
"Failed to access N-Tuple tree:"+cntName);
168 if ( !par_val.empty() ) {
177 getline(is, title,
';') >> clid >> c >> siz >>
c;
178 status = ntupleSvc->create(clid, title, nt);
179 for (
int j = 0; j < siz && status.
isSuccess(); j++ ) {
181 getline(is, title,
';') >> typ >>
c;
185 status =
createItem(tree, nt, is, title,
true, (
unsigned char)0);
188 status =
createItem(tree, nt, is, title,
true, (
unsigned short)0);
191 status =
createItem(tree, nt, is, title,
true, (
unsigned int)0);
194 status =
createItem(tree, nt, is, title,
true, (
unsigned long)0);
197 status =
createItem(tree, nt, is, title,
true,
char(0));
200 status =
createItem(tree, nt, is, title,
true,
short(0));
203 status =
createItem(tree, nt, is, title,
true,
int(0));
206 status =
createItem(tree, nt, is, title,
true,
long(0));
209 status =
createItem(tree, nt, is, title,
true,
false);
212 status =
createItem(tree, nt, is, title,
true,
float(0.0));
215 status =
createItem(tree, nt, is, title,
true,
double(0.0));
233 status =
createItem(tree, nt, is, title,
true, (
void*)0);
242 <<
"Error connecting (Unknown) column:" << j <<
endmsg
244 return makeError(
"createObj[NTuple]> Cannot determine column!");
248 unsigned long* ipar =
const_cast<unsigned long*
>(rpA->
ipar());
251 ipar[0] = (
unsigned long)con;
270 if ( 0 != tupl && 0 != rpA ) {
277 return i__updateObjRoot(rpA,tupl,tree,con);
278 #ifdef __POOL_COMPATIBILITY
280 return i__updateObjPool(rpA,tupl,tree,con);
282 return makeError(
"Failed to access reference branch for data tree:"+rpA->
par()[1]);
285 return makeError(
"Failed to access data tree:"+pAddr->
par()[1]);
287 return makeError(
"updateObj> Failed to access data source!");
289 return makeError(
"updateObj> Invalid Tuple reference.");
295 const string*
par = rpA->
par();
296 unsigned long* ipar =
const_cast<unsigned long*
>(rpA->
ipar());
298 if ( Long64_t(ipar[1]) <= tree->GetEntries() ) {
300 Cont& it = tupl->
items();
301 size_t k,
n = it.
size();
304 for(k = 0; k <
n; ++k) {
305 Cont::value_type j = it[k];
310 tree->SetBranchAddress(j->name().c_str(),&paddr[k]);
317 ULong64_t last = (ULong64_t)tree->GetEntries();
322 if ( !(criteria.length() == 0 || criteria ==
"*") ) {
325 rpA->
select =
new TTreeFormula(tree->GetName(),criteria.c_str(), tree);
327 rpA->
select->SetTree(tree);
328 for( ; ipar[1] < last; ++ipar[1]) {
329 tree->LoadTree(ipar[1]);
338 if ( ipar[1] < last ) {
339 unsigned long entry = ipar[1];
340 if ( tree->GetEntry(entry) > 1 ) {
343 for(k = 0; k <
n; ++k) {
344 Cont::value_type j = it[k];
351 spar = (
string*)pA->
par();
352 ipar = (
unsigned long*)pA->
ipar();
364 if (
log().isActive() ) {
365 log() <<
"Refs: LS [" << entry <<
"] -> "
402 if ( 0 != pRegistry ) {
409 string path = fileName(pRegistry);
410 string cntName = containerName(pRegistry);
411 string secName = cntName.c_str();
413 StatusCode status = m_dbMgr->connectDatabase(path, IDataConnection::UPDATE, &con);
415 return makeError(
"Failed to access Tuple file:"+path);
423 os << nt->
title()<<
';'<<pObj->
clID()<<
';'<<items.
size()<<
';';
426 for(item_no = 0; item_no < items.
size(); ++item_no ) {
430 const string&
n = itm->
name();
431 switch( itm->
type() )
435 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
439 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
443 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
447 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
451 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
455 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
459 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
463 b = tree->Branch(n.c_str(),(
void*)itm->
buffer(),desc.c_str());
466 return makeError(
"Column "+it->
index()+
" is not a valid index column!");
471 for(item_no = 0; item_no < items.
size(); ++item_no ) {
473 const string&
n = it->
name();
481 os << it->
index() <<
';';
483 switch( itm->
type() )
510 return makeError(
"NTuple:"+pRegistry->
name()+
" Column "+it->
index()+
511 " is not a valid index column!");
514 for (
long k = 0; k < it->
ndim(); k++ ) {
515 os << it->
dim(k) <<
';';
523 os << 0 <<
';' << 0 <<
';';
527 os << 0 <<
';' << 0 <<
';';
530 if ( it->
length() == 1 ) {
532 os << 0 <<
';' << 0 <<
';';
533 cl = TClass::GetClass(desc.c_str(),kTRUE);
537 if ( it->
length() == 1 ) {
538 os << 0 <<
';' << 0 <<
';';
539 cl = TClass::GetClass(it->
typeID(), kTRUE);
588 return makeError(
"Create item[FAIL]: "+it->
name());
591 if ( branches.
find(n) == branches.
end() ) {
600 sprintf(text,
"[%ld]",it->
dim(0));
605 desc = n + tmp +
"[" + itm->
name() +
"]" + desc;
608 sprintf(text,
"[%ld]",it->
dim(0));
609 desc = n + tmp + text + desc;
612 log() <<
MSG::DEBUG <<
"Create branch:" << n <<
" Desc:" << desc
617 branches[
n] = tree->Branch(n.c_str(),cl->GetName(),(
void*)it->
buffer());
620 branches[
n] = tree->Branch(n.c_str(),cl->GetName(),(
void*)it->
buffer());
623 branches[
n] = tree->Branch(n.c_str(),(
void*)it->
buffer(),desc.c_str());
631 status = saveDescription(path,cntName,os.str(),
"",pObj->
clID());
633 status = m_dbMgr->commitOutput(path,
true);
635 string spar[] = {
path, cntName};
636 unsigned long ipar[] = { (
unsigned long)con, ~0x0u };
637 status = m_dbMgr->createAddress(repSvcType(),pObj->
clID(),spar,ipar,pAddr);
640 ((
unsigned long*)rpA->
ipar())[0] = (
unsigned long)con;
661 if ( tupl && pReg && rpA ) {
662 string cntName = containerName(pReg);
663 unsigned long* ipar =
const_cast<unsigned long*
>(pAddr->
ipar());
668 Cont& it = tupl->
items();
669 size_t k,
n = it.
size();
672 for(k = 0; k <
n; ++k) {
674 Cont::value_type j = it[k];
683 addr[k].entry = pA->
ipar()[1];
685 tree->SetBranchAddress(j->name().c_str(),&paddr[k]);
691 int nb = tree->Fill();
692 if ( nb>1 ) ++ipar[1];
693 for(k = 0; k <
n; ++k) it[k]->reset();
696 return makeError(
"fillRepRefs> Failed to access data tree:"+cntName);
698 return makeError(
"fillRepRefs> Failed to access data source!");
700 return makeError(
"fillRepRefs> Invalid Tuple reference.");
703 #ifdef __POOL_COMPATIBILITY
714 virtual ~IOBuffer() { m_pointer=0; m_length=0; m_buffer=0;}
715 void start() {m_pointer=0; m_buffer=(
char*)d.m_buffer; m_length=d.m_size;}
720 template <
class T>
static inline int load(
int blob, IOBuffer&
s,
void* buff) {
724 s.swapFromBuffer(buff, len*
sizeof(T));
730 template <>
inline int load<string>(
int blob, IOBuffer&
s,
void* ptr) {
732 string* str = (
string*)ptr;
741 const string*
par = rpA->
par();
742 unsigned long* ipar =
const_cast<unsigned long*
>(rpA->
ipar());
744 if ( Long64_t(ipar[1]) <= tree->GetEntries() ) {
745 Cont& it = tupl->
items();
746 size_t k,
n = it.
size();
750 for(k = 0; k <
n; ++k) {
751 Cont::value_type j = it[k];
756 tree->SetBranchAddress(j->name().c_str(),&paddr[k]);
759 if ( 0 == tree->GetBranch(j->name().c_str()) ) blob_items[k] = 1;
763 ULong64_t last = (ULong64_t)tree->GetEntries();
768 if ( !(criteria.length() == 0 || criteria ==
"*") ) {
771 rpA->
select =
new TTreeFormula(tree->GetName(),criteria.c_str(), tree);
773 rpA->
select->SetTree(tree);
775 for( ; ipar[1] < last; ++ipar[1]) {
776 tree->LoadTree(ipar[1]);
785 if ( ipar[1] < last ) {
788 tree->GetBranch(
"BlobData")->SetAddress(&pblob);
789 if ( tree->GetEntry(ipar[1]) > 1 ) {
792 for(k = 0; k <
n; ++k) {
793 Cont::value_type j = it[k];
794 char* buf = (
char*)j->buffer();
801 string *spar = (
string*)pA->
par();
802 ipar = (
unsigned long*)pA->
ipar();
807 ipar[1] = addr[k].token.m_oid.second;
842 log() <<
"CANNOT Set Ntuple token: dynamic_cast<GenericAddress*> is NULL";
845 log() <<
"CANNOT Set Ntuple token: invalid address buffer";