-
Notifications
You must be signed in to change notification settings - Fork 5
/
frmprepareglobal.cpp
1474 lines (1227 loc) · 53.3 KB
/
frmprepareglobal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Qt includes
#include <QtGui>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlError>
#include <QProcess>
// project includes
#include "frmprepareglobal.h"
#include "frmterminaldialog.h"
#include "Debug.h"
#include "DbConnection.h"
// Defines
#define TIB_ID "TIB/TID"
#define TOB_ID "TOB"
#define TECP_ID "TEC+"
#define TECM_ID "TEC-"
#define O2O_ID "O2O"
#define PREPAREGLOBAL_SCRIPT "/nfshome0/trackerpro/o2o/scripts/prepareGlobal_slc5.sh"
#define SELECTPARTNAMES "select partitionname, max(o2oid) as o2oid from partition, StateHistory, CurrentState, O2OPartition where StateHistory.partitionid=Partition.partitionId and StateHistory.stateHistoryId=CurrentState.stateHistoryId and Partition.partitionId = O2OPartition.partitionid and SUBDETECTOR = '%1' group by partitionname order by O2OID asc"
#define SELECTXCHECK "select PkgO2OPartition.getO2OXChecked('%1') from dual"
#define SELECTXCHECKNONE "select count(runnumber) from o2opartition where runnumber=(select max(runnumber) from o2opartition) and subdetector='%1'"
#define SELECTXCHECKO2O "select count(runnumber) from o2opartition where runnumber=(select max(runnumber) from o2opartition) and subdetector='%1'"
#define SELECTCHECKDUPLICATE "select count(runnumber) from partition, o2opartition where partition.partitionid = o2opartition.partitionid and partition.partitionname = '%1' and o2opartition.runnumber = %2"
#define SELECTCHECKDUPLICATESUB "select count(runnumber) from o2opartition where runnumber=%1 and subdetector='%2'"
#define SELECTNEXTRUNNUMBER "with nextglobalrun as (select max(runnumbertbl.runnumber+1) runnumber from CMS_RUNINFO.runnumbertbl), lasto2o as (select max(o2opartition.runnumber) runnumber from o2opartition) select nextglobalrun.runnumber, lasto2o.runnumber from nextglobalrun, lasto2o"
#define EXECINSERTOPERATION "BEGIN PkgO2OPartition.insertO2OOperation('%1', '%2', %3); END;"
#define EXECCONFIRMO2O "BEGIN PkgO2OPartition.insertO2OConfirmation(%1); END;"
#define SELECTLATESTVERSION "select RUNNUMBER, PARTITIONNAME, FECVERSIONMAJORID, FECVERSIONMINORID, FEDVERSIONMAJORID, FEDVERSIONMINORID, CONNECTIONVERSIONMAJORID, CONNECTIONVERSIONMINORID, DCUINFOVERSIONMAJORID, DCUINFOVERSIONMINORID, DCUPSUMAPVERSIONMAJORID, DCUPSUMAPVERSIONMINORID from ViewLastO2OPartitions" // unused
#define SELECTLATESTVERSIONS "select FECVERSIONMAJORID, FECVERSIONMINORID, FEDVERSIONMAJORID, FEDVERSIONMINORID, CONNECTIONVERSIONMAJORID, CONNECTIONVERSIONMINORID, DCUINFOVERSIONMAJORID, DCUINFOVERSIONMINORID, DCUPSUMAPVERSIONMAJORID, DCUPSUMAPVERSIONMINORID, MASKVERSIONMAJORID, MASKVERSIONMINORID from ViewLastO2OPartitions where RUNNUMBER=%1 and PARTITIONNAME='%2'"
#define SELECTLATESTFEDVALUES "select distinct allvalues.readroute, allvalues.fedmode, allvalues.supermode from fedvalues allvalues join (select fedid,max(versionminorid) versionminorid, versionmajorid from fedvalues join fed using(fedid) join viewcurrentstate cs on cs.partitionname='%1' and cs.fedversionmajorid=fedvalues.versionmajorid and fedvalues.versionminorid<=cs.fedversionminorid group by fedid, versionmajorid) goodvalues on allvalues.fedid=goodvalues.fedid and allvalues.versionmajorid=goodvalues.versionmajorid and allvalues.versionminorid=goodvalues.versionminorid"
#define EXECCHANGEREADROUTE "BEGIN TestPackages.changeFedParameter('%1','FEDVALUES','READROUTE','%2',0); END;"
#define EXECCHANGEMODE "BEGIN TestPackages.changeFedParameter('%1','FEDVALUES','FEDMODE', '%2',0); END;"
#define EXECCHANGESUPERMODE "BEGIN TestPackages.changeFedParameter('%1','FEDVALUES','SUPERMODE','%2',0); END;"
#define EXECREFRESHCACHE "BEGIN TestPackages.TestPkgFedDownload('%1'); END;"
#define NONE_STRING "(none)"
enum {SLINK64, VME};
enum {VR = 100, ZS_NORMAL = 201, ZS_LITE = 202, ZS_FAKE_NORMAL = 203, ZS_FAKE_LITE = 204, SCOPE = 300};
enum {RESULT_OK = 3, RESULT_ALMOST_OK = 2, RESULT_UNKNOWN = 1, RESULT_WARNING = 0, RESULT_ERROR = -1};
enum {MIN = 0,
TIBPART, TOBPART, TECPPART, TECMPART,
TIBRR, TOBRR, TECPRR, TECMRR,
TIBMSM, TOBMSM, TECPMSM, TECMMSM,
CONFTIB, CONFTOB, CONFTECP, CONFTECM, MAX
};
std::map<int, QComboBox*> configuration;
PrepareGlobal::PrepareGlobal(QWidget * parent):
QMainWindow(parent)
{
setupUi(this);
addReadRoutes();
addModesAndSuperModes();
textLabel1->setText("");
latencyTib->setText("--");
latencyTib->setEnabled(false);
latencyTob->setText("--");
latencyTob->setEnabled(false);
latencyTecp->setText("--");
latencyTecp->setEnabled(false);
latencyTecm->setText("--");
latencyTecm->setEnabled(false);
configuration[TIBPART] = cmbTib;
configuration[TOBPART] = cmbTob;
configuration[TECPPART] = cmbTecp;
configuration[TECMPART] = cmbTecm;
configuration[TIBRR] = comboBoxReadRouteTib;
configuration[TOBRR] = comboBoxReadRouteTob;
configuration[TECPRR] = comboBoxReadRouteTecp;
configuration[TECMRR] = comboBoxReadRouteTecm;
configuration[TIBMSM] = comboBoxMSMTib;
configuration[TOBMSM] = comboBoxMSMTob;
configuration[TECPMSM] = comboBoxMSMTecp;
configuration[TECMMSM] = comboBoxMSMTecm;
populatePartitions();
checkVersions();
setPartitions();
getCurrentConfiguration();
cacheOldConfiguration();
readoutChanged();
}
PrepareGlobal::~PrepareGlobal() {
}
void PrepareGlobal::addReadRoutes() {
addReadRouteTo(comboBoxReadRouteTib);
addReadRouteTo(comboBoxReadRouteTob);
addReadRouteTo(comboBoxReadRouteTecp);
addReadRouteTo(comboBoxReadRouteTecm);
}
void PrepareGlobal::addReadRouteTo(QComboBox* readRouteList) {
QString sLink = "SLINK64";
QString vme = "VME";
readRouteList->insertItem(readRouteList->count(), sLink);
readRouteList->insertItem(readRouteList->count(), vme);
}
void PrepareGlobal::addModesAndSuperModes() {
readoutModes[100] = 0;//VR ;
readoutModes[201] = 1;//ZS_NORMAL ;
readoutModes[202] = 2;//ZS_LITE ;
readoutModes[203] = 3;//ZS_FAKE_NORMAL;
readoutModes[204] = 4;//ZS_FAKE_LITE ;
readoutModes[300] = 5;//SCOPE ;
addModeAndSuperModeTo(comboBoxMSMTib);
addModeAndSuperModeTo(comboBoxMSMTob);
addModeAndSuperModeTo(comboBoxMSMTecp);
addModeAndSuperModeTo(comboBoxMSMTecm);
}
void PrepareGlobal::addModeAndSuperModeTo(QComboBox* modeList) {
std::vector<QString> modesAndSuperModes;
modesAndSuperModes.push_back("VIRGIN_RAW/NORMAL");
modesAndSuperModes.push_back("ZERO_SUPPRESSION/NORMAL");
modesAndSuperModes.push_back("ZERO_SUPPRESSION/ZERO_LITE");
modesAndSuperModes.push_back("ZERO_SUPPRESSION/FAKE");
modesAndSuperModes.push_back("ZERO_SUPPRESSION/FAKE_ZERO_LITE");
modesAndSuperModes.push_back("SCOPE");
std::vector<QString>::const_iterator it = modesAndSuperModes.begin();
std::vector<QString>::const_iterator itEnd = modesAndSuperModes.end();
for(; it != itEnd; ++it) modeList->insertItem(modeList->count(), *it);
}
void PrepareGlobal::partitionForConfiguration(QLabel* label, int partitionLabel) {
QString partition = configuration[partitionLabel - 12]->currentText();
if (partition != NONE_STRING) {
QString text = label->text();
text.truncate(text.toStdString().find(" "));
text = text + " (" + partition + ")";
if (iOldConfiguration[partitionLabel] == RESULT_WARNING) {
QPalette pal = label->palette();
pal.setColor(QPalette::WindowText, QColor(Qt::red));
label->setPalette(pal);
label->setText(text);
}
else label->setText(text);
}
else {
QString text = label->text();
text.truncate(text.toStdString().find(" "));
QPalette pal = label->palette();
pal.setColor(QPalette::WindowText, QColor(Qt::red));
label->setPalette(pal);
label->setText(text);
}
}
void PrepareGlobal::setPartitions() {
partitionForConfiguration(txtTib_2 , CONFTIB );
partitionForConfiguration(txtTob_2 , CONFTOB );
partitionForConfiguration(txtTecp_2, CONFTECP );
partitionForConfiguration(txtTecm_2, CONFTECM );
}
int PrepareGlobal::getCurrentConfiguration() {
QVector<QLabel*> labels;
labels.push_back(txtTib_2);
labels.push_back(txtTob_2);
labels.push_back(txtTecp_2);
labels.push_back(txtTecm_2);
for(size_t i = 1; i<=4; ++i ) iOldConfiguration[i+12] = getCurrentConfigurationFor(labels[i-1],configuration[i+4],configuration[i+8]);
return 1;
}
int PrepareGlobal::getCurrentConfigurationFor(QLabel *label, QComboBox* comboReadRoute, QComboBox* comboMSM ) {
int returnValue = RESULT_UNKNOWN;
QString lblText = label->text();
QString subDetector = lblText.section( '(',1,1);
subDetector.truncate((subDetector.length() - 1));
QString readroute, fedmode, supermode;
if(subDetector == NONE_STRING || subDetector == "") return RESULT_OK;
if (DbConnection::Inst()->dbConnected()) {
QString myQuery;
myQuery = QString(SELECTLATESTFEDVALUES).arg(subDetector);
QSqlQuery query(myQuery);
int resultCounter = 0;
while (query.next()) {
readroute = query.value(0).toString();
fedmode = query.value(1).toString();
supermode = query.value(2).toString();
resultCounter++;
}
if(resultCounter == 1) {
returnValue = RESULT_OK;
QPalette pal = label->palette();
pal.setColor(QPalette::WindowText, QColor(Qt::black));
label->setPalette(pal);
}
else {
statusBar()->showMessage("Partition is in a mixed state. Enter global running like this only if you know what you are doing");
returnValue = RESULT_WARNING;
QPalette pal = label->palette();
pal.setColor(QPalette::WindowText, QColor(Qt::red));
label->setPalette(pal);
}
if(Debug::Inst()->getEnabled()) {
qDebug() << qPrintable(readroute) << ' ' << qPrintable(fedmode) << ' ' << qPrintable(supermode) << "\n";
qDebug() << qPrintable(readroute) << ' ' << qPrintable(fedmode) << ' ' << qPrintable(supermode) << "\n";
}
if(readroute == "VME") comboReadRoute->setCurrentIndex(VME);
else comboReadRoute->setCurrentIndex(SLINK64);
updateMSM(comboMSM, fedmode.toStdString().c_str(), supermode.toStdString().c_str());
}
return returnValue;
}
bool PrepareGlobal::updateMSM(QComboBox* combo, QString fedmode, QString supermode) {
int mode = 0;
if(fedmode == "VIRGIN_RAW") {
mode = 100;
}
else if(fedmode == "ZERO_SUPPRESSION") {
mode = 200;
if(supermode == "NORMAL") mode += 1;
if(supermode == "ZERO_LITE") mode += 2;
if(supermode == "FAKE") mode += 3;
if(supermode == "FAKE_ZERO_LITE") mode += 4;
}
else if(fedmode == "SCOPE") {
mode = 300;
}
else {
return false;
}
if(readoutModes.find(mode) == readoutModes.end() ) {
if(Debug::Inst()->getEnabled()) qDebug() << "OBS, did not find this mode/supermode combination\n";
}
else combo->setCurrentIndex(readoutModes.find(mode)->second );
return true;
}
void PrepareGlobal::addChoosePartitionName(QComboBox * myPartList) {
QString selectedItem;
Partitions w;
w.setModal(true);
w.populatePartitions();
if (w.exec()==QDialog::Accepted) {
selectedItem = w.selectedPartition();
if (selectedItem != "") {
myPartList->insertItem(myPartList->count(), selectedItem);
myPartList->setCurrentIndex(myPartList->count()-1);
checkVersions();
}
}
}
void PrepareGlobal::on_btnTibMore_clicked() {
addChoosePartitionName(cmbTib);
partitionForConfiguration(txtTib_2, CONFTIB );
readoutChanged();
}
void PrepareGlobal::on_btnTobMore_clicked() {
addChoosePartitionName(cmbTob);
partitionForConfiguration(txtTob_2, CONFTOB );
readoutChanged();
}
void PrepareGlobal::on_btnTecpMore_clicked() {
addChoosePartitionName(cmbTecp);
partitionForConfiguration(txtTecp_2, CONFTECP );
readoutChanged();
}
void PrepareGlobal::on_btnTecmMore_clicked() {
addChoosePartitionName(cmbTecm);
partitionForConfiguration(txtTecm_2, CONFTECM );
readoutChanged();
}
void PrepareGlobal::readoutChanged() {
activatePartition(cmbTib, comboBoxReadRouteTib, comboBoxMSMTib);
activatePartition(cmbTob, comboBoxReadRouteTob, comboBoxMSMTob);
activatePartition(cmbTecp, comboBoxReadRouteTecp, comboBoxMSMTecp);
activatePartition(cmbTecm, comboBoxReadRouteTecm, comboBoxMSMTecm);
bool isChanged = false;
for(size_t i = TIBRR; i <= TECMMSM; ++i) {
if(iOldConfiguration[i] != configuration[i]->currentIndex()) isChanged = true;
}
if(isChanged) {
QMessageBox::warning( this, "Prepare Running State"
"Warning",
"This feature is not yet connected to the DB\n"
"Changes made here are NOT propagated to the tracker",
"OK", 0, 0, 1) ;
btnApplyChanges->setEnabled(true);
btnRevertConfiguration->setEnabled(true);
}
else {
btnApplyChanges->setEnabled(false);
btnRevertConfiguration->setEnabled(false);
}
checkReadoutConfiguration();
}
void PrepareGlobal::activatePartition(QComboBox* subDet, QComboBox* readRoute, QComboBox* modeSuperMode) {
if (subDet->currentText() == NONE_STRING) {
readRoute->setEnabled(false);
modeSuperMode->setEnabled(false);
}
else {
readRoute->setEnabled(true);
modeSuperMode->setEnabled(true);
}
}
void PrepareGlobal::checkReadoutConfiguration() {
std::vector<int> status;
std::vector<int> partitionStatus;
int valid = RESULT_OK;
int partitionValid = RESULT_OK;
status.clear();
partitionStatus.clear();
for(size_t partition = 1; partition <= 4; ++partition) {
if(configuration[partition]->currentText() != NONE_STRING) {
status.push_back( validCombination( configuration[partition+4], configuration[partition+8] ) );
partitionStatus.push_back(iOldConfiguration[partition+12]);
}
}
for(size_t stat = 0; stat < status.size(); ++stat) {
if(status[stat] == RESULT_ERROR) valid = RESULT_ERROR;
if(status[stat] == RESULT_WARNING && valid != RESULT_ERROR) valid = RESULT_WARNING;
}
for(size_t stat = 0; stat < partitionStatus.size(); ++stat) {
if(partitionStatus[stat] == RESULT_ERROR) partitionValid = RESULT_ERROR;
if(partitionStatus[stat] == RESULT_WARNING && partitionValid != RESULT_ERROR) partitionValid = RESULT_WARNING;
}
displayStatus( (valid < partitionValid ? valid : partitionValid) );
if(partitionValid == RESULT_ERROR && valid == RESULT_ERROR ) statusBar()->showMessage("Both partition state and readout are problematic for global running");
else if(partitionValid == RESULT_WARNING && valid == RESULT_ERROR ) statusBar()->showMessage("Please make sure you really want to use this readout configuration");
else if(partitionValid == RESULT_WARNING && valid == RESULT_WARNING ) statusBar()->showMessage("Partition state and readout are not a priori suitable for global running, please check");
else if(partitionValid == RESULT_OK && valid == RESULT_WARNING ) statusBar()->showMessage("Partition state is OK but the readout is not the default");
else if(partitionValid == RESULT_OK && valid == RESULT_OK ) statusBar()->showMessage("Partition state and readout are ready for global running");
}
void PrepareGlobal::displayStatus(int newStatus ) {
QString icon_name;
QString statusMessage = "";
switch (newStatus) {
case RESULT_ERROR:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_error.png";
//statusMessage = "Last O2O upload does not correspond to this configuration";
break;
case RESULT_UNKNOWN:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_question.png";
//statusMessage = "ERROR: I encountered an unexpected problem. Please check the command line for possible detailed error messages";
break;
case RESULT_OK:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_ok.png";
// statusMessage = "Last O2O upload corresponds to this configuration";
// statusMessage = "Readout configuration appears to be ok";
break;
case RESULT_ALMOST_OK:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_almost_ok.png";
//statusMessage = "Partitions are in correct state, waiting for O2O confirmation";
break;
case RESULT_WARNING:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/triangle_attention.png";
//statusMessage = "This combination of Mode/Supermode and Readroute is NOT recommended, be sure that you really want this configuration!";
break;
default:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_question.png";
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR in PrepareGlobal::displayStatus unexpected status\n";
break;
}
if(statusMessage != "")
statusBar()->showMessage(statusMessage);
validReadOut->setPixmap(qPixmapFromMimeSource(icon_name));
}
void PrepareGlobal::displayStatus(int newStatus, const int& nextRunNumber, const int& lastIovRunNumber, bool allowO2O ) {
QString icon_name;
QString statusMessage;
switch (newStatus) {
case RESULT_ERROR:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_error.png";
statusMessage = "Last O2O upload does not correspond to this configuration";
break;
case RESULT_UNKNOWN:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_question.png";
statusMessage = "ERROR: I encountered an unexpected problem. Please check the command line for possible detailed error messages";
break;
case RESULT_OK:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_ok.png";
statusMessage = "Last O2O upload corresponds to this configuration";
allowO2O = false;
break;
case RESULT_ALMOST_OK:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_almost_ok.png";
statusMessage = "Partition(s) are in correct state, waiting for O2O confirmation";
allowO2O = false;
break;
default:
icon_name = "/opt/cmssw/shifter/avartak/qtRoot/NewCommissioningGui/Stable/TkCommissioner/images/round_question.png";
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR in PrepareGlobal::displayStatus unexpected status\n";
break;
}
statusBar()->showMessage(statusMessage);
linLastIov->setText(QString("%1").arg(lastIovRunNumber));
linNextRun->setText(QString("%1").arg(nextRunNumber));
lblUpdate->setPixmap(qPixmapFromMimeSource(icon_name));
validReadOut->setPixmap(qPixmapFromMimeSource(icon_name));
btnSetConf->setEnabled(allowO2O);
}
int PrepareGlobal::validCombination(QComboBox* comboReadRoute, QComboBox* comboMSM) {
int route = comboReadRoute->currentIndex();
int mode = comboMSM ->currentIndex();
if(route == SLINK64) {
if(mode == readoutModes[ZS_NORMAL] ||
mode == readoutModes[ZS_LITE] ||
mode == readoutModes[ZS_FAKE_NORMAL] ||
mode == readoutModes[ZS_FAKE_LITE]) {
return RESULT_OK;
} else {
return RESULT_WARNING;
}
}
if(route == VME) {
return RESULT_WARNING;
statusBar()->showMessage("A partition which is potentially included in global running is in VME read route");
}
if(Debug::Inst()->getEnabled()) qDebug() << "OBS, you got an unknown readout route, this should never happen!\n";
return RESULT_UNKNOWN;
}
void PrepareGlobal::populatePartition(QStringList partitionNames, QComboBox* cmbPart, bool usedPart) {
for (QStringList::iterator it = partitionNames.begin(); it!=partitionNames.end(); ++it) {
cmbPart->insertItem(cmbPart->count(), *it);
}
cmbPart->setCurrentIndex(cmbPart->count()-1);
// std::cout << "subdet " << usedPart << std::endl; // debug
if (!usedPart) cmbPart->setItemText(cmbPart->currentIndex(), NONE_STRING);
}
void PrepareGlobal::populatePartitions() {
QStringList partitionNames;
bool usedPart;
for(size_t partition = 1; partition <= 4; ++partition) {
configuration[partition]->clear();
configuration[partition]->insertItem(configuration[partition]->count(), NONE_STRING);
}
partitionNames = getUsedPartitionNames(TIB_ID, usedPart);
populatePartition(partitionNames, cmbTib, usedPart);
partitionNames = getUsedPartitionNames(TOB_ID, usedPart);
populatePartition(partitionNames, cmbTob, usedPart);
partitionNames = getUsedPartitionNames(TECP_ID, usedPart);
populatePartition(partitionNames, cmbTecp, usedPart);
partitionNames = getUsedPartitionNames(TECM_ID, usedPart);
populatePartition(partitionNames, cmbTecm, usedPart);
}
QStringList PrepareGlobal::getUsedPartitionNames(QString subDetector, bool& used) {
used = true;
QStringList partitionNames;
if (DbConnection::Inst()->dbConnected()) {
QString myQuery;
myQuery = QString(SELECTPARTNAMES).arg(subDetector);
QSqlQuery query(myQuery);
while (query.next()) {
QString aPartitionName = query.value(0).toString();
partitionNames.append(aPartitionName);
}
myQuery = QString(SELECTXCHECKNONE).arg(subDetector);
QSqlQuery query2(myQuery);
int resultCounter = 0;
while (query2.next()) {
int partition = query2.value(0).toInt();
if (partition==1) used = true;
else if (partition==0) used = false;
else {
used = true;
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: in PrepareGlobal::getUsedPartitionNames" << "I found more that one partition for the same subdetector in the latest version set\n";
}
resultCounter++;
}
if (resultCounter!=1) {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: in PrepareGlobal::getUsedPartitionNames " << "I found more that one answer to the SELECT query\n";
used = true;
}
}
else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: dbConnection id NULL in " << "PrepareGlobal::getUsedPartitionNames(QString subDetector)\n";
}
return partitionNames;
}
int PrepareGlobal::xCheckPartition( QString partitionName , QString subDetector) {
int result=RESULT_UNKNOWN;
if (DbConnection::Inst()->dbConnected()) {
if (partitionName==NONE_STRING) {
QString myQuery;
myQuery = QString(SELECTXCHECKNONE).arg(subDetector);
QSqlQuery query(myQuery);
int resultCounter = 0;
while (query.next()) {
int partition = query.value(0).toInt();
if (partition==0) {
result=RESULT_OK;
} else {
result=RESULT_ERROR;
}
resultCounter++;
}
if (resultCounter!=1) {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: in PrepareGlobal::xCheckPartition I found more than one answer to the SELECT query\n";
result=RESULT_UNKNOWN;
}
}
else if ((partitionName==O2O_ID)&&(subDetector==O2O_ID)) {
QString myQuery;
myQuery = QString(SELECTXCHECKO2O).arg(subDetector);
QSqlQuery query(myQuery);
bool rset = query.exec();
int resultCounter = 0;
if (rset) {
while (query.next()) {
int partition = query.value(0).toInt();
if (partition==1) {
result=RESULT_OK;
} else {
result=RESULT_ERROR;
}
resultCounter++;
}
}
if (resultCounter!=1) {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: in PrepareGlobal::xCheckPartition I found more than one answer to the SELECT query\n";
result=RESULT_UNKNOWN;
}
}
else {
QString myQuery;
myQuery = QString(SELECTXCHECK).arg(partitionName);
QSqlQuery query(myQuery);
int resultCounter = 0;
while (query.next()) {
int partition = query.value(0).toInt();
if (partition==1) {
result=RESULT_OK;
} else {
result=RESULT_ERROR;
}
resultCounter++;
}
if (resultCounter!=1) {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: in PrepareGlobal::xCheckPartition I found more than one answer to the SELECT query\n";
result=RESULT_UNKNOWN;
}
}
}
else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: dbConnection is NULL in PrepareGlobal::xCheckPartition\n";
result=RESULT_UNKNOWN;
}
return result;
}
int PrepareGlobal::checkVersions() {
return checkVersions(true);
}
int PrepareGlobal::checkVersions( bool checkO2O ){
QString icon_name;
int tibr, tobr, tecpr, tecmr, runnr, o2or;
int nextRunNumber;
int lastIovRunNumber;
int resultState=RESULT_UNKNOWN;
bool allowO2O = true;
tibr = xCheckPartition(cmbTib->currentText(), TIB_ID);
//std::cout << "tibr: " << tibr << std::endl; // debug
tobr = xCheckPartition(cmbTob->currentText(), TOB_ID);
//std::cout << "tobr: " << tobr << std::endl; // debug
tecpr = xCheckPartition(cmbTecp->currentText(), TECP_ID);
//std::cout << "tecpr: " << tecpr << std::endl; // debug
tecmr = xCheckPartition(cmbTecm->currentText(), TECM_ID);
//std::cout << "tecmr: " << tecmr << std::endl; // debug
runnr=getRunNumbers(nextRunNumber, lastIovRunNumber);
//std::cout << "runnr: " << runnr << std::endl; // debug
if (checkO2O) {
o2or = xCheckPartition(O2O_ID, O2O_ID);
if ((o2or==RESULT_OK)&&(nextRunNumber==lastIovRunNumber)) {
allowO2O = false;
}
} else {
o2or = RESULT_UNKNOWN;
}
// DEBUG
//o2or = RESULT_OK;
// END DEBUG
if ((tibr==RESULT_OK)&&
(tobr==RESULT_OK)&&
(tecpr==RESULT_OK)&&
(tecmr==RESULT_OK)&&
(o2or==RESULT_OK)) {
resultState=RESULT_OK;
}
if ((tibr==RESULT_ERROR)||
(tobr==RESULT_ERROR)||
(tecpr==RESULT_ERROR)||
(tecmr==RESULT_ERROR)||
(o2or==RESULT_ERROR)){
resultState=RESULT_ERROR;
}
if ((tibr==RESULT_UNKNOWN) ||
(tobr==RESULT_UNKNOWN) ||
(tecpr==RESULT_UNKNOWN)||
(tecmr==RESULT_UNKNOWN)||
(runnr==RESULT_UNKNOWN)||
(o2or==RESULT_UNKNOWN)){
resultState=RESULT_UNKNOWN;
}
if ((tibr==RESULT_OK)&&
(tobr==RESULT_OK)&&
(tecpr==RESULT_OK)&&
(tecmr==RESULT_OK)&&
(o2or==RESULT_UNKNOWN)) {
resultState=RESULT_ALMOST_OK;
}
// TODO: update the partition names if resultState==RESULT_OK
displayStatus(resultState, nextRunNumber, lastIovRunNumber, allowO2O);
return resultState;
}
int PrepareGlobal::getRunNumbers ( int &nextRunNumber, int &lastIovRunNumber ) {
int result=RESULT_UNKNOWN;
nextRunNumber = -1;
lastIovRunNumber = -1;
if (DbConnection::Inst()->dbConnected()) {
QString myQuery;
myQuery = QString(SELECTNEXTRUNNUMBER);
QSqlQuery query(myQuery);
int resultCounter = 0;
while (query.next()) {
nextRunNumber = query.value(0).toInt();
lastIovRunNumber = query.value(1).toInt();
resultCounter++;
}
if (resultCounter==1) result=RESULT_OK;
else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: in PrepareGlobal::getRunNumbers I found more that one answer to the SELECT query\n";
result=RESULT_UNKNOWN;
}
}
else if(Debug::Inst()->getEnabled()) qDebug() << "ERROR dbConnection is NULL in PrepareGlobal::getRunNumbers\n";
return result;
}
void PrepareGlobal::cacheOldConfiguration() {
for(int i = TIBRR; i <= TECMMSM; ++i) iOldConfiguration[i] = configuration[i]->currentIndex();
}
void PrepareGlobal::on_btnAllToGlobal_clicked()
{
// set route to SLINK64
setAllToReadout(SLINK64);
// set Mode/SuperMode to ZS Normal
setAllToModeSuperMode(readoutModes[ZS_NORMAL]);
readoutChanged();
}
void PrepareGlobal::on_btnAllToLocal_clicked()
{
// set route to VME
//setAllToReadout(VME);
setAllToModeSuperMode(readoutModes[VR]);
readoutChanged();
//displayStatus(RESULT_WARNING);
}
void PrepareGlobal::setAllToModeSuperMode(int modeSuperMode)
{
if(cmbTib->currentText() != NONE_STRING) comboBoxMSMTib ->setCurrentIndex(modeSuperMode);
if(cmbTob->currentText() != NONE_STRING) comboBoxMSMTob ->setCurrentIndex(modeSuperMode);
if(cmbTecp->currentText() != NONE_STRING) comboBoxMSMTecp->setCurrentIndex(modeSuperMode);
if(cmbTecm->currentText() != NONE_STRING) comboBoxMSMTecm->setCurrentIndex(modeSuperMode);
}
void PrepareGlobal::setAllToReadout(int readoutMode)
{
if(cmbTib->currentText() != NONE_STRING) comboBoxReadRouteTib ->setCurrentIndex(readoutMode);
if(cmbTob->currentText() != NONE_STRING) comboBoxReadRouteTob ->setCurrentIndex(readoutMode);
if(cmbTecp->currentText() != NONE_STRING) comboBoxReadRouteTecp->setCurrentIndex(readoutMode);
if(cmbTecm->currentText() != NONE_STRING) comboBoxReadRouteTecm->setCurrentIndex(readoutMode);
}
bool PrepareGlobal::preparePartitionState(QString partitionName, QString subDetector, int nextRunNumber) {
bool result = false;
if (DbConnection::Inst()->dbConnected()) {
int existingEntries=99;
QString myQuery;
myQuery = QString(SELECTCHECKDUPLICATE).arg(partitionName).arg(nextRunNumber);
QSqlQuery query(myQuery);
bool rset = query.exec();
if (rset) {
query.next();
existingEntries = query.value(0).toInt();
if (existingEntries>0) {
// std::cerr << "There is already " << existingEntries << " entry with the same properties. Skipping the insertion" << std::endl; // debug
result = true;
}
if (existingEntries>1) {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: There are nore than 1 partition with the same state (" << existingEntries << "): either the check is wrong or the database is corrupted.\n";
}
}
else {
if(Debug::Inst()->getEnabled()) qDebug() << "Could not count existing entries in o2opartition table. Skipping insertion\n"; // error message
existingEntries = 99;
result = false;
}
if (existingEntries==0) {
myQuery = QString(EXECINSERTOPERATION).arg(partitionName).arg(subDetector).arg(nextRunNumber);
QSqlQuery query2(myQuery);
query2.exec();
DbConnection::Inst()->dbConnection().commit();
result=true;
}
}
else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR dbConnection is NULL in PrepareGlobal::preparePartitionState\n";
}
return result;
}
bool PrepareGlobal::confirmO2O(int nextRunNumber) {
bool result = false;
if (DbConnection::Inst()->dbConnected()) {
QString myQuery;
// TODO: check if the o2o was already confirmed
myQuery = QString(EXECCONFIRMO2O).arg(nextRunNumber);
// std::cerr << myQuery.latin1() << std::endl; // debug
QSqlQuery query(myQuery);
query.exec();
DbConnection::Inst()->dbConnection().commit();
result=true;
}
else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR dbConnection is NULL in PrepareGlobal::confirmO2O\n";
}
return result;
}
QString PrepareGlobal::createCfgLines(QString subDetectorShort, QString partitionName,
int fecMajor, int fecMinor,
int fedMajor, int fedMinor,
int cablingMajor, int cablingMinor,
int dcuMajor, int dcuMinor,
int maskMajor, int maskMinor,
int dcuPsuMajor, int dcuPsuMinor){
QString cfgLines;
cfgLines = QString("\tPart%1= cms.untracked.PSet(\\\n").arg(subDetectorShort);
cfgLines += QString("\t\tPartitionName = cms.untracked.string(\"%1\"),\\\n").arg(partitionName);
cfgLines += QString("\t\tForceCurrentState = cms.untracked.bool(False),\\\n");
cfgLines += QString("\t\tForceVersions = cms.untracked.bool(True), \\\n");
cfgLines += QString("\t\tCablingVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(cablingMajor).arg(cablingMinor);
cfgLines += QString("\t\tFecVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(fecMajor).arg(fecMinor);
cfgLines += QString("\t\tFedVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(fedMajor).arg(fedMinor);
cfgLines += QString("\t\tDcuDetIdsVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(dcuMajor).arg(dcuMinor);
cfgLines += QString("\t\tMaskVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(maskMajor).arg(maskMinor);
cfgLines += QString("\t\tDcuPsuMapVersion = cms.untracked.vuint32(%1,%2)\\\n").arg(dcuPsuMajor).arg(dcuPsuMinor);
cfgLines += QString("\t\t\\\n\t)\\\n");
return cfgLines;
}
int PrepareGlobal::getVersions(QString partitionName, int runNumber,
int& fecMajor, int& fecMinor,
int& fedMajor, int& fedMinor,
int& cablingMajor, int& cablingMinor,
int& dcuMajor, int& dcuMinor,
int& maskMajor, int& maskMinor,
int& dcuPsuMajor, int& dcuPsuMinor){
int result = RESULT_UNKNOWN;
if (DbConnection::Inst()->dbConnected()) {
QString myQuery;
myQuery = QString(SELECTLATESTVERSIONS).arg(runNumber).arg(partitionName);
QSqlQuery query(myQuery);
bool rset = query.exec();
int resultCounter = 0;
if (rset) {
while (query.next()) {
fecMajor = query.value(0).toInt();
fecMinor = query.value(1).toInt();
fedMajor = query.value(2).toInt();
fedMinor = query.value(3).toInt();
cablingMajor = query.value(4).toInt();
cablingMinor = query.value(5).toInt();
dcuMajor = query.value(6).toInt();
dcuMinor = query.value(7).toInt();
dcuPsuMajor = query.value(8).toInt();
dcuPsuMinor = query.value(9).toInt();
maskMajor = query.value(10).toInt();
maskMinor = query.value(11).toInt();
resultCounter++;
}
}
if (resultCounter==1) {
result=RESULT_OK;
} else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: in PrepareGlobal::getVersions "
<< "I found more that one answer to the SELECT query\n";
result=RESULT_UNKNOWN;
}
} else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR dbConnection is NULL "
<< "in PrepareGlobal::getVersions\n";
}
return result;
}
QString PrepareGlobal::createCfgLines(QString subDetectorShort, QString partitionName,
int runNumber, bool& isValid, bool &isFirst) {
int fecMajor=0;
int fecMinor=0;
int fedMajor=0;
int fedMinor=0;
int cablingMajor=0;
int cablingMinor=0;
int dcuMajor=0;
int dcuMinor=0;
int dcuPsuMajor=0;
int dcuPsuMinor=0;
int maskMajor=0;
int maskMinor=0;
int result = RESULT_UNKNOWN;
QString cfgLines=QString("");
if (DbConnection::Inst()->dbConnected()) {
QString myQuery;
myQuery = QString(SELECTLATESTVERSIONS).arg(runNumber).arg(partitionName);
QSqlQuery query(myQuery);
bool rset = query.exec();
int resultCounter = 0;
if (rset) {
while (query.next()) {
fecMajor = query.value(0).toInt();
fecMinor = query.value(1).toInt();
fedMajor = query.value(2).toInt();
fedMinor = query.value(3).toInt();
cablingMajor = query.value(4).toInt();
cablingMinor = query.value(5).toInt();
dcuMajor = query.value(6).toInt();
dcuMinor = query.value(7).toInt();
dcuPsuMajor = query.value(8).toInt();
dcuPsuMinor = query.value(9).toInt();
maskMajor = query.value(10).toInt();
maskMinor = query.value(11).toInt();
resultCounter++;
}
}
if (resultCounter==1) {
result=RESULT_OK;
} else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR: in PrepareGlobal::getVersions "
<< "I found more that one answer to the SELECT query\n";
result=RESULT_UNKNOWN;
}
} else {
if(Debug::Inst()->getEnabled()) qDebug() << "ERROR dbConnection is NULL "
<< "in PrepareGlobal::getVersions\n";
}
if (result==RESULT_OK) {
//cfgLines = QString::QString(Form("%s",(isFirst ? "\\\n" : ",\\\n") ));
cfgLines = QString("%1").arg( (isFirst ? "\\\n" : ",\\\n"));
cfgLines += QString("\tPart%1= cms.untracked.PSet(\\\n").arg(subDetectorShort);
cfgLines += QString("\t\tPartitionName = cms.untracked.string(\"%1\"),\\\n").arg(partitionName);
cfgLines += QString("\t\tForceCurrentState = cms.untracked.bool(False),\\\n");
cfgLines += QString("\t\tForceVersions = cms.untracked.bool(True), \\\n");
cfgLines += QString("\t\tCablingVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(cablingMajor).arg(cablingMinor);
cfgLines += QString("\t\tFecVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(fecMajor).arg(fecMinor);
cfgLines += QString("\t\tFedVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(fedMajor).arg(fedMinor);
cfgLines += QString("\t\tDcuDetIdsVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(dcuMajor).arg(dcuMinor);
cfgLines += QString("\t\tMaskVersion = cms.untracked.vuint32(%1,%2),\\\n").arg(maskMajor).arg(maskMinor);
cfgLines += QString("\t\tDcuPsuMapVersion = cms.untracked.vuint32(%1,%2)\\\n").arg(dcuPsuMajor).arg(dcuPsuMinor);
cfgLines += QString("\t\t\\\n\t)");
if(isFirst == true) isFirst = false;
} else {
isValid = false;
}
return cfgLines;
}
void PrepareGlobal::on_btnSetConf_clicked() {
int nextRun, lastIovRun, result;
QString partitionName;
/* int fecMajor; int fecMinor; */