Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:06

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author Paolo Ronchese INFN Padova
0005  *
0006  */
0007 
0008 //----------------------
0009 // This Class' Header --
0010 //----------------------
0011 #include "CondFormats/DTObjects/interface/DTHVStatus.h"
0012 
0013 //-------------------------------
0014 // Collaborating Class Headers --
0015 //-------------------------------
0016 #include "CondFormats/DTObjects/interface/DTBufferTree.h"
0017 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0018 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
0019 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0020 
0021 //---------------
0022 // C++ Headers --
0023 //---------------
0024 #include <iostream>
0025 #include <sstream>
0026 
0027 //-------------------
0028 // Initializations --
0029 //-------------------
0030 
0031 //----------------
0032 // Constructors --
0033 //----------------
0034 DTHVStatus::DTHVStatus() : dataVersion(" "), dBuf(new DTBufferTree<int, int>) { dataList.reserve(10); }
0035 
0036 DTHVStatus::DTHVStatus(const std::string& version) : dataVersion(version), dBuf(new DTBufferTree<int, int>) {
0037   dataList.reserve(10);
0038 }
0039 
0040 DTHVStatusId::DTHVStatusId() : wheelId(0), stationId(0), sectorId(0), slId(0), layerId(0), partId(0) {}
0041 
0042 DTHVStatusData::DTHVStatusData() : flagA(0), flagC(0), flagS(0) {}
0043 
0044 //--------------
0045 // Destructor --
0046 //--------------
0047 DTHVStatus::~DTHVStatus() {}
0048 
0049 DTHVStatusId::~DTHVStatusId() {}
0050 
0051 DTHVStatusData::~DTHVStatusData() {}
0052 
0053 //--------------
0054 // Operations --
0055 //--------------
0056 int DTHVStatus::get(int wheelId,
0057                     int stationId,
0058                     int sectorId,
0059                     int slId,
0060                     int layerId,
0061                     int partId,
0062                     int& fCell,
0063                     int& lCell,
0064                     int& flagA,
0065                     int& flagC,
0066                     int& flagS) const {
0067   fCell = lCell = flagA = flagC = flagS = 0;
0068 
0069   std::vector<int> chanKey;
0070   chanKey.reserve(6);
0071   chanKey.push_back(wheelId);
0072   chanKey.push_back(stationId);
0073   chanKey.push_back(sectorId);
0074   chanKey.push_back(slId);
0075   chanKey.push_back(layerId);
0076   chanKey.push_back(partId);
0077   int ientry;
0078   int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0079   if (!searchStatus) {
0080     const DTHVStatusData& data(dataList[ientry].second);
0081     fCell = data.fCell;
0082     lCell = data.lCell;
0083     flagA = data.flagA;
0084     flagC = data.flagC;
0085     flagS = data.flagS;
0086   }
0087 
0088   return searchStatus;
0089 }
0090 
0091 int DTHVStatus::get(const DTLayerId& id, int partId, int& fCell, int& lCell, int& flagA, int& flagC, int& flagS) const {
0092   return get(
0093       id.wheel(), id.station(), id.sector(), id.superLayer(), id.layer(), partId, fCell, lCell, flagA, flagC, flagS);
0094 }
0095 
0096 int DTHVStatus::get(const DTWireId& id, int& flagA, int& flagC, int& flagS) const {
0097   flagA = flagC = flagS = 0;
0098   int iCell = id.wire();
0099   int fCell;
0100   int lCell;
0101   int fCheck =
0102       get(id.wheel(), id.station(), id.sector(), id.superLayer(), id.layer(), 0, fCell, lCell, flagA, flagC, flagS);
0103   if ((fCheck == 0) && (fCell <= iCell) && (lCell >= iCell))
0104     return 0;
0105   fCheck =
0106       get(id.wheel(), id.station(), id.sector(), id.superLayer(), id.layer(), 1, fCell, lCell, flagA, flagC, flagS);
0107   if ((fCheck == 0) && (fCell <= iCell) && (lCell >= iCell))
0108     return 0;
0109   flagA = flagC = flagS = 0;
0110   return 1;
0111 }
0112 
0113 int DTHVStatus::offChannelsNumber() const {
0114   int offNum = 0;
0115   DTHVStatus::const_iterator iter = begin();
0116   DTHVStatus::const_iterator iend = end();
0117   while (iter != iend) {
0118     const std::pair<DTHVStatusId, DTHVStatusData>& entry = *iter++;
0119     DTHVStatusId hvId = entry.first;
0120     DTHVStatusData data = entry.second;
0121     int offA = data.flagA & 1;
0122     int offC = data.flagC & 1;
0123     int offS = data.flagS & 1;
0124     if (offA || offC || offS)
0125       offNum += (1 + data.lCell - data.fCell);
0126   }
0127   return offNum;
0128 }
0129 
0130 int DTHVStatus::offChannelsNumber(const DTChamberId& id) const {
0131   int offNum = 0;
0132   DTHVStatus::const_iterator iter = begin();
0133   DTHVStatus::const_iterator iend = end();
0134   while (iter != iend) {
0135     const std::pair<DTHVStatusId, DTHVStatusData>& entry = *iter++;
0136     DTHVStatusId hvId = entry.first;
0137     DTHVStatusData data = entry.second;
0138     if (hvId.wheelId != id.wheel())
0139       continue;
0140     if (hvId.stationId != id.station())
0141       continue;
0142     if (hvId.sectorId != id.sector())
0143       continue;
0144     int offA = data.flagA & 1;
0145     int offC = data.flagC & 1;
0146     int offS = data.flagS & 1;
0147     if (offA || offC || offS)
0148       offNum += (1 + data.lCell - data.fCell);
0149   }
0150   return offNum;
0151 }
0152 
0153 int DTHVStatus::badChannelsNumber() const {
0154   int offNum = 0;
0155   DTHVStatus::const_iterator iter = begin();
0156   DTHVStatus::const_iterator iend = end();
0157   while (iter != iend) {
0158     const std::pair<DTHVStatusId, DTHVStatusData>& entry = *iter++;
0159     DTHVStatusId hvId = entry.first;
0160     DTHVStatusData data = entry.second;
0161     if (data.flagA || data.flagC || data.flagS)
0162       offNum += (1 + data.lCell - data.fCell);
0163   }
0164   return offNum;
0165 }
0166 
0167 int DTHVStatus::badChannelsNumber(const DTChamberId& id) const {
0168   int offNum = 0;
0169   DTHVStatus::const_iterator iter = begin();
0170   DTHVStatus::const_iterator iend = end();
0171   while (iter != iend) {
0172     const std::pair<DTHVStatusId, DTHVStatusData>& entry = *iter++;
0173     DTHVStatusId hvId = entry.first;
0174     DTHVStatusData data = entry.second;
0175     if (hvId.wheelId != id.wheel())
0176       continue;
0177     if (hvId.stationId != id.station())
0178       continue;
0179     if (hvId.sectorId != id.sector())
0180       continue;
0181     if (data.flagA || data.flagC || data.flagS)
0182       offNum += (1 + data.lCell - data.fCell);
0183   }
0184   return offNum;
0185 }
0186 
0187 const std::string& DTHVStatus::version() const { return dataVersion; }
0188 
0189 std::string& DTHVStatus::version() { return dataVersion; }
0190 
0191 void DTHVStatus::clear() {
0192   dataList.clear();
0193   dataList.reserve(10);
0194   initialize();
0195   return;
0196 }
0197 
0198 int DTHVStatus::set(int wheelId,
0199                     int stationId,
0200                     int sectorId,
0201                     int slId,
0202                     int layerId,
0203                     int partId,
0204                     int fCell,
0205                     int lCell,
0206                     int flagA,
0207                     int flagC,
0208                     int flagS) {
0209   std::vector<int> chanKey;
0210   chanKey.reserve(6);
0211   chanKey.push_back(wheelId);
0212   chanKey.push_back(stationId);
0213   chanKey.push_back(sectorId);
0214   chanKey.push_back(slId);
0215   chanKey.push_back(layerId);
0216   chanKey.push_back(partId);
0217   int ientry;
0218   int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0219 
0220   if (!searchStatus) {
0221     DTHVStatusData& data(dataList[ientry].second);
0222     data.fCell = fCell;
0223     data.lCell = lCell;
0224     data.flagA = flagA;
0225     data.flagC = flagC;
0226     data.flagS = flagS;
0227     return -1;
0228   } else {
0229     DTHVStatusId key;
0230     key.wheelId = wheelId;
0231     key.stationId = stationId;
0232     key.sectorId = sectorId;
0233     key.slId = slId;
0234     key.layerId = layerId;
0235     key.partId = partId;
0236     DTHVStatusData data;
0237     data.fCell = fCell;
0238     data.lCell = lCell;
0239     data.flagA = flagA;
0240     data.flagC = flagC;
0241     data.flagS = flagS;
0242     ientry = dataList.size();
0243     dataList.push_back(std::pair<DTHVStatusId, DTHVStatusData>(key, data));
0244     dBuf->insert(chanKey.begin(), chanKey.end(), ientry);
0245     return 0;
0246   }
0247 
0248   return 99;
0249 }
0250 
0251 int DTHVStatus::set(const DTLayerId& id, int partId, int fCell, int lCell, int flagA, int flagC, int flagS) {
0252   return set(
0253       id.wheel(), id.station(), id.sector(), id.superLayer(), id.layer(), partId, fCell, lCell, flagA, flagC, flagS);
0254 }
0255 
0256 int DTHVStatus::setFlagA(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int flag) {
0257   int fCell;
0258   int lCell;
0259   int flagA;
0260   int flagC;
0261   int flagS;
0262   get(wheelId, stationId, sectorId, slId, layerId, partId, fCell, lCell, flagA, flagC, flagS);
0263   return set(wheelId, stationId, sectorId, slId, layerId, partId, fCell, lCell, flag, flagC, flagS);
0264 }
0265 
0266 int DTHVStatus::setFlagA(const DTLayerId& id, int partId, int flag) {
0267   return setFlagA(id.wheel(), id.station(), id.sector(), id.superLayer(), id.layer(), partId, flag);
0268 }
0269 
0270 int DTHVStatus::setFlagC(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int flag) {
0271   int fCell;
0272   int lCell;
0273   int flagA;
0274   int flagC;
0275   int flagS;
0276   get(wheelId, stationId, sectorId, slId, layerId, partId, fCell, lCell, flagA, flagC, flagS);
0277   return set(wheelId, stationId, sectorId, slId, layerId, partId, fCell, lCell, flagA, flag, flagS);
0278 }
0279 
0280 int DTHVStatus::setFlagC(const DTLayerId& id, int partId, int flag) {
0281   return setFlagC(id.wheel(), id.station(), id.sector(), id.superLayer(), id.layer(), partId, flag);
0282 }
0283 
0284 int DTHVStatus::setFlagS(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int flag) {
0285   int fCell;
0286   int lCell;
0287   int flagA;
0288   int flagC;
0289   int flagS;
0290   get(wheelId, stationId, sectorId, slId, layerId, partId, fCell, lCell, flagA, flagC, flagS);
0291   return set(wheelId, stationId, sectorId, slId, layerId, partId, fCell, lCell, flagA, flagC, flag);
0292 }
0293 
0294 int DTHVStatus::setFlagS(const DTLayerId& id, int partId, int flag) {
0295   return setFlagS(id.wheel(), id.station(), id.sector(), id.superLayer(), id.layer(), partId, flag);
0296 }
0297 
0298 DTHVStatus::const_iterator DTHVStatus::begin() const { return dataList.begin(); }
0299 
0300 DTHVStatus::const_iterator DTHVStatus::end() const { return dataList.end(); }
0301 
0302 std::string DTHVStatus::mapName() const {
0303   std::stringstream name;
0304   name << dataVersion << "_map_HV" << this;
0305   return name.str();
0306 }
0307 
0308 void DTHVStatus::initialize() {
0309   dBuf->clear();
0310 
0311   int entryNum = 0;
0312   int entryMax = dataList.size();
0313   std::vector<int> chanKey;
0314   chanKey.reserve(6);
0315   while (entryNum < entryMax) {
0316     const DTHVStatusId& chan = dataList[entryNum].first;
0317 
0318     chanKey.clear();
0319     chanKey.push_back(chan.wheelId);
0320     chanKey.push_back(chan.stationId);
0321     chanKey.push_back(chan.sectorId);
0322     chanKey.push_back(chan.slId);
0323     chanKey.push_back(chan.layerId);
0324     chanKey.push_back(chan.partId);
0325     dBuf->insert(chanKey.begin(), chanKey.end(), entryNum++);
0326   }
0327 
0328   return;
0329 }