CMS 3D CMS Logo

L1TMuonBarrelParamsESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: L1TMuonBarrelParamsESProducer
4 //
5 // Original Author: Giannis Flouris
6 // Created:
7 //
8 //
9 
10 
11 // system include files
12 #include <memory>
13 
14 // user include files
19 
23 
27 
32 
34 
35 // class declaration
36 //
37 typedef std::map<short, short, std::less<short> > LUT;
38 
40  public:
43  int load_pt(std::vector<LUT>& , std::vector<int>&, unsigned short int, std::string);
44  int load_phi(std::vector<LUT>& , unsigned short int, unsigned short int, std::string);
45  int load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>&, unsigned short int, unsigned short int );
46  //void print(std::vector<LUT>& , std::vector<int>& ) const;
47  int getPtLutThreshold(int ,std::vector<int>& ) const;
48  typedef std::shared_ptr<L1TMuonBarrelParams> ReturnType;
49 
50  ReturnType produce(const L1TMuonBarrelParamsRcd&);
51  private:
52  //L1TMuonBarrelParams m_params;
54 };
55 
56 //
57 // constants, enums and typedefs
58 //
59 
60 //
61 // static data member definitions
62 //
63 
64 //
65 // constructors and destructor
66 //
68 {
69  //the following line is needed to tell the framework what
70  // data is being produced
71  setWhatProduced(this);
72  // Firmware version
73  unsigned fwVersion = iConfig.getParameter<unsigned>("fwVersion");
74  std::string AssLUTpath = iConfig.getParameter<std::string>("AssLUTPath");
75  //m_params.setAssLUTPath(AssLUTpath);
76 
77  // int PT_Assignment_nbits_Phi = iConfig.getParameter<int>("PT_Assignment_nbits_Phi");
78  // int PT_Assignment_nbits_PhiB = iConfig.getParameter<int>("PT_Assignment_nbits_PhiB");
79  // int PHI_Assignment_nbits_Phi = iConfig.getParameter<int>("PHI_Assignment_nbits_Phi");
80  // int PHI_Assignment_nbits_PhiB = iConfig.getParameter<int>("PHI_Assignment_nbits_PhiB");
81  // int Extrapolation_nbits_Phi = iConfig.getParameter<int>("Extrapolation_nbits_Phi");
82  // int Extrapolation_nbits_PhiB = iConfig.getParameter<int>("Extrapolation_nbits_PhiB");
83  // int BX_min = iConfig.getParameter<int>("BX_min");
84  // int BX_max = iConfig.getParameter<int>("BX_max");
85  // int Extrapolation_Filter = iConfig.getParameter<int>("Extrapolation_Filter");
86  // int OutOfTime_Filter_Window = iConfig.getParameter<int>("OutOfTime_Filter_Window");
87  // bool OutOfTime_Filter = iConfig.getParameter<bool>("OutOfTime_Filter");
88  // bool Open_LUTs = iConfig.getParameter<bool>("Open_LUTs");
89  // bool EtaTrackFinder = iConfig.getParameter<bool>("EtaTrackFinder");
90  // bool Extrapolation_21 = iConfig.getParameter<bool>("Extrapolation_21");
91  bool configFromXML = iConfig.getParameter<bool>("configFromXML");
92  // bool DisableNewAlgo = iConfig.getParameter<bool>("DisableNewAlgo");
93 
94  std::map<std::string, int> allInts;
95  std::map<std::string, bool> allBools;
96  std::map<std::string, std::vector<std::string> > allMasks;
97 
98  allInts["PT_Assignment_nbits_Phi"] = iConfig.getParameter<int>("PT_Assignment_nbits_Phi");
99  allInts["PT_Assignment_nbits_PhiB"] = iConfig.getParameter<int>("PT_Assignment_nbits_PhiB");
100  allInts["PHI_Assignment_nbits_Phi"] = iConfig.getParameter<int>("PHI_Assignment_nbits_Phi");
101  allInts["PHI_Assignment_nbits_PhiB"] = iConfig.getParameter<int>("PHI_Assignment_nbits_PhiB");
102  allInts["Extrapolation_nbits_Phi"] = iConfig.getParameter<int>("Extrapolation_nbits_Phi");
103  allInts["Extrapolation_nbits_PhiB"] = iConfig.getParameter<int>("Extrapolation_nbits_PhiB");
104  allInts["BX_min"] = iConfig.getParameter<int>("BX_min");
105  allInts["BX_max"] = iConfig.getParameter<int>("BX_max");
106  allInts["Extrapolation_Filter"] = iConfig.getParameter<int>("Extrapolation_Filter");
107  allInts["OutOfTime_Filter_Window"] = iConfig.getParameter<int>("OutOfTime_Filter_Window");
108  allBools["OutOfTime_Filter"] = iConfig.getParameter<bool>("OutOfTime_Filter");
109  allBools["Open_LUTs"] = iConfig.getParameter<bool>("Open_LUTs");
110  allBools["EtaTrackFinder"] = iConfig.getParameter<bool>("EtaTrackFinder");
111  allBools["Extrapolation_21"] = iConfig.getParameter<bool>("Extrapolation_21");
112  allBools["configFromXML"] = iConfig.getParameter<bool>("configFromXML");
113  allBools["DisableNewAlgo"] = iConfig.getParameter<bool>("DisableNewAlgo");
114 
115  allMasks["mask_phtf_st1"] = iConfig.getParameter< std::vector <string> >("mask_phtf_st1");
116  allMasks["mask_phtf_st2"] = iConfig.getParameter< std::vector <string> >("mask_phtf_st2");
117  allMasks["mask_phtf_st3"] = iConfig.getParameter< std::vector <string> >("mask_phtf_st3");
118  allMasks["mask_phtf_st4"] = iConfig.getParameter< std::vector <string> >("mask_phtf_st4");
119 
120  allMasks["mask_ettf_st1"] = iConfig.getParameter< std::vector <string> >("mask_ettf_st1");
121  allMasks["mask_ettf_st2"] = iConfig.getParameter< std::vector <string> >("mask_ettf_st2");
122  allMasks["mask_ettf_st3"] = iConfig.getParameter< std::vector <string> >("mask_ettf_st3");
123 
124 /*
125  m_params.set_PT_Assignment_nbits_Phi(PT_Assignment_nbits_Phi);
126  m_params.set_PT_Assignment_nbits_PhiB(PT_Assignment_nbits_PhiB);
127  m_params.set_PHI_Assignment_nbits_Phi(PHI_Assignment_nbits_Phi);
128  m_params.set_PHI_Assignment_nbits_PhiB(PHI_Assignment_nbits_PhiB);
129  m_params.set_Extrapolation_nbits_Phi(Extrapolation_nbits_Phi);
130  m_params.set_Extrapolation_nbits_PhiB(Extrapolation_nbits_PhiB);
131  m_params.set_BX_min(BX_min);
132  m_params.set_BX_max(BX_max);
133  m_params.set_Extrapolation_Filter(Extrapolation_Filter);
134  m_params.set_OutOfTime_Filter_Window(OutOfTime_Filter_Window);
135  m_params.set_OutOfTime_Filter(OutOfTime_Filter);
136  m_params.set_Open_LUTs(Open_LUTs);
137  m_params.set_EtaTrackFinder(EtaTrackFinder);
138  m_params.set_Extrapolation_21(Extrapolation_21);
139  m_params.setFwVersion(fwVersion);
140  m_params.set_DisableNewAlgo(DisableNewAlgo);
141 
142 
144  std::vector<LUT> pta_lut(0); pta_lut.reserve(19);
145  std::vector<int> pta_threshold(6); pta_threshold.reserve(9);
146  if ( load_pt(pta_lut,pta_threshold, PT_Assignment_nbits_Phi, AssLUTpath) != 0 ) {
147  cout << "Can not open files to load pt-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
148  }
149  m_params.setpta_lut(pta_lut);
150  m_params.setpta_threshold(pta_threshold);
151 
153  std::vector<LUT> phi_lut(0); phi_lut.reserve(2);
154  if ( load_phi(phi_lut, PHI_Assignment_nbits_Phi, PHI_Assignment_nbits_PhiB, AssLUTpath) != 0 ) {
155  cout << "Can not open files to load phi-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
156  }
157  m_params.setphi_lut(phi_lut);
158 
159 
160 
161 
162  m_params.l1mudttfparams.reset();
163 
164  std::vector <std::string> mask_phtf_st1 = iConfig.getParameter< std::vector <string> >("mask_phtf_st1");
165  std::vector <std::string> mask_phtf_st2 = iConfig.getParameter< std::vector <string> >("mask_phtf_st2");
166  std::vector <std::string> mask_phtf_st3 = iConfig.getParameter< std::vector <string> >("mask_phtf_st3");
167  std::vector <std::string> mask_phtf_st4 = iConfig.getParameter< std::vector <string> >("mask_phtf_st4");
168 
169  std::vector <std::string> mask_ettf_st1 = iConfig.getParameter< std::vector <string> >("mask_ettf_st1");
170  std::vector <std::string> mask_ettf_st2 = iConfig.getParameter< std::vector <string> >("mask_ettf_st2");
171  std::vector <std::string> mask_ettf_st3 = iConfig.getParameter< std::vector <string> >("mask_ettf_st3");
172 
173  for( int wh=-3; wh<4; wh++ ) {
174  int sec = 0;
175  for(char& c : mask_phtf_st1[wh+3]) {
176  int mask = c - '0';
177  m_params.l1mudttfmasks.set_inrec_chdis_st1(wh,sec,mask);
178  sec++;
179  }
180  sec = 0;
181  for(char& c : mask_phtf_st2[wh+3]) {
182  int mask = c - '0';
183  m_params.l1mudttfmasks.set_inrec_chdis_st2(wh,sec,mask);
184  sec++;
185  }
186  sec = 0;
187  for(char& c : mask_phtf_st3[wh+3]) {
188  int mask = c - '0';
189  m_params.l1mudttfmasks.set_inrec_chdis_st3(wh,sec,mask);
190  sec++;
191  }
192  sec = 0;
193  for(char& c : mask_phtf_st4[wh+3]) {
194  int mask = c - '0';
195  m_params.l1mudttfmasks.set_inrec_chdis_st4(wh,sec,mask);
196  sec++;
197  }
198  sec = 0;
199  for(char& c : mask_ettf_st1[wh+3]) {
200  int mask = c - '0';
201  m_params.l1mudttfmasks.set_etsoc_chdis_st1(wh,sec,mask);
202  sec++;
203  }
204  sec = 0;
205  for(char& c : mask_ettf_st2[wh+3]) {
206  int mask = c - '0';
207  m_params.l1mudttfmasks.set_etsoc_chdis_st2(wh,sec,mask);
208  sec++;
209  }
210  sec = 0;
211  for(char& c : mask_ettf_st3[wh+3]) {
212  int mask = c - '0';
213  m_params.l1mudttfmasks.set_etsoc_chdis_st3(wh,sec,mask);
214  //Not used in BMTF - mask
215  m_params.l1mudttfmasks.set_inrec_chdis_csc(wh,sec,true);
216  sec++;
217  }
218 
219  }
220 
221 
223  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> ext_lut(0); ext_lut.reserve(12);
224  if ( load_ext(ext_lut, PHI_Assignment_nbits_Phi, PHI_Assignment_nbits_PhiB) != 0 ) {
225  cout << "Can not open files to load extrapolation look-up tables for L1TMuonBarrelTrackProducer!" << endl;
226  }
227  m_params.setext_lut(ext_lut);
228 
229  //m_params.l1mudttfextlut.load();
230 
231  */
232 
233  m_params_helper.configFromPy(allInts, allBools, allMasks, fwVersion, AssLUTpath);
234  if(configFromXML){
235  cout<<"Configuring BMTF Emulator from xml files.\n";
236  edm::FileInPath hwXmlFile(iConfig.getParameter<std::string>("hwXmlFile"));
237  edm::FileInPath topCfgXmlFile(iConfig.getParameter<std::string>("topCfgXmlFile"));
238  std::string xmlCfgKey = iConfig.getParameter<std::string>("xmlCfgKey");
239 
240  l1t::TriggerSystem trgSys;
241  trgSys.configureSystemFromFiles(hwXmlFile.fullPath().c_str(),topCfgXmlFile.fullPath().c_str(),xmlCfgKey.c_str());
242 
243  /* std::map<std::string, std::string> procRole = trgSys.getProcRole();
244 
245  for(auto it_proc=procRole.begin(); it_proc!=procRole.end(); it_proc++ ){
246 
247  std::string procId = it_proc->first;
248 
249  std::map<std::string, l1t::Setting> settings = trgSys.getSettings(procId);
250  std::vector<l1t::TableRow> tRow = settings["regTable"].getTableRows();
251  for(auto it=tRow.begin(); it!=tRow.end(); it++)
252  {
253  if (it->getRowValue<std::string>("register_path").find("open_lut") != std::string::npos){
254  //std::cout << "Value is: " << it->getRowValue<bool>("register_value") << std::endl;
255  m_params.set_Open_LUTs(it->getRowValue<bool>("register_value"));
256  }
257  if (it->getRowValue<std::string>("register_path").find("sel_21") != std::string::npos){
258  //std::cout << "Value is: " << it->getRowValue<bool>("register_value") << std::endl;
259  m_params.set_Extrapolation_21(it->getRowValue<bool>("register_value"));
260  }
261 
262  if (it->getRowValue<std::string>("register_path").find("dis_newalgo") != std::string::npos){
263  //std::cout << "Value is: " << it->getRowValue<int>("register_value") << std::endl;
264  //int fwv = (it->getRowValue<int>("register_value")==1) ? 1 : 2;
265  //m_params.setFwVersion(fwv);
266  bool disnewalgo = (it->getRowValue<int>("register_value")==1);
267  m_params.set_DisableNewAlgo(disnewalgo);
268  }
269 
270  string masks[5] = {"mask_ctrl_N2", "mask_ctrl_N1", "mask_ctrl_0", "mask_ctrl_P1", "mask_ctrl_P2"};
271 
272  for(int m=0; m<5; m++){
273 
274  if (it->getRowValue<std::string>("register_path").find(masks[m]) != std::string::npos){
275  string mask_ctrl = it->getRowValue<string>("register_value");
276  const char *hexstring = mask_ctrl.c_str();
278  int mask = (int)strtol((hexstring+7), NULL, 16);
279  int mask_all = (int)strtol((hexstring), NULL, 16);
281  if(!( mask_all==0x111111 || mask_all==0x222222 || mask_all==0x333333 || mask_all==0x444444 ||
282  mask_all==0x555555 || mask_all==0x666666 || mask_all==0x777777) )
283  cerr<<"BMTF: Cannot re-emulate properly. Individual link masking cannot be handled."<<endl;
284 
285  if((mask&1)>0) {
286  for(int sec=0; sec<12; sec++){
287  if(masks[m]=="mask_ctrl_N2"){
288  m_params.l1mudttfmasks.set_inrec_chdis_st1(-3,sec,true);
289  m_params.l1mudttfmasks.set_etsoc_chdis_st1(-3,sec,true);
290  }
291  if(masks[m]=="mask_ctrl_N1"){
292  m_params.l1mudttfmasks.set_inrec_chdis_st1(-2,sec,true);
293  m_params.l1mudttfmasks.set_etsoc_chdis_st1(-2,sec,true);
294  }
295 
296  if(masks[m]=="mask_ctrl_0"){
297  m_params.l1mudttfmasks.set_inrec_chdis_st1(-1,sec,true);
298  m_params.l1mudttfmasks.set_inrec_chdis_st1(1,sec,true);
299  m_params.l1mudttfmasks.set_etsoc_chdis_st1(-1,sec,true);
300  m_params.l1mudttfmasks.set_etsoc_chdis_st1(1,sec,true);
301  }
302  if(masks[m]=="mask_ctrl_P1"){
303  m_params.l1mudttfmasks.set_inrec_chdis_st1(2,sec,true);
304  m_params.l1mudttfmasks.set_etsoc_chdis_st1(2,sec,true);
305  }
306  if(masks[m]=="mask_ctrl_P2"){
307  m_params.l1mudttfmasks.set_inrec_chdis_st1(3,sec,true);
308  m_params.l1mudttfmasks.set_etsoc_chdis_st1(3,sec,true);
309  }
310  }
311 
312  }
313 
314  if((mask&2)>0) {
315  for(int sec=0; sec<12; sec++){
316  if(masks[m]=="mask_ctrl_N2"){
317  m_params.l1mudttfmasks.set_inrec_chdis_st2(-3,sec,true);
318  m_params.l1mudttfmasks.set_etsoc_chdis_st2(-3,sec,true);
319  }
320  if(masks[m]=="mask_ctrl_N1"){
321  m_params.l1mudttfmasks.set_inrec_chdis_st2(-2,sec,true);
322  m_params.l1mudttfmasks.set_etsoc_chdis_st2(-2,sec,true);
323  }
324 
325  if(masks[m]=="mask_ctrl_0"){
326  m_params.l1mudttfmasks.set_inrec_chdis_st2(-1,sec,true);
327  m_params.l1mudttfmasks.set_inrec_chdis_st2(1,sec,true);
328  m_params.l1mudttfmasks.set_etsoc_chdis_st2(-1,sec,true);
329  m_params.l1mudttfmasks.set_etsoc_chdis_st2(1,sec,true);
330  }
331  if(masks[m]=="mask_ctrl_P1"){
332  m_params.l1mudttfmasks.set_inrec_chdis_st2(2,sec,true);
333  m_params.l1mudttfmasks.set_etsoc_chdis_st2(2,sec,true);
334  }
335  if(masks[m]=="mask_ctrl_P2"){
336  m_params.l1mudttfmasks.set_inrec_chdis_st2(3,sec,true);
337  m_params.l1mudttfmasks.set_etsoc_chdis_st2(3,sec,true);
338  }
339  }
340  }
341 
342  if((mask&4)>0) {
343  for(int sec=0; sec<12; sec++){
344  if(masks[m]=="mask_ctrl_N2"){
345  m_params.l1mudttfmasks.set_inrec_chdis_st3(-3,sec,true);
346  m_params.l1mudttfmasks.set_etsoc_chdis_st3(-3,sec,true);
347  }
348  if(masks[m]=="mask_ctrl_N1"){
349  m_params.l1mudttfmasks.set_inrec_chdis_st3(-2,sec,true);
350  m_params.l1mudttfmasks.set_etsoc_chdis_st3(-2,sec,true);
351  }
352 
353  if(masks[m]=="mask_ctrl_0"){
354  m_params.l1mudttfmasks.set_inrec_chdis_st3(-1,sec,true);
355  m_params.l1mudttfmasks.set_inrec_chdis_st3(1,sec,true);
356  m_params.l1mudttfmasks.set_etsoc_chdis_st3(-1,sec,true);
357  m_params.l1mudttfmasks.set_etsoc_chdis_st3(1,sec,true);
358  }
359  if(masks[m]=="mask_ctrl_P1"){
360  m_params.l1mudttfmasks.set_inrec_chdis_st3(2,sec,true);
361  m_params.l1mudttfmasks.set_etsoc_chdis_st3(2,sec,true);
362  }
363  if(masks[m]=="mask_ctrl_P2"){
364  m_params.l1mudttfmasks.set_inrec_chdis_st3(3,sec,true);
365  m_params.l1mudttfmasks.set_etsoc_chdis_st3(3,sec,true);
366  }
367  }
368  }
369 
370  if((mask&8)>0) {
371  for(int sec=0; sec<12; sec++){
372  if(masks[m]=="mask_ctrl_N2"){
373  m_params.l1mudttfmasks.set_inrec_chdis_st4(-3,sec,true);
374  }
375  if(masks[m]=="mask_ctrl_N1"){
376  m_params.l1mudttfmasks.set_inrec_chdis_st4(-2,sec,true);
377  }
378 
379  if(masks[m]=="mask_ctrl_0"){
380  m_params.l1mudttfmasks.set_inrec_chdis_st4(-1,sec,true);
381  m_params.l1mudttfmasks.set_inrec_chdis_st4(1,sec,true);
382  }
383  if(masks[m]=="mask_ctrl_P1"){
384  m_params.l1mudttfmasks.set_inrec_chdis_st4(2,sec,true);
385  }
386  if(masks[m]=="mask_ctrl_P2"){
387  m_params.l1mudttfmasks.set_inrec_chdis_st4(3,sec,true);
388  }
389  }
390  }
391  }///if register path
392  }///for masks
393  }///for it tRow
394  }///for it procRole */
396  }
397  //m_params = cast_to_L1TMuonBarrelParams((L1TMuonBarrelParams_PUBLIC)m_params_helper);
398 
399 
400 }
401 
402 
404 {
405 
406 }
407 
408 /*int L1TMuonBarrelParamsESProducer::load_pt(std::vector<LUT>& pta_lut,
409  std::vector<int>& pta_threshold,
410  unsigned short int nbitphi,
411  std::string AssLUTpath
412  ){
413 
414 
415 // maximal number of pt assignment methods
416 const int MAX_PTASSMETH = 19;
417 const int MAX_PTASSMETHA = 12;
418 
419 // pt assignment methods
420 enum PtAssMethod { PT12L, PT12H, PT13L, PT13H, PT14L, PT14H,
421  PT23L, PT23H, PT24L, PT24H, PT34L, PT34H,
422  PB12H, PB13H, PB14H, PB21H, PB23H, PB24H, PB34H,
423  NODEF };
424 
425  // get directory name
426  string pta_str = "";
427  // precision : in the look-up tables the following precision is used :
428  // phi ...12 bits (address) and pt ...5 bits
429  // now convert phi and phib to the required precision
430  int nbit_phi = nbitphi;
431  int sh_phi = 12 - nbit_phi;
432 
433  // loop over all pt-assignment methods
434  for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
435  switch ( pam ) {
436  case PT12L : { pta_str = "pta12l"; break; }
437  case PT12H : { pta_str = "pta12h"; break; }
438  case PT13L : { pta_str = "pta13l"; break; }
439  case PT13H : { pta_str = "pta13h"; break; }
440  case PT14L : { pta_str = "pta14l"; break; }
441  case PT14H : { pta_str = "pta14h"; break; }
442  case PT23L : { pta_str = "pta23l"; break; }
443  case PT23H : { pta_str = "pta23h"; break; }
444  case PT24L : { pta_str = "pta24l"; break; }
445  case PT24H : { pta_str = "pta24h"; break; }
446  case PT34L : { pta_str = "pta34l"; break; }
447  case PT34H : { pta_str = "pta34h"; break; }
448  case PB12H : { pta_str = "ptb12h_Feb2016"; break; }
449  case PB13H : { pta_str = "ptb13h_Feb2016"; break; }
450  case PB14H : { pta_str = "ptb14h_Feb2016"; break; }
451  case PB21H : { pta_str = "ptb21h_Feb2016"; break; }
452  case PB23H : { pta_str = "ptb23h_Feb2016"; break; }
453  case PB24H : { pta_str = "ptb24h_Feb2016"; break; }
454  case PB34H : { pta_str = "ptb34h_Feb2016"; break; }
455 
456  }
457 
458  // assemble file name
459  string lutpath = AssLUTpath;
460  edm::FileInPath lut_f = edm::FileInPath(string(lutpath + pta_str + ".lut"));
461  string pta_file = lut_f.fullPath();
462 
463  // open file
464  L1TriggerLutFile file(pta_file);
465  if ( file.open() != 0 ) return -1;
466 
467  // get the right shift factor
468  int shift = sh_phi;
469  int adr_old = -2048 >> shift;
470  if (pam >= MAX_PTASSMETHA) adr_old = -512 >> shift;
471 
472  LUT tmplut;
473 
474  int number = -1;
475  int sum_pt = 0;
476 
477  if ( file.good() ) {
478  int threshold = file.readInteger();
479  pta_threshold[pam/2] = threshold;
480  }
481 
482  // read values and shift to correct precision
483  while ( file.good() ) {
484 
485  int adr = (file.readInteger()) >> shift;
486  int pt = file.readInteger();
487 
488  number++;
489  //cout<<pam<<" "<<number<<" "<<MAX_PTASSMETHA<<endl;
490  if ( adr != adr_old ) {
491  assert(number);
492  tmplut.insert(make_pair( adr_old, (sum_pt/number) ));
493 
494  adr_old = adr;
495  number = 0;
496  sum_pt = 0;
497  }
498 
499  sum_pt += pt;
500 
501  if ( !file.good() ) file.close();
502 
503  }
504 
505  file.close();
506  pta_lut.push_back(tmplut);
507  }
508  return 0;
509 
510 }
511 
512 
513 
514 
515 int L1TMuonBarrelParamsESProducer::load_phi(std::vector<LUT>& phi_lut,
516  unsigned short int nbit_phi,
517  unsigned short int nbit_phib,
518  std::string AssLUTpath
519  ) {
520 
521 
522  // precision : in the look-up tables the following precision is used :
523  // address (phib) ...10 bits, phi ... 12 bits
524 
525  int sh_phi = 12 - nbit_phi;
526  int sh_phib = 10 - nbit_phib;
527 
528  string phi_str;
529  // loop over all phi-assignment methods
530  for ( int idx = 0; idx < 2; idx++ ) {
531  switch ( idx ) {
532  case 0 : { phi_str = "phi12"; break; }
533  case 1 : { phi_str = "phi42"; break; }
534  }
535 
536  // assemble file name
537  edm::FileInPath lut_f = edm::FileInPath(string(AssLUTpath + phi_str + ".lut"));
538  string phi_file = lut_f.fullPath();
539 
540  // open file
541  L1TriggerLutFile file(phi_file);
542  if ( file.open() != 0 ) return -1;
543 
544  LUT tmplut;
545 
546  int number = -1;
547  int adr_old = -512 >> sh_phib;
548  int sum_phi = 0;
549 
550  // read values
551  while ( file.good() ) {
552 
553  int adr = (file.readInteger()) >> sh_phib;
554  int phi = file.readInteger();
555 
556  number++;
557 
558  if ( adr != adr_old ) {
559  assert(number);
560  tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
561 
562  adr_old = adr;
563  number = 0;
564  sum_phi = 0;
565  }
566 
567  sum_phi += phi;
568 
569  if ( !file.good() ) file.close();
570 
571  }
572 
573  file.close();
574  phi_lut.push_back(tmplut);
575  }
576  return 0;
577 
578 }
579 
580 
581 int L1TMuonBarrelParamsESProducer::getPtLutThreshold(int pta_ind, std::vector<int>& pta_threshold) const {
582 
583  if ( pta_ind >= 0 && pta_ind < 13/2 ) {
584  return pta_threshold[pta_ind];
585  }
586  else {
587  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
588  return 0;
589  }
590 
591 }
592 
593 */
594 
595 
596 
597 
598 //
599 // load extrapolation look-up tables
600 //
601 /*
602 int L1TMuonBarrelParamsESProducer::load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>& ext_lut,
603  unsigned short int nbit_phi,
604  unsigned short int nbit_phib) {
605 
606  //max. number of Extrapolations
607  const int MAX_EXT = 12;
608 
609  // extrapolation types
610  enum Extrapolation { EX12, EX13, EX14, EX21, EX23, EX24, EX34,
611  EX15, EX16, EX25, EX26, EX56 };
612 
613  // get directory name
614  string defaultPath = "L1Trigger/L1TMuon/data/bmtf_luts/";
615  string ext_dir = "LUTs_Ext/";
616  string ext_str = "";
617 
618  // precision : in the look-up tables the following precision is used :
619  // phi ...12 bits (low, high), phib ...10 bits (address)
620  // now convert phi and phib to the required precision
621 
622  int sh_phi = 12 - nbit_phi;
623  int sh_phib = 10 - nbit_phib;
624 
625  // loop over all extrapolations
626  for ( int ext = 0; ext < MAX_EXT; ext++ ) {
627  switch (ext) {
628  case EX12 : ext_str = "ext12"; break;
629  case EX13 : ext_str = "ext13"; break;
630  case EX14 : ext_str = "ext14"; break;
631  case EX21 : ext_str = "ext21"; break;
632  case EX23 : ext_str = "ext23"; break;
633  case EX24 : ext_str = "ext24"; break;
634  case EX34 : ext_str = "ext34"; break;
635  case EX15 : ext_str = "ext15"; break;
636  case EX16 : ext_str = "ext16"; break;
637  case EX25 : ext_str = "ext25"; break;
638  case EX26 : ext_str = "ext26"; break;
639  case EX56 : ext_str = "ext56"; break;
640  }
641 
642  // assemble file name
643  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
644  string ext_file = lut_f.fullPath();
645 
646  // open file
647  L1TriggerLutFile file(ext_file);
648  if ( file.open() != 0 ) return -1;
649  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
650  // << file.getName() << endl;
651 
652  L1TMuonBarrelParams::LUTParams::extLUT tmplut;
653 
654  int number = -1;
655  int adr_old = -512 >> sh_phib;
656  int sum_low = 0;
657  int sum_high = 0;
658 
659  // read values and shift to correct precision
660  while ( file.good() ) {
661 
662  int adr = ( file.readInteger() ) >> sh_phib; // address (phib)
663  int low = ( file.readInteger() ); // low value (phi)
664  int high = ( file.readInteger() ); // high value (phi)
665 
666  number++;
667 
668  if ( adr != adr_old ) {
669 
670  tmplut.low[adr_old] = sum_low >> sh_phi;
671  tmplut.high[adr_old] = sum_high >> sh_phi;
672 
673  adr_old = adr;
674  number = 0;
675  sum_low = 0;
676  sum_high = 0;
677 
678  }
679 
680  if (number == 0) sum_low = low;
681  if (number == 0) sum_high = high;
682 
683  if ( !file.good() ) file.close();
684  }
685 
686  file.close();
687  ext_lut.push_back(tmplut);
688  }
689  return 0;
690 
691 }
692 
693 
694 //
695 // member functions
696 //
697 */
698 // ------------ method called to produce the data ------------
701 {
702  using namespace edm::es;
703 
704  return std::make_shared<L1TMuonBarrelParams>(m_params_helper);
705 }
706 
707 //define this as a plug-in
T getParameter(std::string const &) const
std::shared_ptr< L1TMuonBarrelParams > ReturnType
int getPtLutThreshold(int, std::vector< int > &) const
int load_phi(std::vector< LUT > &, unsigned short int, unsigned short int, std::string)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void configureSystemFromFiles(const char *hwCfgFile, const char *topCfgFile, const char *key)
Definition: TriggerSystem.cc:8
L1TMuonBarrelParamsESProducer(const edm::ParameterSet &)
int load_pt(std::vector< LUT > &, std::vector< int > &, unsigned short int, std::string)
std::map< short, short, std::less< short > > LUT
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void configFromPy(std::map< std::string, int > &allInts, std::map< std::string, bool > &allBools, std::map< std::string, std::vector< std::string > > allMasks, unsigned int fwVersion, const std::string &AssLUTpath)
ReturnType produce(const L1TMuonBarrelParamsRcd &)
std::string fullPath() const
Definition: FileInPath.cc:184
void configFromDB(l1t::TriggerSystem &trgSys)
int load_ext(std::vector< L1TMuonBarrelParams::LUTParams::extLUT > &, unsigned short int, unsigned short int)