forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.cxx
More file actions
1234 lines (1228 loc) · 37.8 KB
/
Configuration.cxx
File metadata and controls
1234 lines (1228 loc) · 37.8 KB
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
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file Configuration.cxx
/// \author Roman Lietava
#include "DataFormatsCTP/Configuration.h"
#include "CCDB/CcdbApi.h"
#include "CCDB/BasicCCDBManager.h"
#include <sstream>
#include <regex>
#include "CommonUtils/StringUtils.h"
#include <fairlogger/Logger.h>
#include <iostream>
using namespace o2::ctp;
//
const std::map<std::string, std::string> CTPInput::run2DetToRun3Det = {{"T", "FT0"}, {"V", "FV0"}, {"U", "FDD"}, {"E", "EMC"}, {"D", "EMC"}, {"H", "TRD"}, {"O", "TOF"}, {"P", "PHS"}, {"Z", "ZDC"}};
const std::map<std::string, std::string> CTPConfiguration::detName2LTG = {{"FV0", "1"}, {"FT0", "2"}, {"FDD", "3"}, {"ITS", "4"}, {"TOF", "5"}, {"MFT", "6"}, {"TPC", "7"}, {"MCH", "8"}, {"MID", "9"}, {"TST", "10"}, {"TRD", "13"}, {"HMP", "14"}, {"ZDC", "15"}, {"PHS", "16"}, {"EMC", "17"}, {"CPV", "18"}};
//
bool CTPConfiguration::isDetector(const o2::detectors::DetID& det)
{
bool isdet = det.getID() >= det.getNDetectors();
isdet |= det.getID() < 0;
if (isdet) {
LOG(error) << " Detector does not exist: " << det.getID();
return false;
}
return true;
}
void CTPConfiguration::capitaliseString(std::string& str)
{
for (auto& c : str) {
c = std::toupper(c);
}
}
bool CTPConfiguration::isNumber(const std::string& s)
{
return !s.empty() && std::find_if(s.begin(),
s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
}
//
int BCMask::setBCmask(std::vector<std::string>& tokens)
{
BCmask.reset();
name = tokens[1];
bool coded = tokens[2].find("L") != std::string::npos;
coded |= tokens[2].find("H") != std::string::npos;
std::cout << "coded:" << coded << std::endl;
if (coded) {
// jusko notation
std::string bcmaskstr = tokens[2];
size_t pos = 0;
size_t posnext = 0;
int bccur = 0;
while (bccur < 3564) {
// std::cout << "pos:" << pos << std::endl;
size_t posH = bcmaskstr.find('H', pos);
size_t posL = bcmaskstr.find('L', pos);
// std::cout << "H:" << posH << " L:" << posL << std::endl;
bool b = 1;
posnext = posH;
if (posL < posH) {
posnext = posL;
b = 0;
}
std::string bcsub = bcmaskstr.substr(pos, posnext - pos);
// std::cout << "bcsub:" << bcsub << " b:" << b << std::endl;
int bcrange = 0;
try {
bcrange = std::stoull(bcsub);
} catch (...) {
LOG(warning) << "problem in bcmask decoding H:" << posH << " posL:" << posL << " bcsub:" << bcsub;
return 1;
}
if (b) {
for (int bc = bccur; bc < bccur + bcrange; bc++) {
try {
BCmask.set(bc, 1);
} catch (...) {
LOG(warning) << "BC mask decoding to big bc:" << bc;
}
}
}
bccur += bcrange;
pos = posnext + 1;
// std::cout << "bccur:" << bccur << std::endl;
}
} else {
// list of integers
for (uint32_t i = 2; i < tokens.size(); i++) {
uint32_t bc;
try {
bc = std::stoull(tokens[i]);
} catch (...) {
LOG(info) << "mask syntax:" << i << ":" << tokens[i];
continue;
}
BCmask.set(bc, 1);
}
}
return 0;
}
void BCMask::printStream(std::ostream& stream) const
{
stream << "CTP BC mask:" << name << ":" << mask; /// << std::endl;
stream << " # of active BC:" << BCmask.count() << std::endl;
}
//
const std::set<std::string> CTPGenerator::Generators = {"bcd1m", "bcd2m", "bcd10", "bcd20", "rnd1m", "rnd2m", "rnd10", "rnd20"};
void CTPGenerator::printStream(std::ostream& stream) const
{
stream << "CTP generator:" << name << " frequency:" << frequency << std::endl;
}
//
CTPInput::CTPInput(std::string& name, std::string& det, uint32_t index)
{
this->name = name;
inputMask = (1ull << (index - 1));
detID = o2::detectors::DetID(det.c_str());
}
CTPInput::CTPInput(const char* name, const char* det, uint32_t index)
{
this->name = std::string(name);
inputMask = (1ull << (index - 1));
detID = o2::detectors::DetID(det);
}
void CTPInput::setRun3DetName(std::string& run2Name)
{
std::string run3Name = CTPInput::run2DetToRun3Det.at(run2Name);
detID = o2::detectors::DetID(run3Name.c_str());
}
void CTPInput::printStream(std::ostream& stream) const
{
stream << "CTP Input:" << name << " Detector:" << getInputDetName() << " Level:" << level << " Hardware mask:0x" << std::hex << inputMask << std::dec;
stream << " index:" << getIndex() << std::endl;
}
//
std::uint64_t CTPDescriptor::getInputsMask() const
{
uint64_t mask = 0;
for (const auto& inp : inputs) {
mask |= inp->inputMask;
}
return mask;
}
void CTPDescriptor::printStream(std::ostream& stream) const
{
stream << "CTP Descriptor:" << name << " Inputs:";
for (const auto& inp : inputs) {
stream << inp->name << " ";
}
stream << std::endl;
}
//
void CTPDetector::printStream(std::ostream& stream) const
{
stream << "CTP Detector:" << getName() << " HBaccepted:" << HBaccepted;
stream << " Mode:" << mode << " FErst:" << ferst << std::endl;
}
void CTPCluster::printStream(std::ostream& stream) const
{
stream << "CTP Cluster:" << name << " " << getClusterDetNames();
stream << " det mask:0b" << std::hex << maskCluster << " " << std::dec;
stream << " clust index:" << hwMask;
stream << std::endl;
}
void CTPClass::printStream(std::ostream& stream) const
{
stream << "CTP Class:" << name << " Hardware mask:" << classMask << " Cluster index:" << clusterIndex << " Desc index:" << descriptorIndex;
stream << " Downscale:" << downScale;
stream << " BCM:";
for (const auto& bcm : BCClassMask) {
stream << bcm->name << " ";
}
if (descriptor != nullptr) {
stream << " Descriptor:" << descriptor->name;
}
if (cluster != nullptr) {
stream << " Cluster:" << cluster->name;
}
stream << std::endl;
}
/// CTP configuration
/// Assuming Run2 format + LTG
int CTPConfiguration::addInput(std::string& inp, int clsindex, std::map<int, std::vector<int>>& descInputsIndex)
{
LOG(info) << "adding input:" << inp;
CTPInput ctpinp;
std::string sinp = inp;
;
if (inp[0] == '~') {
sinp = inp.substr(1, inp.size() - 1);
ctpinp.neg = 0;
}
if (inp[0] == 'b') { // BC downscale
ctpinp.level = "b";
ctpinp.name = inp;
} else if (inp[0] == 'r') { // randpm gen
ctpinp.level = "r";
ctpinp.name = inp;
} else if (isNumber(sinp)) { // inputs as number
int index = std::stoi(sinp);
ctpinp.name = CTPInputsConfiguration::getInputNameFromIndex100(index);
ctpinp.inputMask = 1ull << (index - 1);
ctpinp.level = ctpinp.name[0];
if (ctpinp.neg == 0) {
ctpinp.name = "~" + ctpinp.name;
}
} else { // input as string or error
ctpinp.name = inp;
int index = CTPInputsConfiguration::getInputIndexFromName(inp);
ctpinp.level = sinp[0];
ctpinp.inputMask = 1ull << (index - 1);
}
// add to desc
// check if already there
for (uint32_t i = 0; i < mInputs.size(); i++) {
if (mInputs[i].name == ctpinp.name) {
LOG(info) << "input found at:" << i;
descInputsIndex[clsindex].push_back(i);
return 0;
}
}
mInputs.push_back(ctpinp);
descInputsIndex[clsindex].push_back(mInputs.size() - 1);
LOG(info) << "input inderted at:" << mInputs.size() - 1;
return 0;
}
int CTPConfiguration::loadConfigurationRun3(const std::string& ctpconfiguration)
{
LOG(info) << "Loading CTP configuration.";
std::map<int, std::vector<int>> clsDescIndex;
CTPInputsConfiguration::initDefaultInputConfig();
mConfigString = ctpconfiguration;
std::istringstream iss(ctpconfiguration);
int ret = 0;
int level = START;
std::string line;
int ver = 0;
int iline = 0;
while (std::getline(iss, line)) {
o2::utils::Str::trim(line);
if (line.size() == 0) {
continue;
}
if (line.at(0) == '#') {
continue;
}
if (iline == 0) {
if (line.find("ver") != std::string::npos) {
ver = 1;
LOG(info) << "CTP Config vesrion:" << line;
} else {
LOG(info) << "CTP Config version: 0";
}
}
iline++;
if (ver == 0) {
ret = processConfigurationLineRun3(line, level, clsDescIndex);
} else {
ret = processConfigurationLineRun3v2(line, level, clsDescIndex);
}
if (ret) {
return ret;
}
}
if (ver == 0) {
for (auto& cls : mCTPClasses) {
cls.cluster = &mClusters[cls.clusterIndex];
if (cls.descriptorIndex != 0xff) {
cls.descriptor = &mDescriptors[cls.descriptorIndex];
if (cls.getIndex() != 0xff) {
for (auto const& inp : clsDescIndex[cls.getIndex()]) {
mDescriptors.at(cls.descriptorIndex).inputs.push_back(&mInputs.at(inp));
}
}
}
}
createInputsInDecriptorsFromNames();
} else {
for (auto& cls : mCTPClasses) {
cls.cluster = &mClusters[cls.clusterIndex];
}
}
return ret;
}
int CTPConfiguration::processConfigurationLineRun3(std::string& line, int& level, std::map<int, std::vector<int>>& descInputsIndex)
{
LOG(info) << "Processing line";
LOG(info) << "line:" << line << " lev:" << level;
//
std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
size_t ntokens = tokens.size();
if (ntokens == 0) {
LOG(warning) << "# of tokens zero in line:" << line;
return 0;
}
size_t first;
if (((first = line.find("run")) != std::string::npos) && (level == START)) {
level = RUN;
} else if ((line.find("inp") != std::string::npos) && ((level == RUN) || (level == INPUTS))) {
level = INPUTS;
} else if (((first = line.find("bcm")) != std::string::npos) && ((level == RUN) || (level == INPUTS) || (level == MASKS))) {
level = MASKS;
} else if (CTPGenerator::Generators.count(tokens[0]) && ((level == RUN) || (level == INPUTS) || (level == MASKS) || (level == GENS))) {
level = GENS;
} else if ((first = line.find("LTG")) != std::string::npos) {
level = LTG;
} else if ((first = line.find("cluster")) != std::string::npos) {
level = CLUSTER;
} else {
bool knownlevels = ((level == LTGitems) || (level == CLASS));
if (knownlevels == false) {
level = UNKNOWN;
}
}
LOG(info) << "Level:" << level;
switch (level) {
case RUN: {
try {
mRunNumber = std::stoul(tokens[1]);
} catch (...) {
LOG(error) << "RUN:" << tokens[1] << std::endl;
}
level = RUN;
break;
}
case INPUTS: {
level = INPUTS;
if (tokens.size() < 3) {
LOG(error) << "Wrong input line:" << line;
break;
}
CTPInput ctpinp;
ctpinp.name = tokens[1];
ctpinp.level = tokens[1][0];
std::string run2Name{tokens[1][1]};
ctpinp.setRun3DetName(run2Name);
uint32_t index = std::stoul(tokens[2]);
ctpinp.inputMask = (1ull << (index - 1));
mInputs.push_back(ctpinp);
LOG(info) << "Input:" << ctpinp.name << " index:" << index;
break;
}
case MASKS: {
BCMask bcmask;
if (tokens.size() < 3) {
LOG(error) << "Wrong bc mask:" << line;
break;
}
bcmask.name = tokens[1];
bool coded = tokens[2].find("L") != std::string::npos;
coded |= tokens[2].find("H") != std::string::npos;
// std::cout << "coded:" << coded << std::endl;
if (coded) {
// jusko notation
} else {
// list of integers
for (uint32_t i = 2; i < ntokens; i++) {
uint32_t bc;
try {
bc = std::stoull(tokens[i]);
} catch (...) {
LOG(info) << "mask syntax:" << i << ":" << tokens[i];
continue;
}
bcmask.BCmask.set(bc, 1);
}
}
mBCMasks.push_back(bcmask);
LOG(info) << "BC mask added:" << bcmask.name;
break;
}
case GENS: {
CTPGenerator gen;
gen.name = tokens[0];
gen.frequency = tokens[1];
LOG(info) << "Gen added:" << line;
break;
}
case LTG: {
CTPDetector ctpdet;
std::string detname = tokens[1];
capitaliseString(detname);
o2::detectors::DetID det(detname.c_str());
if (isDetector(det)) {
ctpdet.detID = det.getID();
LOG(info) << "Detector found:" << det.getID() << " " << detname;
} else {
LOG(info) << "Unknown detectors:" << line;
}
mDetectors.push_back(ctpdet);
level = LTGitems;
break;
}
case LTGitems: {
if (ntokens == 1) {
mDetectors.back().mode = tokens[0];
}
LOG(info) << "LTGitem:" << line;
break;
}
case CLUSTER: {
CTPCluster cluster;
try {
cluster.hwMask = std::stoull(tokens[0]);
} catch (...) {
LOG(info) << "Cluster syntax error:" << line;
return level;
}
LOG(info) << "Cluster:" << line;
cluster.name = tokens[2];
o2::detectors::DetID::mask_t mask;
for (uint32_t item = 3; item < ntokens; item++) {
std::string detname = tokens[item];
capitaliseString(detname);
// LOG(info) << "Detector:" << detname;
o2::detectors::DetID det(detname.c_str());
isDetector(det);
mask |= det.getMask();
}
cluster.maskCluster = mask;
mClusters.push_back(cluster);
level = CLASS;
// LOG(info) << "Cluster done:" << cluster.name << std::endl;
break;
}
case CLASS: {
// add to the last cluster
if (tokens.size() < 3) {
LOG(error) << "CTPClass: less than 3 items in class:" << line;
break;
}
uint64_t index;
try {
index = std::stoull(tokens[0]);
} catch (...) {
LOG(info) << "Class syntax error:" << line;
return level;
}
LOG(info) << "Class:" << line;
CTPClass cls;
cls.classMask = 1ull << index;
cls.name = tokens[1];
cls.clusterIndex = mClusters.size() - 1;
CTPDescriptor desc;
desc.name = "d" + cls.name;
// LOG(info) << "point:" << cls.cluster << " " << &mClusters.front();
for (uint32_t i = 2; i < tokens.size(); i++) {
std::string token = tokens[i];
bool isGenerator = 0;
for (auto const& gen : CTPGenerator::Generators) {
if (token.find(gen) != std::string::npos) {
isGenerator = 1;
break;
}
}
if (isGenerator) {
addInput(token, index, descInputsIndex);
LOG(info) << "Class generator found:" << desc.name;
} else if (token.find("~") != std::string::npos) { // inverted input
// std::cout << "Inverted input" << std::endl;
addInput(token, index, descInputsIndex);
} else if (isNumber(token)) { // normal input as number
// std::cout << "Normal input" << std::endl;
addInput(token, index, descInputsIndex);
// LOG(info) << "Class input descriptor:" << mDescriptors[mDescriptors.size() - 1].name;
} else if (token.find("0x") != std::string::npos) { // downscale
// std::cout << "Downscale" << std::endl;
cls.downScale = std::stoul(token, nullptr, 16);
} else if (token.find("bcm") != std::string::npos) { // bcmask
// std::cout << "Mask" << std::endl;
uint32_t i = 0;
for (auto const& bcm : mBCMasks) {
if (bcm.name == token) {
cls.BCClassMask.push_back(&bcm);
LOG(info) << "Class BCMask found:" << token;
break;
}
i++;
}
if (i == mBCMasks.size()) {
LOG(error) << "Class BCMask NOT found:" << token << " assuming input";
}
} else { // input as string or descriptor
addInput(token, index, descInputsIndex);
}
}
mDescriptors.push_back(desc);
cls.descriptorIndex = mDescriptors.size() - 1;
//
mCTPClasses.push_back(cls);
break;
}
default: {
LOG(info) << "unknown line:" << line;
}
}
return 0;
}
int CTPConfiguration::processConfigurationLineRun3v2(std::string& line, int& level, std::map<int, std::vector<int>>& descInputsIndex)
{
LOG(debug) << "Processing line";
LOG(debug) << "line:" << line << " lev:" << level;
//
std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
size_t ntokens = tokens.size();
if (ntokens == 0) {
LOG(warning) << "# of tokens zero in line:" << line;
return 0;
}
size_t first;
if (((first = line.find("ver")) != std::string::npos) && (level == START)) {
mVersion = line;
// std::cout << "debug:" << mVersion << std::endl;
level = VERSION;
return 0;
} else if (((first = line.find("run")) != std::string::npos) && (level == VERSION)) {
level = RUN;
} else if ((line.find("INPUTS") != std::string::npos) && (level == RUN)) {
level = INPUTS;
return 0;
} else if ((line.find("inp") != std::string::npos) && (level == INPUTS)) {
level = INPUTS;
} else if ((line.find("BCMASKS") != std::string::npos) && ((level == INPUTS) || (level == RUN))) {
level = MASKS;
return 0;
} else if (((first = line.find("bcm")) != std::string::npos) && (level == MASKS)) {
level = MASKS;
} else if (line.find("GENS") != std::string::npos) {
level = GENS;
return 0;
} else if (CTPGenerator::Generators.count(tokens[0]) && (level == GENS)) {
level = GENS;
} else if (line.find("DESCRIPTORS") != std::string::npos) {
level = DESCRIPTORS;
return 0;
} else if ((tokens[0][0] == 'D') && (level == DESCRIPTORS)) {
level = DESCRIPTORS;
} else if ((first = line.find("LTG")) != std::string::npos) {
level = LTG;
} else if ((first = line.find("cluster")) != std::string::npos) {
level = CLUSTER;
} else {
bool knownlevels = ((level == LTGitems) || (level == CLASS));
if (knownlevels == false) {
level = UNKNOWN;
}
}
LOG(debug) << "Level:" << level;
switch (level) {
case VERSION: {
break;
}
case RUN: {
try {
mRunNumber = std::stoul(tokens[1]);
} catch (...) {
LOG(error) << "RUN line:" << line;
}
level = RUN;
break;
}
case INPUTS: {
level = INPUTS;
if (tokens.size() != 3) {
LOG(error) << "Wrong input line:" << line;
return 1;
}
CTPInput ctpinp;
ctpinp.name = tokens[1];
ctpinp.level = tokens[1][0];
std::string run2Name{tokens[1][1]};
ctpinp.setRun3DetName(run2Name);
uint32_t index = std::stoul(tokens[2]);
ctpinp.inputMask = (1ull << (index - 1));
mInputs.push_back(ctpinp);
LOG(debug) << "Input:" << ctpinp.name << " index:" << index;
break;
}
case MASKS: {
BCMask bcmask;
if (tokens.size() < 3) {
LOG(error) << "Wrong bc mask:" << line;
break;
}
bcmask.setBCmask(tokens);
mBCMasks.push_back(bcmask);
LOG(debug) << "BC mask added:" << bcmask.name;
break;
}
case GENS: {
CTPGenerator gen;
gen.name = tokens[0];
gen.frequency = tokens[1];
mGenerators.push_back(gen);
LOG(debug) << "Gen added:" << line;
break;
}
case DESCRIPTORS: {
if ((tokens.size() < 2)) {
if (line.find("TRUE") != std::string::npos) {
CTPDescriptor desc;
desc.name = tokens[0];
mDescriptors.push_back(desc);
break;
} else {
LOG(warning) << "Unexpected Descriptor:" << line;
break;
}
}
CTPDescriptor desc;
desc.name = tokens[0];
for (uint32_t i = 1; i < tokens.size(); i++) {
const CTPInput* inp = isInputInConfig(tokens[i]);
if (inp != nullptr) {
desc.inputs.push_back(inp);
}
}
mDescriptors.push_back(desc);
break;
}
case LTG: {
CTPDetector ctpdet;
std::string detname = tokens[1];
capitaliseString(detname);
o2::detectors::DetID det(detname.c_str());
if (isDetector(det)) {
ctpdet.detID = det.getID();
LOG(debug) << "Detector found:" << det.getID() << " " << detname;
} else {
LOG(error) << "Unknown detectors:" << line;
}
mDetectors.push_back(ctpdet);
level = LTGitems;
break;
}
case LTGitems: {
if (ntokens == 1) {
mDetectors.back().mode = tokens[0];
}
LOG(debug) << "LTGitem:" << line;
break;
}
case CLUSTER: {
CTPCluster cluster;
try {
cluster.hwMask = std::stoull(tokens[0]);
} catch (...) {
LOG(error) << "Cluster syntax error:" << line;
return level;
}
LOG(debug) << "Cluster:" << line;
cluster.name = tokens[2];
o2::detectors::DetID::mask_t mask;
for (uint32_t item = 3; item < ntokens; item++) {
std::string detname = tokens[item];
capitaliseString(detname);
// LOG(info) << "Detector:" << detname;
o2::detectors::DetID det(detname.c_str());
isDetector(det);
mask |= det.getMask();
}
cluster.maskCluster = mask;
mClusters.push_back(cluster);
level = CLASS;
// LOG(info) << "Cluster done:" << cluster.name << std::endl;
break;
}
case CLASS: {
// add to the last cluster
if (tokens.size() < 6) {
LOG(error) << "CTPClass items < 6" << line;
break;
}
uint64_t index;
try {
index = std::stoull(tokens[1]);
} catch (...) {
LOG(error) << "Class syntax error:" << line;
return level;
}
LOG(debug) << "Class:" << line;
CTPClass cls;
cls.classMask = 1ull << index;
cls.name = tokens[0];
// Descriptor
std::string descname = tokens[2];
int dindex;
if (descname.find("DTRUE") != std::string::npos) {
descname = "DTRUE";
}
const CTPDescriptor* desc = isDescriptorInConfig(descname, dindex);
if (desc != nullptr) {
cls.descriptor = desc;
cls.descriptorIndex = dindex;
}
cls.clusterIndex = mClusters.size() - 1;
// PF not member of class
std::string bcmask = tokens[5];
bcmask = bcmask.substr(1, bcmask.size() - 2);
if (bcmask.size()) {
const BCMask* bcm = isBCMaskInConfigP(bcmask);
if (bcm != nullptr) {
cls.BCClassMask.push_back(bcm);
}
}
// Down scaling
if (tokens.size() > 6) {
cls.downScale = std::stoul(tokens[6], nullptr, 16);
}
mCTPClasses.push_back(cls);
break;
}
default: {
LOG(warning) << "unknown line:" << line;
}
}
return 0;
}
void CTPConfiguration::printStream(std::ostream& stream) const
{
stream << "Configuration:" << mName << " Version:" << mVersion << std::endl;
stream << "Run:" << mRunNumber << " cfg name:" << mName << std::endl;
stream << "CTP BC masks:" << std::endl;
for (const auto& i : mBCMasks) {
i.printStream(stream);
}
stream << "CTP inputs:" << mInputs.size() << std::endl;
for (const auto& i : mInputs) {
i.printStream(stream);
}
stream << "CTP generators:" << std::endl;
for (const auto& i : mGenerators) {
i.printStream(stream);
}
stream << "CTP descriptors:" << mDescriptors.size() << std::endl;
for (const auto& i : mDescriptors) {
i.printStream(stream);
}
stream << "CTP detectors:" << mDetectors.size() << std::endl;
for (const auto& i : mDetectors) {
i.printStream(stream);
}
stream << "CTP clusters:" << std::endl;
for (const auto& i : mClusters) {
i.printStream(stream);
}
stream << "CTP classes:" << std::endl;
for (const auto& i : mCTPClasses) {
i.printStream(stream);
}
}
uint64_t CTPConfiguration::getInputMask(const std::string& name) const
{
for (auto const& inp : mInputs) {
if (inp.name == name) {
return inp.inputMask;
}
}
return 0;
}
int CTPConfiguration::getInputIndex(const std::string& name) const
{
int index = 0xff;
const CTPInput* inp = isInputInConfig(name);
if (inp != nullptr) {
index = inp->getIndex();
}
LOG(info) << "input:" << name << " index:" << index;
return index;
}
std::string CTPConfiguration::getClassNameFromIndex(int index)
{
if (index < mCTPClasses.size()) {
return mCTPClasses[index].name;
} else {
std::string name = "Cls" + std::to_string(index);
return name;
}
};
std::string CTPConfiguration::getClassNameFromHWIndex(int index)
{
for (auto& cls : mCTPClasses) {
if (cls.classMask == (1ull << index)) {
return cls.name;
}
}
std::string ret = "not found";
return ret;
}
const CTPClass* CTPConfiguration::getCTPClassFromHWIndex(int index) const
{
const CTPClass* clsfound = nullptr;
for (auto const& cls : mCTPClasses) {
if (index == cls.getIndex()) {
clsfound = &cls;
break;
}
}
return clsfound;
}
bool CTPConfiguration::isMaskInInputs(const uint64_t& mask) const
{
for (auto const& inp : mInputs) {
if (inp.inputMask == mask) {
return true;
}
}
return false;
}
bool CTPConfiguration::isBCMaskInConfig(const std::string maskname) const
{
for (auto& bcm : mBCMasks) {
if (bcm.name == maskname) {
return true;
}
}
return false;
}
const BCMask* CTPConfiguration::isBCMaskInConfigP(const std::string maskname) const
{
for (const auto& bcm : mBCMasks) {
if (bcm.name == maskname) {
LOG(info) << "isBCMaskInConfigP found:" << maskname;
return &bcm;
}
}
LOG(info) << "isBCMaskInConfigP NOT found:" << maskname;
return nullptr;
}
const CTPInput* CTPConfiguration::isInputInConfig(const std::string inpname) const
{
for (const auto& inp : mInputs) {
if (inp.name == inpname) {
LOG(info) << "isInputInConfig found:" << inpname;
return &inp;
}
}
LOG(info) << "isInputInConfig NOT found:" << inpname;
return nullptr;
}
const CTPInput* CTPConfiguration::isInputInConfig(const uint32_t index) const
{
for (const auto& inp : mInputs) {
// std::cout << "isInputINConfig:" << inp.name << " " << inp.getIndex() << " " << index << std::endl;
if (inp.getIndex() == index) {
LOG(info) << "Found input:" << inp.name << " index:" << inp.getIndex();
return &inp;
}
}
return nullptr;
}
const CTPDescriptor* CTPConfiguration::isDescriptorInConfig(const std::string descname, int& index) const
{
index = 0;
for (const auto& desc : mDescriptors) {
if (desc.name == descname) {
LOG(info) << "isDescriptorInConfig found:" << descname;
return &desc;
}
index++;
}
LOG(info) << "isDescriptorInConfig NOT found:" << descname;
return nullptr;
}
void CTPConfiguration::createInputsInDecriptorsFromNames()
// using run3 conventions for inputs
{
LOG(info) << "Creating Inputs";
for (auto& des : mDescriptors) {
if (CTPConfiguration::isNumber(des.name)) {
// parse here if more inputs
uint32_t index = std::stoul(des.name);
if (index > 100) {
index = index - 100;
}
// CTPInput* inp = const_cast<CTPInput*>(isInputInConfig(index));
LOG(info) << "Desc index:" << index;
const CTPInput* inp = isInputInConfig(index);
if (inp) {
des.inputs.push_back(inp);
} else {
LOG(warning) << "Descriptor not found:" << des.name;
}
} else {
LOG(info) << "Input is not a number:" << des.name;
}
}
}
std::map<o2::detectors::DetID::ID, std::vector<CTPInput>> CTPConfiguration::getDet2InputMap()
{
std::map<o2::detectors::DetID::ID, std::vector<CTPInput>> det2inp;
for (auto const& inp : mInputs) {
det2inp[inp.detID].push_back(inp);
}
return det2inp;
}
uint64_t CTPConfiguration::getTriggerClassMask() const
{
uint64_t clsmask = 0;
for (auto const& cls : mCTPClasses) {
clsmask |= cls.classMask;
}
return clsmask;
}
uint64_t CTPConfiguration::getTriggerClassMaskWInputs() const
{
uint64_t clsmask = 0;
for (auto const& cls : mCTPClasses) {
if (cls.name.find("TRUE") != std::string::npos) { // ignoring internal ctp generators
continue;
}
clsmask |= cls.classMask;
}
return clsmask;
}
uint64_t CTPConfiguration::getTriggerClassMaskWInputsNoTrgDets() const
{
uint64_t clsmask = 0;
for (auto const& cls : mCTPClasses) {
bool exclude = cls.name.find("TRUE") != std::string::npos; // ignoring internal ctp generators
exclude += cls.name.find("EMC") != std::string::npos;
exclude += cls.name.find("TRD") != std::string::npos;
exclude += cls.name.find("HMP") != std::string::npos;
if (!exclude)
clsmask |= cls.classMask;
}
return clsmask;
}
// Hardware positions of classes
std::vector<int> CTPConfiguration::getTriggerClassList() const
{
uint64_t clsmask = getTriggerClassMask();
std::vector<int> classlist;
for (int i = 0; i < 64; i++) {
if ((1ull << i) & clsmask) {
classlist.push_back(i);
}
}
return classlist;
}
std::vector<std::string> CTPConfiguration::getDetectorList() const
{
std::vector<std::string> detlist;
for (auto const& det : mDetectors) {
std::string sdet(det.getName());
detlist.push_back(sdet);
}
return detlist;
}
o2::detectors::DetID::mask_t CTPConfiguration::getDetectorMask() const
{
o2::detectors::DetID::mask_t mask = 0;
for (auto const& det : mDetectors) {
mask |= det.getMask();
}
return mask;
}
// This is special case of general approach:
// classmask = fin(inputmask)g
uint64_t CTPConfiguration::getClassMaskForInputMask(uint64_t inputMask) const
{
uint64_t clsmask = 0;
for (auto const& cls : mCTPClasses) {
if (cls.descriptor) {
// std::cout << cls.name << std::hex << " " << cls.descriptor->getInputsMask() << " " << inputMask << std::endl;
if (cls.descriptor->getInputsMask() & inputMask) {
clsmask += cls.classMask;
// std::cout << " clsmask:" << clsmask << std::endl;
}
}
}
return clsmask;
}
int CTPConfiguration::assignDescriptors()
{
for (auto& cls : mCTPClasses) {
cls.descriptor = &mDescriptors[cls.descriptorIndex];
}
return 0;
}
int CTPConfiguration::checkConfigConsistency() const
{
LOG(info) << "Checking consistency run:" << mRunNumber;
int ret = 0;
// All inputs used ?
// std::map<const CTPInput*, int> inputs;
std::map<std::string, int> inputs;
for (auto const& inp : mInputs) {