CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  static bool done = false;
72  if(done) return;
74 
75  string mode = ps_.getParameter<string>("mode");
76  bool iomode;
77  const bool iomode_read = false;
78  const bool iomode_write = true;
79 
80  if(mode == "online_config" || mode == "combine_config"){
81  iomode =iomode_write;
82  string fname = ps_.getParameter<string>("onlineSrpConfigFile");
83  ifstream f(fname.c_str());
84  if(!f.good()){
85  throw cms::Exception("EcalSRCondTools") << "Failed to open file " << fname;
86  }
87  importSrpConfigFile(*sr, f, true);
88  }
89 
90  if(mode=="python_config" || mode=="combine_config"){
91  iomode = iomode_write;
92  importParameterSet(*sr, ps_);
93  }
94 
95  if(mode=="read"){
96  iomode = iomode_read;
97  }
98 
99  if(!(mode=="python_config" || mode == "online_config" || mode == "combine_config" || (mode=="read"))){
100  throw cms::Exception("Config") << "Invalid value," << mode << ", for parameter mode. "
101  << "Valid values: online_config, python_config, combine_config, read";
102  }
103 
104  if(iomode==iomode_write){
105  sr->bxGlobalOffset_ = ps_.getParameter<int>("bxGlobalOffset");
106  sr->automaticSrpSelect_ = ps_.getParameter<int>("automaticSrpSelect");
107  sr->automaticMasks_ = ps_.getParameter<int>("automaticMasks");
108 
110  if( !db.isAvailable() ){
111  throw cms::Exception("CondDBAccess") << "Failed to connect to PoolDBOutputService\n";
112  }
113  //fillup DB
114  //create new infinite IOV
115  cond::Time_t firstSinceTime = db->beginOfTime();
116  db->writeOne(sr,firstSinceTime,"EcalSRSettingsRcd");
117  done = true;
118  } else {//read mode
120  es.get<EcalSRSettingsRcd>().get(hSr);
121  if(!hSr.isValid()){
122  cout << "EcalSRSettings record not found. Check the Cond DB Global tag.\n";
123  } else{
124  const EcalSRSettings* sr = hSr.product();
125  cout << "ECAL Seletive readout settings:\n";
126  cout << *sr << "\n" << endl;
127  }
128 
129  //trigger tower thresholds (from FENIX configuration):
131  es.get<EcalTPGPhysicsConstRcd>().get(hTp);
132  if(!hTp.isValid()){
133  cout << "EcalTPGPhysicsConst record not found. Check the Cond DB Global tag.\n";
134  } else{
135  const EcalTPGPhysicsConst * tp = hTp.product();
136  const EcalTPGPhysicsConstMap mymap = tp->getMap();
137  if(mymap.size()!=2){
138  cout << "Error: TPG physics record is of unexpected size: "
139  << mymap.size() << " elements instead of two (one for EB, one for EE)\n";
140  } else{
141  EcalTPGPhysicsConstMap::const_iterator it=mymap.begin();
142  cout << "----------------------------------------------------------------------\n"
143  "Trigger tower Et thresholds extracted from TPG configuration \n"
144  "(EcalSRCondTools modules supports only read mode for these parameters):\n\n";
145  cout<< "EB: " << "LT = " << it->second.ttf_threshold_Low << " GeV "
146  << "HT = "<< it->second.ttf_threshold_High << " GeV\n";
147  ++it;
148  cout<< "EE: " << "LT = " << it->second.ttf_threshold_Low << " GeV "
149  << "HT = "<< it->second.ttf_threshold_High << " GeV\n";
150 
151  }
152  }
153  }
154 }
155 
157  sr.deltaPhi_.resize(1);
158  sr.deltaPhi_[0] = ps.getParameter<int >("deltaPhi");
159  sr.deltaEta_.resize(1);
160  sr.deltaEta_[0] = ps.getParameter<int >("deltaEta");
161  sr.ecalDccZs1stSample_.resize(1);
162  sr.ecalDccZs1stSample_[0] = ps.getParameter<int >("ecalDccZs1stSample");
163  sr.ebDccAdcToGeV_ = ps.getParameter<double >("ebDccAdcToGeV");
164  sr.eeDccAdcToGeV_ = ps.getParameter<double >("eeDccAdcToGeV");
165  sr.dccNormalizedWeights_.resize(1);
166  const std::vector<double>& w = ps.getParameter<std::vector<double> >("dccNormalizedWeights");
167  sr.dccNormalizedWeights_[0].resize(w.size());
168  std::copy(w.begin(), w.end(), sr.dccNormalizedWeights_[0].begin());
169  sr.symetricZS_.resize(1);
170  sr.symetricZS_[0] = ps.getParameter<bool >("symetricZS");
171  sr.srpLowInterestChannelZS_.resize(2);
172  const int eb = 0;
173  const int ee = 1;
174  sr.srpLowInterestChannelZS_[eb] = ps.getParameter<double >("srpBarrelLowInterestChannelZS");
175  sr.srpLowInterestChannelZS_[ee] = ps.getParameter<double >("srpEndcapLowInterestChannelZS");
176  sr.srpHighInterestChannelZS_.resize(2);
177  sr.srpHighInterestChannelZS_[eb] = ps.getParameter<double >("srpBarrelHighInterestChannelZS");
178  sr.srpHighInterestChannelZS_[ee] = ps.getParameter<double >("srpEndcapHighInterestChannelZS");
179  //sr.trigPrimBypass_.resize(1);
180  //sr.trigPrimBypass_[0] = ps.getParameter<bool >("trigPrimBypass");
181  //sr.trigPrimBypassMode_.resize(1);
182  //sr.trigPrimBypassMode_[0] = ps.getParameter<int >("trigPrimBypassMode");
183  //sr.trigPrimBypassLTH_.resize(1);
184  //sr.trigPrimBypassLTH_[0] = ps.getParameter<double >("trigPrimBypassLTH");
185  //sr.trigPrimBypassHTH_.resize(1);
186  //sr.trigPrimBypassHTH_[0] = ps.getParameter<double >("trigPrimBypassHTH");
187  //sr.trigPrimBypassWithPeakFinder_.resize(1);
188  //sr.trigPrimBypassWithPeakFinder_[0] = ps.getParameter<bool >("trigPrimBypassWithPeakFinder");
189  //sr.defaultTtf_.resize(1);
190  //sr.defaultTtf_[0] = ps.getParameter<int >("defaultTtf");
191  sr.actions_ = ps.getParameter<std::vector<int> >("actions");
192 }
193 
195  //initialize vectors:
196  sr.deltaEta_ = vector<int>(1,0);
197  sr.deltaPhi_ = vector<int>(1,0);
198  sr.actions_ = vector<int>(4, 0);
199  sr.tccMasksFromConfig_ = vector<short>(EcalSRSettings::nTccs_, 0);
200  sr.srpMasksFromConfig_ = vector<vector<short> >(EcalSRSettings::nSrps_, vector<short>(8, 0));
201  sr.dccMasks_ = vector<short>(EcalSRSettings::nDccs_);
202  sr.srfMasks_ = vector<short>(EcalSRSettings::nDccs_);
203  sr.substitutionSrfs_ = vector<vector<short> >(EcalSRSettings::nSrps_, vector<short>(68,0));
204  sr.testerTccEmuSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
205  sr.testerSrpEmuSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
206  sr.testerDccTestSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
207  sr.testerSrpTestSrpIds_ = vector<int>(EcalSRSettings::nSrps_, 0);
208  sr.bxOffsets_ = vector<short>(EcalSRSettings::nSrps_, 0);
209  sr.automaticMasks_ = 0;
210  sr.automaticSrpSelect_ = 0;
211 
212  //string line;
213  int iLine = 0;
214  int iValueSet = -1;
215  const int nValueSets = 6*EcalSRSettings::nSrps_+9;
216  string line;
217  stringstream sErr("");
218  while(!f.eof() && sErr.str().empty()){
219  getline(f, line);
220  ++iLine;
221  line = trim(line);
222  if(line[0] == '#' || line.empty()){//comment line and empty line to ignore
223  continue;
224  } else{
225  ++iValueSet;
226  }
227  if(iValueSet>=nValueSets) break;
228  uint32_t value;
229  string sValue;
230  int pos = 0;
231  int iCh = 0;
232  int nChs[nValueSets] = {
233  //TCC masks: 0-11
234  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
235  //SRP masks: 12-23
236  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
237  //DCC masks: 24-35
238  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
239  //SRF Masks: 36-47
240  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
241  //substitution SRFs: 48-59
242  68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
243  //Tester card to emulate or test: 60-71
244  4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
245  //Bx offsets: 72
246  12,
247  //algo type: 73
248  1,
249  //action flags: 74
250  4,
251  //pattern file directory: 75
252  1,
253  //VME slots: 76
254  12,
255  //card types: 77
256  12,
257  //config Mode
258  1,
259  //VME Interface card
260  1,
261  //Spy Mode
262  12,
263  };
264 
265  while(((sValue = tokenize(line, " \t", pos))!=string(""))
266  && (iCh<nChs[iValueSet]) && sErr.str().empty()){
267  value = strtoul(sValue.c_str(), 0, 0);
268  const int iSrp = iValueSet%EcalSRSettings::nSrps_;
269  if(iValueSet<12){//TCC
270  assert((unsigned)iSrp < sizeof(tccNum) / sizeof(tccNum[0]));
271  assert((unsigned)iCh < sizeof(tccNum[0]) / sizeof(tccNum[0][0]));
272  int tcc = tccNum[iSrp][iCh];
273  if(tcc>=0) {
274  if(d) cout << "tccMasksFromConfig_[" << tcc << "] <- "
275  << value << "\n";
276  sr.tccMasksFromConfig_[tcc-1] = value;
277  }
278  } else if(iValueSet<24){//SRP-SRP
279  if(d) cout << "srpMasks_[" << iSrp << "][" << iCh << "] <- "
280  << value << "\n";
281  sr.srpMasksFromConfig_[iSrp][iCh] = value;
282  } else if(iValueSet<36) {//DCC output
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  assert((unsigned)(dcc-1) < sr.dccMasks_.size());
288  if(d) cout << "dccMasks_[" << (dcc-1) << "] <- "
289  << value << "\n";
290  sr.dccMasks_[dcc-1] = value;
291  }
292  } else if(iValueSet<48){//SRF masks
293  assert((unsigned)iSrp < sizeof(dccNum) / sizeof(dccNum[0]));
294  assert((unsigned)iCh < sizeof(dccNum[0]) / sizeof(dccNum[0][0]));
295  int dcc = dccNum[iSrp][iCh];
296  if(dcc > 0){
297  if(d) cout << "srfMasks_[" << (dcc-1) << "] <- "
298  << value << "\n";
299  assert((unsigned)(dcc-1) < sr.srfMasks_.size());
300  sr.srfMasks_[dcc-1] = value;
301  }
302  } else if(iValueSet<60){//substiution SRFs
303  assert((unsigned)iSrp < sr.substitutionSrfs_.size());
304  assert((unsigned)iCh < sr.substitutionSrfs_[0].size());
305  if(d) cout << "substitutionMasks_[" << iSrp << "][" << iCh << "] <- "
306  << value << "\n";
307  sr.substitutionSrfs_[iSrp][iCh] = value;
308  } else if(iValueSet<72){//Tester card config
309  switch(iCh){
310  case 0:
311  assert((unsigned)iSrp < sr.testerTccEmuSrpIds_.size());
312  if(d) cout << "testerTccEmuSrpIds_[" << iSrp << "] <- "
313  << value << "\n";
314  sr.testerTccEmuSrpIds_[iSrp] = value;
315  break;
316  case 1:
317  assert((unsigned)iSrp < sr.testerSrpEmuSrpIds_.size());
318  if(d) cout << "testerSrpEmuSrpIds_[" << iSrp << "] <- "
319  << value << "\n";
320  sr.testerSrpEmuSrpIds_[iSrp] = value;
321  break;
322  case 2:
323  assert((unsigned)iSrp < sr.testerDccTestSrpIds_.size());
324  if(d) cout << "testerDccTestSrpIds_[" << iSrp << "] <- "
325  << value << "\n";
326  sr.testerDccTestSrpIds_[iSrp] = value;
327  break;
328  case 3:
329  assert((unsigned)iSrp < sr.testerSrpTestSrpIds_.size());
330  if(d) cout << "testerSrpTestSrpIds_[" << iSrp << "] <- "
331  << value << "\n";
332  sr.testerSrpTestSrpIds_[iSrp] = value;
333  break;
334  default:
335  sErr << "Syntax error in SRP system configuration "
336  << " line " << iLine << ".";
337  }
338  } else if(iValueSet<73){//bx offsets
339  assert((unsigned)iCh < sr.bxOffsets_.size());
340  if(d) cout << "bxOffset_[" << iCh << "] <- "
341  << value << "\n";
342  sr.bxOffsets_[iCh] = value;
343  } else if(iValueSet<74){//algo type
344  int algo = value;
345  switch(algo){
346  case 0:
347  sr.deltaEta_[0] = sr.deltaPhi_[0] = 1;
348  break;
349  case 1:
350  sr.deltaEta_[0] = sr.deltaPhi_[0] = 2;
351  break;
352  default:
353  throw cms::Exception("OutOfRange") << "Value of parameter algo ," << algo
354  << ", is invalid. Valid values are 0 and 1.";
355  }
356  if(d) cout << "deltaEta_[0] <- " << sr.deltaEta_[0] << "\t"
357  << "deltaPhi_[0] <- " << sr.deltaPhi_[0] << "\n";
358  } else if(iValueSet<75){//action flags
359  assert((unsigned)iCh < sr.actions_.size());
360  if(d) cout << "actions_[" << iCh << "] <- "
361  << value << "\n";
362  sr.actions_[iCh] = value;
363  } else if(iValueSet<76){//pattern file directory
364 // emuDir_ = sValue;
365 // if(d) cout << "emuDir_ <= "
366 // << value << "\n";
367  } else if(iValueSet<77){//VME slots
368  // slotIds_[iCh] = value;
369  // if(d) cout << "slotIds_[" << iCh << "] <= "
370  // << value << "\n";
371  } else if(iValueSet<78){//card types
372  // cardTypes_[iCh] = sValue[0];
373  // if(d) cout << "cardTypes_[" << iCh << "] <= "
374  // << value << "\n";
375  } else if (iValueSet<79){//config mode
376  //TODO validity check on value
377  // configMode_ = (ConfigMode)value;
378  // if(d) cout << "config mode <= " << value << "\n";
379  } else if (iValueSet<80){//VME I/F
380  //TODO validity check on value
381  // vmeInterface_ = (Vme::type_t)value;
382  //if(d) cout << "Vme Interface code <= " << value << "\n";
383  } else if (iValueSet<81){//Spy Mode
384  //TODO validity check on value
385  // spyMode_[iCh] = value & 0x3;
386  // if(d) cout << "Spy mode <= " << value << "\n";
387  } else{//should never be reached!
388  assert(false);
389  }
390  ++iCh;
391  }
392  if(iCh!=nChs[iValueSet]){//error
393  sErr << "Syntax error in imported SRP system configuration file "
394  /*<< filename <<*/ " line " << iLine << ".";
395  }
396  }
397  if(sErr.str().empty() && iValueSet!=(nValueSets-1)){//error
398  sErr << "Syntax Error in imported SRP system configuration file "
399  /*<< filename <<*/ " line " << iLine << ".";
400  }
401  if(sErr.str().size()!=0) throw cms::Exception("SyntaxError") << sErr.str();
402 }
403 
405  //Fix sign bit in case only the 12 least significant bits of hwWeight were set
406  //(hardware reprensentation uses only 12 bits)
407  if(hwWeight & (1<<11)) hwWeight |= ~0xEFF;
408  return hwWeight/1024.;
409 }
410 
411 string EcalSRCondTools::tokenize(const string& s, const string& delim, int& pos){
412  if(pos<0) return "";
413  int pos0 = pos;
414  int len = s.size();
415  //eats delimeters at beginning of the string
416  while(pos0<len && find(delim.begin(), delim.end(), s[pos0])!=delim.end()){
417  ++pos0;
418  }
419  if(pos0==len) return "";
420  pos = s.find_first_of(delim, pos0);
421  return s.substr(pos0, (pos>0?pos:len)-pos0);
422 }
423 
425  std::string::size_type pos0 = s.find_first_not_of(" \t");
426  if(pos0==string::npos){
427  pos0=0;
428  }
429  string::size_type pos1 = s.find_last_not_of(" \t") + 1;
430  if(pos1==string::npos){
431  pos1 = pos0;
432  }
433  return s.substr(pos0, pos1-pos0);
434 }
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
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)
assert(m_qm.get())
tuple db
Definition: EcalCondDB.py:151
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:7
uint16_t size_type
#define constexpr
static std::string trim(std::string s)
std::vector< float > srpHighInterestChannelZS_
std::vector< int > actions_
tuple d
Definition: ztail.py:151
const int nChs
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]
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
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_
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
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_
virtual void analyze(const edm::Event &evt, const edm::EventSetup &es)
tuple cout
Definition: gather_cfg.py:145
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:47
EcalSRCondTools(const edm::ParameterSet &)
std::vector< std::vector< short > > srpMasksFromConfig_