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 }
EMap::EMapRow::topbottom
std::string topbottom
Definition: LMap.h:90
HcalOther
Definition: HcalAssistant.h:38
LMapRow::rctcra
int rctcra
Definition: LMap.h:47
EMap::EMapRow::subdet
std::string subdet
Definition: LMap.h:90
MessageLogger.h
LMap.h
HcalGenericDetId
Definition: HcalGenericDetId.h:15
LMap
Definition: LMap.h:66
EMap::EMapRow::slot
int slot
Definition: LMap.h:89
LMapRow::let_code
std::string let_code
Definition: LMap.h:51
LMap::impl
Definition: LMap.cc:30
EMap::EMapRow::crate
int crate
Definition: LMap.h:89
LMap::~LMap
~LMap()
Definition: LMap.cc:45
LMap_test::_lmap
std::shared_ptr< LMap > _lmap
Definition: LMap.h:135
HcalAssistant::getZDCSectionString
std::string getZDCSectionString(HcalZDCDetId::Section _section)
Definition: HcalAssistant.cc:172
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:58
LMap_test::LMap_test
LMap_test()
Definition: LMap.cc:327
LMap::impl::~impl
~impl()
Definition: LMap.cc:33
EMap::EMapRow::zdc_channel
int zdc_channel
Definition: LMap.h:93
LMapRow::rctnam
std::string rctnam
Definition: LMap.h:48
HcalGenericDetId::HcalGenEndcap
Definition: HcalGenericDetId.h:20
LMapRow::eta
int eta
Definition: LMap.h:37
HcalGenericDetId.h
LMapRow::phi
int phi
Definition: LMap.h:37
LMapRow::fedid
int fedid
Definition: LMap.h:49
LMap::impl::impl
impl()
Definition: LMap.cc:32
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
HcalBarrel
Definition: HcalAssistant.h:33
EMap::EMapRow::spigot
int spigot
Definition: LMap.h:89
LMapRow::dphi
int dphi
Definition: LMap.h:37
EMap::EMapRow
Definition: LMap.h:87
LMapRow::crate
int crate
Definition: LMap.h:42
LMap::impl::_table
std::vector< LMapRow > _table
Definition: LMap.cc:36
EMap::EMapRow::operator<
bool operator<(const EMapRow &other) const
Definition: LMap.cc:318
EMap::EMapRow::zdc_zside
int zdc_zside
Definition: LMap.h:93
HcalElectronicsMap::lookupTrigger
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Definition: HcalElectronicsMap.cc:80
EMap::EMapRow::iphi
int iphi
Definition: LMap.h:89
HcalGenericDetId::HcalGenZDC
Definition: HcalGenericDetId.h:24
HcalZDCDetId
Definition: HcalZDCDetId.h:16
LMapRow::rm
int rm
Definition: LMap.h:41
LMapRow::qie
int qie
Definition: LMap.h:41
LMapRow::rm_fi
int rm_fi
Definition: LMap.h:41
LMap::impl::get_map
std::map< int, LMapRow > & get_map(void)
Definition: LMap.cc:36
LMap::impl::_lmap
std::map< int, LMapRow > _lmap
Definition: LMap.cc:40
HcalAssistant.h
LMapRow::depth
int depth
Definition: LMap.h:37
LMapRow::rbx
std::string rbx
Definition: LMap.h:40
RooGKCounter.h
LMapRow::dcc_sl
int dcc_sl
Definition: LMap.h:45
EMap_test::test_read_map
int test_read_map(std::string filename)
Definition: LMap.cc:321
EMap::EMapRow::fiber
int fiber
Definition: LMap.h:89
LMapRow::adc
int adc
Definition: LMap.h:41
LMapRow::slb
int slb
Definition: LMap.h:45
LMapRow::rctcon
int rctcon
Definition: LMap.h:47
LMapRow::rctcar
int rctcar
Definition: LMap.h:47
LMapRow::side
int side
Definition: LMap.h:34
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
RooGKCounter
Definition: RooGKCounter.h:10
HcalOuter
Definition: HcalAssistant.h:35
LMap::impl::read
int read(std::string accessor, std::string type)
Definition: LMap.cc:51
trackingPlots.other
other
Definition: trackingPlots.py:1464
HcalElectronicsMap::allElectronicsIdTrigger
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
Definition: HcalElectronicsMap.cc:130
EMap::EMapRow::idepth
int idepth
Definition: LMap.h:89
LMap::p_impl
std::shared_ptr< impl > p_impl
Definition: LMap.h:76
HcalAssistant
Definition: HcalAssistant.h:43
LMapRow::htr_fi
int htr_fi
Definition: LMap.h:44
LMap::read
int read(std::string accessor, std::string type="HBEF")
Definition: LMap.cc:47
EMap::EMapRow::fiberchan
int fiberchan
Definition: LMap.h:89
groupFilesInBlocks.lines
lines
Definition: groupFilesInBlocks.py:95
LMapRow::fi_ch
int fi_ch
Definition: LMap.h:41
LMapRow::slbin2
std::string slbin2
Definition: LMap.h:46
EMap::EMapRow::dcc
int dcc
Definition: LMap.h:89
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
HcalDetId.h
recoMuon::in
Definition: RecoMuonEnumerators.h:6
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
EMap::EMapRow::zdc_section
std::string zdc_section
Definition: LMap.h:94
EMap
Definition: LMap.h:80
LMapRow::spigo
int spigo
Definition: LMap.h:45
LMap::get_map
std::map< int, LMapRow > & get_map(void)
Definition: LMap.cc:49
HcalDetId
Definition: HcalDetId.h:12
HcalGenericDetId::HcalGenBarrel
Definition: HcalGenericDetId.h:19
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HcalElectronicsMap::allElectronicsIdPrecision
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
Definition: HcalElectronicsMap.cc:122
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
HcalElectronicsMap
Definition: HcalElectronicsMap.h:31
HcalAssistant::getSubdetectorString
std::string getSubdetectorString(HcalSubdetector _det)
Definition: HcalAssistant.cc:155
HcalForward
Definition: HcalAssistant.h:36
EMap::read_map
int read_map(std::string filename)
Definition: LMap.cc:268
LMapRow::det
HcalSubdetector det
Definition: LMap.h:39
LMapRow::fpga
std::string fpga
Definition: LMap.h:43
LMapRow::htr
int htr
Definition: LMap.h:42
impl
Definition: trackAlgoPriorityOrder.h:18
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HcalElectronicsMap::lookup
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
Definition: HcalElectronicsMap.cc:70
LMap::LMap
LMap()
Definition: LMap.cc:43
HcalEndcap
Definition: HcalAssistant.h:34
LMapRow::pixel
int pixel
Definition: LMap.h:41
LMapRow::slbin
std::string slbin
Definition: LMap.h:46
EMap::get_map
std::vector< EMap::EMapRow > & get_map(void)
Definition: LMap.cc:316
EMap::EMapRow::ieta
int ieta
Definition: LMap.h:89
LMapRow::dcc
int dcc
Definition: LMap.h:45
HcalGenericDetId::HcalGenOuter
Definition: HcalGenericDetId.h:21
genParticles_cff.map
map
Definition: genParticles_cff.py:11
HcalGenericDetId::HcalGenForward
Definition: HcalGenericDetId.h:22
LMap_test::test_read
int test_read(std::string accessor, std::string type="HBEF")
Definition: LMap.cc:329
EMap::EMapRow::rawId
int rawId
Definition: LMap.h:89
LMapRow::slnam
std::string slnam
Definition: LMap.h:46
LMapRow
Definition: LMap.h:31
EMap::EMap
EMap()
Definition: LMap.h:82
LMapRow::wedge
int wedge
Definition: LMap.h:41
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14