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