StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fcsDetectorPosition_db.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fcsDetectorPosition_db(char* opt = "", char* input) {
5  gROOT->Macro("LoadLogger.C");
6  gSystem->Load("St_base.so");
7  gSystem->Load("libStDb_Tables.so");
8  gSystem->Load("StDbLib.so");
9 
10  // structure to fill up
11  fcsDetectorPosition_st detpos;
12 
13  TString option(opt);
14  std::cout << "Opt =" << opt << "\n";
15  std::cout << "writedb = " << option.Contains("writedb") << "\n";
16 
17  TString data(input);
18  TString storeTime("");
19  TString flavor;
20  if(data.Contains("run21sim")){ //nominal
21  storeTime = "2020-12-10 00:01:00"; flavor="sim";
22  detpos.xoff[0]=-6.570*2.54; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 16.69
23  detpos.xoff[1]= 6.570*2.54; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54; //z=710.16
24  detpos.xoff[2]=-7.430*2.54; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 18.87
25  detpos.xoff[3]= 7.430*2.54; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54; //z=782.63
26  }
27  if(data.Contains("run21ofl")){ //open
28  storeTime = "2020-12-20 00:00:00"; flavor="ofl";
29  detpos.xoff[0]=-6.570*2.54-50; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54;
30  detpos.xoff[1]= 6.570*2.54+50; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
31  detpos.xoff[2]=-7.430*2.54-50; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54;
32  detpos.xoff[3]= 7.430*2.54+50; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
33  }
34  if(data.Contains("run21Feb17")){ //closed but not quite
35  storeTime = "2021-02-17 18:00:00"; flavor="ofl";
36  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
37  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
38  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
39  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
40  }
41  if(data.Contains("run21Mar31")){ //wide open
42  storeTime = "2021-03-31 18:00:00"; flavor="ofl";
43  detpos.xoff[0]=-6.850*2.54-50; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54;
44  detpos.xoff[1]= 6.850*2.54+50; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
45  detpos.xoff[2]=-8.380*2.54-50; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54;
46  detpos.xoff[3]= 8.380*2.54+50; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
47  }
48  if(data.Contains("run21May06")){ //closed
49  storeTime = "2021-05-06 20:00:00"; flavor="ofl";
50  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
51  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
52  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
53  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
54  }
55  if(data.Contains("run21May20")){ //ecal open (hcal stayed closed)
56  storeTime = "2021-05-20 18:00:00"; flavor="ofl";
57  detpos.xoff[0]=-6.850*2.54-50; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
58  detpos.xoff[1]= 6.850*2.54+50; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
59  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
60  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
61  }
62  if(data.Contains("run21May24")){ //hcal open (ecal stayed open)
63  storeTime = "2021-05-24 15:00:00"; flavor="ofl";
64  detpos.xoff[0]=-6.850*2.54-50; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
65  detpos.xoff[1]= 6.850*2.54+50; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
66  detpos.xoff[2]=-8.380*2.54-50; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
67  detpos.xoff[3]= 8.380*2.54+50; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
68  }
69  if(data.Contains("run21Jun27")){ //closed
70  storeTime = "2021-06-27 15:00:00"; flavor="ofl";
71  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
72  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
73  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
74  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
75  }
76  if(data.Contains("run22sim")){ //nominal
77  storeTime = "2021-10-15 00:00:00"; flavor="sim";
78  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
79  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
80  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
81  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
82  }
83  if(data.Contains("run22simA")){ //nominal with measured Y
84  storeTime = "2021-10-15 00:01:00"; flavor="sim";
85  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=-5.26; detpos.zoff[0]=279.592*2.54; //x= 17.399
86  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=-5.26; detpos.zoff[1]=279.592*2.54;
87  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=+1.80; detpos.zoff[2]=308.123*2.54; //x= 21.285
88  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=+1.80; detpos.zoff[3]=308.123*2.54;
89  }
90  if(data.Contains("run22ofl")){ //closed
91  storeTime = "2021-10-25 00:00:00"; flavor="ofl";
92  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
93  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
94  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
95  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
96  }
97  if(data.Contains("run22oflA")){ //closed with measured Y
98  storeTime = "2021-10-25 00:01:00"; flavor="ofl";
99  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=-5.26; detpos.zoff[0]=279.592*2.54; //x= 17.399
100  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=-5.26; detpos.zoff[1]=279.592*2.54;
101  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=+1.80; detpos.zoff[2]=308.123*2.54; //x= 21.285
102  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=+1.80; detpos.zoff[3]=308.123*2.54;
103  }
104  if(data.Contains("run22Dec01")){ //open
105  storeTime = "2021-12-01 00:00:00"; flavor="ofl";
106  detpos.xoff[0]=-6.850*2.54-50; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
107  detpos.xoff[1]= 6.850*2.54+50; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
108  detpos.xoff[2]=-8.380*2.54-50; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
109  detpos.xoff[3]= 8.380*2.54+50; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
110  }
111  if(data.Contains("run22Dec01A")){ //open with measured Y
112  storeTime = "2021-12-01 00:01:00"; flavor="ofl";
113  detpos.xoff[0]=-6.850*2.54-50; detpos.yoff[0]=-5.26; detpos.zoff[0]=279.592*2.54; //x= 17.399
114  detpos.xoff[1]= 6.850*2.54+50; detpos.yoff[1]=-5.26; detpos.zoff[1]=279.592*2.54;
115  detpos.xoff[2]=-8.380*2.54-50; detpos.yoff[2]=+1.80; detpos.zoff[2]=308.123*2.54; //x= 21.285
116  detpos.xoff[3]= 8.380*2.54+50; detpos.yoff[3]=+1.80; detpos.zoff[3]=308.123*2.54;
117  }
118  if(data.Contains("run22Dec20")){ //closed
119  storeTime = "2021-12-20 16:30:00"; flavor="ofl";
120  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=0.0; detpos.zoff[0]=279.592*2.54; //x= 17.399
121  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=0.0; detpos.zoff[1]=279.592*2.54;
122  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=0.0; detpos.zoff[2]=308.123*2.54; //x= 21.285
123  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=0.0; detpos.zoff[3]=308.123*2.54;
124  }
125  if(data.Contains("run22Dec20A")){ //closed with measured Y
126  storeTime = "2021-12-20 16:30:10"; flavor="ofl";
127  detpos.xoff[0]=-6.850*2.54; detpos.yoff[0]=-5.26; detpos.zoff[0]=279.592*2.54; //x= 17.399
128  detpos.xoff[1]= 6.850*2.54; detpos.yoff[1]=-5.26; detpos.zoff[1]=279.592*2.54;
129  detpos.xoff[2]=-8.380*2.54; detpos.yoff[2]=+1.80; detpos.zoff[2]=308.123*2.54; //x= 21.285
130  detpos.xoff[3]= 8.380*2.54; detpos.yoff[3]=+1.80; detpos.zoff[3]=308.123*2.54;
131  }
132 
133  if(storeTime==""){
134  std::cout<<"Invalid year range"<<std::endl;
135  exit;
136  }
137  std::cout << "StoreTime="<<storeTime<<endl;
138  std::cout << "Flavor ="<<flavor<<endl;
139  for(int det=0; det<4; det++){
140  printf("INPUT det=%2d xoff=%8.3f yoff=%8.3f zoff=%8.3f\n",
141  det,detpos.xoff[det],detpos.yoff[det],detpos.zoff[det]);
142  }
143 
144  if(option.Contains("writedb")) {
145  gSystem->Setenv("DB_ACCESS_MODE","write");
146  cout << "DB_ACCESS_MODE="<<gSystem->Getenv("DB_ACCESS_MODE")<<endl;
148  StDbConfigNode* node = mgr->initConfig("Geometry_fcs");
149  StDbTable* table = node->addDbTable("fcsDetectorPosition");
150  mgr->setStoreTime(storeTime.Data());
151  table->SetTable((char*)&detpos,1);
152  table->setFlavor(flavor.Data());
153  mgr->storeDbTable(table);
154  gSystem->Unsetenv("DB_ACCESS_MODE");
155  std::cout << "Done with database upload \n";
156  }
157 
158  gSystem->Load("StChain");
159  gSystem->Load("StBFChain");
160  gSystem->Load("StUtilities");
161  gSystem->Load("StIOMaker");
162  gSystem->Load("StarClassLibrary");
163  gSystem->Load("St_Tables");
164  gSystem->Load("StDbLib");
165  gSystem->Load("StDbBroker");
166  gSystem->Load("St_db_Maker");
167 
168  int date,time,from=0,n=0;
169  TString datetime(storeTime),token;
170  datetime.ReplaceAll("-","");
171  datetime.ReplaceAll(":","");
172  while(datetime.Tokenize(token,from," ")){
173  if(n==0) date=atoi(token.Data());
174  if(n==1) time=atoi(token.Data());
175  n++;
176  }
177  std::cout << "Readout time="<<datetime<<" Date="<<date<<" Time="<<time<<endl;
178 
179  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
180  dbMk->SetDebug();
181  dbMk->SetDateTime(date,time);
182  dbMk->SetFlavor(flavor.Data());
183  dbMk->Init();
184  dbMk->Make();
185 
186  TDataSet *DB = 0;
187  DB = dbMk->GetInputDB("Geometry/fcs");
188  if(!DB){std::cout << "ERROR: no db maker or Geometry/fcs" << std::endl; }
189  St_fcsDetectorPosition *dbTable = (St_fcsDetectorPosition*) DB->Find("fcsDetectorPosition");
190  if(dbTable){
191  std::cout << "Reading fcsDetectorPosition table from DB\n";
192  fcsDetectorPosition_st *dbSt = dbTable->GetTable();
193  Int_t rows = dbTable->GetNRows();
194  for(int i=0; i<rows; i++){
195  for(int det=0; det<4; det++){
196  printf("DbRead row=%2d det=%2d xoff=%8.3f yoff=%8.3f zoff=%8.3f\n",
197  i,det,dbSt[i].xoff[det],dbSt[i].yoff[det],dbSt[i].zoff[det]);
198  }
199  }
200  memcpy(detpos,dbSt,sizeof(detpos));
201  }else{
202  std::cout << "WARNING: No data in fcsDetectorPosition table\n";
203  }
204 }
205 
virtual Int_t Make()
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
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362