StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
write_trigger_thresholds.C
1 int write_trigger_thresholds(int runNumber = 13078009)
2 {
3 
4  // Load all required libraries
5  gROOT->Macro("loadMuDst.C");
6  gROOT->Macro("LoadLogger.C");
7  gSystem->Load("St_base.so");
8  gSystem->Load("libStDb_Tables.so");
9  gSystem->Load("StDbLib.so");
10 
11  gSystem->Load("StEmcRawMaker");
12  gSystem->Load("StEmcADCtoEMaker");
13  gSystem->Load("StEEmcUtil");
14  gSystem->Load("StEEmcDbMaker");
15  gSystem->Load("StTriggerUtilities");
16  //******//
17  gSystem->Setenv("DB_ACCESS_MODE","write");
18  //******//
19  // Initialize db manager
22  StDbConfigNode* node = mgr->initConfig("Calibrations_trg");
23  StDbTable* dbtable = node->addDbTable("triggerThreshold");
24  // beginTime timestamp in MySQL format: "YYYY-MM-DD HH:mm:ss"
25  ifstream intime(Form("beginTimes/%d.beginTimes.txt", runNumber));
26  if(!intime){
27  cout<<"can't open beginTime file"<<endl;
28  return 0;
29  }
30  char date[10];
31  char time[8];
32  intime >> date >> time;
33  TString storeTime(Form("%s %s", date, time));
34  //******//
35  //time stamp 2012-07-30 00:00:0X for test purposes
36  //TString storeTime("2012-07-30 00:00:02");
37  //******//
38  mgr->setStoreTime(storeTime.Data());
39  // */
40  // Create your c-struct
41  triggerThreshold_st table;
42 
43  // Fill structure with data
44  // sample setup for a single channel, please add more channels!
45  strcpy(table.comments, Form("run%d triggerThreshold uploaded by zchang", runNumber));
46  cout<<"comments set to "<<table.comments<<endl;
47 
48  TObjArray objarr = readOnline(runNumber);
49  TBufferFile buf(TBuffer::kWrite);
50  buf << &objarr;
51  objarr.Delete();
52 
53  cout<<"Buffer size: "<<buf.BufferSize()<<endl;
54 
55  memset(table.trigthr, 0, buf.BufferSize());
56  memcpy(table.trigthr, buf.Buffer(), buf.BufferSize());
57  table.size = buf.BufferSize();
58 
59  //******//
60  // Store data to the StDbTable
61  dbtable->SetTable((char*)&table, 1);
62 
63  // uncomment next line to set "sim" flavor. "ofl" flavor is set by default, no need to set it.
64  // dbtable->setFlavor("sim");
65 
66  // Store table to database
67  cout<<"Storing Db table: "<< mgr->storeDbTable(dbtable) << endl;
68  //******//
69 
70  ofstream out(Form("buffer/%d.trigthr.buffer.out", runNumber));
71  assert(out);
72  out.write(buf.Buffer(),buf.BufferSize());
73  out.close();
74 
75  return 1;
76 }
77 TObjArray readOnline(int runNumber)
78 {
79  // Open connection to online database
80  const char* database = "mysql://db04.star.bnl.gov:3411/Conditions_rts?timeout=60";
81  const char* user = "zchang";
82  const char* pass = "";
83  TMySQLServer* mysql = TMySQLServer::Connect(database,user,pass);
84 
85  if (!mysql) {
86  cerr << "Connection to " << database << " failed" << endl;
87  return;
88  }
89 
90  TObjArray arr;
91  TString query;
92  TMySQLResult* result;
93  // TDatime beginTime;
94 
95 
96  query = Form("select object,idx,reg,label,value,defaultvalue from `Conditions_rts`.`dict` where hash=(select dicthash from run where idx_rn = %d)",runNumber);
97 
98  result = (TMySQLResult*)mysql->Query(query);
99  if (result) {
100  TMySQLRow* row;
101  while (row = (TMySQLRow*)result->Next()) {
103  th->object = atoi(row->GetField(0));
104  th->index = atoi(row->GetField(1));
105  th->reg = atoi(row->GetField(2));
106  th->label = row->GetField(3);
107  th->value = atoi(row->GetField(4));
108  th->defaultvalue = atoi(row->GetField(5));
109  delete row;
110  arr.Add(th);
111  }
112  result->Close();
113  }
114 
115  mysql->Close();
116 
117  for (int i = 0; i < arr.GetEntriesFast(); ++i) {
118  StTriggerThreshold* th = (StTriggerThreshold*)arr.At(i);
119  th->print();
120  }
121  return arr;
122 }
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc&#39;d version of data for StRoot
Definition: StDbTable.cc:550
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155