File indexing completed on 2023-05-29 22:27:41
0001
0002
0003
0004
0005
0006
0007 #include "SimCalorimetry/EcalSelectiveReadoutProducers/interface/namespace_ecalsrcondtools.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009
0010 #include <cassert>
0011 #include <fstream>
0012 #include <iostream>
0013 #include <algorithm>
0014
0015 constexpr int tccNum[12][12] = {
0016
0017 {36, 19, 20, 21, 22, 23, 18, 1, 2, 3, 4, 5},
0018 {24, 25, 26, 27, 28, 29, 6, 7, 8, 9, 10, 11},
0019 {30, 31, 32, 33, 34, 35, 12, 13, 14, 15, 16, 17},
0020
0021 {54, 37, 38, 39, 40, 41, -1, -1, -1, -1, -1, -1},
0022 {42, 43, 44, 45, 46, 47, -1, -1, -1, -1, -1, -1},
0023 {48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1, -1},
0024
0025 {72, 55, 56, 57, 58, 59, -1, -1, -1, -1, -1, -1},
0026 {60, 61, 62, 63, 64, 65, -1, -1, -1, -1, -1, -1},
0027 {66, 67, 68, 69, 70, 71, -1, -1, -1, -1, -1, -1},
0028
0029 {90, 73, 74, 75, 76, 77, 108, 91, 92, 93, 94, 95},
0030 {78, 79, 80, 81, 82, 83, 96, 97, 98, 99, 100, 101},
0031 {84, 85, 86, 87, 88, 89, 102, 103, 104, 105, 106, 107}
0032 };
0033
0034 constexpr int dccNum[12][12] = {
0035 {1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1},
0036 {4, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1},
0037 {7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1},
0038 {10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1},
0039 {16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1},
0040 {22, 23, 24, 25, 26, 27, -1, -1, -1, -1, -1, -1},
0041 {28, 29, 30, 31, 32, 33, -1, -1, -1, -1, -1, -1},
0042 {34, 35, 36, 37, 38, 39, -1, -1, -1, -1, -1, -1},
0043 {40, 41, 42, 43, 44, 45, -1, -1, -1, -1, -1, -1},
0044 {46, 47, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1},
0045 {49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1},
0046 {52, 53, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1}
0047 };
0048
0049 using namespace std;
0050
0051 namespace ecalsrcondtools {
0052
0053 string tokenize(const string& s, const string& delim, int& pos) {
0054 if (pos < 0)
0055 return "";
0056 int pos0 = pos;
0057 int len = s.size();
0058
0059 while (pos0 < len && find(delim.begin(), delim.end(), s[pos0]) != delim.end()) {
0060 ++pos0;
0061 }
0062 if (pos0 == len)
0063 return "";
0064 pos = s.find_first_of(delim, pos0);
0065 return s.substr(pos0, (pos > 0 ? pos : len) - pos0);
0066 }
0067
0068 std::string trim(std::string s) {
0069 std::string::size_type pos0 = s.find_first_not_of(" \t");
0070 if (pos0 == string::npos) {
0071 pos0 = 0;
0072 }
0073 string::size_type pos1 = s.find_last_not_of(" \t") + 1;
0074 if (pos1 == string::npos) {
0075 pos1 = pos0;
0076 }
0077 return s.substr(pos0, pos1 - pos0);
0078 }
0079
0080 void importParameterSet(EcalSRSettings& sr, const edm::ParameterSet& ps) {
0081 sr.deltaPhi_.resize(1);
0082 sr.deltaPhi_[0] = ps.getParameter<int>("deltaPhi");
0083 sr.deltaEta_.resize(1);
0084 sr.deltaEta_[0] = ps.getParameter<int>("deltaEta");
0085 sr.ecalDccZs1stSample_.resize(1);
0086 sr.ecalDccZs1stSample_[0] = ps.getParameter<int>("ecalDccZs1stSample");
0087 sr.ebDccAdcToGeV_ = ps.getParameter<double>("ebDccAdcToGeV");
0088 sr.eeDccAdcToGeV_ = ps.getParameter<double>("eeDccAdcToGeV");
0089 sr.dccNormalizedWeights_.resize(1);
0090 const std::vector<double>& w = ps.getParameter<std::vector<double> >("dccNormalizedWeights");
0091 sr.dccNormalizedWeights_[0].resize(w.size());
0092 std::copy(w.begin(), w.end(), sr.dccNormalizedWeights_[0].begin());
0093 sr.symetricZS_.resize(1);
0094 sr.symetricZS_[0] = ps.getParameter<bool>("symetricZS");
0095 sr.srpLowInterestChannelZS_.resize(2);
0096 const int eb = 0;
0097 const int ee = 1;
0098 sr.srpLowInterestChannelZS_[eb] = ps.getParameter<double>("srpBarrelLowInterestChannelZS");
0099 sr.srpLowInterestChannelZS_[ee] = ps.getParameter<double>("srpEndcapLowInterestChannelZS");
0100 sr.srpHighInterestChannelZS_.resize(2);
0101 sr.srpHighInterestChannelZS_[eb] = ps.getParameter<double>("srpBarrelHighInterestChannelZS");
0102 sr.srpHighInterestChannelZS_[ee] = ps.getParameter<double>("srpEndcapHighInterestChannelZS");
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115 sr.actions_ = ps.getParameter<std::vector<int> >("actions");
0116 }
0117
0118 void importSrpConfigFile(EcalSRSettings& sr, std::istream& f, bool d) {
0119
0120 sr.deltaEta_ = vector<int>(1, 0);
0121 sr.deltaPhi_ = vector<int>(1, 0);
0122 sr.actions_ = vector<int>(4, 0);
0123 sr.tccMasksFromConfig_ = vector<short>(EcalSRSettings::nTccs_, 0);
0124 sr.srpMasksFromConfig_ = vector<vector<short> >(EcalSRSettings::nSrps_, vector<short>(8, 0));
0125 sr.dccMasks_ = vector<short>(EcalSRSettings::nDccs_);
0126 sr.srfMasks_ = vector<short>(EcalSRSettings::nDccs_);
0127 sr.substitutionSrfs_ = vector<vector<short> >(EcalSRSettings::nSrps_, vector<short>(68, 0));
0128 sr.testerTccEmuSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
0129 sr.testerSrpEmuSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
0130 sr.testerDccTestSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
0131 sr.testerSrpTestSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
0132 sr.bxOffsets_ = vector<short>(EcalSRSettings::nSrps_, 0);
0133 sr.automaticMasks_ = 0;
0134 sr.automaticSrpSelect_ = 0;
0135
0136
0137 int iLine = 0;
0138 int iValueSet = -1;
0139 const int nValueSets = 6 * EcalSRSettings::nSrps_ + 9;
0140 string line;
0141 stringstream sErr("");
0142 while (!f.eof() && sErr.str().empty()) {
0143 getline(f, line);
0144 ++iLine;
0145 line = trim(line);
0146 if (line[0] == '#' || line.empty()) {
0147 continue;
0148 } else {
0149 ++iValueSet;
0150 }
0151 if (iValueSet >= nValueSets)
0152 break;
0153 uint32_t value;
0154 string sValue;
0155 int pos = 0;
0156 int iCh = 0;
0157 int nChs[nValueSets] = {
0158
0159 12,
0160 12,
0161 12,
0162 12,
0163 12,
0164 12,
0165 12,
0166 12,
0167 12,
0168 12,
0169 12,
0170 12,
0171
0172 8,
0173 8,
0174 8,
0175 8,
0176 8,
0177 8,
0178 8,
0179 8,
0180 8,
0181 8,
0182 8,
0183 8,
0184
0185 12,
0186 12,
0187 12,
0188 12,
0189 12,
0190 12,
0191 12,
0192 12,
0193 12,
0194 12,
0195 12,
0196 12,
0197
0198 6,
0199 6,
0200 6,
0201 6,
0202 6,
0203 6,
0204 6,
0205 6,
0206 6,
0207 6,
0208 6,
0209 6,
0210
0211 68,
0212 68,
0213 68,
0214 68,
0215 68,
0216 68,
0217 68,
0218 68,
0219 68,
0220 68,
0221 68,
0222 68,
0223
0224 4,
0225 4,
0226 4,
0227 4,
0228 4,
0229 4,
0230 4,
0231 4,
0232 4,
0233 4,
0234 4,
0235 4,
0236
0237 12,
0238
0239 1,
0240
0241 4,
0242
0243 1,
0244
0245 12,
0246
0247 12,
0248
0249 1,
0250
0251 1,
0252
0253 12,
0254 };
0255
0256 while (((sValue = tokenize(line, " \t", pos)) != string("")) && (iCh < nChs[iValueSet]) && sErr.str().empty()) {
0257 value = strtoul(sValue.c_str(), nullptr, 0);
0258 const int iSrp = iValueSet % EcalSRSettings::nSrps_;
0259 if (iValueSet < 12) {
0260 assert((unsigned)iSrp < sizeof(tccNum) / sizeof(tccNum[0]));
0261 assert((unsigned)iCh < sizeof(tccNum[0]) / sizeof(tccNum[0][0]));
0262 int tcc = tccNum[iSrp][iCh];
0263 if (tcc >= 0) {
0264 if (d)
0265 cout << "tccMasksFromConfig_[" << tcc << "] <- " << value << "\n";
0266 sr.tccMasksFromConfig_[tcc - 1] = value;
0267 }
0268 } else if (iValueSet < 24) {
0269 if (d)
0270 cout << "srpMasks_[" << iSrp << "][" << iCh << "] <- " << value << "\n";
0271 sr.srpMasksFromConfig_[iSrp][iCh] = value;
0272 } else if (iValueSet < 36) {
0273 assert((unsigned)iSrp < sizeof(dccNum) / sizeof(dccNum[0]));
0274 assert((unsigned)iCh < sizeof(dccNum[0]) / sizeof(dccNum[0][0]));
0275 int dcc = dccNum[iSrp][iCh];
0276 if (dcc > 0) {
0277 assert((unsigned)(dcc - 1) < sr.dccMasks_.size());
0278 if (d)
0279 cout << "dccMasks_[" << (dcc - 1) << "] <- " << value << "\n";
0280 sr.dccMasks_[dcc - 1] = value;
0281 }
0282 } else if (iValueSet < 48) {
0283 assert((unsigned)iSrp < sizeof(dccNum) / sizeof(dccNum[0]));
0284 assert((unsigned)iCh < sizeof(dccNum[0]) / sizeof(dccNum[0][0]));
0285 int dcc = dccNum[iSrp][iCh];
0286 if (dcc > 0) {
0287 if (d)
0288 cout << "srfMasks_[" << (dcc - 1) << "] <- " << value << "\n";
0289 assert((unsigned)(dcc - 1) < sr.srfMasks_.size());
0290 sr.srfMasks_[dcc - 1] = value;
0291 }
0292 } else if (iValueSet < 60) {
0293 assert((unsigned)iSrp < sr.substitutionSrfs_.size());
0294 assert((unsigned)iCh < sr.substitutionSrfs_[0].size());
0295 if (d)
0296 cout << "substitutionMasks_[" << iSrp << "][" << iCh << "] <- " << value << "\n";
0297 sr.substitutionSrfs_[iSrp][iCh] = value;
0298 } else if (iValueSet < 72) {
0299 switch (iCh) {
0300 case 0:
0301 assert((unsigned)iSrp < sr.testerTccEmuSrpIds_.size());
0302 if (d)
0303 cout << "testerTccEmuSrpIds_[" << iSrp << "] <- " << value << "\n";
0304 sr.testerTccEmuSrpIds_[iSrp] = value;
0305 break;
0306 case 1:
0307 assert((unsigned)iSrp < sr.testerSrpEmuSrpIds_.size());
0308 if (d)
0309 cout << "testerSrpEmuSrpIds_[" << iSrp << "] <- " << value << "\n";
0310 sr.testerSrpEmuSrpIds_[iSrp] = value;
0311 break;
0312 case 2:
0313 assert((unsigned)iSrp < sr.testerDccTestSrpIds_.size());
0314 if (d)
0315 cout << "testerDccTestSrpIds_[" << iSrp << "] <- " << value << "\n";
0316 sr.testerDccTestSrpIds_[iSrp] = value;
0317 break;
0318 case 3:
0319 assert((unsigned)iSrp < sr.testerSrpTestSrpIds_.size());
0320 if (d)
0321 cout << "testerSrpTestSrpIds_[" << iSrp << "] <- " << value << "\n";
0322 sr.testerSrpTestSrpIds_[iSrp] = value;
0323 break;
0324 default:
0325 sErr << "Syntax error in SRP system configuration "
0326 << " line " << iLine << ".";
0327 }
0328 } else if (iValueSet < 73) {
0329 assert((unsigned)iCh < sr.bxOffsets_.size());
0330 if (d)
0331 cout << "bxOffset_[" << iCh << "] <- " << value << "\n";
0332 sr.bxOffsets_[iCh] = value;
0333 } else if (iValueSet < 74) {
0334 int algo = value;
0335 switch (algo) {
0336 case 0:
0337 sr.deltaEta_[0] = sr.deltaPhi_[0] = 1;
0338 break;
0339 case 1:
0340 sr.deltaEta_[0] = sr.deltaPhi_[0] = 2;
0341 break;
0342 default:
0343 throw cms::Exception("OutOfRange")
0344 << "Value of parameter algo ," << algo << ", is invalid. Valid values are 0 and 1.";
0345 }
0346 if (d)
0347 cout << "deltaEta_[0] <- " << sr.deltaEta_[0] << "\t"
0348 << "deltaPhi_[0] <- " << sr.deltaPhi_[0] << "\n";
0349 } else if (iValueSet < 75) {
0350 assert((unsigned)iCh < sr.actions_.size());
0351 if (d)
0352 cout << "actions_[" << iCh << "] <- " << value << "\n";
0353 sr.actions_[iCh] = value;
0354 } else if (iValueSet < 76) {
0355
0356
0357
0358 } else if (iValueSet < 77) {
0359
0360
0361
0362 } else if (iValueSet < 78) {
0363
0364
0365
0366 } else if (iValueSet < 79) {
0367
0368
0369
0370 } else if (iValueSet < 80) {
0371
0372
0373
0374 } else if (iValueSet < 81) {
0375
0376
0377
0378 } else {
0379 assert(false);
0380 }
0381 ++iCh;
0382 }
0383 if (iCh != nChs[iValueSet]) {
0384 sErr << "Syntax error in imported SRP system configuration file "
0385 " line "
0386 << iLine << ".";
0387 }
0388 }
0389 if (sErr.str().empty() && iValueSet != (nValueSets - 1)) {
0390 sErr << "Syntax Error in imported SRP system configuration file "
0391 " line "
0392 << iLine << ".";
0393 }
0394 if (!sErr.str().empty())
0395 throw cms::Exception("SyntaxError") << sErr.str();
0396 }
0397
0398 double normalizeWeights(int hwWeight) {
0399
0400
0401 if (hwWeight & (1 << 11))
0402 hwWeight |= ~0xEFF;
0403 return hwWeight / 1024.;
0404 }
0405
0406 }