File indexing completed on 2024-04-06 12:00:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <cstdio>
0015 #include <iostream>
0016 #include <fstream>
0017 #include <sstream>
0018 #include <vector>
0019
0020
0021 #include "CaloOnlineTools/HcalOnlineDb/interface/LMap.h"
0022 #include "CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h"
0023 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0024 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0025 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalAssistant.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027
0028 using namespace std;
0029
0030 class LMap::impl {
0031 public:
0032 impl() {}
0033 ~impl() {}
0034
0035 int read(std::string accessor, std::string type);
0036 std::map<int, LMapRow>& get_map(void) { return _lmap; };
0037
0038 private:
0039 std::vector<LMapRow> _table;
0040 std::map<int, LMapRow> _lmap;
0041 };
0042
0043 LMap::LMap() : p_impl(new impl) {}
0044
0045 LMap::~LMap() {}
0046
0047 int LMap::read(std::string accessor, std::string type) { return p_impl->read(accessor, type); }
0048
0049 std::map<int, LMapRow>& LMap::get_map(void) { return p_impl->get_map(); }
0050
0051 int LMap::impl::read(std::string map_file, std::string type) {
0052 RooGKCounter lines;
0053
0054 std::string _row;
0055 ifstream inFile(map_file.c_str(), std::ios::in);
0056 if (!inFile) {
0057 edm::LogError("LMap") << "Unable to open file with the logical map: " << map_file;
0058 } else {
0059 edm::LogInfo("LMap") << "File with the logical map opened successfully: " << map_file << std::endl
0060 << "Type: " << type;
0061 }
0062 while (getline(inFile, _row)) {
0063 LMapRow aRow;
0064 char det[32];
0065 char rbx[32];
0066 char fpga[32];
0067 char slbin[32];
0068 char slbin2[32];
0069 char slnam[32];
0070 char rctnam[32];
0071
0072 const char* let_code = "Z";
0073
0074 int _read = 0;
0075 if (type == "HBEF") {
0076 const char* _format =
0077 " %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";
0078 _read = sscanf(_row.c_str(),
0079 _format,
0080 &(aRow.side),
0081 &(aRow.eta),
0082 &(aRow.phi),
0083 &(aRow.dphi),
0084 &(aRow.depth),
0085 det,
0086 rbx,
0087 &(aRow.wedge),
0088 &(aRow.rm),
0089 &(aRow.pixel),
0090 &(aRow.qie),
0091 &(aRow.adc),
0092 &(aRow.rm_fi),
0093 &(aRow.fi_ch),
0094 &(aRow.crate),
0095 &(aRow.htr),
0096 fpga,
0097 &(aRow.htr_fi),
0098 &(aRow.dcc_sl),
0099 &(aRow.spigo),
0100 &(aRow.dcc),
0101 &(aRow.slb),
0102 slbin,
0103 slbin2,
0104 slnam,
0105 &(aRow.rctcra),
0106 &(aRow.rctcar),
0107 &(aRow.rctcon),
0108 rctnam,
0109 &(aRow.fedid));
0110 } else if (type == "HO") {
0111 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";
0112 _read = sscanf(_row.c_str(),
0113 _format,
0114 &(aRow.side),
0115 &(aRow.eta),
0116 &(aRow.phi),
0117 &(aRow.dphi),
0118 &(aRow.depth),
0119 det,
0120 rbx,
0121 &(aRow.wedge),
0122 &(aRow.rm),
0123 &(aRow.pixel),
0124 &(aRow.qie),
0125 &(aRow.adc),
0126 &(aRow.rm_fi),
0127 &(aRow.fi_ch),
0128 &let_code,
0129 &(aRow.crate),
0130 &(aRow.htr),
0131 fpga,
0132 &(aRow.htr_fi),
0133 &(aRow.dcc_sl),
0134 &(aRow.spigo),
0135 &(aRow.dcc),
0136 &(aRow.slb));
0137
0138
0139
0140
0141 }
0142 if (_read >= 23) {
0143 lines.count();
0144
0145 std::string _det(det);
0146 if (_det.find("HB") != std::string::npos)
0147 aRow.det = HcalBarrel;
0148 else if (_det.find("HE") != std::string::npos)
0149 aRow.det = HcalEndcap;
0150 else if (_det.find("HF") != std::string::npos)
0151 aRow.det = HcalForward;
0152 else if (_det.find("HO") != std::string::npos)
0153 aRow.det = HcalOuter;
0154 else
0155 aRow.det = HcalOther;
0156
0157 aRow.rbx.append(rbx);
0158 aRow.fpga.append(fpga);
0159 aRow.slbin.append(slbin);
0160 aRow.slbin2.append(slbin2);
0161 aRow.slnam.append(slnam);
0162 aRow.rctnam.append(rctnam);
0163 aRow.let_code.append(let_code);
0164
0165 _table.push_back(aRow);
0166
0167 HcalDetId _hdid(aRow.det, aRow.side * aRow.eta, aRow.phi, aRow.depth);
0168
0169 _lmap[_hdid.rawId()] = aRow;
0170 }
0171 }
0172 inFile.close();
0173 edm::LogInfo("LMap") << lines.getCount() << " lines read";
0174
0175 return 0;
0176 }
0177
0178
0179
0180
0181
0182
0183
0184 EMap::EMap(const HcalElectronicsMap* emap) {
0185 if (emap) {
0186 HcalAssistant _ass;
0187
0188
0189
0190 std::vector<HcalElectronicsId> v_eId = emap->allElectronicsIdPrecision();
0191 for (std::vector<HcalElectronicsId>::const_iterator eId = v_eId.begin(); eId != v_eId.end(); eId++) {
0192 EMapRow row;
0193
0194 row.crate = eId->readoutVMECrateId();
0195 row.slot = eId->htrSlot();
0196 row.dcc = eId->dccid();
0197 row.spigot = eId->spigot();
0198 row.fiber = eId->fiberIndex();
0199 row.fiberchan = eId->fiberChanId();
0200 if (eId->htrTopBottom() == 1)
0201 row.topbottom = "t";
0202 else if (eId->htrTopBottom() == 0)
0203 row.topbottom = "b";
0204 else
0205 row.topbottom = "u";
0206
0207 HcalGenericDetId _gid(emap->lookup(*eId));
0208 if (!(_gid.null()) && (_gid.genericSubdet() == HcalGenericDetId::HcalGenBarrel ||
0209 _gid.genericSubdet() == HcalGenericDetId::HcalGenEndcap ||
0210 _gid.genericSubdet() == HcalGenericDetId::HcalGenForward ||
0211 _gid.genericSubdet() == HcalGenericDetId::HcalGenOuter)) {
0212 HcalDetId _id(emap->lookup(*eId));
0213 row.rawId = _id.rawId();
0214 row.ieta = _id.ieta();
0215 row.iphi = _id.iphi();
0216 row.idepth = _id.depth();
0217 row.subdet = _ass.getSubdetectorString(_id.subdet());
0218
0219 map.push_back(row);
0220 }
0221
0222 else if (!(_gid.null()) && _gid.genericSubdet() == HcalGenericDetId::HcalGenZDC) {
0223 HcalZDCDetId _id(emap->lookup(*eId));
0224 row.zdc_channel = _id.channel();
0225 row.zdc_section = _ass.getZDCSectionString(_id.section());
0226 row.idepth = _id.depth();
0227 row.zdc_zside = _id.zside();
0228
0229 map.push_back(row);
0230 }
0231 }
0232
0233
0234
0235 v_eId = emap->allElectronicsIdTrigger();
0236 for (std::vector<HcalElectronicsId>::const_iterator eId = v_eId.begin(); eId != v_eId.end(); eId++) {
0237 EMapRow row;
0238
0239 row.crate = eId->readoutVMECrateId();
0240 row.slot = eId->htrSlot();
0241 row.dcc = eId->dccid();
0242 row.spigot = eId->spigot();
0243 row.fiber = eId->isVMEid() ? eId->slbSiteNumber() : eId->fiberIndex();
0244 row.fiberchan = eId->isVMEid() ? eId->slbChannelIndex() : eId->fiberChanId();
0245 if (eId->htrTopBottom() == 1)
0246 row.topbottom = "t";
0247 else if (eId->htrTopBottom() == 0)
0248 row.topbottom = "b";
0249 else
0250 row.topbottom = "u";
0251
0252 HcalTrigTowerDetId _id(emap->lookupTrigger(*eId));
0253 if (!(_id.null())) {
0254 row.rawId = _id.rawId();
0255 row.ieta = _id.ieta();
0256 row.iphi = _id.iphi();
0257 row.idepth = _id.depth();
0258 row.subdet = _ass.getSubdetectorString(_id.subdet());
0259
0260 map.push_back(row);
0261 }
0262 }
0263 } else {
0264 edm::LogError("EMap") << "Pointer to HcalElectronicsMap is 0!!!";
0265 }
0266 }
0267
0268 int EMap::read_map(std::string filename) {
0269 RooGKCounter lines;
0270
0271 std::string _row;
0272 ifstream inFile(filename.c_str(), std::ios::in);
0273 if (!inFile) {
0274 edm::LogError("EMap") << "Unable to open file with the electronic map: " << filename;
0275 } else {
0276 edm::LogInfo("EMap") << "File with the electronic map opened successfully: " << filename;
0277 }
0278 while (getline(inFile, _row)) {
0279 EMapRow aRow;
0280 char fpga[32];
0281 char subdet[32];
0282
0283 int _read;
0284 const char* _format = "%d %d %d %s %d %d %d %d %s %d %d %d";
0285 _read = sscanf(_row.c_str(),
0286 _format,
0287 &(aRow.rawId),
0288 &(aRow.crate),
0289 &(aRow.slot),
0290 fpga,
0291 &(aRow.dcc),
0292 &(aRow.spigot),
0293 &(aRow.fiber),
0294 &(aRow.fiberchan),
0295 subdet,
0296 &(aRow.ieta),
0297 &(aRow.iphi),
0298 &(aRow.idepth));
0299 if (_read >= 12) {
0300 lines.count();
0301
0302 aRow.subdet.append(subdet);
0303 aRow.topbottom.append(fpga);
0304
0305 map.push_back(aRow);
0306
0307
0308 }
0309 }
0310 inFile.close();
0311 edm::LogInfo("EMap") << lines.getCount() << " lines read";
0312
0313 return 0;
0314 }
0315
0316 std::vector<EMap::EMapRow>& EMap::get_map(void) { return map; }
0317
0318 bool EMap::EMapRow::operator<(const EMap::EMapRow& other) const { return rawId < other.rawId; }
0319
0320
0321 int EMap_test::test_read_map(std::string filename) {
0322 EMap map(filename);
0323 return 0;
0324 }
0325
0326
0327 LMap_test::LMap_test() : _lmap(new LMap) {}
0328
0329 int LMap_test::test_read(std::string accessor, std::string type) {
0330 _lmap->read(accessor, type);
0331 return 0;
0332 }