BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
compare_db.C
Go to the documentation of this file.
1#define PBSTR "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
2#define PBWIDTH 60
3void printProgress(double percentage)
4{
5 int val = (int)(percentage * 100);
6 int lpad = (int)(percentage * PBWIDTH);
7 int rpad = PBWIDTH - lpad;
8 printf("\r%3d%% [%.*s%*s]", val, lpad, PBSTR, rpad, "");
9 fflush(stdout);
10}
11
13{
14 TStopwatch timer;
15 timer.Start();
16
17 // find all parameters in the old table of the old database
18 cout << "Forming conditions to compare all parameters..." << endl;
19 TObjArray arrayConditions;
20 UniSearchCondition* searchConditionPeriod =
22 arrayConditions.Add((TObject*)searchConditionPeriod);
23 // UniSearchCondition* searchConditionSerial = new UniSearchCondition(UniSearchCondition::columnDCSerial,
24 // UniSearchCondition::conditionNull); arrayConditions.Add((TObject*)searchConditionSerial); UniSearchCondition*
25 // searchConditionName = new UniSearchCondition(UniSearchCondition::columnParameterName,
26 // UniSearchCondition::conditionEqual, (TString)"inl"); arrayConditions.Add((TObject*)searchConditionName);
27
28 cout << "Getting original array for parameters..." << endl;
29 TObjArray* pParameterArray = UniDetectorParameter::Search(arrayConditions);
30 // clean memory for the conditions after the search
31 arrayConditions.Delete();
32
33 // read all parameters and find in the new table of the new database
34 cout << "Reading and searching for corresponding parameters: " << pParameterArray->GetEntriesFast() << endl;
35 for (int i = 0; i < pParameterArray->GetEntriesFast(); i++) {
36 UniDetectorParameter* pParameter = (UniDetectorParameter*)pParameterArray->At(i);
37
38 // printProgress(((double)i)/(pParameterArray->GetEntriesFast()-1));
39 cout << "pParameter->GetDetectorName() = " << pParameter->GetDetectorName()
40 << ". pParameter->GetParameterName() = " << pParameter->GetParameterName()
41 << ". pParameter->GetStartPeriod() = " << pParameter->GetStartPeriod()
42 << ". pParameter->GetStartRun() = " << pParameter->GetStartRun() << endl;
43 if ((pParameter->GetStartPeriod() == 4) && (pParameter->GetStartRun() == 61)
44 && (pParameter->GetParameterName() == "GEM_pedestal"))
45 continue;
46
47 UniDetectorParameterNew* pNewParameter =
48 UniDetectorParameterNew::GetDetectorParameter(pParameter->GetDetectorName(), pParameter->GetParameterName(),
49 pParameter->GetStartPeriod(), pParameter->GetStartRun());
50 if (pNewParameter == nullptr) {
51 cout << "ERROR: returning new parameter was failed, where" << endl
52 << "pParameter->GetDetectorName() = " << pParameter->GetDetectorName()
53 << ". pParameter->GetParameterName() = " << pParameter->GetParameterName()
54 << ". pParameter->GetStartPeriod() = " << pParameter->GetStartPeriod()
55 << ". pParameter->GetStartRun() = " << pParameter->GetStartRun() << endl;
56 return -3;
57 }
58
59 vector<UniValue*> parameter_value;
60 if (pNewParameter->GetParameterValue(parameter_value) != 0) {
61 cout << "ERROR: returning new parameter value was failed for " << pNewParameter->GetParameterType() << endl;
62 return -4;
63 }
64
65 switch (pParameter->GetParameterType()) {
66 case BoolType: {
67 if (pParameter->GetDcSerial() == nullptr) {
68 BoolValue* pValue = (BoolValue*)parameter_value[0];
69 if (parameter_value.size() != 1) {
70 cout << "ERROR: new parameter must have 1 value, but it has " << parameter_value.size()
71 << " (old BoolType)" << endl;
72 return -5;
73 }
74 if (pValue->value != pParameter->GetBool()) {
75 cout << "ERROR: new parameter must be equal to old value " << pParameter->GetBool()
76 << " (BoolType)" << endl;
77 return -6;
78 }
79 } else {
80 bool is_found = false;
81 for (int j = 0; j < parameter_value.size(); j++) {
82 MapBoolValue* pValue = (MapBoolValue*)parameter_value[j];
83 if ((pValue->serial == *(pParameter->GetDcSerial()))
84 && (pValue->channel == *(pParameter->GetChannel()))
85 && (pValue->value == pParameter->GetBool()))
86 {
87 is_found = true;
88 break;
89 }
90 }
91 if (!is_found) {
92 cout << "ERROR: new parameter corresponding to the old value was not found:" << endl
93 << "pParameter->GetDcSerial() = " << *(pParameter->GetDcSerial())
94 << ". pParameter->GetChannel() = " << *(pParameter->GetChannel())
95 << ". pParameter->GetBool() = " << pParameter->GetBool() << endl;
96 return -7;
97 }
98 }
99
100 break;
101 }
102 case IntType: {
103 if (pParameter->GetDcSerial() == nullptr) {
104 IntValue* pValue = (IntValue*)parameter_value[0];
105 if (parameter_value.size() != 1) {
106 cout << "ERROR: new parameter must have 1 value, but it has " << parameter_value.size()
107 << " (old IntType)" << endl;
108 return -8;
109 }
110 if (pValue->value != pParameter->GetInt()) {
111 cout << "ERROR: new parameter must be equal to old value " << pParameter->GetInt()
112 << " (IntType)" << endl;
113 return -9;
114 }
115 } else {
116 bool is_found = false;
117 for (int j = 0; j < parameter_value.size(); j++) {
118 MapIntValue* pValue = (MapIntValue*)parameter_value[j];
119 if ((pValue->serial == *(pParameter->GetDcSerial()))
120 && (pValue->channel == *(pParameter->GetChannel()))
121 && (pValue->value == pParameter->GetInt()))
122 {
123 is_found = true;
124 break;
125 }
126 }
127 if (!is_found) {
128 cout << "ERROR: new parameter corresponding to the old value was not found:" << endl
129 << "pParameter->GetDcSerial() = " << *(pParameter->GetDcSerial())
130 << ". pParameter->GetChannel() = " << *(pParameter->GetChannel())
131 << ". pParameter->GetInt() = " << pParameter->GetInt() << endl;
132 return -10;
133 }
134 }
135
136 break;
137 }
138 case DoubleType: {
139 if (pParameter->GetDcSerial() != nullptr) {
140 cout << "ERROR: old parameter has dc_serial, but it belongs to DoubleType" << endl;
141 return -11;
142 }
143
144 DoubleValue* pValue = (DoubleValue*)parameter_value[0];
145 if (parameter_value.size() != 1) {
146 cout << "ERROR: new parameter must have 1 value, but it has " << parameter_value.size()
147 << " (old DoubleType)" << endl;
148 return -12;
149 }
150 if (pValue->value != pParameter->GetDouble()) {
151 cout << "ERROR: new parameter must be equal to old value " << pParameter->GetDouble()
152 << " (DoubleType)" << endl;
153 return -13;
154 }
155
156 break;
157 }
158 case StringType: {
159 if (pParameter->GetDcSerial() != nullptr) {
160 cout << "ERROR: old parameter has dc_serial, but it belongs to StringType" << endl;
161 return -14;
162 }
163
164 StringValue* pValue = (StringValue*)parameter_value[0];
165 if (parameter_value.size() != 1) {
166 cout << "ERROR: new parameter must have 1 value, but it has " << parameter_value.size()
167 << " (old StringType)" << endl;
168 return -15;
169 }
170 string s(pParameter->GetString().Data());
171 if (pValue->value != s) {
172 cout << "ERROR: new parameter must be equal to old value " << pParameter->GetString()
173 << " (StringType)" << endl;
174 return -16;
175 }
176
177 break;
178 }
179 case IIArrayType: {
180 if (pParameter->GetDcSerial() != nullptr) {
181 cout << "ERROR: old parameter has dc_serial, but it belongs to IIArrayType" << endl;
182 return -17;
183 }
184
185 IIStructure* ii_value = nullptr;
186 int element_count;
187 pParameter->GetIIArray(ii_value, element_count);
188 if (parameter_value.size() != element_count) {
189 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
190 << parameter_value.size() << " (old IIArrayType)" << endl;
191 return -18;
192 }
193 for (int j = 0; j < element_count; j++) {
194 IIValue* pValue = (IIValue*)parameter_value[j];
195 if ((pValue->value1 != ii_value[j].int_1) || (pValue->value2 != ii_value[j].int_2)) {
196 cout << "ERROR: new parameter must be equal to old value " << ii_value[j].int_1
197 << " (IIArrayType)" << endl;
198 return -19;
199 }
200 }
201
202 break;
203 }
204 case IntArrayType: {
205 if (pParameter->GetDcSerial() != nullptr) {
206 cout << "ERROR: old parameter has dc_serial, but it belongs to IntArrayType" << endl;
207 return -20;
208 }
209
210 int* i_value = nullptr;
211 int element_count;
212 pParameter->GetIntArray(i_value, element_count);
213 if (parameter_value.size() != element_count) {
214 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
215 << parameter_value.size() << " (old IntArrayType)" << endl;
216 return -21;
217 }
218 for (int j = 0; j < element_count; j++) {
219 IntValue* pValue = (IntValue*)parameter_value[j];
220 if (pValue->value != i_value[j]) {
221 cout << "ERROR: new parameter must be equal to old value " << i_value[j] << " (IntArrayType)"
222 << endl;
223 return -22;
224 }
225 }
226
227 break;
228 }
229 case DoubleArrayType: {
230 if (pParameter->GetDcSerial() == nullptr) {
231 double* d_value = nullptr;
232 int element_count;
233 pParameter->GetDoubleArray(d_value, element_count);
234 if (parameter_value.size() != element_count) {
235 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
236 << parameter_value.size() << " (old DoubleArrayType)" << endl;
237 return -23;
238 }
239 for (int j = 0; j < element_count; j++) {
240 DoubleValue* pValue = (DoubleValue*)parameter_value[j];
241 if (pValue->value != d_value[j]) {
242 cout << "ERROR: new parameter must be equal to old value " << d_value[j]
243 << " (DoubleArrayType)" << endl;
244 return -22;
245 }
246 }
247 } else {
248 double* d_value = nullptr;
249 int element_count;
250 pParameter->GetDoubleArray(d_value, element_count);
251
252 bool is_global_found = false;
253 for (int j = 0; j < parameter_value.size(); j++) {
254 MapDVectorValue* pMapValue = (MapDVectorValue*)parameter_value[j];
255 // cout<<"old array size = "<<element_count<<"; new array size =
256 // "<<pMapValue->value.size()<<endl;
257 if (pMapValue->value.size() != element_count)
258 continue;
259
260 // cout<<"old serial = "<<*(pParameter->GetDcSerial())<<"; new serial = "<<pMapValue->serial<<".
261 // old channel = "<<*(pParameter->GetChannel())<<"; new channel = "<<pMapValue->channel<<endl;
262 if ((pMapValue->serial != *(pParameter->GetDcSerial()))
263 || (pMapValue->channel != *(pParameter->GetChannel())))
264 continue;
265
266 bool is_found = true;
267 for (int k = 0; k < element_count; k++) {
268 // cout<<"current old value = "<<d_value[k]<<"; current new value =
269 // "<<(pMapValue->value)[k]<<endl; if (fabs((pMapValue->value)[k] - d_value[k]) >
270 // FLT_EPSILON)
271 if ((pMapValue->value)[k] != d_value[k]) {
272 is_found = false;
273 break;
274 }
275 }
276 if (is_found) {
277 is_global_found = true;
278 break;
279 }
280 }
281 if (!is_global_found) {
282 cout << "ERROR: new parameter corresponding to the old value was not found:" << endl
283 << "dc_serial = " << *(pParameter->GetDcSerial())
284 << ". channel = " << *(pParameter->GetChannel()) << ". element_count = " << element_count
285 << endl;
286 return -23;
287 }
288 }
289
290 break;
291 }
292 case BinaryArrayType: {
293 if (pParameter->GetDcSerial() != nullptr) {
294 cout << "ERROR: old parameter has dc_serial, but it belongs to BinaryArrayType" << endl;
295 return -24;
296 }
297
298 BinaryValue* pValue = (BinaryValue*)parameter_value[0];
299 if (parameter_value.size() != 1) {
300 cout << "ERROR: new parameter must have 1 value, but it has " << parameter_value.size()
301 << " (old BinaryArrayType)" << endl;
302 return -25;
303 }
304
305 unsigned char* p_old_bytes = nullptr;
306 size_t byte_count;
307 if (pParameter->GetBinaryArray(p_old_bytes, byte_count) != 0) {
308 cout << "ERROR: returning binary array was failed for BinaryArrayType" << endl;
309 return -26;
310 }
311
312 if (pValue->size != byte_count) {
313 cout << "ERROR: new parameter must have " << byte_count << " values, but it has " << pValue->size
314 << " (old BinaryArrayType)" << endl;
315 return -27;
316 }
317 for (int j = 0; j < byte_count; j++) {
318 if (pValue->value[j] != p_old_bytes[j]) {
319 cout << "ERROR: new parameter must be equal to old value " << p_old_bytes[j]
320 << " (BinaryArrayType)" << endl;
321 return -28;
322 }
323 }
324
325 break;
326 }
327 case UIntArrayType: {
328 if (pParameter->GetDcSerial() != nullptr) {
329 cout << "ERROR: old parameter has dc_serial, but it belongs to UIntArrayType" << endl;
330 return -29;
331 }
332
333 unsigned int* ui_value = nullptr;
334 int element_count;
335 pParameter->GetUIntArray(ui_value, element_count);
336 if (parameter_value.size() != element_count) {
337 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
338 << parameter_value.size() << " (old UIntArrayType)" << endl;
339 return -30;
340 }
341 for (int j = 0; j < element_count; j++) {
342 UIntValue* pValue = (UIntValue*)parameter_value[j];
343 if (pValue->value != ui_value[j]) {
344 cout << "ERROR: new parameter must be equal to old value " << ui_value[j] << " (UIntArrayType)"
345 << endl;
346 return -31;
347 }
348 }
349
350 break;
351 }
352 case DchMapArrayType: {
353 if (pParameter->GetDcSerial() != nullptr) {
354 cout << "ERROR: old parameter has dc_serial, but it belongs to DchMapArrayType" << endl;
355 return -32;
356 }
357
358 DchMapStructure* dch_value = nullptr;
359 int element_count;
360 pParameter->GetDchMapArray(dch_value, element_count);
361 if (parameter_value.size() != element_count) {
362 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
363 << parameter_value.size() << " (old DchMapArrayType)" << endl;
364 return -33;
365 }
366 for (int j = 0; j < element_count; j++) {
367 DchMapValue* pValue = (DchMapValue*)parameter_value[j];
368 if ((pValue->plane != dch_value[j].plane) || (pValue->group != dch_value[j].group)
369 || (pValue->crate != dch_value[j].crate) || (pValue->slot != dch_value[j].slot)
370 || (pValue->channel_low != dch_value[j].channel_low)
371 || (pValue->channel_high != dch_value[j].channel_high))
372 {
373 cout << "ERROR: new parameter must be equal to old value " << dch_value[j].plane
374 << " (DchMapArrayType)" << endl;
375 return -34;
376 }
377 }
378
379 break;
380 }
381 case GemMapArrayType: {
382 if (pParameter->GetDcSerial() != nullptr) {
383 cout << "ERROR: old parameter has dc_serial, but it belongs to GemMapArrayType" << endl;
384 return -35;
385 }
386
387 GemMapStructure* gem_value = nullptr;
388 int element_count;
389 pParameter->GetGemMapArray(gem_value, element_count);
390 if (parameter_value.size() != element_count) {
391 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
392 << parameter_value.size() << " (old GemMapArrayType)" << endl;
393 return -36;
394 }
395 for (int j = 0; j < element_count; j++) {
396 GemMapValue* pValue = (GemMapValue*)parameter_value[j];
397 if ((pValue->serial != gem_value[j].serial) || (pValue->id != gem_value[j].id)
398 || (pValue->station != gem_value[j].station)
399 || (pValue->channel_low != gem_value[j].channel_low)
400 || (pValue->channel_high != gem_value[j].channel_high)
401 || (pValue->hotZone != gem_value[j].hotZone))
402 {
403 cout << "ERROR: new parameter must be equal to old value " << gem_value[j].serial
404 << " (GemMapArrayType)" << endl;
405 return -37;
406 }
407 }
408
409 break;
410 }
411 case GemPedestalArrayType: {
412 if (pParameter->GetDcSerial() != nullptr) {
413 cout << "ERROR: old parameter has dc_serial, but it belongs to GemPedestalArrayType" << endl;
414 return -38;
415 }
416
417 GemPedestalStructure* gem_ped_value = nullptr;
418 int element_count;
419 pParameter->GetGemPedestalArray(gem_ped_value, element_count);
420 if (parameter_value.size() != element_count) {
421 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
422 << parameter_value.size() << " (old GemPedestalArrayType)" << endl;
423 return -39;
424 }
425 for (int j = 0; j < element_count; j++) {
426 GemPedestalValue* pValue = (GemPedestalValue*)parameter_value[j];
427 if ((pValue->serial != gem_ped_value[j].serial) || (pValue->channel != gem_ped_value[j].channel)
428 || (pValue->pedestal != gem_ped_value[j].pedestal) || (pValue->noise != gem_ped_value[j].noise))
429 {
430 cout << "ERROR: new parameter must be equal to old value " << gem_ped_value[j].serial
431 << " (GemPedestalArrayType)" << endl;
432 return -40;
433 }
434 }
435
436 break;
437 }
438 case TriggerMapArrayType: {
439 if (pParameter->GetDcSerial() != nullptr) {
440 cout << "ERROR: old parameter has dc_serial, but it belongs to TriggerMapArrayType" << endl;
441 return -41;
442 }
443
444 TriggerMapStructure* trigger_value = nullptr;
445 int element_count;
446 pParameter->GetTriggerMapArray(trigger_value, element_count);
447 if (parameter_value.size() != element_count) {
448 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
449 << parameter_value.size() << " (old TriggerMapArrayType)" << endl;
450 return -42;
451 }
452 for (int j = 0; j < element_count; j++) {
453 TriggerMapValue* pValue = (TriggerMapValue*)parameter_value[j];
454 if ((pValue->serial != trigger_value[j].serial) || (pValue->slot != trigger_value[j].slot)
455 || (pValue->channel != trigger_value[j].channel))
456 {
457 cout << "ERROR: new parameter must be equal to old TriggerMapArrayType value: iter = " << j
458 << endl
459 << "pValue->serial = " << pValue->serial
460 << "; trigger_value.serial = " << trigger_value[j].serial
461 << ". pValue->slot = " << pValue->slot
462 << "; trigger_value.slot = " << trigger_value[j].slot
463 << ". pValue->channel = " << pValue->channel
464 << "; trigger_value.channel = " << trigger_value[j].channel << endl;
465 return -43;
466 }
467 }
468
469 break;
470 }
471 case LorentzShiftArrayType: {
472 if (pParameter->GetDcSerial() != nullptr) {
473 cout << "ERROR: old parameter has dc_serial, but it belongs to LorentzShiftArrayType" << endl;
474 return -44;
475 }
476
477 LorentzShiftStructure* lorentz_value = nullptr;
478 int element_count;
479 pParameter->GetLorentzShiftArray(lorentz_value, element_count);
480 if (parameter_value.size() != element_count) {
481 cout << "ERROR: new parameter must have " << element_count << " values, but it has "
482 << parameter_value.size() << " (old LorentzShiftArrayType)" << endl;
483 return -45;
484 }
485 for (int j = 0; j < element_count; j++) {
486 LorentzShiftValue* pValue = (LorentzShiftValue*)parameter_value[j];
487 if ((pValue->number != lorentz_value[j].number) || (pValue->ls[0] != lorentz_value[j].ls[0])
488 || (pValue->ls[1] != lorentz_value[j].ls[1]) || (pValue->ls[2] != lorentz_value[j].ls[2]))
489 {
490 cout << "ERROR: new parameter must be equal to old value " << lorentz_value[j].number
491 << " (LorentzShiftArrayType)" << endl;
492 return -46;
493 }
494 }
495
496 break;
497 }
498 case ErrorType: {
499 cout << "ERROR: ErrorType was unexpectedly found" << endl;
500 return -47;
501 }
502 default: {
503 cout << "ERROR: the parameter type was not defined" << endl;
504 return -48;
505 }
506 }
507
508 // cout<<"DetectorName = "<<pParameter->GetDetectorName()<<". ParameterName =
509 // "<<pParameter->GetParameterName()<<". StartPeriod = "<<pParameter->GetStartPeriod()<<". StartRun =
510 // "<<pParameter->GetStartRun()<<". EndPeriod = "<<pParameter->GetEndPeriod()<<". GetEndRun() =
511 // "<<pParameter->GetEndRun()<<". parameter_value size = "<<parameter_value.size()<<endl;
512 // clean memory for destination array
513 for (int j = 0; j < parameter_value.size(); j++)
514 delete parameter_value[j];
515 parameter_value.clear();
516 delete pNewParameter;
517 }
518 cout << endl;
519
520 // clean memory after work
521 delete pParameterArray;
522
523 timer.Stop();
524 Double_t rtime = timer.RealTime(), ctime = timer.CpuTime();
525 printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime);
526
527 cout << "Macro was successfull" << endl;
528
529 return 0;
530}
int i
Definition P4_F32vec4.h:22
double Double_t
Int_t GetEntriesFast() const
void Delete(Option_t *option="") override
TObject * At(Int_t idx) const override
void Add(TObject *obj) override
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
enumValueType GetParameterType()
get parameter type of the current parameter value
int GetStartPeriod()
get start period of the current detector parameter
TString GetParameterName()
get parameter name of the current parameter value
static TObjArray * Search(UniSearchCondition &search_condition)
get parameters' values corresponding to the specified single condition and set owner for search_condi...
TString GetDetectorName()
get detector name of the current detector parameter
int GetStartRun()
get start run of the current detector parameter
#define PBWIDTH
Definition compare_db.C:2
#define PBSTR
Definition compare_db.C:1
void printProgress(double percentage)
Definition compare_db.C:3
int compare_db()
Definition compare_db.C:12
@ IntType
@ StringType
@ BoolType
@ DoubleType
unsigned char * value
STRUCTURES for parameter storing corresponding enumValueType list.
vector< double > value