StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Db.C
1 class St_db_Maker;
2 St_db_Maker *dbMk = 0;
3 class TTable;
4 TTable *table = 0;
5 //________________________________________________________________________________
6 void Load() {
7  if (gClassTable->GetID("StDbManager") < 0) {
8  gROOT->LoadMacro("bfc.C");
9  // bfc(-1,"tpcDb,detDb,CorrX,nodefault");
10  bfc(-2,"tpcDb,detDb,mysql,nodefault,CorrX");
11  // bfc(-2,"tpcDb,detDb,mysql,nodefault,Corr4,DbV20140905");
12  }
13 // gROOT->ProcessLine("typedef trgTimeOffset_st trgTimeOffsetB_st;");
14 // gROOT->ProcessLine("typedef St_trgTimeOffset St_trgTimeOffsetB_;");
15  // dbMk = new St_db_Maker("db","MySQL:StarDb");
16  dbMk = new St_db_Maker("db","MySQL:StarDb","$STAR/StarDb","$PWD/StarDb");
17  // dbMk->SetFlavor("sim","WaferOnLadder");
18  // dbMk->SetDebug(2);
19  // dbMk->SetFlavor("laserDV","tpcDriftVelocity");
20  // dbMk->SetFlavor("ofl+laserDV","tpcDriftVelocity");
21  // dbMk->SetFlavor("NewlaserDV","tpcDriftVelocity");
22  // dbMk->SetFlavor("ofl+sim");
23  // dbMk->SetFlavor("simu","svtWafersPosition");
24  // dbMk->SetFlavor("sim","tpcGlobalPosition");
25  // dbMk->SetFlavor("sim","tpcSectorPosition");
26  // dbMk->SetFlavor("sim","tpcISTimeOffsets");
27  // dbMk->SetFlavor("sim","tpcOSTimeOffsets");
28  // dbMk->SetFlavor("sim","starClockOnl");
29  // dbMk->SetFlavor("ofl+laserDV","tpcDriftVelocity");
30  // dbMk->SetMaxEntryTime(20060620,0);
31  // dbMk->SetMaxEntryTime(20080410,0);
32 }
33 //________________________________________________________________________________
34 //void Db(const Char_t *tabNam = "Calibrations/tpc/noiseElim",
35 void Db(const Char_t *tabNam =
36  "Geometry/tpc/tpcPadPlanes",
37  Int_t date = -1, Int_t time = 0,
38  Int_t debugL = 1,
39  const Char_t *flavor="sim+ofl+laserDV"
40  ){
41  if (dbMk == 0) Load();
42  dbMk->SetDebug(debugL);
43  Int_t D = date;
44  Int_t T = time;
45  if (D <= 0) {
46  TDatime dt;
47  D = dt.GetDate();
48  T = dt.GetTime();
49  cout << "Set Date " << D << " Time " << T << endl;
50  }
51  dbMk->SetDateTime(D,T);
52  TString TabNam(tabNam);
53  if (TabNam.BeginsWith("StarDb/")) TabNam.ReplaceAll("StarDb/","");
54  TString name(gSystem->BaseName(tabNam));
55  TString Flavor(flavor);
56  if (flavor != "") dbMk->SetFlavor(flavor,name);
57  dbMk->Init();
58  table = (TTable *) dbMk->GetDataBase(TabNam);
59  if (table) {
60  TDatime t[2];
61  dbMk->GetValidity(table,t);
62  cout << "==============================================" << endl;
63  Int_t Nrows = table->GetNRows();
64  cout << "Found table " << table->GetName() << " with NRows = " << Nrows << " in db" << endl;
65  cout << "Validity:" << t[0].GetDate() << "/" << t[0].GetTime()
66  << " ----- " << t[1].GetDate() << "/" << t[1].GetTime() << endl;
67  if (name == "tpcPadrowT0") {
68  Double_t t0Inner = 0, t0Outer = 0;
69  Int_t Inner = 0, Outer = 0;
70  tpcPadrowT0_st *row = ((St_tpcPadrowT0 *) table)->GetTable();
71  for (Int_t sec = 0; sec < 24; sec++, row++) {
72  for (Int_t r = 0; r < 45; r++) {
73  if (row->T0[r]) {
74  if (r < 13) {t0Inner += row->T0[r]; Inner++;}
75  else {t0Outer += row->T0[r]; Outer++;}
76  }
77  }
78  }
79  if (Inner > 0) t0Inner /= Inner;
80  if (Outer > 0) t0Outer /= Outer;
81  cout << name.Data() << "\tInner <T0> = " << t0Inner << "\tOuter <T0> = " << t0Outer << endl;
82  }
83  if (Nrows > 10) Nrows = 10;
84  if (table->GetRowSize() < 256) table->Print(0,Nrows);
85  cout << "==============================================" << endl;
86 #if 0
87  name += Form(".%06i.%06i.root",t[0].GetDate(),t[0].GetTime());
88  TFile *f = new TFile(name.Data(),"RECREATE");
89  table->Write();
90  delete f;
91 #else
92  name += Form(".%06i.%06i.C",t[0].GetDate(),t[0].GetTime());
93  ofstream out;
94  out.open(name, ios::out);
95  table->SavePrimitive(out,"");
96 #endif
97  }
98  else cout << "Table:" << tabNam << " has not been found" << endl;
99 }
100 //________________________________________________________________________________
101 void Db(const Char_t *tabNam = "StarDb/AgiGeometry/Geometry",
102  const Char_t *tag){
103  if (dbMk == 0) Load();
104  cout << "Db(" << tabNam << "," << tag << ")" << endl;
105  Int_t date = StMaker::AliasDate(tag);
106  Int_t time = StMaker::AliasTime(tag);
107  Db(tabNam,date,time);
108 }
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1395
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream &quot;out&quot;.
Definition: TTable.cxx:1810
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
Definition: TTable.h:48
virtual Char_t * Print(Char_t *buf, Int_t n) const
Create IDL table defintion (to be used for XDF I/O)
Definition: TTable.cxx:1548