CMS 3D CMS Logo

LMap.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: XMLTools
4 // Class : LMap
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Gena Kukartsev, kukarzev@fnal.gov
10 // Created: Tue Oct 23 14:30:20 CDT 2007
11 //
12 
13 // system include files
14 #include <cstdio>
15 #include <iostream>
16 #include <fstream>
17 #include <sstream>
18 #include <vector>
19 
20 // user include files
27 
28 using namespace std;
29 
30 class LMap::impl {
31 public:
32  impl() {}
33  ~impl() {}
34 
35  int read(std::string accessor, std::string type);
36  std::map<int, LMapRow>& get_map(void) { return _lmap; };
37 
38 private:
39  std::vector<LMapRow> _table;
40  std::map<int, LMapRow> _lmap;
41 };
42 
43 LMap::LMap() : p_impl(new impl) {}
44 
46 
47 int LMap::read(std::string accessor, std::string type) { return p_impl->read(accessor, type); }
48 
49 std::map<int, LMapRow>& LMap::get_map(void) { return p_impl->get_map(); }
50 
53 
54  std::string _row;
55  ifstream inFile(map_file.c_str(), std::ios::in);
56  if (!inFile) {
57  edm::LogError("LMap") << "Unable to open file with the logical map: " << map_file;
58  } else {
59  edm::LogInfo("LMap") << "File with the logical map opened successfully: " << map_file << std::endl
60  << "Type: " << type;
61  }
62  while (getline(inFile, _row)) {
63  LMapRow aRow;
64  char det[32];
65  char rbx[32];
66  char fpga[32];
67  char slbin[32];
68  char slbin2[32];
69  char slnam[32];
70  char rctnam[32];
71 
72  const char* let_code = "Z";
73 
74  int _read = 0;
75  if (type == "HBEF") {
76  const char* _format =
77  " %d %d %d %d %d %s %s %d %d %d %d %d %d %d %d %d %s %d %d %d %d %d %s %s %s %d %d %d %s %d";
78  _read = sscanf(_row.c_str(),
79  _format,
80  &(aRow.side),
81  &(aRow.eta),
82  &(aRow.phi),
83  &(aRow.dphi),
84  &(aRow.depth),
85  det,
86  rbx,
87  &(aRow.wedge),
88  &(aRow.rm),
89  &(aRow.pixel),
90  &(aRow.qie),
91  &(aRow.adc),
92  &(aRow.rm_fi),
93  &(aRow.fi_ch),
94  &(aRow.crate),
95  &(aRow.htr),
96  fpga,
97  &(aRow.htr_fi),
98  &(aRow.dcc_sl),
99  &(aRow.spigo),
100  &(aRow.dcc),
101  &(aRow.slb),
102  slbin,
103  slbin2,
104  slnam,
105  &(aRow.rctcra),
106  &(aRow.rctcar),
107  &(aRow.rctcon),
108  rctnam,
109  &(aRow.fedid));
110  } else if (type == "HO") {
111  const char* _format = " %d %d %d %d %d %s %s %d %d %d %d %d %d %d %s %d %d %s %d %d %d %d %d";
112  _read = sscanf(_row.c_str(),
113  _format,
114  &(aRow.side),
115  &(aRow.eta),
116  &(aRow.phi),
117  &(aRow.dphi),
118  &(aRow.depth),
119  det,
120  rbx,
121  &(aRow.wedge),
122  &(aRow.rm),
123  &(aRow.pixel),
124  &(aRow.qie),
125  &(aRow.adc),
126  &(aRow.rm_fi),
127  &(aRow.fi_ch),
128  &let_code,
129  &(aRow.crate),
130  &(aRow.htr),
131  fpga,
132  &(aRow.htr_fi),
133  &(aRow.dcc_sl),
134  &(aRow.spigo),
135  &(aRow.dcc),
136  &(aRow.slb));
137  //slbin, slbin2, slnam,
138  //&(aRow.rctcra), &(aRow.rctcar), &(aRow.rctcon),
139  //rctnam,
140  //&(aRow.fedid) );
141  }
142  if (_read >= 23) {
143  lines.count();
144 
145  std::string _det(det);
146  if (_det.find("HB") != std::string::npos)
147  aRow.det = HcalBarrel;
148  else if (_det.find("HE") != std::string::npos)
149  aRow.det = HcalEndcap;
150  else if (_det.find("HF") != std::string::npos)
151  aRow.det = HcalForward;
152  else if (_det.find("HO") != std::string::npos)
153  aRow.det = HcalOuter;
154  else
155  aRow.det = HcalOther;
156 
157  aRow.rbx.append(rbx);
158  aRow.fpga.append(fpga);
159  aRow.slbin.append(slbin);
160  aRow.slbin2.append(slbin2);
161  aRow.slnam.append(slnam);
162  aRow.rctnam.append(rctnam);
163  aRow.let_code.append(let_code);
164 
165  _table.push_back(aRow);
166 
167  HcalDetId _hdid(aRow.det, aRow.side * aRow.eta, aRow.phi, aRow.depth);
168 
169  _lmap[_hdid.rawId()] = aRow;
170  }
171  }
172  inFile.close();
173  edm::LogInfo("LMap") << lines.getCount() << " lines read";
174 
175  return 0;
176 }
177 
178 //_______________________________________________________________________
179 //
180 //_____ EMAP stuff
181 //
182 //_______________________________________________________________________
183 
185  if (emap) {
186  HcalAssistant _ass;
187  //
188  //_____ precision channels __________________________________________
189  //
190  std::vector<HcalElectronicsId> v_eId = emap->allElectronicsIdPrecision();
191  for (std::vector<HcalElectronicsId>::const_iterator eId = v_eId.begin(); eId != v_eId.end(); eId++) {
192  EMapRow row;
193  //row.rawId = eId->rawId();
194  row.crate = eId->readoutVMECrateId();
195  row.slot = eId->htrSlot();
196  row.dcc = eId->dccid();
197  row.spigot = eId->spigot();
198  row.fiber = eId->fiberIndex();
199  row.fiberchan = eId->fiberChanId();
200  if (eId->htrTopBottom() == 1)
201  row.topbottom = "t";
202  else if (eId->htrTopBottom() == 0)
203  row.topbottom = "b";
204  else
205  row.topbottom = "u";
206  //
207  HcalGenericDetId _gid(emap->lookup(*eId));
208  if (!(_gid.null()) && (_gid.genericSubdet() == HcalGenericDetId::HcalGenBarrel ||
209  _gid.genericSubdet() == HcalGenericDetId::HcalGenEndcap ||
210  _gid.genericSubdet() == HcalGenericDetId::HcalGenForward ||
211  _gid.genericSubdet() == HcalGenericDetId::HcalGenOuter)) {
212  HcalDetId _id(emap->lookup(*eId));
213  row.rawId = _id.rawId();
214  row.ieta = _id.ieta();
215  row.iphi = _id.iphi();
216  row.idepth = _id.depth();
217  row.subdet = _ass.getSubdetectorString(_id.subdet());
218  // fill the map
219  map.push_back(row);
220  }
221  // ZDC channels
222  else if (!(_gid.null()) && _gid.genericSubdet() == HcalGenericDetId::HcalGenZDC) {
223  HcalZDCDetId _id(emap->lookup(*eId));
224  row.zdc_channel = _id.channel();
225  row.zdc_section = _ass.getZDCSectionString(_id.section());
226  row.idepth = _id.depth();
227  row.zdc_zside = _id.zside();
228  // fill the map
229  map.push_back(row);
230  }
231  }
232  //
233  //_____ trigger channels __________________________________________
234  //
235  v_eId = emap->allElectronicsIdTrigger();
236  for (std::vector<HcalElectronicsId>::const_iterator eId = v_eId.begin(); eId != v_eId.end(); eId++) {
237  EMapRow row;
238  //row.rawId = eId->rawId();
239  row.crate = eId->readoutVMECrateId();
240  row.slot = eId->htrSlot();
241  row.dcc = eId->dccid();
242  row.spigot = eId->spigot();
243  row.fiber = eId->isVMEid() ? eId->slbSiteNumber() : eId->fiberIndex();
244  row.fiberchan = eId->isVMEid() ? eId->slbChannelIndex() : eId->fiberChanId();
245  if (eId->htrTopBottom() == 1)
246  row.topbottom = "t";
247  else if (eId->htrTopBottom() == 0)
248  row.topbottom = "b";
249  else
250  row.topbottom = "u";
251  //
252  HcalTrigTowerDetId _id(emap->lookupTrigger(*eId));
253  if (!(_id.null())) {
254  row.rawId = _id.rawId();
255  row.ieta = _id.ieta();
256  row.iphi = _id.iphi();
257  row.idepth = _id.depth();
258  row.subdet = _ass.getSubdetectorString(_id.subdet());
259  // fill the map
260  map.push_back(row);
261  }
262  }
263  } else {
264  edm::LogError("EMap") << "Pointer to HcalElectronicsMap is 0!!!";
265  }
266 }
267 
270 
271  std::string _row;
272  ifstream inFile(filename.c_str(), std::ios::in);
273  if (!inFile) {
274  edm::LogError("EMap") << "Unable to open file with the electronic map: " << filename;
275  } else {
276  edm::LogInfo("EMap") << "File with the electronic map opened successfully: " << filename;
277  }
278  while (getline(inFile, _row)) {
279  EMapRow aRow;
280  char fpga[32];
281  char subdet[32];
282 
283  int _read;
284  const char* _format = "%d %d %d %s %d %d %d %d %s %d %d %d";
285  _read = sscanf(_row.c_str(),
286  _format,
287  &(aRow.rawId),
288  &(aRow.crate),
289  &(aRow.slot),
290  fpga,
291  &(aRow.dcc),
292  &(aRow.spigot),
293  &(aRow.fiber),
294  &(aRow.fiberchan),
295  subdet,
296  &(aRow.ieta),
297  &(aRow.iphi),
298  &(aRow.idepth));
299  if (_read >= 12) {
300  lines.count();
301 
302  aRow.subdet.append(subdet);
303  aRow.topbottom.append(fpga);
304 
305  map.push_back(aRow);
306  //std::cout << "DEBUG: " << _row << std::endl;
307  //std::cout << "DEBUG: " << aRow.ieta << std::endl;
308  }
309  }
310  inFile.close();
311  edm::LogInfo("EMap") << lines.getCount() << " lines read";
312 
313  return 0;
314 }
315 
316 std::vector<EMap::EMapRow>& EMap::get_map(void) { return map; }
317 
318 bool EMap::EMapRow::operator<(const EMap::EMapRow& other) const { return rawId < other.rawId; }
319 
320 // ===> test procedures for the EMap class
322  EMap map(filename);
323  return 0;
324 }
325 
326 // ===> test procedures for the LMap class
327 LMap_test::LMap_test() : _lmap(new LMap) {}
328 
330  _lmap->read(accessor, type);
331  return 0;
332 }
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
int slot
Definition: LMap.h:89
int rctcra
Definition: LMap.h:47
std::string getSubdetectorString(HcalSubdetector _det)
int read_map(std::string filename)
Definition: LMap.cc:268
int dphi
Definition: LMap.h:37
int zdc_channel
Definition: LMap.h:93
int phi
Definition: LMap.h:37
int pixel
Definition: LMap.h:41
~LMap()
Definition: LMap.cc:45
std::string zdc_section
Definition: LMap.h:94
int qie
Definition: LMap.h:41
int zdc_zside
Definition: LMap.h:93
int iphi
Definition: LMap.h:89
int fedid
Definition: LMap.h:49
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
std::shared_ptr< impl > p_impl
Definition: LMap.h:76
int ieta
Definition: LMap.h:89
std::string getZDCSectionString(HcalZDCDetId::Section _section)
int rawId
Definition: LMap.h:89
int fiber
Definition: LMap.h:89
Log< level::Error, false > LogError
int spigot
Definition: LMap.h:89
int slb
Definition: LMap.h:45
int htr
Definition: LMap.h:42
std::string subdet
Definition: LMap.h:90
std::map< int, LMapRow > & get_map(void)
Definition: LMap.cc:49
int depth
Definition: LMap.h:37
int spigo
Definition: LMap.h:45
int test_read(std::string accessor, std::string type="HBEF")
Definition: LMap.cc:329
std::string slbin
Definition: LMap.h:46
int dcc_sl
Definition: LMap.h:45
int fi_ch
Definition: LMap.h:41
int adc
Definition: LMap.h:41
int read(std::string accessor, std::string type="HBEF")
Definition: LMap.cc:47
impl()
Definition: LMap.cc:32
std::string slnam
Definition: LMap.h:46
int crate
Definition: LMap.h:42
int read(std::string accessor, std::string type)
Definition: LMap.cc:51
std::string rbx
Definition: LMap.h:40
std::map< int, LMapRow > _lmap
Definition: LMap.cc:40
std::string rctnam
Definition: LMap.h:48
int fiberchan
Definition: LMap.h:89
int dcc
Definition: LMap.h:89
int side
Definition: LMap.h:34
std::shared_ptr< LMap > _lmap
Definition: LMap.h:135
Log< level::Info, false > LogInfo
std::map< int, LMapRow > & get_map(void)
Definition: LMap.cc:36
bool operator<(const EMapRow &other) const
Definition: LMap.cc:318
int crate
Definition: LMap.h:89
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::string fpga
Definition: LMap.h:43
int rm_fi
Definition: LMap.h:41
LMap_test()
Definition: LMap.cc:327
int dcc
Definition: LMap.h:45
std::string slbin2
Definition: LMap.h:46
std::string topbottom
Definition: LMap.h:90
int wedge
Definition: LMap.h:41
int rctcon
Definition: LMap.h:47
LMap()
Definition: LMap.cc:43
int rctcar
Definition: LMap.h:47
int test_read_map(std::string filename)
Definition: LMap.cc:321
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
std::vector< EMap::EMapRow > & get_map(void)
Definition: LMap.cc:316
Definition: LMap.h:80
int idepth
Definition: LMap.h:89
int htr_fi
Definition: LMap.h:44
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
std::string let_code
Definition: LMap.h:51
HcalSubdetector det
Definition: LMap.h:39
Definition: LMap.h:31
~impl()
Definition: LMap.cc:33
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
Definition: LMap.h:66
EMap()
Definition: LMap.h:82
int eta
Definition: LMap.h:37
std::vector< LMapRow > _table
Definition: LMap.cc:36
int rm
Definition: LMap.h:41