9 #include "St_DataSetIter.h"
10 #include "StTreeMaker.h"
12 TableImpl(dst_bfc_status);
15 static
void RuncoHist(
StTree *tree);
22 fFile = ioFile; fIOMode=
"0";fTree=0;fFinished=0;
30 if (grandparent) fTreeName = grandparent->GetTreeName();
34 Warning(
"StTreeMaker",
"%s default treeName == bfcTree is used",name);
35 fTreeName =
"bfcTree";
39 StTreeMaker::~StTreeMaker(){
42 Int_t StTreeMaker::Open(
const char*)
46 assert(strchr(
"rwu",fIOMode[0]));
52 printf(
"<%s(%s)::Init> TreeName = %s\n",ClassName(),
GetName(),GetTreeName());
55 if (fIOMode[0]==
'r') {
65 TFilePtr(TFile *f):
fFile(f){;}
66 ~TFilePtr(){
delete fFile;};
67 operator TFile *(){
return fFile; }
68 Bool_t IsZombie()
const {
return fFile?
fFile->IsZombie():kTRUE;}
70 TFilePtr tf = TFile::Open(
fFile,
"read",
"BFC StTree file");
72 Error(
"Init",
"Wrong input file %s\n",(
const char*)
fFile);
77 fTree = StTree::GetTree(tf,GetTreeName()); assert(fTree);
78 fTree->SetIOMode(
"0");
80 printf(
"<%s(%s)::Init> FOUND Tree %s in file %s\n",
82 fTree->GetName(),
fFile.Data());
85 TString firstBr(
fFile);
86 i = firstBr.Last(
'.'); assert(i>0);
87 firstBr.Replace(i,999,
"");
88 i = firstBr.Last(
'.'); assert(i>0);
89 firstBr.Replace(0,i+1,
"");
94 fst = fTree->
Find(firstBr);}
98 printf(
"<%s(%s)::Init> Branch %s is MAIN in tree\n",ClassName(),
GetName(),fst->GetName());
110 fTree->SetFile(
fFile,
"r");
121 TString BaseName,FileName;
125 if (fIOMode[0]==
'u') fTree = (
StTree*)GetDataSet(GetTreeName());
128 StMaker *mk = GetMaker(fTree); assert(mk);
130 printf(
"<%s(%s)::Init> FOUND Tree %s.%s\n",
132 mk->
GetName(),fTree->GetName());
136 fTree =
new StTree(GetTreeName());
142 fTree->SetFile(
fFile,
"w");
144 fTree->Close(
"keep");
152 Int_t StTreeMaker::Init()
157 Int_t StTreeMaker::Skip(
int nskip)
160 return fTree->Skip(nskip);
167 if (fIOMode[0]==
'r') {
171 if (iret!=
kStErr && ntry--)
break;
172 Warning(
"Make",
"%d *** ReadError ***\n",ntry);
183 Int_t StTreeMaker::MakeRead(
const StUKey &RunEvent){
187 xrefMain[0] = StXRefManager::GetMain();
190 if (!RunEvent.IsNull()) iret = fTree->ReadEvent(RunEvent);
191 else iret = fTree->NextEvent( );
194 if (Debug()) hddr->Print(
"");
195 if (iret)
return iret;
200 TString tsBr(br->GetName());
201 if (tsBr.Contains(
"Branch")) {
202 TString tsName = tsBr;
203 tsName.ReplaceAll(
"Branch",
"");
204 if (!br->
Find(tsName)) SetOutput(tsName,br);
206 int lv=1;
if (strncmp(
"runco",br->GetName(),5)==0) lv = 2;
211 if (!runevt)
continue;
215 xrefMain[1] = StXRefManager::GetMain();
217 if (xrefMain[1] && xrefMain[1]!=xrefMain[0] && xrefMain[1]->GetParent()==0 )
222 Int_t StTreeMaker::MakeWrite()
227 if (!GetFailedMaker()) UpdateTree(1);
232 Int_t k2 = GetEventNumber();
233 if (k1 <= 0 || k2 <= 0) { k1 =
GetNumber(); k2=0; }
235 fTree->WriteEvent(ukey);
240 Int_t StTreeMaker::MakeBfcStatus()
242 fBfcStatus->SetNRows(0);
246 EDataSetPass kont=kContinue;
248 while ((ds = nextMk(kont)))
250 name = ds->GetName();
252 if (strcmp(
".make",name)==0)
continue;
254 if (name[0]==
'.')
continue;
256 if (!ds->InheritsFrom(StMaker::Class()))
continue;
257 int ret = ((
StMaker*)ds)->GetMakeReturn();
259 fBfcStatus->SetNRows(++nrows);
260 char * mkName = (*fBfcStatus)[nrows-1].maker_name;
261 mkName[0]=0; strncat(mkName,name,11);
262 (*fBfcStatus)[nrows-1].status = ret;
268 void StTreeMaker::UpdateHddr()
275 StMaker *failmk = GetFailedMaker();
278 ts =
"discarded by ";
279 ts += failmk->ClassName();
287 while ((br = (
StBranch *)nextBr())) {
288 if ((opt = br->GetOption()) && strstr(opt,
"CONST"))
continue;
289 if (!failmk && !br->
First())
continue;
292 if (ds->
Find(
"RunEvent"))
continue;
294 hdd->SetName (
"RunEvent");
297 if (fBfcStatus->
GetNRows()) br->Add(fBfcStatus);
302 void StTreeMaker::UpdateTree(Int_t flag)
307 const char* logs;
int nlog,isSetBr;
311 TString updName,updTitl,updFile,updMode,updOpt,tlog;
313 updList=
Find(
".branches");
314 if (!updList)
return;
316 while ((upd=updNext())) {
317 updTitl = upd->GetTitle();
318 updName = upd->GetName();
319 updFile =
""; updMode =
""; updOpt =
"";
320 isSetBr = (updTitl.Index(
"SetBranch:")==0);
321 if (isSetBr && flag!=0)
continue;
324 cc = strstr(updTitl,
"file=");
325 if (cc) updFile.Replace(0,0,cc+5,strcspn(cc+5,
" "));
326 cc = strstr(updTitl,
"mode=");
327 if (cc) updMode.Replace(0,0,cc+5,strcspn(cc+5,
" "));
328 cc = strstr(updTitl,
"opt=");
329 if (cc) updOpt.Replace (0,0,cc+4,strcspn(cc+4,
" "));
331 if (!updFile.IsNull())
delete upd;
334 if (updName[0]==
'*') {
335 if (!updMode.IsNull() || !updFile.IsNull()) fTree->SetFile(updFile,updMode,1);
339 if (!br) {br =
new StBranch(updName,fTree);br->SetIOMode(fIOMode);}
340 if (!updMode.IsNull() || !updFile.IsNull()) br->SetFile(updFile,updMode);
341 if (!updOpt.IsNull()) br->SetOption((
const char*)updOpt);
343 if (flag==0)
continue;
345 logs = (
const char*)updTitl;nlog=0;
348 logs += nlog + strspn(logs+nlog,
" "); nlog = strcspn(logs,
" ");
if(!nlog)
break;
349 tlog.Replace(0,999,logs,nlog);
350 dat = GetDataSet(tlog);
if (!dat)
continue;
351 if (dat->InheritsFrom(StMaker::Class())) dat = dat->
Find(
".data");
353 if (*dat->GetName()!=
'.' && !dat->InheritsFrom(StBranch::Class()))
358 while((ds = nextDs())) br->Add(ds);
368 if (fFinished)
return 0;
370 if (!fTree)
return 0;
371 if (fIOMode[0]!=
'r') {
375 while ((br = (
StBranch*)nextBr())) {
376 if (strncmp(
"hist" ,br->GetName(),4)
377 && strncmp(
"runco",br->GetName(),5))
continue;
380 fTree->WriteEvent((ULong_t)(-2));
388 Int_t StTreeMaker::Save()
392 TString saveName,saveDir,regPath;
395 while ((br = (
StBranch*)nextBr())) {
396 if (strncmp(
"hist",br->GetName(),4))
continue;
400 if (!brSave)
return 0;
401 regPath = brSave->GetFile();
402 if (!regPath.Contains(
".root"))
return 0;
403 saveDir = gSystem->DirName (regPath);
404 saveName = gSystem->BaseName(regPath);
405 saveName.Replace(0,0,
"save.");
406 savePath = gSystem->ConcatFileName(saveDir,saveName);
408 brSave->SetFile((
const char*)savePath);
409 brSave->WriteEvent((ULong_t)(-2));
410 fTree->Close(
"keep");
413 brSave->SetFile((
const char*)regPath);
421 void StTreeMaker::Close(Option_t *)
424 m_DataSet->
Remove(fTree); fTree->Close();
425 delete fTree; fTree=0;}
432 if (fTree) {m_DataSet->
Remove(fTree);fTree->Clear();}
434 if (fTree) m_DataSet->Add(fTree);
440 void StTreeMaker::FillHistBranch(
StBranch *histBr)
445 const char *bname = histBr->GetName();
448 while((upp=GetMaker(top))) top = upp;
451 while ((ds= nextDs())) {
452 par = ds->GetParent();
454 if (strcmp(
".make",par->GetName()))
continue;
456 TString ts(ds->GetName());
457 if (strncmp(bname,
"hist" ,4)==0) ts +=
"Hist";
458 if (strncmp(bname,
"runco", 5)==0) ts +=
"Runco";
463 if (ts.Contains(
"StMaker.h")
464 && ds->IsA() != StMaker::Class()) {
465 ds->Warning(
"StMaker::Init",
"GetCVS is not overloaded");
466 printf(
" Please add into file %s the following line: \n",ds->IsA()->GetDeclFileName());
467 printf(
" virtual const char *GetCVS() const\n");
468 printf(
" {static const char cvs[]=\"Tag %sName:$ %sId:$ built \"__DATE__\" \" __TIME__ ; return cvs;}\n\n",
"$",
"$");
474 if (strncmp(bname,
"hist" ,4)==0) {
475 dothist = ds->
Find(
".hist");
476 if (!dothist) {
delete os;
continue;}
478 if (!tl || !tl->First()) {
delete os;
continue;}
482 if (strncmp(bname,
"runco",5)==0) {
483 dotrcp = ds->
Find(
".runco");
484 if (!dotrcp)
continue;
490 histBr->SetIOMode(
"0");
491 if (nAkt) histBr->SetIOMode(
"w");
497 static void RuncoHist(
StTree *tree)
504 if (strcmp(br->GetName(),
"histBranch" )==0) br->SetOption(
"const");
505 if (strcmp(br->GetName(),
"runcoBranch")==0) br->SetOption(
"const");
virtual TDataSet * First() const
Return the first object in the list. Returns 0 when list is empty.
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Int_t fNIO
Main file name name.
TString fTreeName
r=read,w=write,u=update
virtual Int_t GetNumber() const
STAR methods.
virtual void Delete(Option_t *opt="")
virtual void Remove(TDataSet *set)
Remiove the "set" from this TDataSet.
virtual TDataSet * Last() const
Return the last object in the list. Returns 0 when list is empty.
virtual TObject * Clone(const char *newname="") const
the custom implementation fo the TObject::Clone
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
virtual void Clear(Option_t *opt)
User defined functions.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual const char * GetName() const
special overload
virtual void AddFirst(TDataSet *dataset)
Add TDataSet object at the beginning of the dataset list of this dataset.
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
virtual void Shunt(TDataSet *newParent=0)
virtual TDataSet * FindByName(const char *name, const char *path="", Option_t *opt="") const
virtual TDataSet * Find(const char *path) const