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
00011 int cid = 0;
00012 int hid = hwId( endcap, station, vme, dmb, tmb );
00013
00014 std::map<int,int>::const_iterator it = hw2sw_.find( hid );
00015 if ( it != hw2sw_.end() ) {
00016 cid = it->second;
00017
00018
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
00030 int cid = chamber( endcap, station, vme, dmb, tmb );
00031
00032
00033
00034
00035 endcap = CSCDetId::endcap( cid );
00036 station = CSCDetId::station( cid );
00037 int chamber = CSCDetId::chamber( cid );
00038 int ring = CSCDetId::ring( cid );
00039
00040
00041
00042 if ( station == 1 && ring == 1 && cfeb == 4 ) {
00043
00044 ring = 4;
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
00057 if ( hw2sw_.insert( std::make_pair(hid, sid) ).second ) {
00058
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
00070 return CSCDetId::rawIdMaker( endcap, station, ring, chamber, 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
00081
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 }