CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCReadoutMapping.cc
Go to the documentation of this file.
3 #include <iostream>
4 
5 CSCReadoutMapping::CSCReadoutMapping() : myName_("CSCReadoutMapping"), debugV_( false ) {}
6 
8 
9 int CSCReadoutMapping::chamber( int endcap, int station, int vme, int dmb, int tmb ) const {
10  // Build hw id from input, find sw id to match
11  int cid = 0;
12  int hid = hwId( endcap, station, vme, dmb, tmb );
13  // Search for that hw id in mapping
14  std::map<int,int>::const_iterator it = hw2sw_.find( hid );
15  if ( it != hw2sw_.end() ) {
16  cid = it->second;
17  // std::cout << "hwid = " << hid << ", swid = " << cid << std::endl;
18  // LogDebug("CSC") << " for requested hw id = " << hid << ", found sw id = " << cid;
19  }
20  else {
21  edm::LogError("CSC") << " cannot find requested hw id = " << hid << " in mapping.";
22  }
23  return cid;
24 }
25 
26 CSCDetId CSCReadoutMapping::detId( int endcap, int station, int vme, int dmb, int tmb, int cfeb,
27  int layer ) const {
28 
29  // Find CSCDetId index of chamber corresponding to the hardware readout arguments
30  int cid = chamber( endcap, station, vme, dmb, tmb );
31 
32  // Decode the individual labels
33  // ... include endcap & station for MTCC when they are unique in the mapping file
34  // and so do not need to be specified as input arguments
35  endcap = CSCDetId::endcap( cid );
36  station = CSCDetId::station( cid );
37  int chamber = CSCDetId::chamber( cid );
38  int ring = CSCDetId::ring( cid );
39 
40  // Now sort out ME1a from ME11-combined
41  // cfeb =0-3 for ME1b, cfeb=4 for ME1a (pre-LS1) cfeb=4-6 (post-LS1)
42  if ( station == 1 && ring == 1 && cfeb >= 4 && cfeb <= 6 ) {
43  // This is ME1a region
44  ring = 4; // reset from 1 to 4 which flags ME1a
45  }
46 
47  return CSCDetId( endcap, station, ring, chamber, layer );
48 }
49 
50 void CSCReadoutMapping::addRecord( int endcap, int station, int ring, int chamber,
51  int vmecrate, int dmb, int tmb, int tsector, int cscid, int ddu, int dcc ) {
52 
53  CSCLabel newRecord( endcap, station, ring, chamber, vmecrate, dmb, tmb, tsector, cscid, ddu, dcc );
54  mapping_.push_back( newRecord );
55  int hid = hwId( endcap, station, vmecrate, dmb, tmb );
56  int sid = swId( endcap, station, ring, chamber);
57  // LogDebug("CSC") << " map hw " << hid << " to sw " << sid;
58  if ( hw2sw_.insert( std::make_pair(hid, sid) ).second ) {
59  // LogDebug("CSC") << " insert pair succeeded.";
60  }
61  else {
62  edm::LogError("CSC") << " already have key = " << hid;
63  }
65  sw2hw_.insert( std::make_pair(sid, newRecord) );
66 
67 }
68 
69 int CSCReadoutMapping::swId( int endcap, int station, int ring, int chamber ) const {
70  // Software id is just CSCDetId for the chamber - but no distinction within ME11
71  return CSCDetId::rawIdMaker( endcap, station, ring, chamber, 0 ); // usual detid for chamber, i.e. layer=0
72 }
73 
75  CSCLabel hid;
76  int sid=CSCDetId::rawIdMaker(id.endcap(), id.station(), id.ring(), id.chamber(), 0 );
78  std::map<int,CSCLabel>::const_iterator it = sw2hw_.find( sid );
79  if ( it != sw2hw_.end() ) {
80  hid = it->second;
81  // std::cout << "hwid = " << hid << ", swid = " << cid << std::endl;
82  // LogDebug("CSC") << " for requested hw id = " << hid << ", found sw id = " << cid;
83  }
84  else {
85  edm::LogError("CSC") << " cannot find requested sw id = " << id << " in mapping.";
86  }
87  return hid;
88 }
89 
90 int CSCReadoutMapping::crate(const CSCDetId & id) const {
91  CSCLabel hid = findHardwareId(id);
92  return hid.vmecrate_;
93 }
94 int CSCReadoutMapping::dmbId(const CSCDetId & id) const {
95  CSCLabel hid = findHardwareId(id);
96  return hid.dmb_;
97 }
98 int CSCReadoutMapping::dduId(const CSCDetId & id) const {
99  CSCLabel hid = findHardwareId(id);
100  return hid.ddu_;
101 }
102 int CSCReadoutMapping::dccId(const CSCDetId & id) const {
103  CSCLabel hid = findHardwareId(id);
104  return hid.dcc_;
105 }
int chamber() const
Definition: CSCDetId.h:70
std::vector< CSCLabel > mapping_
int chamber(int endcap, int station, int vmecrate, int dmb, int tmb) const
int swId(int endcap, int station, int ring, int chamber) const
static int rawIdMaker(int iendcap, int istation, int iring, int ichamber, int ilayer)
Definition: CSCDetId.h:146
int dmbId(const CSCDetId &) const
returns dmbId given CSCDetId
CSCLabel findHardwareId(const CSCDetId &) const
returns hardware ids given chamber id
virtual int hwId(int endcap, int station, int vme, int dmb, int tmb) const =0
CSCDetId detId(int endcap, int station, int vmecrate, int dmb, int tmb, int cfeb, int layer=0) const
int endcap() const
Definition: CSCDetId.h:95
int crate(const CSCDetId &) const
returns vmecrate given CSCDetId
void addRecord(int endcap, int station, int ring, int chamber, int vmecrate, int dmb, int tmb, int tsector, int cscid, int ddu, int dcc)
std::map< int, int > hw2sw_
int dccId(const CSCDetId &) const
returns DCC# given CSCDetId
int ring() const
Definition: CSCDetId.h:77
CSCReadoutMapping()
Default constructor.
int station() const
Definition: CSCDetId.h:88
int dduId(const CSCDetId &) const
returns DDU# given CSCDetId
std::map< int, CSCLabel > sw2hw_
virtual ~CSCReadoutMapping()
Destructor.