CMS 3D CMS Logo

EcalSRCondTools.cc
Go to the documentation of this file.
1 //emacs settings:-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  *
4  * author: Ph Gras. June, 2010
5  */
6 
9 
10 #include <cassert>
11 #include <fstream>
12 #include <iostream>
13 #include <algorithm>
14 
15 constexpr int tccNum[12][12] = {
16  /* EE- */
17  {36, 19, 20, 21, 22, 23, 18, 1, 2, 3, 4, 5}, //SRP 1
18  {24, 25, 26, 27, 28, 29, 6, 7, 8, 9, 10, 11}, //SRP 2
19  {30, 31, 32, 33, 34, 35, 12, 13, 14, 15, 16, 17}, //SRP 3
20  /* EB- */
21  {54, 37, 38, 39, 40, 41, -1, -1, -1, -1, -1, -1}, //SRP 4
22  {42, 43, 44, 45, 46, 47, -1, -1, -1, -1, -1, -1}, //SRP 5
23  {48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1, -1}, //SRP 6
24  /* EB+ */
25  {72, 55, 56, 57, 58, 59, -1, -1, -1, -1, -1, -1}, //SRP 7
26  {60, 61, 62, 63, 64, 65, -1, -1, -1, -1, -1, -1}, //SRP 8
27  {66, 67, 68, 69, 70, 71, -1, -1, -1, -1, -1, -1}, //SRP 9
28  /* EE+ */
29  {90, 73, 74, 75, 76, 77, 108, 91, 92, 93, 94, 95}, //SRP 10
30  {78, 79, 80, 81, 82, 83, 96, 97, 98, 99, 100, 101}, //SRP 11
31  {84, 85, 86, 87, 88, 89, 102, 103, 104, 105, 106, 107} //SRP 12
32 };
33 
34 constexpr int dccNum[12][12] = {
35  {1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1}, //SRP 1
36  {4, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1}, //SRP 2
37  {7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1}, //SRP 3
38  {10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1}, //SRP 4
39  {16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1}, //SRP 5
40  {22, 23, 24, 25, 26, 27, -1, -1, -1, -1, -1, -1}, //SRP 6
41  {28, 29, 30, 31, 32, 33, -1, -1, -1, -1, -1, -1}, //SRP 7
42  {34, 35, 36, 37, 38, 39, -1, -1, -1, -1, -1, -1}, //SRP 8
43  {40, 41, 42, 43, 44, 45, -1, -1, -1, -1, -1, -1}, //SRP 9
44  {46, 47, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1}, //SRP 10
45  {49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1}, //SRP 11
46  {52, 53, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1} //SRP 12
47 };
48 
49 using namespace std;
50 
51 namespace ecalsrcondtools {
52 
53  string tokenize(const string& s, const string& delim, int& pos) {
54  if (pos < 0)
55  return "";
56  int pos0 = pos;
57  int len = s.size();
58  //eats delimeters at beginning of the string
59  while (pos0 < len && find(delim.begin(), delim.end(), s[pos0]) != delim.end()) {
60  ++pos0;
61  }
62  if (pos0 == len)
63  return "";
64  pos = s.find_first_of(delim, pos0);
65  return s.substr(pos0, (pos > 0 ? pos : len) - pos0);
66  }
67 
69  std::string::size_type pos0 = s.find_first_not_of(" \t");
70  if (pos0 == string::npos) {
71  pos0 = 0;
72  }
73  string::size_type pos1 = s.find_last_not_of(" \t") + 1;
74  if (pos1 == string::npos) {
75  pos1 = pos0;
76  }
77  return s.substr(pos0, pos1 - pos0);
78  }
79 
81  sr.deltaPhi_.resize(1);
82  sr.deltaPhi_[0] = ps.getParameter<int>("deltaPhi");
83  sr.deltaEta_.resize(1);
84  sr.deltaEta_[0] = ps.getParameter<int>("deltaEta");
85  sr.ecalDccZs1stSample_.resize(1);
86  sr.ecalDccZs1stSample_[0] = ps.getParameter<int>("ecalDccZs1stSample");
87  sr.ebDccAdcToGeV_ = ps.getParameter<double>("ebDccAdcToGeV");
88  sr.eeDccAdcToGeV_ = ps.getParameter<double>("eeDccAdcToGeV");
89  sr.dccNormalizedWeights_.resize(1);
90  const std::vector<double>& w = ps.getParameter<std::vector<double> >("dccNormalizedWeights");
91  sr.dccNormalizedWeights_[0].resize(w.size());
92  std::copy(w.begin(), w.end(), sr.dccNormalizedWeights_[0].begin());
93  sr.symetricZS_.resize(1);
94  sr.symetricZS_[0] = ps.getParameter<bool>("symetricZS");
95  sr.srpLowInterestChannelZS_.resize(2);
96  const int eb = 0;
97  const int ee = 1;
98  sr.srpLowInterestChannelZS_[eb] = ps.getParameter<double>("srpBarrelLowInterestChannelZS");
99  sr.srpLowInterestChannelZS_[ee] = ps.getParameter<double>("srpEndcapLowInterestChannelZS");
100  sr.srpHighInterestChannelZS_.resize(2);
101  sr.srpHighInterestChannelZS_[eb] = ps.getParameter<double>("srpBarrelHighInterestChannelZS");
102  sr.srpHighInterestChannelZS_[ee] = ps.getParameter<double>("srpEndcapHighInterestChannelZS");
103  //sr.trigPrimBypass_.resize(1);
104  //sr.trigPrimBypass_[0] = ps.getParameter<bool >("trigPrimBypass");
105  //sr.trigPrimBypassMode_.resize(1);
106  //sr.trigPrimBypassMode_[0] = ps.getParameter<int >("trigPrimBypassMode");
107  //sr.trigPrimBypassLTH_.resize(1);
108  //sr.trigPrimBypassLTH_[0] = ps.getParameter<double >("trigPrimBypassLTH");
109  //sr.trigPrimBypassHTH_.resize(1);
110  //sr.trigPrimBypassHTH_[0] = ps.getParameter<double >("trigPrimBypassHTH");
111  //sr.trigPrimBypassWithPeakFinder_.resize(1);
112  //sr.trigPrimBypassWithPeakFinder_[0] = ps.getParameter<bool >("trigPrimBypassWithPeakFinder");
113  //sr.defaultTtf_.resize(1);
114  //sr.defaultTtf_[0] = ps.getParameter<int >("defaultTtf");
115  sr.actions_ = ps.getParameter<std::vector<int> >("actions");
116  }
117 
118  void importSrpConfigFile(EcalSRSettings& sr, std::istream& f, bool d) {
119  //initialize vectors:
120  sr.deltaEta_ = vector<int>(1, 0);
121  sr.deltaPhi_ = vector<int>(1, 0);
122  sr.actions_ = vector<int>(4, 0);
123  sr.tccMasksFromConfig_ = vector<short>(EcalSRSettings::nTccs_, 0);
124  sr.srpMasksFromConfig_ = vector<vector<short> >(EcalSRSettings::nSrps_, vector<short>(8, 0));
125  sr.dccMasks_ = vector<short>(EcalSRSettings::nDccs_);
126  sr.srfMasks_ = vector<short>(EcalSRSettings::nDccs_);
127  sr.substitutionSrfs_ = vector<vector<short> >(EcalSRSettings::nSrps_, vector<short>(68, 0));
128  sr.testerTccEmuSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
129  sr.testerSrpEmuSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
130  sr.testerDccTestSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
131  sr.testerSrpTestSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
132  sr.bxOffsets_ = vector<short>(EcalSRSettings::nSrps_, 0);
133  sr.automaticMasks_ = 0;
134  sr.automaticSrpSelect_ = 0;
135 
136  //string line;
137  int iLine = 0;
138  int iValueSet = -1;
139  const int nValueSets = 6 * EcalSRSettings::nSrps_ + 9;
140  string line;
141  stringstream sErr("");
142  while (!f.eof() && sErr.str().empty()) {
143  getline(f, line);
144  ++iLine;
145  line = trim(line);
146  if (line[0] == '#' || line.empty()) { //comment line and empty line to ignore
147  continue;
148  } else {
149  ++iValueSet;
150  }
151  if (iValueSet >= nValueSets)
152  break;
153  uint32_t value;
154  string sValue;
155  int pos = 0;
156  int iCh = 0;
157  int nChs[nValueSets] = {
158  //TCC masks: 0-11
159  12,
160  12,
161  12,
162  12,
163  12,
164  12,
165  12,
166  12,
167  12,
168  12,
169  12,
170  12,
171  //SRP masks: 12-23
172  8,
173  8,
174  8,
175  8,
176  8,
177  8,
178  8,
179  8,
180  8,
181  8,
182  8,
183  8,
184  //DCC masks: 24-35
185  12,
186  12,
187  12,
188  12,
189  12,
190  12,
191  12,
192  12,
193  12,
194  12,
195  12,
196  12,
197  //SRF Masks: 36-47
198  6,
199  6,
200  6,
201  6,
202  6,
203  6,
204  6,
205  6,
206  6,
207  6,
208  6,
209  6,
210  //substitution SRFs: 48-59
211  68,
212  68,
213  68,
214  68,
215  68,
216  68,
217  68,
218  68,
219  68,
220  68,
221  68,
222  68,
223  //Tester card to emulate or test: 60-71
224  4,
225  4,
226  4,
227  4,
228  4,
229  4,
230  4,
231  4,
232  4,
233  4,
234  4,
235  4,
236  //Bx offsets: 72
237  12,
238  //algo type: 73
239  1,
240  //action flags: 74
241  4,
242  //pattern file directory: 75
243  1,
244  //VME slots: 76
245  12,
246  //card types: 77
247  12,
248  //config Mode
249  1,
250  //VME Interface card
251  1,
252  //Spy Mode
253  12,
254  };
255 
256  while (((sValue = tokenize(line, " \t", pos)) != string("")) && (iCh < nChs[iValueSet]) && sErr.str().empty()) {
257  value = strtoul(sValue.c_str(), nullptr, 0);
258  const int iSrp = iValueSet % EcalSRSettings::nSrps_;
259  if (iValueSet < 12) { //TCC
260  assert((unsigned)iSrp < sizeof(tccNum) / sizeof(tccNum[0]));
261  assert((unsigned)iCh < sizeof(tccNum[0]) / sizeof(tccNum[0][0]));
262  int tcc = tccNum[iSrp][iCh];
263  if (tcc >= 0) {
264  if (d)
265  cout << "tccMasksFromConfig_[" << tcc << "] <- " << value << "\n";
266  sr.tccMasksFromConfig_[tcc - 1] = value;
267  }
268  } else if (iValueSet < 24) { //SRP-SRP
269  if (d)
270  cout << "srpMasks_[" << iSrp << "][" << iCh << "] <- " << value << "\n";
271  sr.srpMasksFromConfig_[iSrp][iCh] = value;
272  } else if (iValueSet < 36) { //DCC output
273  assert((unsigned)iSrp < sizeof(dccNum) / sizeof(dccNum[0]));
274  assert((unsigned)iCh < sizeof(dccNum[0]) / sizeof(dccNum[0][0]));
275  int dcc = dccNum[iSrp][iCh];
276  if (dcc > 0) {
277  assert((unsigned)(dcc - 1) < sr.dccMasks_.size());
278  if (d)
279  cout << "dccMasks_[" << (dcc - 1) << "] <- " << value << "\n";
280  sr.dccMasks_[dcc - 1] = value;
281  }
282  } else if (iValueSet < 48) { //SRF masks
283  assert((unsigned)iSrp < sizeof(dccNum) / sizeof(dccNum[0]));
284  assert((unsigned)iCh < sizeof(dccNum[0]) / sizeof(dccNum[0][0]));
285  int dcc = dccNum[iSrp][iCh];
286  if (dcc > 0) {
287  if (d)
288  cout << "srfMasks_[" << (dcc - 1) << "] <- " << value << "\n";
289  assert((unsigned)(dcc - 1) < sr.srfMasks_.size());
290  sr.srfMasks_[dcc - 1] = value;
291  }
292  } else if (iValueSet < 60) { //substiution SRFs
293  assert((unsigned)iSrp < sr.substitutionSrfs_.size());
294  assert((unsigned)iCh < sr.substitutionSrfs_[0].size());
295  if (d)
296  cout << "substitutionMasks_[" << iSrp << "][" << iCh << "] <- " << value << "\n";
297  sr.substitutionSrfs_[iSrp][iCh] = value;
298  } else if (iValueSet < 72) { //Tester card config
299  switch (iCh) {
300  case 0:
301  assert((unsigned)iSrp < sr.testerTccEmuSrpIds_.size());
302  if (d)
303  cout << "testerTccEmuSrpIds_[" << iSrp << "] <- " << value << "\n";
304  sr.testerTccEmuSrpIds_[iSrp] = value;
305  break;
306  case 1:
307  assert((unsigned)iSrp < sr.testerSrpEmuSrpIds_.size());
308  if (d)
309  cout << "testerSrpEmuSrpIds_[" << iSrp << "] <- " << value << "\n";
310  sr.testerSrpEmuSrpIds_[iSrp] = value;
311  break;
312  case 2:
313  assert((unsigned)iSrp < sr.testerDccTestSrpIds_.size());
314  if (d)
315  cout << "testerDccTestSrpIds_[" << iSrp << "] <- " << value << "\n";
316  sr.testerDccTestSrpIds_[iSrp] = value;
317  break;
318  case 3:
319  assert((unsigned)iSrp < sr.testerSrpTestSrpIds_.size());
320  if (d)
321  cout << "testerSrpTestSrpIds_[" << iSrp << "] <- " << value << "\n";
322  sr.testerSrpTestSrpIds_[iSrp] = value;
323  break;
324  default:
325  sErr << "Syntax error in SRP system configuration "
326  << " line " << iLine << ".";
327  }
328  } else if (iValueSet < 73) { //bx offsets
329  assert((unsigned)iCh < sr.bxOffsets_.size());
330  if (d)
331  cout << "bxOffset_[" << iCh << "] <- " << value << "\n";
332  sr.bxOffsets_[iCh] = value;
333  } else if (iValueSet < 74) { //algo type
334  int algo = value;
335  switch (algo) {
336  case 0:
337  sr.deltaEta_[0] = sr.deltaPhi_[0] = 1;
338  break;
339  case 1:
340  sr.deltaEta_[0] = sr.deltaPhi_[0] = 2;
341  break;
342  default:
343  throw cms::Exception("OutOfRange")
344  << "Value of parameter algo ," << algo << ", is invalid. Valid values are 0 and 1.";
345  }
346  if (d)
347  cout << "deltaEta_[0] <- " << sr.deltaEta_[0] << "\t"
348  << "deltaPhi_[0] <- " << sr.deltaPhi_[0] << "\n";
349  } else if (iValueSet < 75) { //action flags
350  assert((unsigned)iCh < sr.actions_.size());
351  if (d)
352  cout << "actions_[" << iCh << "] <- " << value << "\n";
353  sr.actions_[iCh] = value;
354  } else if (iValueSet < 76) { //pattern file directory
355  // emuDir_ = sValue;
356  // if(d) cout << "emuDir_ <= "
357  // << value << "\n";
358  } else if (iValueSet < 77) { //VME slots
359  // slotIds_[iCh] = value;
360  // if(d) cout << "slotIds_[" << iCh << "] <= "
361  // << value << "\n";
362  } else if (iValueSet < 78) { //card types
363  // cardTypes_[iCh] = sValue[0];
364  // if(d) cout << "cardTypes_[" << iCh << "] <= "
365  // << value << "\n";
366  } else if (iValueSet < 79) { //config mode
367  //TODO validity check on value
368  // configMode_ = (ConfigMode)value;
369  // if(d) cout << "config mode <= " << value << "\n";
370  } else if (iValueSet < 80) { //VME I/F
371  //TODO validity check on value
372  // vmeInterface_ = (Vme::type_t)value;
373  //if(d) cout << "Vme Interface code <= " << value << "\n";
374  } else if (iValueSet < 81) { //Spy Mode
375  //TODO validity check on value
376  // spyMode_[iCh] = value & 0x3;
377  // if(d) cout << "Spy mode <= " << value << "\n";
378  } else { //should never be reached!
379  assert(false);
380  }
381  ++iCh;
382  }
383  if (iCh != nChs[iValueSet]) { //error
384  sErr << "Syntax error in imported SRP system configuration file "
385  /*<< filename <<*/ " line "
386  << iLine << ".";
387  }
388  }
389  if (sErr.str().empty() && iValueSet != (nValueSets - 1)) { //error
390  sErr << "Syntax Error in imported SRP system configuration file "
391  /*<< filename <<*/ " line "
392  << iLine << ".";
393  }
394  if (!sErr.str().empty())
395  throw cms::Exception("SyntaxError") << sErr.str();
396  }
397 
398  double normalizeWeights(int hwWeight) {
399  //Fix sign bit in case only the 12 least significant bits of hwWeight were set
400  //(hardware reprensentation uses only 12 bits)
401  if (hwWeight & (1 << 11))
402  hwWeight |= ~0xEFF;
403  return hwWeight / 1024.;
404  }
405 
406 } // namespace ecalsrcondtools
static const int nTccs_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const int nDccs_
T w() const
constexpr int dccNum[12][12]
std::vector< short > srfMasks_
static void trim(std::string &s)
std::vector< std::vector< float > > dccNormalizedWeights_
std::vector< int > testerSrpEmuSrpIds_
double normalizeWeights(int hwWeight)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
uint16_t size_type
std::vector< float > srpHighInterestChannelZS_
std::vector< int > actions_
const int nChs
std::vector< std::vector< short > > substitutionSrfs_
std::vector< int > testerDccTestSrpIds_
std::vector< int > ecalDccZs1stSample_
double f[11][100]
Definition: value.py:1
d
Definition: ztail.py:151
std::vector< short > tccMasksFromConfig_
std::vector< short > bxOffsets_
std::vector< short > dccMasks_
std::vector< int > deltaPhi_
std::vector< int > symetricZS_
float ebDccAdcToGeV_
ADC to GeV conversion factor used in ZS filter for EB.
std::vector< int > testerTccEmuSrpIds_
string tokenize(const string &s, const string &delim, int &pos)
std::vector< float > srpLowInterestChannelZS_
std::vector< int > deltaEta_
std::vector< int > testerSrpTestSrpIds_
void importSrpConfigFile(EcalSRSettings &sr, std::istream &f, bool debug=false)
constexpr int tccNum[12][12]
float eeDccAdcToGeV_
ADC to GeV conversion factor used in ZS filter for EE.
static const int nSrps_
void importParameterSet(EcalSRSettings &sr, const edm::ParameterSet &ps)
std::vector< std::vector< short > > srpMasksFromConfig_