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