StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
read_trigger_definitions.C
1 int read_trigger_definitions(int runNumber = 13078009)
2 {
3  // Load libraries
4  // base libraries
5  //gSystem->Load("St_base");
6  //gSystem->Load("StChain");
7  //gSystem->Load("StUtilities");
8  //gSystem->Load("StIOMaker");
9  //gSystem->Load("StarClassLibrary");
10  gROOT->Macro("loadMuDst.C");
11  gROOT->Macro("LoadLogger.C");
12 
13 
14  // db-related libraries
15  gSystem->Load("St_Tables");
16  gSystem->Load("StDbLib");
17  gSystem->Load("StDbBroker");
18  gSystem->Load("St_db_Maker");
19 
20  gSystem->Load("StEmcRawMaker");
21  gSystem->Load("StEmcADCtoEMaker");
22  gSystem->Load("StEEmcUtil");
23  gSystem->Load("StEEmcDbMaker");
24 
25  gSystem->Load("StTriggerUtilities");
26 
27  ifstream in(Form("beginTimes/%d.beginTimes.txt", runNumber));
28  if(!in) {
29  cout<<"can't open input file\n";
30  return 0;
31  }
32  char run[16];
33  char date[16];
34  char time[16];
35  in>>date>>time;
36  cout<<"beginTime:"<<date<<" "<<time<<endl;
37  int yr, mnth, dy;
38  int hh,mm,ss;
39  sscanf(date,"%d-%d-%d", &yr, &mnth, &dy);
40  sscanf(time,"%d:%d:%d", &hh, &mm, &ss);
41 
42  int idate = yr*10000 + mnth*100 + dy;
43  int itime = hh*10000 + mm *100 + ss;
44  cout<<idate<<" "<<itime<<endl;
45 
46  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
47  dbMk->SetDebug();
48  dbMk->SetDateTime(idate, itime);
49  // dbMk->SetDateTime(20120730,1); // event or run start time, set to your liking
50  dbMk->SetFlavor("ofl");
51 
52  dbMk->Init();
53  dbMk->Make();
54 
55  TDataSet *DB = 0;
56  DB = dbMk->GetDataBase("Calibrations/trg/triggerDefinition");
57  if (!DB) {
58  std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
59  }
60 
61  St_triggerDefinition *dataset = 0;
62  dataset = (St_triggerDefinition*) DB->Find("triggerDefinition");
63  Int_t rows = dataset->GetNRows();
64  if (rows > 1) {
65  std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
66  }
67 
68  if (dataset) {
69  TDatime val[2];
70  dbMk->GetValidity((TTable*)dataset,val);
71  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - "
72  << val[1].GetDate() << "." << val[1].GetTime() << " ] "
73  << std::endl;
74 
75  triggerDefinition_st *table = dataset->GetTable();
76  for (Int_t i = 0; i < rows; i++) {
77  // sample output of first member variable
78  std::cout << i << "th row : " << table[i].comments << std::endl;
79  TBufferFile buf(TBuffer::kRead);
80  buf.SetBuffer(table[i].trigdef, sizeof(table[i].trigdef), false);
81  TObjArray *a = 0;
82  buf >> a;
83  a->Print();
84 
85  cout << "Total entries: " << a->GetEntriesFast() << endl;
86 
87  for (int i = 0; i < a->GetEntriesFast(); ++i) {
88  StTriggerDefinition* trgdef = (StTriggerDefinition*)a->At(i);
89  trgdef->print();
90  }
91 
92  }
93  } else {
94  std::cout << "ERROR: dataset does not contain requested table" << std::endl;
95  }
96 
97  return 1;
98 }
virtual Int_t Make()
Definition: TTable.h:48
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362