CMS 3D CMS Logo

DTTFMasksOnlineProd.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DTTFMasksOnlineProd
4 // Class: DTTFMasksOnlineProd
5 //
13 //
14 // Original Author: J. Troconiz - UAM Madrid
15 // Created: Fri Apr 3 00:26:52 CEST 2009
16 //
17 //
18 
19 // system include files
20 #include <iostream>
21 
22 // user include files
24 
27 
28 //
29 // class declaration
30 //
31 
32 class DTTFMasksOnlineProd : public L1ConfigOnlineProdBase<L1MuDTTFMasksRcd, L1MuDTTFMasks> {
33 public:
35  ~DTTFMasksOnlineProd() override;
36 
37  std::unique_ptr<L1MuDTTFMasks> newObject(const std::string& objectKey) override;
38 
39 private:
40  // ----------member data ---------------------------
41 };
42 
43 //
44 // constructors and destructor
45 //
48  //the following line is needed to tell the framework what
49  // data is being produced
50 
51  //now do what ever other initialization is needed
52 }
53 
55  // do anything here that needs to be done at desctruction time
56  // (e.g. close files, deallocate resources etc.)
57 }
58 
59 std::unique_ptr<L1MuDTTFMasks> DTTFMasksOnlineProd::newObject(const std::string& objectKey) {
60  auto pDTTFMasks = std::make_unique<L1MuDTTFMasks>();
61 
62  pDTTFMasks->reset();
63 
64  std::string dttfSchema = "CMS_DT_TF";
65 
66  // Order of strings is used below -- don't change!
67  std::vector<std::string> crateMaskColumns;
68  crateMaskColumns.push_back("WEDGE_CRATE_1");
69  crateMaskColumns.push_back("WEDGE_CRATE_2");
70  crateMaskColumns.push_back("WEDGE_CRATE_3");
71  crateMaskColumns.push_back("WEDGE_CRATE_4");
72  crateMaskColumns.push_back("WEDGE_CRATE_5");
73  crateMaskColumns.push_back("WEDGE_CRATE_6");
74  crateMaskColumns.push_back("WEDGE_CRATE_1_E");
75  crateMaskColumns.push_back("WEDGE_CRATE_2_E");
76  crateMaskColumns.push_back("WEDGE_CRATE_3_E");
77  crateMaskColumns.push_back("WEDGE_CRATE_4_E");
78  crateMaskColumns.push_back("WEDGE_CRATE_5_E");
79  crateMaskColumns.push_back("WEDGE_CRATE_6_E");
80 
81  l1t::OMDSReader::QueryResults crateMaskResults = m_omdsReader.basicQuery(crateMaskColumns,
82  dttfSchema,
83  "DTTF_RUN_SETTINGS",
84  "DTTF_RUN_SETTINGS.ID",
85  m_omdsReader.singleAttribute(objectKey));
86 
87  if (crateMaskResults.queryFailed() || crateMaskResults.numberRows() != 1) // check query successful
88  {
89  edm::LogError("L1-O2O") << "Problem with L1MuDTTFMasks key " << objectKey;
90  return std::unique_ptr<L1MuDTTFMasks>();
91  }
92 
93  // Cache crate masks
94  unsigned long crateMaskL[6];
95  unsigned long crateMaskR[6];
96  unsigned long krateMaskL[6];
97  unsigned long krateMaskR[6];
98  for (int icrate = 0; icrate < 6; ++icrate) {
99  std::string crateMask;
100  crateMaskResults.fillVariable(crateMaskColumns[icrate], crateMask);
101  char* pEnd;
102  crateMaskL[icrate] = std::strtol(crateMask.c_str(), &pEnd, 16);
103  crateMaskR[icrate] = std::strtol(pEnd, (char**)nullptr, 16);
104 
105  crateMaskResults.fillVariable(crateMaskColumns[icrate + 6], crateMask);
106  krateMaskL[icrate] = std::strtol(crateMask.c_str(), &pEnd, 16);
107  krateMaskR[icrate] = std::strtol(pEnd, (char**)nullptr, 16);
108 
109  std::cout << "Crate " << icrate << " masks"
110  << " L: " << std::hex << crateMaskL[icrate] << " " << std::hex << krateMaskL[icrate] << " R: " << std::hex
111  << crateMaskR[icrate] << " " << std::hex << krateMaskR[icrate] << std::endl;
112  }
113 
114  // Map of sector (0-11) to name (L/R)
115  std::string sectorNames[12] = {"R", "L", "R", "L", "L", "R", "L", "R", "R", "L", "R", "L"};
116 
117  // Map of sector (0-11) to crate (0-5)
118  int crateNumbers[12] = {3, 3, 4, 4, 5, 5, 2, 2, 1, 1, 0, 0};
119 
120  // Map of wheel array index to wheel number (+- 3, 2, 1).
121  int wheelNumbers[6] = {-3, -2, -1, 1, 2, 3};
122 
123  // Map of wheel array index to name ({N,P}{0,1,2}).
124  std::string wheelNames[6] = {"N2", "N1", "N0", "P0", "P1", "P2"};
125 
126  // Map of sector+wheel name to bit number in crate mask
127  std::map<std::string, unsigned int> crateMaskBitmap;
128  crateMaskBitmap.insert(std::make_pair("N2", 24));
129  crateMaskBitmap.insert(std::make_pair("N1", 20));
130  crateMaskBitmap.insert(std::make_pair("N0", 16));
131  crateMaskBitmap.insert(std::make_pair("P0", 8));
132  crateMaskBitmap.insert(std::make_pair("P1", 4));
133  crateMaskBitmap.insert(std::make_pair("P2", 0));
134 
135  std::map<std::string, unsigned int> krateMaskBitmap;
136  krateMaskBitmap.insert(std::make_pair("N2", 16));
137  krateMaskBitmap.insert(std::make_pair("N1", 12));
138  krateMaskBitmap.insert(std::make_pair("P0", 8));
139  krateMaskBitmap.insert(std::make_pair("P1", 4));
140  krateMaskBitmap.insert(std::make_pair("P2", 0));
141 
142  // Loop over sectors 0-11
143  for (int isc = 0; isc < 12; ++isc) {
144  int crateNumber = crateNumbers[isc];
145  unsigned long crateMask = crateMaskL[crateNumber];
146  if (sectorNames[isc] == "R")
147  crateMask = crateMaskR[crateNumber];
148  unsigned long krateMask = krateMaskL[crateNumber];
149  if (sectorNames[isc] == "R")
150  krateMask = krateMaskR[crateNumber];
151  std::cout << "isc " << isc << " icr " << crateNumber << std::endl;
152 
153  // Loop over wheels 0-5
154  for (int iwh = 0; iwh < 6; ++iwh) {
155  std::string sectorWheelName = sectorNames[isc] + wheelNames[iwh];
156 
157  unsigned int maskBit = 30;
158  std::map<std::string, unsigned int>::const_iterator itr = crateMaskBitmap.find(wheelNames[iwh]);
159  if (itr != crateMaskBitmap.end())
160  maskBit = itr->second;
161 
162  unsigned long phtfEnabled = (crateMask >> maskBit) & 0xF;
163 
164  if (wheelNames[iwh] == "P2")
165  phtfEnabled += (crateMask >> 24) & 0x10;
166  if (wheelNames[iwh] == "N2")
167  phtfEnabled += (crateMask >> 25) & 0x10;
168 
169  std::cout << "Bits " << std::dec << maskBit << " (" << sectorWheelName << ") of mask " << std::hex << crateMask
170  << " is " << std::hex << phtfEnabled << std::endl;
171 
172  int nwh = wheelNumbers[iwh];
173 
174  unsigned long chmask = phtfEnabled & 0x1;
175  std::cout << " INREC_CHDIS_ST1 " << 1 - chmask;
176  pDTTFMasks->set_inrec_chdis_st1(nwh, isc, 1 - chmask);
177  chmask = (phtfEnabled >> 1) & 0x1;
178  std::cout << " INREC_CHDIS_ST2 " << 1 - chmask;
179  pDTTFMasks->set_inrec_chdis_st2(nwh, isc, 1 - chmask);
180  chmask = (phtfEnabled >> 2) & 0x1;
181  std::cout << " INREC_CHDIS_ST3 " << 1 - chmask;
182  pDTTFMasks->set_inrec_chdis_st3(nwh, isc, 1 - chmask);
183  chmask = (phtfEnabled >> 3) & 0x1;
184  std::cout << " INREC_CHDIS_ST4 " << 1 - chmask;
185  pDTTFMasks->set_inrec_chdis_st4(nwh, isc, 1 - chmask);
186  chmask = (phtfEnabled >> 4) & 0x1;
187  std::cout << " INREC_CHDIS_CSC " << 1 - chmask << std::endl;
188  pDTTFMasks->set_inrec_chdis_csc(nwh, isc, 1 - chmask);
189 
190  if (wheelNames[iwh] == "N0")
191  continue;
192 
193  maskBit = 20;
194  itr = krateMaskBitmap.find(wheelNames[iwh]);
195  if (itr != krateMaskBitmap.end())
196  maskBit = itr->second;
197 
198  unsigned long ettfEnabled = (krateMask >> maskBit) & 0x7;
199 
200  std::cout << "Bits " << std::dec << maskBit << " (" << sectorWheelName << ") of mask " << std::hex << krateMask
201  << " is " << std::hex << ettfEnabled << std::endl;
202 
203  chmask = ettfEnabled & 0x1;
204  std::cout << " ETSOC_CHDIS_ST1 " << 1 - chmask;
205  pDTTFMasks->set_etsoc_chdis_st1(nwh, isc, 1 - chmask);
206  chmask = (ettfEnabled >> 1) & 0x1;
207  std::cout << " ETSOC_CHDIS_ST2 " << 1 - chmask;
208  pDTTFMasks->set_etsoc_chdis_st2(nwh, isc, 1 - chmask);
209  chmask = (ettfEnabled >> 2) & 0x1;
210  std::cout << " ETSOC_CHDIS_ST3 " << 1 - chmask << std::endl;
211  pDTTFMasks->set_etsoc_chdis_st3(nwh, isc, 1 - chmask);
212  }
213  }
214 
215  return pDTTFMasks;
216 }
217 
218 // ------------ method called to produce the data ------------
219 
220 //define this as a plug-in
std::unique_ptr< L1MuDTTFMasks > newObject(const std::string &objectKey) override
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:259
Log< level::Error, false > LogError
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
Definition: OMDSReader.cc:75
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:274
DTTFMasksOnlineProd(const edm::ParameterSet &)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60