StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bemcCalibTxtUpload.C
1 #include <iostream>
2 #include <fstream>
3 
4 // detector numbers
5 #define BEMCMODULES 120
6 #define MAXDETBARREL 4
7 #define BTOW 1
8 #define BPRS 2
9 #define BSMDE 3
10 #define BSMDP 4
11 
12 #define STATUS_OK 1
13 #define CAP1 124
14 #define CAP2 125
15 
16 using namespace std;
17 TString changetime(TString time, int shift);
18 
19 void bemcCalibTxtUpload(const char* gainfilename="./electron.gains.2012.final")
20 {
21  const int ntowers=4800;
22 
23  gROOT->Macro("LoadLogger.C");
24  gROOT->Macro("loadMuDst.C");
25  gSystem->Load("StDaqLib");
26 
27  StBemcTablesWriter *bemctables = new StBemcTablesWriter();
28 
29  TString time = "20111220.000001";
30  cout<<time.Data()<<endl;
31  time = changetime(time,0); //get right format
32  cout<<time.Data()<<endl;
33  bemctables->loadTables(time.Data());
34  ifstream infile(gainfilename);
35  while(1){
36  int id, status;
37  float gain, rms;
38  infile >> id >> gain >> rms >> status;
39  if(!infile.good())break;
40 
41  bemctables->setCalib(BTOW,id,1,gain);
42  bemctables->setCalibStatus(BTOW,id,(unsigned short)status);
43  }
44  return; //remove to write to DB
45  //bemctables->writeToDb("bemcCalib",time.Data()); // Uncomment to write to DB
46  infile.close();
47 }
48 
49 TString changetime(TString timea, int shift)
50 {
51  TString y,m,d,h,min,s,newtime;
52  int year,month,day,hour,minute,second;
53  y+=timea(0,4); cout<<"year "<<y<<endl;
54  m+=timea(4,2); cout<<"month "<<m<<endl;
55  d+=timea(6,2); cout<<"day "<<d<<endl;
56  h+=timea(9,2); cout<<"hour "<<h<<endl;
57  min+=timea(11,2); cout<<"minute "<<min<<endl;
58  s+=timea(13,2); cout<<"second "<<s<<endl;
59 
60  TTimeStamp tstamp;
61  tstamp.Set(y.Atoi(),m.Atoi(),d.Atoi(),h.Atoi(),min.Atoi(),s.Atoi(),0,1,shift);
62  newtime += tstamp.AsString("yyyy-mm-dd HH:mm:ss");
63  return newtime;
64 }
void loadTables(const char *sqlTime, const char *flavor="ofl")
load directly from DB, no Maker needed