CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CondFormats/CSCObjects/src/CSCReadoutMapping.cc

Go to the documentation of this file.
00001 #include <CondFormats/CSCObjects/interface/CSCReadoutMapping.h>
00002 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00003 #include <iostream>
00004 
00005 CSCReadoutMapping::CSCReadoutMapping() : myName_("CSCReadoutMapping"), debugV_( false ) {}
00006 
00007 CSCReadoutMapping::~CSCReadoutMapping(){}
00008 
00009 int CSCReadoutMapping::chamber( int endcap, int station, int vme, int dmb, int tmb ) const {
00010   // Build hw id from input, find sw id to match
00011   int cid = 0;
00012   int hid = hwId( endcap, station, vme, dmb, tmb );
00013   // Search for that hw id in mapping
00014   std::map<int,int>::const_iterator it = hw2sw_.find( hid );
00015   if ( it != hw2sw_.end() ) {
00016     cid = it->second;
00017     //    std::cout << "hwid = " << hid << ", swid = " << cid << std::endl;
00018     //    LogDebug("CSC") << " for requested hw id = " << hid << ", found sw id = " << cid;
00019   }
00020   else {
00021     edm::LogError("CSC") << " cannot find requested hw id = " << hid << " in mapping.";
00022   }
00023   return cid;
00024 }
00025 
00026 CSCDetId CSCReadoutMapping::detId( int endcap, int station, int vme, int dmb, int tmb, int cfeb, 
00027         int layer ) const {
00028 
00029   // Find CSCDetId index of chamber corresponding to the hardware readout arguments
00030   int cid = chamber( endcap, station, vme, dmb, tmb );
00031 
00032   // Decode the individual labels
00033   // ... include endcap & station for MTCC when they are unique in the mapping file
00034   // and so do not need to be specified as input arguments
00035       endcap  = CSCDetId::endcap( cid );
00036       station = CSCDetId::station( cid );
00037   int chamber = CSCDetId::chamber( cid );
00038   int ring    = CSCDetId::ring( cid );
00039 
00040   // Now sort out ME1a from ME11-combined
00041   // cfeb =0-3 for ME1b, cfeb=4 for ME1a
00042   if ( station == 1  && ring == 1 && cfeb == 4 ) {
00043       // This is ME1a region
00044       ring = 4; // reset from 1 to 4 which flags ME1a
00045   }
00046   return CSCDetId( endcap, station, ring, chamber, layer );
00047 }
00048 
00049 void CSCReadoutMapping::addRecord( int endcap, int station, int ring, int chamber, 
00050            int vmecrate, int dmb, int tmb, int tsector, int cscid, int ddu, int dcc ) {
00051 
00052   CSCLabel newRecord( endcap, station, ring, chamber, vmecrate, dmb, tmb, tsector, cscid, ddu, dcc );
00053   mapping_.push_back( newRecord );
00054   int hid = hwId( endcap, station, vmecrate, dmb, tmb );
00055   int sid = swId( endcap, station, ring, chamber);
00056   // LogDebug("CSC") << " map hw " << hid << " to sw " << sid;
00057   if ( hw2sw_.insert( std::make_pair(hid, sid) ).second ) {
00058     // LogDebug("CSC") << " insert pair succeeded.";
00059   }
00060   else {
00061     edm::LogError("CSC") << " already have key = " << hid;
00062   }
00064   sw2hw_.insert( std::make_pair(sid, newRecord) );
00065 
00066 } 
00067 
00068 int CSCReadoutMapping::swId( int endcap, int station, int ring, int chamber ) const {
00069   // Software id is just CSCDetId for the chamber - but no distinction within ME11
00070   return CSCDetId::rawIdMaker( endcap, station, ring, chamber, 0 ); // usual detid for chamber, i.e. layer=0
00071 }
00072 
00073 CSCReadoutMapping::CSCLabel CSCReadoutMapping::findHardwareId(const CSCDetId & id) const{
00074   CSCLabel hid;
00075   int sid=CSCDetId::rawIdMaker(id.endcap(), id.station(), id.ring(), id.chamber(), 0 );  
00077   std::map<int,CSCLabel>::const_iterator it = sw2hw_.find( sid );
00078   if ( it != sw2hw_.end() ) {
00079     hid = it->second;
00080     //    std::cout << "hwid = " << hid << ", swid = " << cid << std::endl;
00081     //    LogDebug("CSC") << " for requested hw id = " << hid << ", found sw id = " << cid;
00082   }
00083   else {
00084     edm::LogError("CSC") << " cannot find requested sw id = " << id << " in mapping.";
00085   }
00086   return hid;
00087 }
00088 
00089 int CSCReadoutMapping::crate(const CSCDetId & id) const {
00090   CSCLabel hid = findHardwareId(id);
00091   return hid.vmecrate_;
00092 }
00093 int CSCReadoutMapping::dmbId(const CSCDetId & id) const {
00094   CSCLabel hid = findHardwareId(id);
00095   return hid.dmb_;
00096 }
00097 int CSCReadoutMapping::dduId(const CSCDetId & id) const {
00098   CSCLabel hid = findHardwareId(id);
00099   return hid.ddu_;
00100 }
00101 int CSCReadoutMapping::dccId(const CSCDetId & id) const {
00102   CSCLabel hid = findHardwareId(id);
00103   return hid.dcc_;
00104 }