StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
checkDbTable.C
1 /*------------------------------------------------------------------------------
2 |
3 | checkDBTable.C
4 | Macro to compare a table in a file with a table saved on STAR
5 | databse
6 |
7 | First argument is the file name. The file names for tables to be saved on DB
8 | includes information about the kind of table and time stamp. The macro
9 | gets this information to make the comparison. For the table on Db, an
10 | object of the class StEmcDbHandler is created which returns
11 | table in the appropriate format to be compared to the one in the file.
12 |
13 | Second argument is the maximum entry time in the database. It means that the
14 | table had to be *saved* before that time. Do not mistake this as the
15 | timestamp
16 |
17 | Third argument is the flavor the tables is save in the database
18 |
19 |
20 | author: Marcia Maria de Moura 2005-03-22
21 |
22 |-----------------------------------------------------------------------------*/
23 std::string DBTIME;
24 bool checkDbTable(char* fileSource, char* MAXENTRY = "2030-01-01 00:00:00",char* flavor = "ofl")
25 {
26  bool equal=true;
27  TFile* tableFile=new TFile(fileSource);
28 
29  TString tempString = fileSource;
30  char slash = '/';
31  int index = tempString.Last(slash);
32  TString fileName = tempString(index+1,tempString.Length()-index);
33 
34  int index2 = fileName.Index(".");
35 
36  TString tableName = fileName(0,index2);
37  TString date = fileName(index2+1,4) + "-" +
38  fileName(index2+5,2) + "-" +
39  fileName(index2+7,2);
40 
41  TString time = fileName(index2+10,2) + ":" +
42  fileName(index2+12,2) + ":" +
43  fileName(index2+14,2);
44 
45  TString timeStamp = date + " " + time;
46 
47  StEmcDbHandler* dbHandler = new StEmcDbHandler();
48 cout << "Requesting table name=" << tableName << ", timestamp=" << timeStamp << " flavor=" << flavor << " maxentry=" << MAXENTRY << endl;
49  dbHandler->setTableName(tableName.Data());
50  dbHandler->setTimeStamp(timeStamp.Data());
51  dbHandler->setMaxEntryTime(MAXENTRY);
52  dbHandler->setFlavor(flavor);
53 
54  StDbTable *table = dbHandler->getDbTable();
55  DBTIME = dbHandler->timeToSqlTime(table->getBeginDateTime());
56  if (tableName=="bemcCalib" || tableName=="bprsCalib" )
57  {
58  emcCalib_st* tableInFile = (emcCalib_st*) ((St_emcCalib*)tableFile->Get(tableName.Data()))->GetTable();
59  emcCalib_st* tableInDb = (emcCalib_st*) table->GetTable();
60  equal=compare(tableInFile,tableInDb);
61  }
62 
63  if (tableName=="bsmdeCalib" || tableName=="bsmdpCalib" )
64  {
65  smdCalib_st* tableInFile = (smdCalib_st*) ((St_smdCalib*)tableFile->Get(tableName.Data()))->GetTable();
66  smdCalib_st* tableInDb = (smdCalib_st*) table->GetTable();
67  equal=compare(tableInFile,tableInDb);
68  }
69 
70  if (tableName=="bemcGain" || tableName=="bprsGain" )
71  {
72  emcGain_st* tableInFile = (emcGain_st*) ((St_emcGain*)tableFile->Get(tableName.Data()))->GetTable();
73  emcGain_st* tableInDb = (emcGain_st*) table->GetTable();
74  equal=compare(tableInFile,tableInDb);
75  }
76 
77  if (tableName=="bsmdeGain" || tableName=="bsmdpGain" )
78  {
79  smdGain_st* tableInFile = (smdGain_st*) ((St_smdGain*)tableFile->Get(tableName.Data()))->GetTable();
80  smdGain_st* tableInDb = (smdGain_st*) table->GetTable();
81  equal=compare(tableInFile,tableInDb);
82  }
83 
84  if (tableName=="bemcPed" || tableName=="bprsPed" )
85  {
86  emcPed_st* tableInFile = (emcPed_st*) ((St_emcPed*)tableFile->Get(tableName.Data()))->GetTable();
87  emcPed_st* tableInDb = (emcPed_st*) table->GetTable();
88  equal=compare(tableInFile,tableInDb);
89  }
90 
91  if (tableName=="bsmdePed" || tableName=="bsmdpPed" )
92  {
93  smdPed_st* tableInFile = (smdPed_st*) ((St_smdPed*)tableFile->Get(tableName.Data()))->GetTable();
94  smdPed_st* tableInDb = (smdPed_st*) table->GetTable();
95  equal=compare(tableInFile,tableInDb);
96  }
97 
98  if (tableName=="bemcStatus" || tableName=="bprsStatus" )
99  {
100  emcStatus_st* tableInFile = (emcStatus_st*) ((St_emcStatus*)tableFile->Get(tableName.Data()))->GetTable();
101  emcStatus_st* tableInDb = (emcStatus_st*) table->GetTable();
102  equal=compare(tableInFile,tableInDb);
103  }
104 
105  if (tableName=="bsmdeStatus" || tableName=="bsmdpStatus" )
106  {
107  smdStatus_st* tableInFile = (smdStatus_st*) ((St_smdStatus*)tableFile->Get(tableName.Data()))->GetTable();
108  smdStatus_st* tableInDb = (smdStatus_st*) table->GetTable();
109  equal=compare(tableInFile,tableInDb);
110  }
111 
112  if (tableName=="emcTriggerPed")
113  {
114  emcTriggerPed_st* tableInFile = (emcTriggerPed_st*) ((St_emcTriggerPed*)tableFile->Get(tableName.Data()))->GetTable();
115  emcTriggerPed_st* tableInDb = (emcTriggerPed_st*) table->GetTable();
116  equal=compare(tableInFile,tableInDb);
117  }
118 
119  if (tableName=="emcTriggerStatus")
120  {
121  emcTriggerStatus_st* tableInFile = (emcTriggerStatus_st*) ((St_emcTriggerStatus*)tableFile->Get(tableName.Data()))->GetTable();
122  emcTriggerStatus_st* tableInDb = (emcTriggerStatus_st*) table->GetTable();
123  equal=compare(tableInFile,tableInDb);
124  }
125 
126  if (tableName=="emcTriggerLUT")
127  {
128  emcTriggerLUT_st* tableInFile = (emcTriggerLUT_st*) ((St_emcTRiggerLUT*)tableFile->Get(tableName.Data()))->GetTable();
129  emcTriggerLUT_st* tableInDb = (emcTriggerLUT_st*) table->GetTable();
130  equal=compare(tableInFile,tableInDb);
131  }
132  tableFile->Close();
133  delete tableFile;
134  delete dbHandler;
135  cout << (equal ? "EQUAL" : "NOT EQUAL") << endl;
136  return equal;
137 
138 }
139 
140 // Functions to compare two tables
141 //------------------------------------------------------------------------------
142 bool compare(emcCalib_st* t1, emcCalib_st* t2)
143 {
144  bool equal = true;
145  for(int i = 0; i<4800;i++)
146  {
147  for(int j=0;j<5;j++)
148  if(t1->AdcToE[i][j]!=t2->AdcToE[i][j]) equal = false;
149  if(t1->Status[i]!=t2->Status[i]) equal = false;
150  }
151  return equal;
152 }
153 //------------------------------------------------------------------------------
154 bool compare(smdCalib_st* t1, smdCalib_st* t2)
155 {
156  bool equal = true;
157  for(int i = 0; i<18000;i++)
158  {
159  for(int j=0;j<5;j++)
160  if(t1->AdcToE[i][j]!=t2->AdcToE[i][j]) equal = false;
161  if(t1->Status[i]!=t2->Status[i]) equal = false;
162  }
163  return equal;
164 }
165 //------------------------------------------------------------------------------
166 bool compare(emcStatus_st* t1, emcStatus_st* t2)
167 {
168  bool equal = true;
169  for(int i = 0; i<4800;i++)
170  {
171  if(t1->Status[i]!=t2->Status[i])
172  {
173  equal = false;
174  //cout <<"i = "<<i<<" "<<(int)t1->Status[i]<<" "<<(int)t2->Status[i]<<endl;
175  }
176  }
177  return equal;
178 }
179 //------------------------------------------------------------------------------
180 bool compare(smdStatus_st* t1, smdStatus_st* t2)
181 {
182  bool equal = true;
183  for(int i = 0; i<18000;i++)
184  {
185  if(t1->Status[i]!=t2->Status[i]) equal = false;
186  }
187  return equal;
188 }
189 //------------------------------------------------------------------------------
190 bool compare(emcGain_st* t1, emcGain_st* t2)
191 {
192  bool equal = true;
193  for(int i = 0; i<4800;i++)
194  {
195  if(t1->Gain[i]!=t2->Gain[i]) equal = false;
196  }
197  return equal;
198 }
199 //------------------------------------------------------------------------------
200 bool compare(smdGain_st* t1, smdGain_st* t2)
201 {
202  bool equal = true;
203  for(int i = 0; i<18000;i++)
204  {
205  if(t1->Gain[i]!=t2->Gain[i]) equal = false;
206  }
207  return equal;
208 }
209 //------------------------------------------------------------------------------
210 bool compare(emcPed_st* t1, emcPed_st* t2)
211 {
212  bool equal = true;
213  for(int i = 0; i<4800;i++)
214  {
215  if(t1->AdcPedestal[i]!=t2->AdcPedestal[i]) equal = false;
216  if(t1->AdcPedestalRMS[i]!=t2->AdcPedestalRMS[i]) equal = false;
217  if(t1->Status[i]!=t2->Status[i]) equal = false;
218  }
219  return equal;
220 }
221 //------------------------------------------------------------------------------
222 bool compare(smdPed_st* t1, smdPed_st* t2)
223 {
224  bool equal = true;
225  for(int i = 0; i<18000;i++)
226  {
227  if(t1->AdcPedestal[i][0]!=t2->AdcPedestal[i][0]) equal = false;
228  if(t1->AdcPedestal[i][1]!=t2->AdcPedestal[i][1]) equal = false;
229  if(t1->AdcPedestal[i][2]!=t2->AdcPedestal[i][2]) equal = false;
230  if(t1->AdcPedestalRMS[i]!=t2->AdcPedestalRMS[i]) equal = false;
231  if(t1->Status[i]!=t2->Status[i]) equal = false;
232  }
233  return equal;
234 }
235 //------------------------------------------------------------------------------
236 bool compare(emcTriggerPed_st* t1, emcTriggerPed_st* t2)
237 {
238  bool equal = true;
239  for(int i = 0; i<4800;i++)
240  {
241  if(t1->PedShift!=t2->PedShift) equal = false;
242  for(int c=0;c<30;c++)
243  {
244  for(int p=0;p<10;p++)
245  if(t1->BitConversionMode[c][p]!=t2->BitConversionMode[c][p]) equal = false;
246  for(int p=0;p<160;p++)
247  if(t1->Ped[c][p]!=t2->Ped[c][p]) equal = false;
248  }
249  }
250  return equal;
251 }
252 //------------------------------------------------------------------------------
253 bool compare(emcTriggerStatus_st* t1, emcTriggerStatus_st* t2)
254 {
255  bool equal = true;
256  for(int i = 0; i<4800;i++)
257  {
258  if(t1->PedShift!=t2->PedShift) equal = false;
259  for(int c=0;c<30;c++)
260  {
261  for(int p=0;p<10;p++)
262  {
263  if(t1->PatchStatus[c][p]!=t2->PatchStaus[c][p]) equal = false;
264  if(t1->HighTowerStatus[c][p]!=t2->HighTowerStaus[c][p]) equal = false;
265  }
266  for(int p=0;p<160;p++)
267  if(t1->TowerStatus[c][p]!=t2->TowerStatus[c][p]) equal = false;
268  }
269  }
270  return equal;
271 }
272 //------------------------------------------------------------------------------
273 bool compare(emcTriggerLUT_st* t1, emcTriggerLUT_st* t2)
274 {
275  if(notLoaded) loadLibrariesCompare();
276  bool equal = true;
277  for(int c=0;c<30;c++)
278  {
279  for(int p=0;p<10;p++)
280  {
281  if(t1->FormulaTag[c][p]!=t2->FormulaTag[c][p]) equal = false;
282  if(t1->FormulaParameter0[c][p]!=t2->FormulaParameter0[c][p]) equal = false;
283  if(t1->FormulaParameter1[c][p]!=t2->FormulaParameter1[c][p]) equal = false;
284  if(t1->FormulaParameter2[c][p]!=t2->FormulaParameter2[c][p]) equal = false;
285  if(t1->FormulaParameter3[c][p]!=t2->FormulaParameter3[c][p]) equal = false;
286  if(t1->FormulaParameter4[c][p]!=t2->FormulaParameter4[c][p]) equal = false;
287  if(t1->FormulaParameter5[c][p]!=t2->FormulaParameter5[c][p]) equal = false;
288  }
289  }
290  return equal;
291 }
292 //******************************************************************************
StDbTable * getDbTable()