Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:56

0001 #include <CondFormats/CSCObjects/interface/CSCReadoutMapping.h>
0002 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0003 #include <iostream>
0004 
0005 CSCReadoutMapping::CSCReadoutMapping() : myName_("CSCReadoutMapping"), debugV_(false) {}
0006 
0007 CSCReadoutMapping::~CSCReadoutMapping() {}
0008 
0009 int CSCReadoutMapping::chamber(int endcap, int station, int vme, int dmb, int tmb) const {
0010   // Build hw id from input, find sw id to match
0011   int cid = 0;
0012   int hid = hwId(endcap, station, vme, dmb, tmb);
0013   // Search for that hw id in mapping
0014   std::map<int, int>::const_iterator it = hw2sw_.find(hid);
0015   if (it != hw2sw_.end()) {
0016     cid = it->second;
0017     //    std::cout << "hwid = " << hid << ", swid = " << cid << std::endl;
0018     //    LogDebug("CSC") << " for requested hw id = " << hid << ", found sw id = " << cid;
0019   } else {
0020     edm::LogError("CSC") << " cannot find requested hw id = " << hid << " in mapping.";
0021   }
0022   return cid;
0023 }
0024 
0025 CSCDetId CSCReadoutMapping::detId(int endcap, int station, int vme, int dmb, int tmb, int cfeb, int layer) const {
0026   // Find CSCDetId index of chamber corresponding to the hardware readout arguments
0027   int cid = chamber(endcap, station, vme, dmb, tmb);
0028 
0029   // Decode the individual labels
0030   // ... include endcap & station for MTCC when they are unique in the mapping file
0031   // and so do not need to be specified as input arguments
0032   endcap = CSCDetId::endcap(cid);
0033   station = CSCDetId::station(cid);
0034   int chamber = CSCDetId::chamber(cid);
0035   int ring = CSCDetId::ring(cid);
0036 
0037   // Now sort out ME1a from ME11-combined
0038   // cfeb =0-3 for ME1b, cfeb=4 for ME1a (pre-LS1) cfeb=4-6 (post-LS1)
0039   if (station == 1 && ring == 1 && cfeb >= 4 && cfeb <= 6) {
0040     // This is ME1a region
0041     ring = 4;  // reset from 1 to 4 which flags ME1a
0042   }
0043 
0044   return CSCDetId(endcap, station, ring, chamber, layer);
0045 }
0046 
0047 void CSCReadoutMapping::addRecord(int endcap,
0048                                   int station,
0049                                   int ring,
0050                                   int chamber,
0051                                   int vmecrate,
0052                                   int dmb,
0053                                   int tmb,
0054                                   int tsector,
0055                                   int cscid,
0056                                   int ddu,
0057                                   int dcc) {
0058   CSCLabel newRecord(endcap, station, ring, chamber, vmecrate, dmb, tmb, tsector, cscid, ddu, dcc);
0059   mapping_.push_back(newRecord);
0060   int hid = hwId(endcap, station, vmecrate, dmb, tmb);
0061   int sid = swId(endcap, station, ring, chamber);
0062   // LogDebug("CSC") << " map hw " << hid << " to sw " << sid;
0063   if (hw2sw_.insert(std::make_pair(hid, sid)).second) {
0064     // LogDebug("CSC") << " insert pair succeeded.";
0065   } else {
0066     edm::LogError("CSC") << " already have key = " << hid;
0067   }
0068   ///reverse mapping for software -> hadrware labels
0069   sw2hw_.insert(std::make_pair(sid, newRecord));
0070 }
0071 
0072 int CSCReadoutMapping::swId(int endcap, int station, int ring, int chamber) const {
0073   // Software id is just CSCDetId for the chamber - but no distinction within ME11
0074   return CSCDetId::rawIdMaker(endcap, station, ring, chamber, 0);  // usual detid for chamber, i.e. layer=0
0075 }
0076 
0077 CSCReadoutMapping::CSCLabel CSCReadoutMapping::findHardwareId(const CSCDetId& id) const {
0078   CSCLabel hid;
0079   int sid = CSCDetId::rawIdMaker(id.endcap(), id.station(), id.ring(), id.chamber(), 0);
0080   /// Search for that sw id in mapping
0081   std::map<int, CSCLabel>::const_iterator it = sw2hw_.find(sid);
0082   if (it != sw2hw_.end()) {
0083     hid = it->second;
0084     //    std::cout << "hwid = " << hid << ", swid = " << cid << std::endl;
0085     //    LogDebug("CSC") << " for requested hw id = " << hid << ", found sw id = " << cid;
0086   } else {
0087     edm::LogError("CSC") << " cannot find requested sw id = " << id << " in mapping.";
0088   }
0089   return hid;
0090 }
0091 
0092 int CSCReadoutMapping::crate(const CSCDetId& id) const {
0093   CSCLabel hid = findHardwareId(id);
0094   return hid.vmecrate_;
0095 }
0096 int CSCReadoutMapping::dmbId(const CSCDetId& id) const {
0097   CSCLabel hid = findHardwareId(id);
0098   return hid.dmb_;
0099 }
0100 int CSCReadoutMapping::dduId(const CSCDetId& id) const {
0101   CSCLabel hid = findHardwareId(id);
0102   return hid.ddu_;
0103 }
0104 int CSCReadoutMapping::dccId(const CSCDetId& id) const {
0105   CSCLabel hid = findHardwareId(id);
0106   return hid.dcc_;
0107 }