CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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 (pre-LS1) cfeb=4-6 (post-LS1)
00042   if ( station == 1  && ring == 1 && cfeb >= 4 && cfeb <= 6 ) {
00043       // This is ME1a region
00044       ring = 4; // reset from 1 to 4 which flags ME1a
00045   }
00046   
00047   return CSCDetId( endcap, station, ring, chamber, layer );
00048 }
00049 
00050 void CSCReadoutMapping::addRecord( int endcap, int station, int ring, int chamber, 
00051            int vmecrate, int dmb, int tmb, int tsector, int cscid, int ddu, int dcc ) {
00052 
00053   CSCLabel newRecord( endcap, station, ring, chamber, vmecrate, dmb, tmb, tsector, cscid, ddu, dcc );
00054   mapping_.push_back( newRecord );
00055   int hid = hwId( endcap, station, vmecrate, dmb, tmb );
00056   int sid = swId( endcap, station, ring, chamber);
00057   // LogDebug("CSC") << " map hw " << hid << " to sw " << sid;
00058   if ( hw2sw_.insert( std::make_pair(hid, sid) ).second ) {
00059     // LogDebug("CSC") << " insert pair succeeded.";
00060   }
00061   else {
00062     edm::LogError("CSC") << " already have key = " << hid;
00063   }
00065   sw2hw_.insert( std::make_pair(sid, newRecord) );
00066 
00067 } 
00068 
00069 int CSCReadoutMapping::swId( int endcap, int station, int ring, int chamber ) const {
00070   // Software id is just CSCDetId for the chamber - but no distinction within ME11
00071   return CSCDetId::rawIdMaker( endcap, station, ring, chamber, 0 ); // usual detid for chamber, i.e. layer=0
00072 }
00073 
00074 CSCReadoutMapping::CSCLabel CSCReadoutMapping::findHardwareId(const CSCDetId & id) const{
00075   CSCLabel hid;
00076   int sid=CSCDetId::rawIdMaker(id.endcap(), id.station(), id.ring(), id.chamber(), 0 );  
00078   std::map<int,CSCLabel>::const_iterator it = sw2hw_.find( sid );
00079   if ( it != sw2hw_.end() ) {
00080     hid = it->second;
00081     //    std::cout << "hwid = " << hid << ", swid = " << cid << std::endl;
00082     //    LogDebug("CSC") << " for requested hw id = " << hid << ", found sw id = " << cid;
00083   }
00084   else {
00085     edm::LogError("CSC") << " cannot find requested sw id = " << id << " in mapping.";
00086   }
00087   return hid;
00088 }
00089 
00090 int CSCReadoutMapping::crate(const CSCDetId & id) const {
00091   CSCLabel hid = findHardwareId(id);
00092   return hid.vmecrate_;
00093 }
00094 int CSCReadoutMapping::dmbId(const CSCDetId & id) const {
00095   CSCLabel hid = findHardwareId(id);
00096   return hid.dmb_;
00097 }
00098 int CSCReadoutMapping::dduId(const CSCDetId & id) const {
00099   CSCLabel hid = findHardwareId(id);
00100   return hid.ddu_;
00101 }
00102 int CSCReadoutMapping::dccId(const CSCDetId & id) const {
00103   CSCLabel hid = findHardwareId(id);
00104   return hid.dcc_;
00105 }