304 #include "TBrowser.h"
307 #include "TInterpreter.h"
310 #include "St_db_Maker.h"
311 #include "TDataSetIter.h"
312 #include "TFileSet.h"
315 #include "TTableDescriptor.h"
317 #include "TUnixTime.h"
318 #include "StDbBroker/StDbBroker.h"
320 #include "StValiSet.h"
324 enum eKIND { kXDFkind = 1, kCkind=2, kROOTkind = 3};
325 enum eDBMAKER { kUNIXOBJ = 0x2000};
334 TString FullFileName(
const TDataSet* ds)
336 TString dbfile(ds->GetTitle()+5);
337 TString dbDir(gSystem->BaseName(dbfile.Data()));
339 TString full(ds->
Path());
342 int idx = full.Index(dbDir);
if (idx<0)
break;
343 full.Remove(0,idx+dbDir.Length()-1);
346 TString name(ds->GetName());
347 int idx = name.Index(
".");
if (idx>=0) name.Remove(idx,999);
349 full.ReplaceAll(name,
"");
350 full.Insert(0,dbfile);
351 gSystem->ExpandPathName(full);
374 for (
int i=0;i<5;i++) {fTimer[i].Stop();}
377 memset(fEvents,0,
sizeof(fEvents)+
sizeof(fDataSize));
398 fQueryTs = time(NULL);
399 fMaxEntryTime = ut.GetUTime();
402 St_db_Maker::~St_db_Maker()
404 delete fDBBroker; fDBBroker =0;
406 delete fHierarchy;fHierarchy=0;
409 Int_t St_db_Maker::InitRun(
int runumber)
411 if (!fDBBroker || !runumber)
return 0;
413 fDBBroker->SetRunNumber(runumber);
418 Int_t St_db_Maker::Init()
426 int snap = fDataBase!=0;
427 for (
int idir=0;!snap && idir < 10 && !fDirs[idir].IsNull(); idir++) {
430 gSystem->ExpandPathName(dir);
431 if (strncmp(
"MySQL:", (
const char*)dir,6)==0){
432 fileset = OpenMySQL(((
const char*)dir)+6);
433 if (!fileset)
return kStErr;
434 fileset->
Pass(PrepareDB,0);
438 fileset =
new TFileSet(dir,gSystem->BaseName(dir));
439 if (!fileset->
First()) {
delete fileset; fileset = 0;
continue;}
442 fileset->
Pass(PrepareDB,&dir);
446 assert(strcmp(fDataBase->GetName(),fileset->GetName())==0);
447 fDataBase->
Update(fileset);
delete fileset;
448 }
else {fDataBase = fileset; }
453 SetOutputAll(fDataBase,1);
455 if (Debug()>1) fDataBase->
ls(
"*");
459 ResetBIT(kInitBeg);
SetBIT(kInitEnd);
461 return StMaker::Init();
467 for (
int i=0;i<6;i++) fTimer[i].Stop();
468 Printf(
"St_db_Maker::Init ");fTimer[0].Print();
469 Printf(
" MySQL::Init ");fTimer[2].Print();
470 Printf(
"St_db_Maker::Make ");fTimer[1].Print();
471 Printf(
" MySQL::Make ");fTimer[3].Print();
472 Printf(
" MySQL::Data ");fTimer[4].Print();
474 if (fEvents[1]<=0)
return 0;
475 double estiTime = fTimer[4].RealTime()*fTimer[5].CpuTime()/fTimer[5].RealTime();
476 double eachEvt = double(fEvents[0]) /(fEvents[1]+3e-33);
477 double MperTim = (fDataSize[1]*1e-6)/(estiTime+3e-33);
478 double timPerE = estiTime/(fEvents[1]+3e-33);
479 double cpuPerE = fTimer[4].CpuTime() /(fEvents[1]+3e-33);
480 double timPct = fTimer[4].RealTime()/fTimer[5].RealTime() *100;
481 double cpuPct = fTimer[4].CpuTime() /fTimer[5].CpuTime() *100;
483 Info(
"dbStat",
"Evts = %d dbEvts=%d Evts/dbEvts = %4.1f\n"
484 ,fEvents[0], fEvents[1],eachEvt);
486 Info(
"dbStat",
"dbData =%10.1f dbTime=%g dbData/dbTime=%g\n"
487 ,fDataSize[1]*1e-6,estiTime,MperTim);
489 Info(
"dbStat",
"dbTime =%10.1f dbEvts=%d dbTime/dbEvts =%g\n"
490 ,estiTime,fEvents[1],timPerE);
492 Info(
"dbStat",
"dbCpu =%10.1f dbEvts=%d dbCpu/dbEvts =%g\n"
493 ,fTimer[4].CpuTime() ,fEvents[1],cpuPerE);
495 Info(
"dbStat",
"dbTime/tot =%10.2f dbCpu/tot=%10.2f \n"
507 TDatime td = GetDateTime();
508 if (td.GetDate() >= 20330101) {
509 Error(
"Make",
"TimeStamp not set. Can not make request to DB");
521 if (!fDBBroker)
return;
523 if (fDataSize[0]) fEvents[1]++;
524 fDataSize[1]+=fDataSize[0];
527 time_t now = time(NULL);
528 if ( ( now - fQueryTs ) < 30 ) {
return; }
530 fDBBroker->Release();
533 TDatime St_db_Maker::Time(
const char *filename)
535 int lfilename,lname,idate,itime;
537 TDatime time; time.Set(kMaxTime,0);
538 TString tfilename(filename);
539 tfilename.ReplaceAll(
".C",
"");
540 tfilename.ReplaceAll(
".root",
"");
542 lfilename = tfilename.Length();
543 lname = strcspn(tfilename.Data(),
".");
544 if (lfilename== lname) {
545 time.Set(kMinTime,0);
548 idate = AliasDate(tfilename.Data()+lname+1);
549 itime = AliasTime(tfilename.Data()+lname+1);
552 time.Set(idate,itime);
return time;
555 if (lname+16 <= lfilename &&
556 tfilename[lname+0 ]==
'.' &&
557 tfilename[lname+9 ]==
'.' ) {
558 idate = atoi(tfilename.Data()+lname+ 1);
559 itime = atoi(tfilename.Data()+lname+10);
561 ::Error(
"St_db_Maker::Time",
"Unrecognised File name %s IGNORED",filename);
564 time.Set(idate,itime);
return time;
568 int St_db_Maker::Kind(
const char *filename)
572 lfilename = strlen(filename);
573 if (!strcmp(filename+lfilename-4,
".xdf" ))
return kXDFkind;
574 if (!strcmp(filename+lfilename-2,
".C" ))
return kCkind;
575 if (!strcmp(filename+lfilename-2,
".c" ))
return kCkind;
576 if (!strcmp(filename+lfilename-5,
".root"))
return kROOTkind;
580 TDataSet *St_db_Maker::OpenMySQL(
const char *dbname)
586 fTimer[0].Stop(); fTimer[2].Start(0);
588 if (Debug() > 1) fDBBroker->setVerbose(1);
590 fDBBroker->SetProdTime(fMaxEntryTime);
591 for (std::map<std::pair<std::string,std::string>,UInt_t>::iterator it = fMaxEntryTimeOverride.begin(); it != fMaxEntryTimeOverride.end(); it++ ) {
592 fDBBroker->AddProdTimeOverride((*it).second, (
char*)((*it).first.first).c_str(), (
char*)((*it).first.second).c_str());
595 const TAttr *attl = GetAttr();
599 while ((obj = next())) {
600 if (strcmp(
"blacklist",obj->GetName())!=0)
continue;
601 fDBBroker->addBlacklistedDomain(obj->GetTitle());
602 Info(
"OpenMySQL",
"Block domain %s",obj->GetTitle());
605 TString ts(dbname); ts+=
"_hierarchy";
607 thy = fDBBroker->InitConfig(dbname,nrows);
608 fTimer[0].Start(0); fTimer[2].Stop();
610 Warning(
"OpenMySQL",
"***Can not open MySQL DB %s ***",dbname);
613 fHierarchy->
Adopt(nrows,thy);
614 if (GetDebug()>1) fHierarchy->
Print(0,nrows);
617 top->SetTitle(
"directory");
620 memset(dss,0,nrows*
sizeof(
void*));
623 for (irow=0,ihy=thy; irow <nrows ; irow++,ihy++)
625 if (strcmp(ihy->tabtype,
".node")==0) {
627 ds->SetTitle(
"directory");
629 const char *ty = ihy->tabtype;
630 if (ty[0]==
'.') ty++;
633 Warning(
"OpenMySQL",
"Unknown table %s/%s.%s",ihy->parname,ihy->tabname,ihy->tabtype);
continue;}
635 if (ds) ds->SetUniqueID(ihy->tabID);
640 for (irow=0,ihy=thy; irow <nrows ; irow++,ihy++)
642 ds = dss[irow];
if (!ds)
continue;
643 if (strcmp(ihy->parname,top->GetName())==0) top->Add(ds);
644 if(ds->GetParent())
continue;
645 for (jrow=0,jhy=thy; jrow <nrows ; jrow++,jhy++)
647 if (jrow==irow)
continue;
648 if (ihy->parID != jhy->tabID)
continue;
649 if (strcmp(
".node" ,jhy->tabtype))
continue;
650 if (strcmp(ihy->parname,jhy->tabname))
continue;
651 node = dss[jrow];
if (!node)
continue;
652 node->Add(ds);
break;
654 if (ds->GetParent())
continue;
655 delete ds; dss[irow]=0;
656 Error(
"OpenMySQL",
"WRONG parent %s/%s\n",ihy->parname,ihy->tabname);
670 ds->
Pass(&UpdateDB,
this);
674 int St_db_Maker::UpdateTable(UInt_t parId,
TTable* dat
675 ,
const TDatime &req,TDatime val[2] )
678 assert(fDBBroker);assert(dat);
682 fDBBroker->SetDateTime(req.GetDate(),req.GetTime());
687 fDBBroker->SetDictionary(rowTL);
688 fDBBroker->SetTableName (dat->GetName());
689 fDBBroker->SetStructName(dat->GetTitle());
693 void *dbstruct = fDBBroker->Use(dat->GetUniqueID(),parId);
695 Int_t d1 = fDBBroker->GetBeginDate();
696 Int_t t1 = fDBBroker->GetBeginTime();
698 Warning(
"UpdateTable",
"Table %s.%s Unacceptable Begin Date/Time %d/%d reset to 19950101/000001",
699 dat->GetName(),dat->GetTitle(),d1,t1);
700 d1 = 19950101; t1 = 1;
702 Int_t d2 = fDBBroker->GetEndDate ();
703 Int_t t2 = fDBBroker->GetEndTime ();
705 Warning(
"UpdateTable",
"Table %s.%s Unacceptable End Date/Time %d/%d reset to 19950101/000001",
706 dat->GetName(),dat->GetTitle(),d2,t2);
707 d2 = 19950101; t2 = 1;
713 if ( val[0].Get() >= val[1].Get()) {
714 Error(
"UpdateTable",
"val[0].Get() = %u >= val[1].Get() = %u\n",val[0].Get(),val[1].Get());
715 Error(
"UpdateTable:",
"Table %s.%s Suspicious Ranges Date/Time %d/%d->%d/%d\n",
716 dat->GetName(),dat->GetTitle(),d1,t1,d2,t2);
717 Error(
"UpdateTable",
"Table %s.%s Suspicious Ranges Date/Time %d/%d->%d/%d",
718 dat->GetName(),dat->GetTitle(),d1,t1,d2,t2);
719 assert(! ( val[0].Get() >= val[1].Get()));
722 fTimer[1].Start(0); fTimer[3].Stop();fTimer[4].Stop();
726 if(Debug()>1) Warning(
"UpdateTable",
"Table %s.%s Not FOUND in DB",dat->GetName(),dat->GetTitle());
730 int nRows = fDBBroker->GetNRows();
732 dat->
Adopt(nRows,dbstruct);
735 if (!nRows || ((
char*)dbstruct)[dat->
GetRowSize()*nRows-1]) {}
745 EDataSetPass St_db_Maker::UpdateDB(
TDataSet* ds,
void *user )
748 if (strcmp(
"directory",ds->GetTitle())==0)
return kContinue;
749 if (strcmp(
".Val" ,ds->GetTitle())!=0)
return kPrune;
754 if (mk->fUpdateMode && !val->IsModified())
return kPrune;
756 TDatime currenTime = mk->GetDateTime();
757 UInt_t uevent = currenTime.Get();
761 if (val->fTimeMin.Get() <= uevent
762 && val->fTimeMax.Get() > uevent)
return kPrune;
765 const char *fname = mk->SAttr(
"dbSnapshot");
766 if (!fname || !*fname) {
769 if (!mk->fDBBroker) {
770 mk->Error(
"UpdateDB",
"DbSnapshot mode: wrong validity for %s ignored( ???? )"
777 mk->UpdateValiSet(val,currenTime);
778 if (val->fGood) par->
AddFirst(val->fDat);
782 int St_db_Maker::UpdateValiSet(
StValiSet *val,
const TDatime ¤Timep)
784 static int nCall=0; nCall++;
785 TDatime currenTime(currenTimep);
786 if (currenTime.GetDate() >=kMaxTime) currenTime.Set(kMaxTime-1,0);
788 TDatime valsCINT[2],valsSQL[2];
789 UInt_t uevent = currenTime.Get();
792 val->fTimeMin.Set(kMaxTime,0);
793 val->fTimeMax.Set(kMinTime,0);
796 valsSQL[0].Set(kMinTime,0);
797 valsSQL[1].Set(kMaxTime,0);
798 if (fDBBroker && val->fTabId ) {
799 assert(val->fTabId==val->fDat->GetUniqueID());
800 int ierr = UpdateTable(val->fParId,(
TTable*)val->fDat,currenTime,valsSQL );
802 fQueryTs = time(NULL);
805 left = FindLeft(val,valsCINT,currenTime);
808 SWITCH:
switch (kase) {
811 val->fTimeMin = valsSQL[0]; val->fTimeMax = valsSQL[1];
815 val->fTimeMin = valsSQL[0]; val->fTimeMax = valsSQL[1];
816 val->fGood=1; kase=4;
goto SWITCH;
819 newGuy = LoadTable(left);
820 if (!val->fDat) { val->fDat = newGuy; val->
AddFirst(newGuy);}
821 else if(val->fDat->InheritsFrom(TTable::Class()))
822 { val->fDat->
Update(newGuy);
delete newGuy ;}
823 else {
delete val->fDat; val->fDat = newGuy ;}
824 val->fTimeMin = valsCINT[0]; val->fTimeMax = valsCINT[1];
825 val->fGood=1; kase=4;
goto SWITCH;
828 if (valsCINT[0].Get()>=valsSQL[0].Get()) {
830 if (valsCINT[1].Get()>valsSQL[1].Get()) valsCINT[1] = valsSQL[1];
833 if (valsSQL[1].Get()>valsCINT[1].Get()) valsSQL[1] = valsCINT[1];
838 if( ! ((val->fTimeMin.Get()<= uevent) && (uevent<val->fTimeMax.Get()) )){
840 if (val->
Path().Contains(
"RunLog/onl"))
break;
847 (void) printf(
"CheckFail:: Assert will fail for Table %s TimeMin=%d TimeMax=%d uevent=%d\n",
848 val->GetName(),val->fTimeMin.Get(),val->fTimeMax.Get(),uevent);
849 (void) printf(
"\tTimeMin "); val->fTimeMin.Print();
850 (void) printf(
"\tuevent "); currenTime.Print();
851 (void) printf(
"\tTimeMax "); val->fTimeMax.Print();
853 assert((val->fTimeMin.Get()<= uevent) && (val->fTimeMax.Get()>uevent));
861 if (val->fTimeMin.Get() == val->fTimeMax.Get()) {
862 Warning(
"UpdateDB",
"Zero size validity for %s",val->GetName());
863 printf(
"\tTimeMin "); val->fTimeMin.Print();
864 printf(
"\tuevent "); currenTime.Print();
865 printf(
"\tTimeMax "); val->fTimeMax.Print();
866 Warning(
"UpdateDB",
"Ask Mike DeFillips WHY!!!!!");
872 TDataSet *St_db_Maker::FindLeft(
StValiSet *val, TDatime vals[2],
const TDatime ¤Time)
877 UInt_t uevent = currenTime.Get();
879 vals[0].Set(kMinTime,0);
880 vals[1].Set(kMaxTime,0);
881 UInt_t utmp,udifleft=(UInt_t)(-1),udifrite=(UInt_t)(-1);
883 TListIter next(val->GetList());
885 if (set == val->fDat)
continue;
886 const char *filename = set->GetName();
887 UInt_t ucur = St_db_Maker::Time(filename).Get();
889 Warning(
"FindLeft",
"*** Unrecognozed file %s ***",filename);
891 }
else if (uevent < ucur) {
892 utmp = ucur - uevent;
893 if (utmp <= udifrite) { udifrite=utmp; rite=set;}
895 utmp = uevent - ucur;
896 if (utmp <= udifleft) { udifleft=utmp; left=set;}
901 if (left) vals[0] = St_db_Maker::Time(left->GetName());
902 if (rite) vals[1] = St_db_Maker::Time(rite->GetName());
914 TString dbfile(FullFileName(left));
915 assert(dbfile.Length()>0);
917 int kind = Kind(left->GetName());
923 if (GetDebug()) printf(
"Load XdfFile: %s\n",(
const char*)dbfile);
928 command =
".L "; command += dbfile;
929 if (GetDebug()) printf(
"LoadTable: %s\n",(
const char*)command);
930 TInterpreter::EErrorCode ee;
931 gInterpreter->ProcessLine(command,&ee);
933 newdat = (
TDataSet *) gInterpreter->Calc(
"CreateTable()",&ee);
935 command.ReplaceAll(
".L ",
".U ");
936 gInterpreter->ProcessLine(command,&ee);
943 tf =
new TFile(dbfile);
944 to = StIO::Read (tf,
"*");
947 if (GetDebug()) printf(
"Load TFile: %s\n",(
const char*)dbfile);
948 if (strcmp(to->ClassName(),
"StIOEvent")==0) to = ((
StIOEvent*)to)->fObj;
950 if (to->InheritsFrom(TDataSet::Class())) {
960 if (newdat) newdat->SetUniqueID(kUNIXOBJ+kind);
966 EDataSetPass St_db_Maker::PrepareDB(
TDataSet* ds,
void *user)
970 const char *dsname,*filename,*dot;
975 TList *list = ds->GetList();
976 if (!list)
return kContinue;
977 if (strcmp(
"directory",ds->GetTitle())!=0)
return kPrune;
978 dsname = ds->GetName(); ;
979 if (!strcmp(
"CVS",dsname)) {
delete ds;
return kPrune;}
981 TString newTitle =
"file ";
982 if (user) newTitle += *((TString*)user);
985 pseudo = 0; psname[0]=
'.'; psname[1]=0;
986 TListIter next(list);
988 filename = set->GetName();
989 int isSql =(set->InheritsFrom(TTable::Class())!=0);
991 lpsname = strlen(filename);
993 if (strncmp(
"file",set->GetTitle(),4)!=0)
continue;
994 if (!(dot = strchr(filename,
'.')))
continue;
995 int k = Kind(filename);
998 if (!k){
delete set;
continue;}
999 set->SetTitle(newTitle);
1000 lpsname = dot - filename;
1002 if (strncmp(filename,psname+1,lpsname)) {
1003 psname[1]=0; strncat(psname,filename,lpsname);
1005 pseudo->fParId = ds->GetUniqueID();
1011 pseudo->fTabId = set->GetUniqueID();
1019 TDataSet *St_db_Maker::GetDataBase(
const char* logInput,
const TDatime *td)
1025 ds = GetDataSet(logInput);
1026 if (!ds || strncmp(ds->GetTitle(),
"directory",9)!=0)
1031 for (
int i=0;logInput[i];i++)
if (logInput[i]==
'/') lst=i;
1032 if (lst<0) { ds=0;
goto RETN;}
1035 ts.Insert(lst+1,
".");
1036 ds = GetDataSet(ts.Data());
1042 Error(
"GetDataBase",
"Request for directory %s with user time is FORBIDDEN"
1046 assert(!strcmp(
".Val",ds->GetTitle()));
1049 myVS->fTabId = vs->fTabId;
1050 myVS->fParId = vs->fParId;
1055 if (ty.EndsWith(
"_st")) ty.
Remove(ty.Length()-3,99);
1057 myVS->fDat->SetUniqueID(myVS->fTabId);
1061 while ((to=(
TDataSet*)next())){ myVS->Add(to);}
1063 UpdateValiSet(myVS,*td);
1064 myVS->GetList()->Clear(
"nodelete");
1066 myVS->fDat->Add(myVS);
1076 if (idir)
goto RETN;
1077 ds = GetDataSet(logInput);
1078 RETN: fTimer[1].Stop();
return ds;
1081 const TDatime &St_db_Maker::GetDateTime()
const
1083 if (!fIsDBTime)
return StMaker::GetDateTime();
1088 void St_db_Maker::SetDateTime(Int_t idat,Int_t itim)
1090 fIsDBTime=0;
if (idat==0)
return;
1091 fIsDBTime=1; fDBTime.Set(idat,itim);
1092 Info(
"SetDateTime",
"Setting Startup Date=%d Time=%d",idat,itim);
1093 StMaker::SetDateTime(idat,itim);
1096 void St_db_Maker::SetDateTime(
const char *alias)
1099 int idat = AliasDate(alias);
1100 int itim = AliasTime(alias);
1102 Info(
"SetDateTime",
"(\"%s\") == Startup Date=%d Time=%d",alias,idat,itim);
1103 fDBTime.Set(idat,itim);
1104 StMaker::SetDateTime(idat,itim);
1107 void St_db_Maker::SetOn(
const char *path)
1108 { AddAlias(
"On" ,path,
".onoff"); OnOff();}
1110 Int_t St_db_Maker::Save(
const char *path,
const TDatime *newtime)
1119 top = GetDataBase(path);
1122 TDataSet::EDataSetPass mode = TDataSet::kContinue;
1123 while((ds = nextDS(mode))) {
1124 mode = TDataSet::kContinue;
1125 if (ds->GetName()[0]==
'.') { mode = TDataSet::kPrune;
continue; }
1126 if (!ds->InheritsFrom(TTable::Class()))
continue;
1128 i = ts.Index(
".const/"); assert(i>0); ts.Replace(0 ,i+7,
"");
1129 int jdot = ts.Index(
".",(Ssiz_t)1,(Ssiz_t)0 ,TString::kExact);
1131 int jsla = ts.Index(
"/",(Ssiz_t)1,(Ssiz_t)jdot,TString::kExact);
1133 ts.Remove(jdot,jsla-jdot+1);
1136 if (ts[i]!=
'/')
continue;
1137 dir.Replace(0,999,ts,i);
1138 gSystem->MakeDirectory(dir);
1141 if (newtime) { val[0] = *newtime;}
1142 else {i = GetValidity(tb,val); assert(i>=0);}
1143 sprintf(cbuf,
".%08d.%06d.C",val[0].GetDate(),val[0].GetTime());
1145 out.open((
const char*)ts);
1153 Int_t St_db_Maker::SaveDataSet(
TDataSet* ds,
int type,
bool savenext) {
1154 if (!ds || !ds->InheritsFrom(TTable::Class())) {
1159 int jdot = 0, jsla = 0;
1163 i = 0; i = ts.Index(
".const/"); assert(i>0); ts.Replace(0,i+7,
"");
1164 jdot = 0; jdot = ts.Index(
".",(Ssiz_t)1,(Ssiz_t)0 ,TString::kExact); assert(jdot>0);
1165 jsla = 0; jsla = ts.Index(
"/",(Ssiz_t)1,(Ssiz_t)jdot,TString::kExact); assert(jsla>0);
1166 ts.Remove(jdot, jsla-jdot + 1);
1167 int l = ts.Length();
1169 for (i = 0; i < l; i++) {
1170 if (ts[i]!=
'/')
continue;
1171 dir.Replace(0,999,ts,i);
1172 gSystem->MakeDirectory(dir);
1176 return SaveDataSetAsRootFile((
TTable*)ds, ts, savenext);
1179 return SaveDataSetAsCMacro((
TTable*)ds, ts, savenext);
1189 Int_t St_db_Maker::SaveDataSetAsCMacro(
TTable* tb, TString ts,
bool savenext) {
1192 int i = 0; i = GetValidity(tb,val); assert(i>=0);
1193 std::stringstream ostr;
1194 ostr << ts <<
"." << std::setw(6) << std::setfill(
'0') <<val[0].GetDate() <<
"." << std::setw(6) << std::setfill(
'0')
1195 << val[0].GetTime() <<
".C";
1196 out.open( ostr.str().c_str() );
1200 if (savenext ==
true) {
1201 std::string tbname( std::string(ts.Data()).substr(7) );
1202 if (val[1].GetDate() < 20330101 ) {
1204 ds_r = GetDataBase(tbname.c_str(), &val[1]);
1206 SaveDataSetAsCMacro((
TTable*)ds_r, ts,
false);
1214 Int_t St_db_Maker::SaveDataSetAsRootFile(
TTable* tb, TString ts,
bool savenext) {
1216 int i = 0; i = GetValidity(tb,val); assert(i>=0);
1217 std::stringstream ostr;
1218 ostr << ts <<
"." << std::setw(6) << std::setfill(
'0') <<val[0].GetDate() <<
"." << std::setw(6) << std::setfill(
'0')
1219 << val[0].GetTime() <<
".root";
1220 TFile ofile(ostr.str().c_str(),
"RECREATE" );
1224 if (savenext ==
true) {
1225 std::string tbname( std::string(ts.Data()).substr(7) );
1226 if (val[1].GetDate() < 20330101 ) {
1228 ds_r = GetDataBase(tbname.c_str(), &val[1]);
1230 SaveDataSetAsRootFile((
TTable*)ds_r, ts,
false);
1240 Int_t St_db_Maker::SaveSnapshotPlus(
char* path,
int type)
1244 TDataSet::EDataSetPass mode = TDataSet::kContinue;
1246 maxDbTime.Set(kMaxTime,0);
1249 top = GetDataBase(path);
1258 SaveDataSet(top, type,
true);
1262 while ((ds = nextDS(mode))) {
1263 mode = TDataSet::kContinue;
1264 if (ds->GetName()[0]==
'.') { mode = TDataSet::kPrune;
continue; }
1265 SaveDataSet(ds, type,
true);
1271 void St_db_Maker::SetFlavor(
const char *flav,
const char *tabname)
1277 flaDir =
Find(
".flavor");
1278 if (flaDir) fl = flaDir->
Find(tabname);
1279 if (fl && strcmp(fl->GetTitle(),flav)==0)
return;
1285 if (!fDBBroker)
return;
1287 flaDir =
Find(
".flavor");
1288 if (!flaDir)
return;
1292 const char *tabName = val->GetName();
1293 if (tabName[0] !=
'.')
continue;
1294 if (strcmp(val->GetTitle(),
".Val")!=0)
continue;
1296 if (val->fDat==0)
continue;
1297 if (val->fDat->GetUniqueID() >= kUNIXOBJ)
continue;
1300 while((fl = flaNext())) {
1301 const char *flaName = fl->GetName();
1302 if (strcmp(flaName,
".all" )!=0
1303 && strcmp(flaName,tabName)!=0)
continue;
1304 const char *flaType = fl->GetTitle();
1305 if (val->fFla == flaType)
continue;
1308 val->fFla = flaType;
1310 val->fTimeMin.Set(kMaxTime,0);
1311 val->fTimeMax.Set(kMinTime,0);
1312 int tabID = (int)val->fDat->GetUniqueID();
1313 int parID = (int)par->GetUniqueID();
1315 fTimer[1].Stop(); fTimer[3].Start(0);
1316 fDBBroker->SetTableFlavor(flaType,tabID, parID);
1317 fTimer[1].Start(0); fTimer[3].Stop();
1318 fl->SetUniqueID(fl->GetUniqueID()+1);
1320 if (Debug()<2)
continue;
1321 if (strcmp(
"ofl",flaType)==0)
continue;
1322 printf(
"<St_db_Maker::SetFlavor> Set flavor %s to %s\n",flaType,tabName);
1329 while((fl = flaNext())) {
1330 if (fl->GetUniqueID())
continue;
1331 if (strcmp(fl->GetName(),
".all" )==0)
continue;
1332 Warning(
"SetFlavor",
"Flavor %s for table %s was NOT USED",
1333 fl->GetTitle(),fl->GetName());
1337 if (GetDateTime().GetDate() >= 20330101)
return;
1342 Int_t St_db_Maker::GetValidity(
const TTable *tb, TDatime *
const val)
1345 TString ts(
"."); ts+=tb->GetName();
1352 val[0] = vs->fTimeMin;
1353 val[1] = vs->fTimeMax;
1358 Int_t St_db_Maker::Drop(
TDataSet *ds)
1361 TString ts(
"."); ts+=ds->GetName();
1364 assert(ts == pa->GetName());
1366 assert(ds == vs->fDat);
1375 void St_db_Maker::SetOff(
const char *path)
1376 { AddAlias(
"Off",path,
".onoff"); OnOff();}
1378 void St_db_Maker::OnOff()
1381 if (!fDataBase)
return;
1385 TString tsBase,tsDir,tsTit;
1388 while((ono=onoffNext())) {
1389 Off = (strcmp(
"Off",ono->GetName())==0);
1390 tsDir = gSystem->DirName(ono->GetTitle());
1391 tsBase = gSystem->BaseName(ono->GetTitle());
1392 TRegexp rex(tsBase,1);
1393 TDataSet *dsDir = GetDataSet(tsDir);
1394 if (!dsDir)
continue;
1395 if (GetMaker(dsDir) !=
this)
continue;
1398 while ((val=nextVal())) {
1399 const char *name = val->GetName();
1400 if(name[0]!=
'.')
continue;
1401 tsTit = val->GetTitle();
1402 int ival = tsTit.Index(
".Val");
1403 if (ival<0)
continue;
1404 if (Off != (ival==0))
continue;
1405 if (rex.Index(name+1,&len)!=0)
continue;
1406 if ( Off) tsTit.Replace(0,0,
".Off");
1407 if (!Off) tsTit.Replace(0,4,
"" );
1408 val->SetTitle(tsTit);
1409 printf(
"<%s::Set%s> %s/%s\n"
1410 ,ClassName(),ono->GetName(),(
const char*)tsDir,val->GetName()+1);
1415 void St_db_Maker::SetMaxEntryTime(Int_t idate,Int_t itime)
1418 ut.SetGTime(idate,itime);
1419 fMaxEntryTime = ut.GetUTime();
1423 void St_db_Maker::AddMaxEntryTimeOverride(Int_t idate,Int_t itime,
char*
dbType,
char*
dbDomain) {
1425 std::string mDbType =
"";
1426 std::string mDbDomain =
"";
1429 for (
char* p = dbType; *p !=
'\0'; p++) {
1430 *p = (char)std::tolower(*p);
1432 dbType[0] = std::toupper(dbType[0]);
1437 for (
char* p = dbDomain; *p !=
'\0'; p++) {
1438 *p = (char)std::tolower(*p);
1440 mDbDomain = dbDomain;
1444 ut.SetGTime(idate,itime);
1445 fMaxEntryTimeOverride.insert( std::make_pair( std::make_pair(mDbType,mDbDomain), ut.GetUTime() ) );
1449 #define private public
1450 #include "TGeoManager.h"
1452 int St_db_Maker::Snapshot (
int flag)
1457 const char *fname = SAttr(
"dbSnapshot");
1458 if (!fname || !*fname)
return 0;
1461 if (gSystem->AccessPathName(fname, kFileExists))
return 0;
1462 if (gSystem->AccessPathName(fname, kReadPermission))
return 0;
1463 tfSnap = TFile::Open(fname,
"READ");
1464 if (!tfSnap)
return 0;
1465 if (tfSnap->IsZombie()) {
delete tfSnap;
return 0;}
1467 Info(
"Snapshot",
"Use DB from file %s\n",fname);
1468 ians = set.Read(
"dbSnapshot");
1483 if (!gSystem->AccessPathName(fname, kFileExists))
return 0;
1485 tfSnap = TFile::Open(fname,
"NEW");
1486 if (!tfSnap || tfSnap->IsZombie()) {
1487 Error(
"Snapshot",
"Can not open file for write");
1496 TDataSet *parent = fDataBase->GetParent();
1497 fDataBase->
Shunt(0);
1499 Info(
"Snapshot",
"Save DB to file %s\n",fname);
1500 ians = set.
Write(
"dbSnapshot",TObject::kOverwrite);
1501 fDataBase->
Shunt(parent);
virtual TDataSet * First() const
Return the first object in the list. Returns 0 when list is empty.
virtual void Clear(Option_t *opt="")
User defined functions.
virtual EDataSetPass Pass(EDataSetPass(*callback)(TDataSet *), Int_t depth=0)
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
virtual const Char_t * GetType() const
Returns the type of the wrapped C-structure kept as the TNamed title.
virtual void Remove(TDataSet *set)
Remiove the "set" from this TDataSet.
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
virtual void SetBIT(EMakerStatus k)
Maker Status Bits.
virtual TTableDescriptor * GetRowDescriptors() const
to be documented
virtual void ls(Option_t *option="") const
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual void AddFirst(TDataSet *dataset)
Add TDataSet object at the beginning of the dataset list of this dataset.
virtual Int_t Purge(Option_t *opt="")
static TTable * New(const Char_t *name, const Char_t *type, void *array, UInt_t size)
This static method creates a new TTable object if provided.
virtual void Shunt(TDataSet *newParent=0)
virtual void Sort()
Sort recursively all members of the TDataSet with TList::Sort method.
virtual TString Path() const
return the full path of this data set
virtual Char_t * Print(Char_t *buf, Int_t n) const
Create IDL table defintion (to be used for XDF I/O)
virtual void Adopt(Int_t n, void *array)
virtual TDataSet * Find(const char *path) const