00001
00002
00003
00020 #define STAR_LOGGER 1
00021 #include "StMaker.h"
00022 #include "Stiostream.h"
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025
00026 #include "TSystem.h"
00027 #include "TClass.h"
00028 #include "TROOT.h"
00029 #include "TError.h"
00030 #if 0
00031 #include "THtml.h"
00032 #endif
00033 #include "TH1.h"
00034
00035 #include "TChain.h"
00036 #include "TTree.h"
00037 #include "TList.h"
00038 #include "TClonesArray.h"
00039 #include "TBrowser.h"
00040
00041 #include "StChainOpt.h"
00042 #include "TObjectSet.h"
00043 #include "StChain.h"
00044 #include "TTable.h"
00045 #ifdef TMEMSTATinSTAR
00046 #include "TMemStat.h"
00047 #else
00048 #include "StMemStat.h"
00049 #endif
00050 #include "TAttr.h"
00051 #include "StMkDeb.h"
00052 #include "StMessMgr.h"
00053
00054 StMaker *StMaker::fgTopChain = 0;
00055 StMaker *StMaker::fgStChain = 0;
00056 StMaker *StMaker::fgFailedMaker = 0;
00057 StTestMaker *StMaker::fgTestMaker = 0;
00058 Int_t StMaker::fgTallyMaker[kStFatal+1] = {0,0,0,0,0};
00059 Int_t MaxWarnings = 26;
00060
00061 class MyObjectSet : public TObjectSet
00062 {
00063 typedef void (*MyDelete_t)(void *p);
00064 public:
00065 MyObjectSet(const char *name,void *p,void *d):TObjectSet(name,(TObject*)p,0)
00066 {fD=(MyDelete_t)d;}
00067 ~MyObjectSet(){ (*fD)(GetObject());}
00068 private:
00069 MyDelete_t fD;
00070 };
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 #include "GeometryDbAliases.h"
00183
00184 #define TURN_LOGGER(maker) \
00185 if (!fLogger) fLogger = StMessMgr::Instance(ClassName()); \
00186 StTurnLogger SaveRestoreLogger(maker->GetLogger());
00187
00188
00189 ClassImp(StMaker)
00190
00191 static void doPs(const Char_t *who,const Char_t *where);
00192
00193
00194 StMaker::StMaker(const Char_t *name,const Char_t *):TDataSet(name,".maker"),
00195 m_Mode(0), m_Number(0), m_LastRun(-3),
00196 m_DebugLevel(0),m_MakeReturn(0),fStatus(0),
00197 fLogger(0),fLoggerHold(0)
00198 {
00199 m_Attr=0;
00200 m_Inputs = 0;
00201 if (!fgStChain) {
00202 fgTopChain = fgStChain = this;
00203 gROOT->GetListOfBrowsables()->Add(this,GetName());
00204 AddData(0,".make");
00205 } else {
00206 fgStChain->AddData(this,".make");
00207 }
00208 m_DataSet = new TObjectSet(".data") ;Add(m_DataSet);
00209 m_ConstSet = new TObjectSet(".const");Add(m_ConstSet);
00210 m_GarbSet = new TObjectSet(".garb" );Add(m_GarbSet);
00211 m_Inputs = new TObjectSet(".aliases" );Add(m_Inputs);
00212 m_Runco = new TObjectSet(".runco" );Add(m_Runco);
00213 AddHist(0); m_Histograms = GetHistList();
00214 ::doPs(GetName(),"constructor");
00215 m_Timer.Stop();
00216 fMemStatMake = 0;
00217 fMemStatClear = 0;
00218 memset(fTallyMaker,0,(kStFatal+1)*sizeof(Int_t));
00219 SetActive();
00220 StMkDeb::Register(this);
00221 }
00222
00223
00224 void StMaker::AddMaker(StMaker *mk)
00225 {
00226 TDataSet *dotmk = Find(".make");
00227 if (!dotmk) dotmk = new TDataSet(".make",this);
00228 mk->Shunt(dotmk);
00229 }
00230
00231 StMaker::~StMaker()
00232 {
00233 if (fgTopChain == this) fgTopChain = 0;
00234 if (fgStChain == this) fgStChain = 0;
00235 delete fMemStatMake; fMemStatMake = 0;
00236 delete fMemStatClear; fMemStatClear = 0;
00237 TDataSet *ds = this;
00238 Cleanup(ds);
00239 StMkDeb::Cancel(this);
00240
00241 }
00242
00243 const Char_t *StMaker::GetName() const
00244 {
00245 static Int_t occ = 0;
00246 const Char_t *name = TNamed::GetName();
00247 if (name && *name ) return name;
00248 TString ts(ClassName());
00249 ts+="#"; ts+=(occ++);
00250 ((TNamed*)this)->SetName(ts.Data());
00251 return GetName();
00252 }
00253
00254 void StMaker::SetNumber(Int_t number)
00255 {
00256 StMaker *par = GetParentMaker();
00257 if (par) par->SetNumber(number);
00258 m_Number = number;
00259 SetIventNumber(number);
00260 }
00261
00262 Int_t StMaker::GetNumber() const
00263 {
00264 StMaker *par = GetParentMaker();
00265 if (par) return par->GetNumber();
00266 return m_Number;
00267 }
00268
00269 StMaker *StMaker::GetParentMaker() const
00270 {
00271 TDataSet *par = GetParent(); if (!par) return 0;
00272 return (StMaker*)par->GetParent();
00273 }
00274
00275 StMaker *StMaker::GetMaker(const Char_t *mkname)
00276 {
00277 TString path(".make/"); path+=mkname;
00278 return (StMaker*)GetDataSet((const char*)path);
00279 }
00280
00281 TObject *StMaker::GetDirObj(const Char_t *dir) const
00282 {
00283 TObjectSet *h = (TObjectSet*)Find(dir);
00284 if (!h) return 0;
00285 return h->GetObject();
00286 }
00287
00288 void StMaker::SetDirObj(TObject *obj,const Char_t *dir)
00289 {
00290 TObjectSet *set = (TObjectSet *)Find(dir);
00291 if (!set) {
00292 set = new TObjectSet(dir); Add(set);}
00293 set->SetObject(obj);
00294 }
00295
00296 TDataSet *StMaker::AddObj(TObject *obj,const Char_t *dir,int owner)
00297 {
00298 assert (dir[0]=='.');
00299 if (strcmp(".hist",dir)==0) {
00300 AddHist((TH1*)obj); return 0;
00301 } else if (strcmp(".data",dir)==0) {
00302 return ToWhiteBoard(obj->GetName(),obj,owner);
00303
00304 } else if (strcmp(".const",dir)==0) {
00305 return ToWhiteConst(obj->GetName(),obj);
00306 } else { assert(0 && "No .data || .const ||.hist");}
00307 }
00308
00309 void StMaker::AddHist(TH1 *h,const Char_t *)
00310 {
00311 TObjectSet *set = (TObjectSet*)Find(".hist");
00312 if (!set) {
00313 set = new TObjectSet(".hist"); Add(set);}
00314
00315 TList *list = (TList *)set->GetObject();
00316 if (!list) {
00317 list = new TList(); set->SetObject(list);}
00318
00319 if (!h) return ;
00320 if(!list->FindObject(h)) list->Add(h);
00321 if (h->InheritsFrom(TH1::Class())) h->SetDirectory(0);
00322 }
00323
00324 void StMaker::AddRunco (Double_t par,const Char_t *name,const Char_t *comment)
00325 {
00326 assert (name && name && comment[0]);
00327
00328 TDataSet *dp = new TDataSet(name,m_Runco);
00329 TString ts(" // "); ts += comment;
00330 Char_t buf[40];
00331 sprintf(buf,"%f",par);
00332 ts.Replace(0,0,buf);
00333 dp->SetTitle((const char*)ts);
00334 }
00335
00336
00337
00338 void StMaker::AddData(TDataSet *ds, const Char_t *dir)
00339 {
00340 assert (dir); assert(dir[0]=='.');
00341 TDataSet *set = Find(dir);
00342 if (!set) {
00343 set = new TObjectSet(dir); Add(set);}
00344 if (!ds) return;
00345 Int_t dotMake = (strcmp(dir,".make")==0);
00346 Int_t inhMake = ds->InheritsFrom(StMaker::Class());
00347 if (dotMake!=inhMake) {
00348 Error("AddData","Add to %s is NOT allowed: %s.%s\n"
00349 ,dir,ds->ClassName(),ds->GetName());
00350 return;}
00351
00352 TList *tl = set->GetList();
00353 if (!tl || !tl->FindObject(ds->GetName())) {
00354 set->Add(ds);
00355 } else {
00356 Error("AddData","Data %s/%s is not added. ***Name clash***",dir,ds->GetName());
00357 return;
00358 }
00359 return;
00360 }
00361
00362 TDataSet *StMaker::GetData(const Char_t *name, const Char_t *dir) const
00363 {
00364 TDataSet *set = Find(dir);
00365 if (!set) return 0;
00366 return set->Find(name);
00367 }
00368
00369 TDataSet *StMaker::ToWhiteBoard(const Char_t *name, void *dat)
00370 {
00371 TObjectSet *envelop = new TObjectSet(name,(TObject*)dat,0);
00372 envelop->SetTitle(".envelop");
00373 AddData(envelop,".data");
00374 return envelop;
00375 }
00376
00377 TDataSet *StMaker::ToWhiteBoard(const Char_t *name, void *dat, void *owner)
00378 {
00379 MyObjectSet *envelop = new MyObjectSet(name,dat,owner);
00380 envelop->SetTitle(".envelop");
00381 AddData(envelop,".data");
00382 return envelop;
00383 }
00384
00385 TDataSet *StMaker::ToWhiteBoard(const Char_t *name, TObject *dat, Int_t owner)
00386 {
00387 TObjectSet *envelop = new TObjectSet(name,dat,owner);
00388 envelop->SetTitle(".envelop");
00389 AddData(envelop,".data");
00390 return envelop;
00391 }
00392
00393 TDataSet *StMaker::ToWhiteConst(const Char_t *name, void *dat)
00394 {
00395 TObjectSet *envelop = new TObjectSet(name,(TObject*)dat,0);
00396 envelop->SetTitle(".envelop");
00397 AddData(envelop,".const");
00398 return envelop;
00399 }
00400
00401 TDataSet *StMaker::ToWhiteConst(const Char_t *name, TObject *dat)
00402 {
00403 TObjectSet *envelop = new TObjectSet(name,dat,0);
00404 envelop->SetTitle(".envelop");
00405 AddData(envelop,".const");
00406 return envelop;
00407 }
00408
00409 TDataSet *StMaker::WhiteBoard(const Char_t *name, void *v) const
00410 {
00411 void **dat = (void **)v;
00412 *dat = 0;
00413 TDataSet *ds = GetDataSet(name);
00414 if (!ds) return 0;
00415 if (strcmp(".envelop",ds->GetTitle())==0) {*dat = ds->GetObject();}
00416 else {*dat = ds ;}
00417 return ds;
00418 }
00419
00420 void StMaker::AddAlias(const Char_t *log, const Char_t *act,const Char_t *dir)
00421 {
00422 TDataSet *ali = new TDataSet(log);
00423 ali->SetTitle(act);
00424 AddData(ali,dir);
00425 }
00426
00427 void StMaker::SetNotify(const Char_t *about, StMaker *mk)
00428 {
00429 TDataSet *ali = new TObjectSet(about,mk,0);
00430 AddData(ali,".notify");
00431 }
00432
00433 void StMaker::NotifyEm(const Char_t *about, const void *ptr)
00434 {
00435
00436 TURN_LOGGER(this);
00437
00438 TDataSet *set = Find(".notify");
00439 if (!set) return;
00440 TDataSetIter iter(set);
00441 TObjectSet *os=0;
00442 while((os=(TObjectSet*)iter())) {
00443 if (strcmp(about,os->GetName())) continue;
00444 StMaker *mk=(StMaker*)os->GetObject();
00445 if (!mk) continue;
00446 TURN_LOGGER(mk);
00447 mk->NotifyMe(about,ptr);
00448 }
00449
00450 }
00451
00452 void StMaker::SetAlias(const Char_t *log, const Char_t *act,const Char_t *dir)
00453 {
00454 TDataSet *ali = GetData(log,dir);
00455 if (ali) {
00456 if (!strcmp(act,ali->GetTitle())) return;
00457 } else {
00458 ali = new TDataSet(log); AddData(ali,dir);
00459 }
00460 ali->SetTitle(act);
00461
00462 if (GetDebug()) {
00463 #ifdef STAR_LOGGER
00464 LOG_DEBUG << "<" << ClassName() << "(" << GetName() << "::SetAlias> "
00465 << log << " = " << act << endm;
00466 #else
00467 printf("<%s(%s)::SetAlias> %s = %s\n",ClassName(),GetName(),log,act);
00468 #endif
00469 }
00470 }
00471
00472 void StMaker::SetOutput(const Char_t *log,TDataSet *ds)
00473 {
00474 Int_t idx;
00475 const Char_t *logname = log;
00476 if (!logname || !logname[0]) logname = ds->GetName();
00477 TString act = ds->Path();
00478 while ((idx=act.Index(".make/"))>=0) act.Replace(0,idx+6,"");
00479 SetOutput(logname,act);
00480 }
00481
00482
00483 void StMaker::SetOutputAll(TDataSet *ds, Int_t level)
00484 {
00485 TDataSet *set;
00486 TDataSetIter next(ds,level);
00487 while ((set = next())) SetOutput(set);
00488 }
00489
00490
00491 TList *StMaker::GetMakeList() const
00492 { TDataSet *ds = Find(".make");
00493 if (!ds) return 0;
00494 return ds->GetList();
00495 }
00496
00497 TString StMaker::GetAlias(const Char_t *log,const Char_t *dir) const
00498 {
00499 Int_t nspn = strcspn(log," /");
00500 TString act(log,nspn);
00501 TDataSet *in = GetData(act,dir);
00502 act ="";
00503 if (in) {act = in->GetTitle(); act += log+nspn;}
00504 return act;
00505 }
00506
00507 TDataSet *StMaker::FindDataSet(const Char_t *logInput,
00508 const StMaker *uppMk,
00509 const StMaker *dowMk) const
00510 {
00511 TURN_LOGGER(this);
00512
00513 TDataSetIter nextMk(0);
00514 TString actInput,findString,tmp;
00515 TDataSet *dataset=0,*dir;
00516 StMaker *parent,*mk;
00517 Int_t icol,islas;
00518
00519 for (int itry=0;itry<2;itry++) {
00520 actInput = (!itry)? GetInput(logInput).Data():logInput;
00521 dataset = 0;
00522 if (actInput.IsNull()) continue;
00523
00524 if (actInput.Contains(".")) dataset = Find(actInput);
00525 if (dataset) goto FOUND;
00526
00527 if (actInput==GetName()) dataset = m_DataSet;
00528 if (dataset) goto FOUND;
00529
00530
00531
00532
00533 icol = actInput.Index(":");
00534 if (icol>=0) {
00535 tmp = actInput;
00536 tmp.Replace(0,0,".make/"); icol +=6;
00537 tmp.Replace(icol,1,"/.data/");
00538 dataset = Find((const char*)tmp);
00539 if (dataset) goto FOUND;
00540 dataset = Find((const char*)tmp+6);
00541 if (dataset) goto FOUND;
00542 tmp.Replace(icol,7,"/.const/");
00543 dataset = Find((const char*)tmp);
00544 if (dataset) goto FOUND;
00545 dataset = Find((const char*)tmp+6);
00546 if (dataset) goto FOUND;
00547 goto DOWN;
00548 }
00549
00550 if (m_DataSet) {
00551 islas = actInput.Index("/");
00552 if (islas>0) {
00553 tmp.Replace(0,999,actInput,islas);
00554 if (tmp == GetName()) {
00555 tmp = actInput;
00556 tmp.Replace(0,islas+1,"");
00557 dataset = m_DataSet->Find(tmp);
00558 if (dataset) goto FOUND;
00559 dataset = m_ConstSet->Find(tmp);
00560 if (dataset) goto FOUND;
00561 }
00562 }
00563
00564 dataset = m_DataSet->Find(actInput);
00565 if (dataset) goto FOUND;
00566 dataset = m_ConstSet->Find(actInput);
00567 if (dataset) goto FOUND;
00568 }
00569
00570
00571 DOWN: if (!(dir = Find(".make"))) goto UP;
00572
00573 nextMk.Reset(dir);
00574 while ((mk = (StMaker* )nextMk()))
00575 {
00576 if (mk==dowMk) continue;
00577 dataset = mk->FindDataSet(actInput,this,0);
00578 if (dataset) goto FOUND;
00579 }
00580
00581
00582 UP: if (uppMk) return 0;
00583
00584 parent = GetMaker(this); if (!parent) goto NOTFOUND;
00585 dataset = parent->FindDataSet(actInput,0,this);
00586 if (dataset) goto FOUND;
00587
00588
00589 NOTFOUND:
00590 if (!dowMk && GetDebug()>1)
00591 if ((MaxWarnings--) > 0) Warning("GetDataSet"," \"%s\" Not Found ***\n",(const char*)actInput);
00592 dataset = 0; continue;
00593
00594
00595 FOUND: if (uppMk || dowMk) return dataset;
00596 if (GetDebug()<2) return dataset;
00597 #ifdef STAR_LOGGER
00598 LOG_DEBUG << Form("<%s::%s> DataSet %s FOUND in %s\n"
00599 ,ClassName(),"GetDataSet",logInput,(const char*)dataset->Path()) << endm;
00600 #else
00601 printf("Remark: <%s::%s> DataSet %s FOUND in %s\n"
00602 ,ClassName(),"GetDataSet",logInput,(const char*)dataset->Path());
00603 #endif
00604 break;
00605 }
00606 return dataset;
00607
00608 }
00609
00610 TDataSet *StMaker::GetDataBase(const Char_t *logInput,const TDatime *td)
00611 {
00612 TURN_LOGGER(this);
00613 TDataSet *ds = 0;
00614 StMaker *mk = GetMakerInheritsFrom("St_db_Maker");
00615 if (mk) ds = mk->GetDataBase(logInput,td);
00616 return ds;
00617 }
00618
00619 StMaker *StMaker::GetMakerInheritsFrom (const Char_t *mktype) const
00620 {
00621 TURN_LOGGER(this);
00622 StMaker *mk = 0;
00623 StMakerIter mkiter(this);
00624 while ((mk = mkiter.NextMaker())) {
00625 if (mk->InheritsFrom(mktype)) break;
00626 }
00627 return mk;
00628 }
00629
00630 void StMaker::SetFlavor(const Char_t *flav,const Char_t *tabname)
00631 {
00632 StMaker *mk = GetMakerInheritsFrom("St_db_Maker");
00633 if (mk) mk->SetFlavor(flav,tabname);
00634 }
00635
00636 void StMaker::Clear(Option_t *option)
00637 {
00638 TURN_LOGGER(this);
00639
00640 m_MakeReturn = 0;
00641 if(option){};
00642 if (m_DataSet) m_DataSet->Delete();
00643
00644
00645
00646 TIter next(GetMakeList(),kIterBackward);
00647 StMaker *maker;
00648 Int_t curr = StMkDeb::GetCurrent();
00649 while ((maker = (StMaker* )next())) {
00650 assert(maker->TestBIT(kCleaBeg)==0);
00651 StMkDeb::SetCurrent(maker,3);
00652 maker->SetBIT(kCleaBeg);
00653 maker->StartTimer();
00654 if (maker->fMemStatClear && GetNumber()>20) maker->fMemStatClear->Start();
00655 TURN_LOGGER(maker);
00656 maker->Clear(option);
00657 if (maker->fMemStatClear && GetNumber()>20) maker->fMemStatClear->Stop();
00658 maker->StopTimer();
00659 maker->ResetBIT(kCleaBeg);
00660 StMkDeb::SetCurrent(curr);
00661 }
00662 TCollection::EmptyGarbageCollection();
00663 doPs(GetName(),"Clear");
00664
00665
00666
00667
00668 return;
00669
00670 }
00671
00672 Int_t StMaker::Init()
00673 {
00674 TURN_LOGGER(this);
00675 TObject *objLast,*objHist;
00676 TList *tl = GetMakeList();
00677 if (!tl) return kStOK;
00678
00679 TIter nextMaker(tl);
00680 StMaker *maker;
00681 Int_t curr = StMkDeb::GetCurrent();
00682 while ((maker = (StMaker* )nextMaker())) {
00683
00684 TURN_LOGGER(maker);
00685
00686 gROOT->cd();
00687 objLast = gDirectory->GetList()->Last();
00688
00689
00690
00691 assert( !( maker->TestBIT(kInitBeg) || maker->TestBIT(kInitEnd) ));
00692 StMkDeb::SetCurrent(maker,1);
00693 maker->SetBIT(kInitBeg);
00694 maker->StartTimer();
00695
00696 if (GetDebug()) {
00697 LOG_DEBUG << "*** Call << " << maker->ClassName() << ":Init() ***" << endm;
00698 }
00699 TString ts1(maker->ClassName()); ts1+="("; ts1+=maker->GetName(); ts1+=")::";
00700 TString ts2 = ts1; ts2+="Make ";
00701 maker->fMemStatMake = new StMemStat(ts2);
00702 ts2 = ts1; ts2+="Clear";
00703 maker->fMemStatClear = new StMemStat(ts2);
00704
00705 if ( maker->Init()) {
00706 LOG_ERROR << " Maker "<< maker->GetName() << " failed in Init" << endm;
00707 return kStErr;
00708 }
00709 maker->StopTimer();
00710
00711
00712
00713 gROOT->cd();
00714 TIter nextHist(gDirectory->GetList());
00715 Int_t ready = !objLast;
00716 while((objHist=nextHist())) {
00717 if (!ready && objHist!=objLast) continue;
00718 ready = 1999;
00719 if (objHist==objLast) continue;
00720 if (!objHist->InheritsFrom("TH1")) continue;
00721
00722
00723 ((TH1*)objHist)->SetDirectory(0);
00724 maker->AddHist((TH1*)objHist);
00725 }
00726 ::doPs(maker->GetName(),"Init");
00727 maker->ResetBIT(kInitBeg);
00728 maker->SetBIT (kInitEnd);
00729 StMkDeb::SetCurrent(curr);
00730 }
00731 return kStOK;
00732 }
00733
00734 void StMaker::StartMaker()
00735 {
00736
00737 if (!fLoggerHold) fLoggerHold = new StTurnLogger(GetLogger());
00738 if (!m_DataSet) {
00739 m_DataSet = Find(".data");
00740 if (!m_DataSet) {m_DataSet = new TObjectSet(".data"); Add(m_DataSet);}
00741 }
00742
00743 if (fMemStatMake && GetNumber()>20) fMemStatMake->Start();
00744
00745
00746
00747 StartTimer();
00748 }
00749
00750 void StMaker::EndMaker(Int_t ierr)
00751 {
00752 SetMakeReturn(ierr);
00753 fgTallyMaker[ierr%10]++;
00754 fTallyMaker [ierr%10]++;
00755 if (m_DataSet) m_DataSet->Pass(ClearDS,0);
00756 if (m_GarbSet) m_GarbSet->Delete();
00757 ::doPs(GetName(),"EndMaker");
00758
00759
00760 if (fMemStatMake && GetNumber()>20) fMemStatMake->Stop();
00761
00762 StopTimer();
00763
00764 if (fLoggerHold) { delete fLoggerHold; fLoggerHold = 0;}
00765
00766 }
00767
00768
00773 Int_t StMaker::Finish()
00774 {
00775 if (TestBIT(kFiniEnd)) return 1;
00776 TURN_LOGGER(this);
00777
00778 Int_t nerr = 0;
00779 Int_t run = GetRunNumber();
00780 if (run>-1) FinishRun(run);
00781
00782 TIter next(GetMakeList(),kIterBackward);
00783 StMaker *maker;
00784 Double_t totalCpuTime = 0;
00785 Double_t totalRealTime = 0;
00786 while ((maker = (StMaker* )next()))
00787 {
00788 totalCpuTime += maker->CpuTime();
00789 totalRealTime += maker->RealTime();
00790 }
00791
00792
00793 if (!totalRealTime) totalRealTime = 1;
00794 if (!totalCpuTime ) totalCpuTime = 1;
00795
00796 next.Reset();
00797 Int_t fst=1;
00798 while ((maker = (StMaker*)next())) {
00799 #ifdef STAR_LOGGER
00800 TURN_LOGGER(maker);
00801
00802 if (fst) {
00803 fst=0;
00804 LOG_QA <<
00805 Form("=================================================================================") << endm;
00806 LOG_QA <<
00807 Form("QAInfo:Chain %20s::%-20s Ast =%6.2f Cpu =%6.2f "
00808 ,ClassName(),GetName(),totalRealTime,totalCpuTime) << endm;
00809 }
00810 LOG_QA <<
00811 Form("QAInfo:Maker %20s::%-20s Ast =%6.2f(%4.1f%%) Cpu =%6.2f(%4.1f%%) "
00812 ,maker->ClassName(),maker->GetName()
00813 ,maker->RealTime()
00814 ,100*maker->RealTime()/totalRealTime
00815 ,maker->CpuTime()
00816 ,100*maker->CpuTime()/totalCpuTime) << endm;
00817
00818 static const Char_t *ee[]={"nStOK","nStWarn","nStEOF","nStErr","nStFatal"};
00819 TString tail("");
00820 for (Int_t j=0;j<=kStFatal;j++) {
00821 if (fTallyMaker[j]) tail += Form(" %s=%d",ee[j],fTallyMaker[j]);}
00822 if (tail != "") LOG_QA << (const Char_t *) tail << endm;
00823 #else
00824 if (fst) {
00825 fst=0;
00826 Printf("=================================================================================\n");
00827 Printf("QAInfo: Chain %20s::%-20s Ast =%6.2f Cpu =%6.2f "
00828 ,ClassName(),GetName(),totalRealTime,totalCpuTime);
00829 }
00830 printf("QAInfo: Maker %20s::%-20s Ast =%6.2f(%4.1f%%) Cpu =%6.2f(%4.1f%%) "
00831 ,maker->ClassName(),maker->GetName()
00832 ,maker->RealTime()
00833 ,100*maker->RealTime()/totalRealTime
00834 ,maker->CpuTime()
00835 ,100*maker->CpuTime()/totalCpuTime);
00836
00837 static const Char_t *ee[]={"nStOK","nStWarn","nStEOF","nStErr","nStFatal"};
00838 for (Int_t j=0;j<=kStFatal;j++) {
00839 if (fTallyMaker[j]) printf(" %s=%d",ee[j],fTallyMaker[j]);}
00840 printf("\n");
00841 #endif
00842 }
00843
00844 next.Reset();
00845 Int_t curr = StMkDeb::GetCurrent();
00846 while ((maker = (StMaker* )next()))
00847 {
00848 TURN_LOGGER(maker);
00849
00850 if (maker->TestBIT(kFiniEnd)) {
00851 maker->Warning("Finish","maker %s.%s Finished twice"
00852 ,maker->GetName(),maker->ClassName());
00853 continue;}
00854 StMkDeb::SetCurrent(maker,4);
00855 maker->SetBIT(kFiniBeg);
00856 if ( maker->Finish() ) nerr++;
00857 maker->ResetBIT(kFiniBeg);
00858 maker->SetBIT (kFiniEnd);
00859 StMkDeb::SetCurrent(curr);
00860 }
00861 if (!GetParent()) {
00862 #ifdef STAR_LOGGER
00863 LOG_INFO << "--------------Error Codes-------------------------" << endm;
00864 LOG_INFO << " nStOK nStWarn nStEOF nStErr nStFatal" << endm;
00865 TString tail("");
00866 for( Int_t i=0; i<=kStFatal; i++) tail += Form("%10d",fgTallyMaker[i]);
00867 if (tail != "")
00868 LOG_INFO << (const Char_t *)tail << endm;
00869 LOG_INFO << "--------------------------------------------------" << endm;
00870 #else
00871 printf("\n--------------Error Codes-------------------------\n");
00872 printf(" nStOK nStWarn nStEOF nStErr nStFatal \n");
00873 for( Int_t i=0; i<=kStFatal; i++) printf("%10d",fgTallyMaker[i]);
00874 printf("\n--------------------------------------------------\n");
00875 #endif
00876 }
00877
00878
00879 if (GetParent()==0) StMemStat::Summary();
00880
00881 return nerr;
00882 }
00883
00884
00895 Int_t StMaker::Make()
00896 {
00897 TURN_LOGGER(this);
00898
00899
00900 Int_t ret,run=-1,oldrun;
00901 TList *tl = GetMakeList();
00902 if (!tl) return kStOK;
00903 StEvtHddr *hd = GetEvtHddr();
00904 TIter nextMaker(tl);
00905 StMaker *maker;
00906 fgFailedMaker = 0;
00907 Int_t curr = StMkDeb::GetCurrent();
00908 while ((maker = (StMaker* )nextMaker())) {
00909 if (!maker->IsActive()) continue;
00910 TURN_LOGGER(maker);
00911 assert(!maker->TestBIT(kMakeBeg));
00912 maker->SetBIT(kMakeBeg);
00913 StMkDeb::SetCurrent(maker,2);
00914 oldrun = maker->m_LastRun;
00915 if (hd && hd->GetRunNumber()!=oldrun) {
00916 if (oldrun>-1) maker->FinishRun(oldrun);
00917 run = hd->GetRunNumber();
00918 if (Debug() && this == fgStChain && m_LastRun!=run){
00919 m_LastRun = run;
00920 #ifdef STAR_LOGGER
00921 LOG_INFO << " +++ New RunNumber found=" << run << " (previous = " << oldrun << ")" << endm;
00922 #else
00923 printf(" +++ New RunNumber found=%d (previous = %d)\n",run,oldrun);
00924 #endif
00925 hd->Print();
00926 }
00927 maker->InitRun(run);
00928 maker->m_LastRun=run;
00929 }
00930
00931 if (fgTestMaker) { fgTestMaker->SetNext(maker); fgTestMaker->Make();}
00932
00933 maker->StartMaker();
00934 ret = maker->Make();
00935 assert((ret%10)>=0 && (ret%10)<=kStFatal);
00936 maker->EndMaker(ret);
00937
00938 if (Debug() || ret) {
00939 #ifdef STAR_LOGGER
00940 LOG_INFO << "*** " << maker->ClassName() << "::Make() == "
00941 << RetCodeAsString(ret) << "(" << ret << ") ***"
00942 << endm;
00943 #else
00944 printf("*** %s::Make() == %s(%d) ***\n"
00945 ,maker->ClassName(),RetCodeAsString(ret),ret);
00946 #endif
00947 }
00948 maker->ResetBIT(kMakeBeg);
00949 StMkDeb::SetCurrent(curr);
00950 if ((ret%10)>kStWarn) {
00951 if ((ret%10) != kStERR) return ret;
00953 fgFailedMaker = maker;
00954 if (maker->IAttr(".Privilege")) return ret;
00955 continue;
00956 }
00957
00958 }
00959 return kStOK;
00960 }
00961
00962 void StMaker::FatalErr(Int_t Ierr, const Char_t *com)
00963 {
00964 #ifdef STAR_LOGGER
00965 LOG_QA << Form("QAInfo:%s::Fatal: Error %d %s",GetName(),Ierr,com) << endm;
00966 LOG_FATAL << Form("QAInfo:%s::Fatal: Error %d %s",GetName(),Ierr,com) << endm;
00967 #else
00968 printf("QAInfo:%s::Fatal: Error %d %s\n",GetName(),Ierr,com);
00969 #endif
00970 StMaker *parent = (StMaker *)GetParent();
00971 if (parent) ((StMaker*)parent)->FatalErr(Ierr,com);
00972 #ifndef STAR_LOGGER
00973 fflush(stdout);
00974 #endif
00975 }
00976
00977 StMaker *StMaker::GetMaker(const TDataSet *ds)
00978 {
00979 const TDataSet *par = ds;
00980 while (par && (par = par->GetParent()) && strncmp(".maker",par->GetTitle(),6)) {}
00981 return ( StMaker*) par;
00982 }
00983
00984
00990 EDataSetPass StMaker::ClearDS (TDataSet* ds,void * )
00991 {
00992 if (ds->InheritsFrom(TTable::Class())){
00993 TTable *table = (TTable *)ds;
00994 Int_t setSize = table->GetTableSize();
00995 table->ReAllocate();
00996 memset((void *)table->At(table->GetNRows()),127,table->GetRowSize());
00997
00998 if (setSize && table->GetTableSize() == 0){
00999 table->Warning("ReAllocate"," Table %s has purged from %d to %d "
01000 ,table->GetName(),setSize,(Int_t) table->GetTableSize());
01001 }
01002 table->NaN();
01003 }
01004 return kContinue;
01005 }
01006
01007 void StMaker::PrintInfo()
01008 {
01009 const char *cvs = GetCVS();
01010 const char *built = 0;
01011 if (cvs && cvs[0]) built = strstr(cvs,"built");
01012 else cvs = "No CVS tag was defined";
01013 #ifdef STAR_LOGGER
01014 if (built > cvs) { LOG_QA << Form("QAInfo:%-20s %s from %.*s",ClassName(),built,built-cvs,cvs)<< endm; }
01015 else { LOG_QA << Form("QAInfo:%-20s from %s",ClassName(),cvs) << endm; }
01016 #else
01017 if (built > cvs) printf("QAInfo:%-20s %s from %.*s\n",ClassName(),built,built-cvs,cvs);
01018 else printf("QAInfo:%-20s from %s\n",ClassName(),cvs);
01019 #endif
01020
01021 TIter next(GetMakeList());
01022 StMaker *maker;
01023 while ((maker = (StMaker* )next())) {
01024 maker->PrintInfo();
01025 }
01026 }
01027
01028
01030 Int_t StMaker::GetIventNumber() const
01031 {
01032 StEvtHddr *hd = GetEvtHddr();
01033 return hd->GetIventNumber();
01034 }
01035
01036
01037 void StMaker::SetIventNumber(Int_t iv)
01038 {
01039 StEvtHddr *hd = GetEvtHddr();
01040 hd->SetIventNumber(iv);
01041 }
01042
01043 Int_t StMaker::GetEventNumber() const
01044 {
01045 StEvtHddr *hd = GetEvtHddr();
01046 return hd->GetEventNumber();
01047 }
01048
01049
01051 Int_t StMaker::GetRunNumber() const
01052 {
01053 StEvtHddr *hd = GetEvtHddr();
01054 return hd->GetRunNumber();
01055 }
01056
01057 StMaker *StMaker::GetParentChain() const
01058 {
01059 const StMaker *mk = GetParentMaker();
01060 while(mk && !mk->IsChain()) {mk = mk->GetParentMaker();}
01061 return (StMaker*) mk;
01062 }
01063
01064 const TDatime &StMaker::GetDateTime() const
01065 {
01066 const StEvtHddr *hd = GetEvtHddr();
01067 return hd->GetDateTime();
01068 }
01069
01070 const TDatime &StMaker::GetDBTime() const
01071 {
01072 StMaker *mk = GetMakerInheritsFrom("St_db_Maker");
01073 assert(mk);
01074 return mk->GetDateTime();
01075 }
01076
01077
01078
01079 Int_t StMaker::GetDate() const {return GetDateTime().GetDate();}
01080
01081 Int_t StMaker::GetTime() const {return GetDateTime().GetTime();}
01082
01083 const Char_t *StMaker::GetEventType() const
01084 {
01085 StEvtHddr *hd = GetEvtHddr();
01086 return hd->GetEventType();
01087 }
01088
01089
01095 void StMaker::PrintTimer(Option_t *option)
01096 {
01097 if(option){};
01098 #ifdef STAR_LOGGER
01099 LOG_QA << Form("QAInfo:%-20s: Real Time = %6.2f seconds Cpu Time = %6.2f seconds, Entries = %d",GetName()
01100 ,m_Timer.RealTime(),m_Timer.CpuTime(),m_Timer.Counter()) << endm;
01101 #else
01102 Printf("QAInfo:%-20s: Real Time = %6.2f seconds Cpu Time = %6.2f seconds, Entries = %d",GetName()
01103 ,m_Timer.RealTime(),m_Timer.CpuTime(),m_Timer.Counter());
01104 #endif
01105 }
01106 void StMaker::lsMakers(const StMaker *top)
01107 {
01108 TDataSetIter iter((TDataSet*)top,20);
01109 Int_t N=0;
01110 for(const TDataSet *mk=top;mk;mk = iter.Next()) {
01111 if (! mk->InheritsFrom("StMaker")) continue;
01112 Int_t l=iter.GetDepth();
01113 N++;
01114 Char_t space[20]; memset(space,' ',sizeof(space));space[l]=0;
01115
01116 printf("%3d(%d) - %s %s::%s\n",N,l/2,space,mk->ClassName(),mk->GetName());
01117 }
01118 }
01119
01120
01121
01122 #if 0
01123
01124 static void MakeAssociatedClassList(const TObject *obj, const Char_t *classDir=0)
01125 {
01142 if (!obj) return;
01143 const Char_t *thisDir = classDir;
01144 if (thisDir == 0 || thisDir[0] == 0)
01145 thisDir = gSystem->DirName(obj->IsA()->GetImplFileName());
01146 const Char_t *thisClassName = obj->IsA()->GetName();
01147
01148
01149 void *dirhandle = 0;
01150 TString className;
01151 if ( (dirhandle = gSystem->OpenDirectory(thisDir)) )
01152 {
01153 const Char_t *n = 0;
01154 ifstream headerFile;
01155 Char_t inBuffer[128] = {0};
01156 Int_t lBuf = sizeof(inBuffer);
01157 Char_t *nextSym = inBuffer;
01158 Int_t status = 0;
01159 const Char_t keyWord[] = "class";
01160 const Int_t lKeyWord = sizeof(keyWord);
01161
01162 while ( (n = gSystem->GetDirEntry(dirhandle)) ) {
01163
01164 if (!strstr(n,".h") || strstr(n,"Cint.h") ) continue;
01165 Char_t *fullFile = gSystem->ConcatFileName(thisDir,n);
01166 headerFile.open(fullFile);
01167 if (headerFile.fail()) continue;
01168 while (headerFile.getline(inBuffer,lBuf) && !headerFile.eof()) {
01169 nextSym = inBuffer;
01170 if (status==0) status = 1;
01171 do {
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196 switch (status) {
01197 case 1: {
01198 if (*nextSym == ' ' || *nextSym == '\t') break;
01199 const Char_t *classFound = strstr(nextSym,keyWord);
01200 if ( classFound && classFound == nextSym){
01201 status = 2;
01202 nextSym += lKeyWord-2;
01203 }
01204 else status = 0;
01205 break;
01206 }
01207 case 2: status = 0;
01208 if (*nextSym == ' ' || *nextSym == '\t') status = 3;
01209 break;
01210 case 3:
01211 if (*nextSym == ' ' || *nextSym == '\t') break;
01212 status = 0;
01213 if (isalpha(*nextSym)) {
01214 className = *nextSym;
01215 nextSym++;
01216 while (isalnum(*nextSym) || *nextSym == '_' ) {
01217 className += *nextSym++; status = 4;
01218 }
01219 nextSym--;
01220 }
01221 break;
01222 case 4:
01223 if (*nextSym == ' ' || *nextSym == '\t') break;
01224 status = 0;
01225 if (*nextSym == 0 || *nextSym == ':' || *nextSym == '{' ||
01226 ( *nextSym == '/' &&
01227 (*(nextSym+1) == '/' || *(nextSym+1) == '*')
01228 )
01229 ) status = 5;
01230 break;
01231 case 5:
01232 if (strcmp(thisClassName,className.Data())) {
01233 printf(" MakeDoc: %s\n", className.Data());
01234 TClass *cl = gROOT->GetClass(className.Data());
01235 if (cl && !cl->InheritsFrom("StMaker") ) {
01236 gHtml->MakeClass((Text_t *)className.Data());
01237 }
01238 }
01239 default: status = 1;
01240 break;
01241 };
01242 } while (*(++nextSym) && status );
01243 }
01244 headerFile.close();
01245 delete [] fullFile;
01246 }
01247 }
01248 }
01249
01250 void StMaker::MakeDoc(const TString &stardir,const TString &outdir, Bool_t baseClasses)
01251 {
01281
01282 TString STAR = stardir;
01283 TString delim = ":";
01284
01285
01286 if (strcmp(gSystem->GetName(),"WinNT") == 0 ) {
01287
01288 delim = ";";
01289 STAR.ReplaceAll("$(afs)","//sol/afs");
01290 }
01291 else
01292 STAR.ReplaceAll("$(afs)","/afs");
01293
01294 TString classname = IsA()->GetName();
01295
01296 THtml thisHtml;
01297
01298
01299
01300
01301
01302
01303
01304 const Char_t *source[] = {"StRoot/St_base" , "TDataSet" , "St_base"
01305 ,"StRoot/StChain" , "StMaker" , "StChain"
01306
01307 ,"StRoot/StarClassLibrary", "" , ""
01308 ,"StRoot/StEvent" , "StEvent" , "StEvent"
01309 ,"StRoot/St_TLA_Maker" , "St_TLA_Maker", "St_TLA_Maker"
01310 ,"include" , "" , ""
01311 ,"include/tables" , "" , ""
01312 };
01313
01314 const Int_t lsource = sizeof(source)/sizeof(const Char_t *);
01315
01316 TString classDir = gSystem->DirName(IsA()->GetImplFileName());
01317 TString lookup = STAR;
01318 lookup += delim;
01319
01320 lookup += STAR;
01321 lookup += "/";
01322 lookup += classDir;
01323 lookup += delim;
01324
01325 lookup += STAR;
01326 lookup += "/StRoot/";
01327 lookup += classname;
01328
01329
01330
01331 Int_t i = 0;
01332 for (i=0;i<lsource-3;i+=3) {
01333 lookup += delim;
01334 lookup += STAR;
01335 lookup += "/";
01336 lookup += source[i];
01337
01338 const Char_t *cl = source[i+1];
01339 const Char_t *so = source[i+2];
01340 if (cl && cl[0] && so && so[0] && !gROOT->GetClass(cl))
01341 {
01342 if (gSystem->Load(so))
01343 printf(" Failed to load the share library %s for class %s\n",so,cl);
01344 }
01345 }
01346
01347
01348
01349
01350
01351 lookup.ReplaceAll("//StRoot/","/StRoot/");
01352 thisHtml.SetSourceDir(lookup);
01353
01354 TString odir = outdir;
01355
01356 gSystem->ExpandPathName(odir);
01357 thisHtml.SetOutputDir(odir);
01358
01359
01360
01361 Char_t *classes[] = {
01362 "St_Module", "TTable"
01363 ,"TDataSet", "TDataSetIter", "TFileSet"
01364 ,"StMaker", "StChain"
01365 ,"table_head_st"
01366 };
01367 Int_t nclass = sizeof(classes)/4;
01368
01369 TString header = "$STAF/inc/table_header.h";
01370
01371 gSystem->ExpandPathName(header);
01372 header.ReplaceAll("//inc/","/inc/");
01373 gROOT->LoadMacro(header);
01374
01375 TClass header1("table_head_st",1,"table_header.h","table_header.h");
01376
01377
01378 static Bool_t makeAllAtOnce = kTRUE;
01379 if (makeAllAtOnce && baseClasses) {
01380 makeAllAtOnce = kFALSE;
01381
01382 for (i=0;i<nclass;i++) thisHtml.MakeClass(classes[i]);
01383 thisHtml.MakeIndex();
01384
01385 }
01386
01387 if (baseClasses) {gHtml= &thisHtml; MakeAssociatedClassList(this, classDir.Data()); }
01388
01389 printf(" Making html for <%s>\n",classname.Data());
01390 thisHtml.MakeClass((Char_t *)classname.Data());
01391
01392
01393 TList *tl = GetMakeList();
01394 if (tl) {
01395 TIter nextMaker(tl);
01396 StMaker *maker;
01397 while ((maker = (StMaker* )nextMaker()))
01398 maker->MakeDoc(stardir,outdir,kFALSE);
01399 }
01400 }
01401 #endif
01402
01403 static void doPs(const Char_t *who, const Char_t *where)
01404 {
01405 static const Char_t *ps =0;
01406 if (!ps) {
01407
01408 ps = gSystem->Getenv("StarEndMakerShell");
01409 ps = (ps) ? "yes" : "";
01410 }
01411 if (!ps[0]) return;
01412 #ifdef STAR_LOGGER_BUG
01413 LOG_QA << Form("QAInfo: doPs for %20s:%12s \t",who,where);
01414 #else
01415 printf("QAInfo: doPs for %20s:%12s \t",who,where);
01416 #endif
01417 StMemStat::PrintMem(0);
01418 #if 0
01419 #ifdef STAR_LOGGER_BUG
01420 LOG_QA << endm;
01421 #else
01422 printf("\n");
01423 #endif
01424 #endif
01425 }
01426
01427
01428 void StMaker::Streamer(TBuffer &)
01429 { LOG_FATAL << Form("%s::Streamer - attempt to write %s",ClassName(),GetName()) << endm;
01430 assert(0);
01431 }
01432
01433 StMaker *StMaker::New(const Char_t *classname, const Char_t *name, void *title)
01434 {
01435
01436
01437 StMaker *maker = 0;
01438 if (classname)
01439 {
01440 TClass *cl = gROOT->GetClass(classname);
01441 if (cl) {
01442 maker = (StMaker *)cl->New();
01443 if (maker) {
01444 if (name && strlen(name)) maker->SetName(name);
01445 if (title) maker->SetTitle((Char_t *) title);
01446 }
01447 }
01448 }
01449 return maker;
01450 }
01451
01452 void StMaker::SetDebug(Int_t l)
01453 {
01454 m_DebugLevel = l;
01455 StMessMgr *log = GetLogger();
01456 if (log) log->SetLevel(m_DebugLevel);
01457 }
01458
01459
01460 void StMaker::SetDEBUG(Int_t l)
01461 {
01462 SetDebug(l);
01463
01464 TList *tl = GetMakeList();
01465 if (!tl) return;
01466
01467 TIter nextMaker(tl);
01468 StMaker *maker;
01469 while ((maker = (StMaker* )nextMaker())) maker->SetDEBUG(l);
01470 }
01471
01485 Int_t StMaker::SetAttr(const Char_t *key, const Char_t *val, const Char_t *to)
01486 {
01487
01488 Int_t count = 0;
01489 TString tk(key);tk.ToLower();tk.ReplaceAll(" ","");tk.ReplaceAll("\t","");
01490 if (!val) val ="";
01491 TString tv(val);tv = tv.Strip(TString::kBoth) ;tv.ReplaceAll("\t","");
01492 if (!to || !to[0]) to =".";
01493 TString tt(to ); tt.ReplaceAll(" ","");tt.ReplaceAll("\t","");
01494 TString tn(tt),tc("*");
01495 Int_t idx = tt.Index("::");
01496 if (idx>=0) {
01497 tn.Replace(0 ,idx+2,""); if (!tn.Length()) tn = "*";
01498 tc=tt;
01499 tc.Replace(idx,999 ,""); if (!tc.Length()) tc = "*";
01500 }
01501 Int_t act=0;
01502 if (tn==".") {act = 1;}
01503 else if (tn=="*") {act = 5;}
01504 else if (tn==GetName()) {act = 1;}
01505 else {act = 4;}
01506
01507 if (tc=="*") {act |=2;}
01508 else if (InheritsFrom(tc.Data())) {act |=2;}
01509
01510 TString fullName(ClassName()); fullName+="::"; fullName+=GetName();
01511
01512 if ((act&3)==3) {
01513 count++;
01514 if (tk == ".call") {
01515 TString command("(("); command += ClassName(); command+="*)";
01516 Char_t buf[20]; sprintf(buf,"%p",(void*)this);
01517 command +=buf; command +=")->"; command+=tv;command+=";";
01518 gROOT->ProcessLineFast(command.Data(),0);}
01519 else {
01520 if (!m_Attr) m_Attr = new TAttr(GetName());
01521 m_Attr->SetAttr(tk.Data(), tv.Data());
01522 if (Debug() > 1) {
01523 LOG_DEBUG << Form("SetAttr(\"%s\",\"%s\",\"%s\")",tk.Data(),tv.Data(),fullName.Data()) << endm;
01524 }
01525 }
01526 }
01527 if (!(act&4)) return count;
01528
01529
01530 TList *tl = GetMakeList();
01531 if (!tl) return count;
01532
01533 TIter nextMaker(tl);
01534 StMaker *maker;
01535 while ((maker = (StMaker*)nextMaker())) count += maker->SetAttr(tk.Data(),tv.Data(),to);
01536 return count;
01537 }
01538 Int_t StMaker::SetAttr(const StMaker *mk)
01539 {
01540 if (!mk) return 0;
01541 if (!mk->m_Attr) return 0;
01542 if (!m_Attr) m_Attr = new TAttr;
01543 return m_Attr->SetAttr(mk->m_Attr);
01544 }
01545
01546 Int_t StMaker::SetAttr(const Char_t *key, Int_t val, const Char_t *to)
01547 {
01548 TString ts; ts+=val; return SetAttr(key, ts.Data(), to);
01549 }
01550
01551 Int_t StMaker::SetAttr(const Char_t *key, UInt_t val, const Char_t *to)
01552 {
01553 TString ts; ts+=val; return SetAttr(key, ts.Data(), to);
01554 }
01555
01556 Int_t StMaker::SetAttr(const Char_t *key, Double_t val, const Char_t *to)
01557 {
01558 TString ts; ts+=val; return SetAttr(key, ts.Data(), to);
01559 }
01560
01561
01562 const Char_t *StMaker::SAttr(const Char_t *key) const
01563 {
01564 if (!m_Attr) return "";
01565 return m_Attr->SAttr(key);
01566 }
01567
01568 Int_t StMaker::IAttr(const Char_t *key) const
01569 {
01570 if (!m_Attr) return 0;
01571 return m_Attr->IAttr(key);
01572 }
01573
01574 UInt_t StMaker::UAttr(const Char_t *key) const
01575 {
01576 if (!m_Attr) return 0;
01577 return m_Attr->UAttr(key);
01578 }
01579
01580 Double_t StMaker::DAttr(const Char_t *key) const
01581 {
01582 if (!m_Attr) return 0;
01583 return m_Attr->DAttr(key);
01584 }
01585
01586 void StMaker::PrintAttr() const
01587 {
01588 if (!m_Attr) return ;
01589 m_Attr->PrintAttr();
01590 }
01591
01592
01593 Int_t StMaker::InitRun (Int_t runumber) {return 0;}
01594
01595 Int_t StMaker::FinishRun(Int_t runumber) {return 0;}
01596
01597
01598 Int_t StMaker::Cleanup(TDataSet *&ds)
01599 {
01600
01601 if (!ds->TObject::TestBit(TObject::kNotDeleted)) {ds=0;return 0;}
01602 TSeqCollection *list = ds->TDataSet::GetCollection();
01603 if (!list) return 0;
01604 assert(list->IsA()==TList::Class() || list->IsA()==TObjArray::Class());
01605
01606 Int_t kount = 0;
01607 TIter iter(list);
01608 TDataSet *son;
01609 Int_t num = list->Capacity();
01610 for (Int_t i=0; i<num; i++) {
01611 son = (TDataSet*)iter.Next();
01612 if (!son) continue;
01613 if (!son->TObject::TestBit(TObject::kNotDeleted)) {list->Remove(son); continue;}
01614 TDataSet* par = son->TDataSet::GetParent();
01615 if ( par != ds) {list->Remove(son); continue;}
01616 assert (son->InheritsFrom(TDataSet::Class()));
01617 if (son->InheritsFrom(StMaker::Class())) continue;
01618 kount = Cleanup(son) + 1;
01619 }
01620 if (!ds->InheritsFrom(TObjectSet::Class())) return kount;
01621 TObjectSet *os = (TObjectSet*)ds;
01622 TObject *to = os->GetObject();
01623 if (!to) return kount;
01624 if (!to->TObject::TestBit(TObject::kNotDeleted)) {
01625 os->DoOwner(0); os->SetObject(0); return kount+1;}
01626 if (!os->IsOwner()) {os->SetObject(0); return kount;}
01627 if (!to->InheritsFrom(TDataSet::Class())) return kount;
01628 TDataSet *t = (TDataSet*)to;
01629 return kount + Cleanup(t);
01630 }
01631
01632 StEvtHddr *StMaker::GetEvtHddr() const
01633 {
01634 StEvtHddr *hddr = (StEvtHddr*)GetDataSet("EvtHddr");
01635 if(!hddr) hddr = new StEvtHddr((TDataSet*)m_ConstSet);
01636 return hddr;
01637 }
01638
01639 void StMaker::SetDateTime(Int_t idat,Int_t itim)
01640 {
01641 StEvtHddr *hddr = GetEvtHddr();
01642 hddr->SetDateTime(idat,itim);
01643 }
01644
01645
01646 const Char_t *StMaker::RetCodeAsString(Int_t kode)
01647 {
01648 static const Char_t *retCodes[] = {
01649 "StOK" ,"StWarn" ,"StEOF" ,"StERR" ,"StFATAL" ,0,0,0,0,0,
01650 "StOK!" ,"StWarn!" ,"StEOF!" ,"StSKIP" ,"StSTOP" ,0,0,0,0,0,
01651 "StOK!!","StWarn!!","StEOF!!","StSKIP!","StSTOP!" ,0,0,0,0,0};
01652
01653 assert(kode>=0);
01654 if (kode>=30) kode = kode%10+20;
01655 const Char_t *res = retCodes[kode];
01656 if (!res) res = "StUNKNOWN";
01657 return res;
01658
01659 }
01660
01661
01662 StMakerIter::StMakerIter(const StMaker *mk,Int_t secondary)
01663 {
01664 fState = 0;
01665 fMaker = mk;
01666 fMakerIter = 0;
01667 fIter = new TDataSetIter(fMaker->Find(".make"));
01668 fItWas = (TDataSet*)(-1);
01669 fSecond = secondary;
01670
01671 }
01672
01673 StMakerIter::~StMakerIter()
01674 {
01675 delete fIter; fIter = 0;
01676 delete fMakerIter; fMakerIter = 0;
01677 fMaker=0; fState = 0;
01678 }
01679
01680 StMaker *StMakerIter::NextMaker()
01681 {
01682 TDataSet *ds;
01683 if (!fMaker) return 0;
01684
01685 AGAIN: switch (fState) {
01686
01687 case 0:
01688 ds = fIter->Next();
01689 if (ds == fItWas) goto AGAIN;
01690 fState = 2; if (!ds) goto AGAIN;
01691 fState = 1;
01692 delete fMakerIter;
01693 fMakerIter = new StMakerIter((StMaker*)ds,1);
01694 goto AGAIN;
01695
01696 case 1:
01697 ds = fMakerIter->NextMaker();
01698 if (ds) return (StMaker* )ds;
01699 fState = 0; goto AGAIN;
01700
01701 case 2:
01702 delete fMakerIter; fMakerIter=0;
01703 delete fIter; fIter = 0;
01704 fState = 3;
01705 return (StMaker*)fMaker;
01706
01707 case 3:
01708 if (fSecond) return 0;
01709 TDataSet *par = fMaker->GetParent();
01710 fItWas = fMaker; fMaker = 0;
01711 if (!par) return 0;
01712 if (strcmp(".make",par->GetName())) return 0;
01713 fMaker = (StMaker* )par->GetParent();
01714 if (!fMaker) return 0;
01715 delete fIter; fIter = new TDataSetIter(par);
01716 fState = 0; goto AGAIN;
01717 }
01718 assert(0); return 0;
01719 }
01720
01721 Int_t StMaker::AliasDate(const Char_t *alias)
01722
01723 {
01724
01725 Int_t n = strcspn(alias," ."); if (n<3) return 0;
01726 Int_t i;
01727 for (i=0;fDbAlias[i].tag && strncmp(alias,fDbAlias[i].tag,n);i++) {}
01728 return fDbAlias[i].date;
01729 }
01730
01731 Int_t StMaker::AliasTime(const Char_t *alias)
01732
01733 {
01734
01735 Int_t n = strcspn(alias," ."); if (n<3) return 0;
01736 Int_t i;
01737 for (i=0;fDbAlias[i].tag && strncmp(alias,fDbAlias[i].tag,n);i++) {}
01738 return fDbAlias[i].time;
01739 }
01740
01741 const Char_t *StMaker::AliasGeometry(const Char_t *alias)
01742
01743 {
01744
01745 Int_t n = strcspn(alias," ."); if (n<3) return 0;
01746 Int_t i;
01747 for (i=0;fDbAlias[i].tag && strncmp(alias,fDbAlias[i].tag,n);i++) {}
01748 return fDbAlias[i].geometry;
01749 }
01750
01751 const DbAlias_t *StMaker::GetDbAliases() {return fDbAlias;}
01752
01753 const StChainOpt *StMaker::GetChainOpt() const
01754 {
01755 StMaker *mk = GetMaker(this);
01756 if (!mk) return 0;
01757 return mk->GetChainOpt();
01758 }
01759
01760 TFile *StMaker::GetTFile() const
01761 {
01762 const static Char_t *mktype = "StBFChain";
01763 StMaker *mk = 0;
01764 if (this->InheritsFrom(mktype)) {mk = (StMaker *) this;}
01765 else {
01766 StMakerIter mkiter(GetChain());
01767 while ((mk = mkiter.NextMaker())) {
01768 if (mk->InheritsFrom(mktype)) {
01769 const StChainOpt *opt = mk->GetChainOpt();
01770 if (!opt) continue;
01771 if (opt->GetTFile()) break;
01772 }
01773 }
01774 }
01775 if (! mk) return 0;
01776 const StChainOpt *opt = mk->GetChainOpt();
01777 if (!opt) return 0;
01778 return opt->GetTFile();
01779 }
01780
01781 ClassImp(StTestMaker)
01782
01783 StTestMaker::StTestMaker(const Char_t *name):StMaker(name)
01784 {
01785 fNext=0; fLast=0;
01786 if (fgStChain == this ) {fgStChain=0;}
01787 else {Shunt() ;}
01788 fgTestMaker = this;
01789 }
01790
01791 void StTestMaker::SetNext(StMaker *mk)
01792 {
01793 fLast=fNext;
01794 fNext=mk;
01795 }
01796
01797 void StTestMaker::Print(const Char_t *) const
01798 {
01799 #ifdef STAR_LOGGER
01800 if (fLast) { LOG_INFO << Form("%s: Last Maker %s::%s(%p)",
01801 ClassName(),fLast->ClassName(),fLast->GetName(),(void*)fLast)<< endm;}
01802 if (fNext) { LOG_INFO << Form("%s: Next Maker %s::%s(%p)",
01803 ClassName(),fNext->ClassName(),fNext->GetName(),(void*)fNext) << endm;}
01804 #else
01805 if (fLast) printf("%s: Last Maker %s::%s(%p)\n",
01806 ClassName(),fLast->ClassName(),fLast->GetName(),(void*)fLast);
01807 if (fNext) printf("%s: Next Maker %s::%s(%p)\n",
01808 ClassName(),fNext->ClassName(),fNext->GetName(),(void*)fNext);
01809 #endif
01810 }
01811
01812 Int_t StMaker::Skip(Int_t NoEventSkip)
01813 {
01814 TURN_LOGGER(this);
01815
01816 TList *tl = GetMakeList();
01817 if (!tl) return kStOK;
01818 TIter nextMaker(tl);
01819 StMaker *maker;
01820 fgFailedMaker = 0;
01821 while ((maker = (StMaker* )nextMaker())) {
01822 if (!maker->IsActive()) continue;
01823 maker->Skip(NoEventSkip);
01824 }
01825 return kStOK;
01826 }
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568