CMS 3D CMS Logo

CSCTMBHeader.cc
Go to the documentation of this file.
11 #include <cmath>
12 #include <cstring> // memcpy
13 
14 #ifdef LOCAL_UNPACK
15 bool CSCTMBHeader::debug = false;
16 #else
17 std::atomic<bool> CSCTMBHeader::debug{false};
18 #endif
19 
20 CSCTMBHeader::CSCTMBHeader(int firmwareVersion, int firmwareRevision)
21  : theHeaderFormat(), theFirmwareVersion(firmwareVersion) {
22  if (firmwareVersion == 2013) {
23  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2013());
24  } else if (firmwareVersion == 2006) {
25  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2006());
26  } else if (firmwareVersion == 2007) {
27  /* Checks for TMB2007 firmware revisions ranges to detect data format
28  * rev.0x50c3 - first revision with changed format
29  * rev.0x42D5 - oldest known from 06/21/2007
30  * There is 4-bits year value rollover in revision number (0 in 2016)
31  */
32  if ((firmwareRevision >= 0x50c3) || (firmwareRevision < 0x42D5)) {
33  // if (firmwareRevision >= 0x7a76) // First OTMB firmware revision with 2013 format
34  /* Revisions > 0x6000 - OTMB firmwares, < 0x42D5 - new TMB revisions in 2016 */
35  if ((firmwareRevision >= 0x6000) || (firmwareRevision < 0x42D5)) {
36  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2013());
37  } else {
38  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2007_rev0x50c3());
39  }
40  } else {
41  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2007());
42  }
43  } else {
44  edm::LogError("CSCTMBHeader|CSCRawToDigi") << "failed to determine TMB firmware version!!";
45  }
46 }
47 
48 //CSCTMBHeader::CSCTMBHeader(const CSCTMBStatusDigi & digi) {
49 // CSCTMBHeader(digi.header());
50 //}
51 
52 CSCTMBHeader::CSCTMBHeader(const unsigned short *buf) : theHeaderFormat() {
54  if (buf[0] == 0xDB0C) {
55  theFirmwareVersion = 2007;
56  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2007(buf));
57  /* Checks for TMB2007 firmware revisions ranges to detect data format
58  * rev.0x50c3 - first revision with changed format
59  * rev.0x42D5 - oldest known from 06/21/2007
60  * There is 4-bits year value rollover in revision number (0 in 2016)
61  */
62  if ((theHeaderFormat->firmwareRevision() >= 0x50c3) || (theHeaderFormat->firmwareRevision() < 0x42D5)) {
63  // if (theHeaderFormat->firmwareRevision() >= 0x7a76) // First OTMB firmware revision with 2013 format
64  /* Revisions > 0x6000 - OTMB firmwares, < 0x42D5 - new TMB revisions in 2016 */
65  if ((theHeaderFormat->firmwareRevision() >= 0x6000) || (theHeaderFormat->firmwareRevision() < 0x42D5)) {
66  theFirmwareVersion = 2013;
67  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2013(buf));
68  } else {
69  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2007_rev0x50c3(buf));
70  }
71  }
72 
73  } else if (buf[0] == 0x6B0C) {
74  theFirmwareVersion = 2006;
75  theHeaderFormat = std::shared_ptr<CSCVTMBHeaderFormat>(new CSCTMBHeader2006(buf));
76  } else {
77  edm::LogError("CSCTMBHeader|CSCRawToDigi") << "failed to determine TMB firmware version!!";
78  }
79 }
80 
81 /*
82 void CSCTMBHeader::swapCLCTs(CSCCLCTDigi& digi1, CSCCLCTDigi& digi2)
83 {
84  bool me11 = (theChamberId.station() == 1 &&
85  (theChamberId.ring() == 1 || theChamberId.ring() == 4));
86  if (!me11) return;
87 
88  int cfeb1 = digi1.getCFEB();
89  int cfeb2 = digi2.getCFEB();
90  if (cfeb1 != cfeb2) return;
91 
92  bool me1a = (cfeb1 == 4);
93  bool me1b = (cfeb1 != 4);
94  bool zplus = (theChamberId.endcap() == 1);
95 
96  if ( (me1a && zplus) || (me1b && !zplus)) {
97  // Swap CLCTs if they have the same quality and pattern # (priority
98  // has to be given to the lower key).
99  if (digi1.getQuality() == digi2.getQuality() &&
100  digi1.getPattern() == digi2.getPattern()) {
101  CSCCLCTDigi temp = digi1;
102  digi1 = digi2;
103  digi2 = temp;
104 
105  // Also re-number them.
106  digi1.setTrknmb(1);
107  digi2.setTrknmb(2);
108  }
109  }
110 }
111 */
112 
113 //FIXME Pick which LCT goes first
114 void CSCTMBHeader::add(const std::vector<CSCCLCTDigi> &digis) {
115  // sort???
116  if (!digis.empty()) {
117  addCLCT0(digis[0]);
118  }
119  if (digis.size() > 1)
120  addCLCT1(digis[1]);
121 }
122 
123 void CSCTMBHeader::add(const std::vector<CSCCorrelatedLCTDigi> &digis) {
124  // sort???
125  if (!digis.empty())
126  addCorrelatedLCT0(digis[0]);
127  if (digis.size() > 1)
128  addCorrelatedLCT1(digis[1]);
129 }
130 
132  CSCTMBHeader2007 *result = dynamic_cast<CSCTMBHeader2007 *>(theHeaderFormat.get());
133  if (result == nullptr) {
134  throw cms::Exception("Could not get 2007 TMB header format");
135  }
136  return *result;
137 }
138 
140  CSCTMBHeader2007_rev0x50c3 *result = dynamic_cast<CSCTMBHeader2007_rev0x50c3 *>(theHeaderFormat.get());
141  if (result == nullptr) {
142  throw cms::Exception("Could not get 2007 rev0x50c3 TMB header format");
143  }
144  return *result;
145 }
146 
148  CSCTMBHeader2013 *result = dynamic_cast<CSCTMBHeader2013 *>(theHeaderFormat.get());
149  if (result == nullptr) {
150  throw cms::Exception("Could not get 2013 TMB header format");
151  }
152  return *result;
153 }
154 
156  CSCTMBHeader2006 *result = dynamic_cast<CSCTMBHeader2006 *>(theHeaderFormat.get());
157  if (result == nullptr) {
158  throw cms::Exception("Could not get 2006 TMB header format");
159  }
160  return *result;
161 }
162 
163 void CSCTMBHeader::selfTest(int firmwareVersion, int firmwareRevision) {
164  constexpr bool debug = false;
165 
166  // tests packing and unpacking
167  for (int station = 1; station <= 4; ++station) {
168  for (int iendcap = 1; iendcap <= 2; ++iendcap) {
169  CSCDetId detId(iendcap, station, 1, 1, 0);
170 
171  // the next-to-last is the BX, which only gets
172  // saved in two bits and must be the same for clct0 and clct1.
173  //CSCCLCTDigi clct0(1, 1, 4, 0, 0, 30, 3, 0, 1); // valid for 2006
174  // In 2007 firmware, there are no distrips, so the 4th argument (strip
175  // type) should always be set to 1 (halfstrips).
176  CSCCLCTDigi clct0(1, 1, 4, 1, 0, 30, 4, 2, 1); // valid for 2007
177  CSCCLCTDigi clct1(1, 1, 3, 1, 1, 31, 1, 2, 2);
178 
179  // BX of LCT (8th argument) is 1-bit word (the least-significant bit
180  // of ALCT's bx).
181  CSCCorrelatedLCTDigi lct0(1, 1, 2, 10, 98, 5, 0, 1, 0, 0, 0, 0);
182  CSCCorrelatedLCTDigi lct1(2, 1, 2, 20, 15, 9, 1, 0, 0, 0, 0, 0);
183 
184  CSCTMBHeader tmbHeader(firmwareVersion, firmwareRevision);
185  tmbHeader.addCLCT0(clct0);
186  tmbHeader.addCLCT1(clct1);
187  tmbHeader.addCorrelatedLCT0(lct0);
188  tmbHeader.addCorrelatedLCT1(lct1);
189  std::vector<CSCCLCTDigi> clcts = tmbHeader.CLCTDigis(detId.rawId());
190  // guess they got reordered
191  assert(cscPackerCompare(clcts[0], clct0));
192  assert(cscPackerCompare(clcts[1], clct1));
193  if (debug) {
194  std::cout << "Match for: " << clct0 << "\n";
195  std::cout << " " << clct1 << "\n \n";
196  }
197 
198  std::vector<CSCCorrelatedLCTDigi> lcts = tmbHeader.CorrelatedLCTDigis(detId.rawId());
199  assert(cscPackerCompare(lcts[0], lct0));
200  assert(cscPackerCompare(lcts[1], lct1));
201  if (debug) {
202  std::cout << "Match for: " << lct0 << "\n";
203  std::cout << " " << lct1 << "\n";
204  }
205 
206  // try packing and re-packing, to make sure they're the same
207  unsigned short int *data = tmbHeader.data();
208  CSCTMBHeader newHeader(data);
209  clcts = newHeader.CLCTDigis(detId.rawId());
210  assert(cscPackerCompare(clcts[0], clct0));
211  assert(cscPackerCompare(clcts[1], clct1));
212  lcts = newHeader.CorrelatedLCTDigis(detId.rawId());
213  assert(cscPackerCompare(lcts[0], lct0));
214  assert(cscPackerCompare(lcts[1], lct1));
215  }
216  }
217 }
218 
219 std::ostream &operator<<(std::ostream &os, const CSCTMBHeader &hdr) {
220  hdr.theHeaderFormat->print(os);
221  return os;
222 }
MessageLogger.h
CSCTMBHeader::CorrelatedLCTDigis
std::vector< CSCCorrelatedLCTDigi > CorrelatedLCTDigis(uint32_t idlayer) const
returns CorrelatedLCT digis
Definition: CSCTMBHeader.h:71
CSCTMBHeader::debug
static std::atomic< bool > debug
Definition: CSCTMBHeader.h:114
relativeConstraints.station
station
Definition: relativeConstraints.py:67
CSCTMBHeader::tmbHeader2013
CSCTMBHeader2013 tmbHeader2013() const
Definition: CSCTMBHeader.cc:147
CSCTMBHeader2007_rev0x50c3.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
CSCTMBHeader2007_rev0x50c3
Definition: CSCTMBHeader2007_rev0x50c3.h:6
cms::cuda::assert
assert(be >=bs)
CSCTMBHeader::tmbHeader2006
CSCTMBHeader2006 tmbHeader2006() const
Definition: CSCTMBHeader.cc:155
CSCCorrelatedLCTDigi.h
CSCTMBHeader::CLCTDigis
std::vector< CSCCLCTDigi > CLCTDigis(uint32_t idlayer)
returns CLCT digis
Definition: CSCTMBHeader.h:68
cscPackerCompare.h
CSCCLCTDigi
Definition: CSCCLCTDigi.h:17
CSCTMBHeader::CSCTMBHeader
CSCTMBHeader(int firmwareVersion, int firmwareRevision)
Definition: CSCTMBHeader.cc:20
CSCTMBHeader2007
Definition: CSCTMBHeader2007.h:6
simCaloStage2Layer1Digis_cfi.firmwareVersion
firmwareVersion
Definition: simCaloStage2Layer1Digis_cfi.py:21
cscPackerCompare
bool cscPackerCompare(const T &t1, const T &t2)
Definition: cscPackerCompare.h:12
CSCTMBHeader::tmbHeader2007
CSCTMBHeader2007 tmbHeader2007() const
will throw if the cast fails
Definition: CSCTMBHeader.cc:131
CSCDMBHeader.h
CSCTMBHeader::addCorrelatedLCT0
void addCorrelatedLCT0(const CSCCorrelatedLCTDigi &digi)
Definition: CSCTMBHeader.h:96
CSCTMBHeader2013.h
CSCTMBHeader::tmbHeader2007_rev0x50c3
CSCTMBHeader2007_rev0x50c3 tmbHeader2007_rev0x50c3() const
Definition: CSCTMBHeader.cc:139
CSCTMBHeader::addCorrelatedLCT1
void addCorrelatedLCT1(const CSCCorrelatedLCTDigi &digi)
Definition: CSCTMBHeader.h:97
CSCTMBHeader::addCLCT1
void addCLCT1(const CSCCLCTDigi &digi)
Definition: CSCTMBHeader.h:93
CSCTMBHeader::addCLCT0
void addCLCT0(const CSCCLCTDigi &digi)
Needed before data packing.
Definition: CSCTMBHeader.h:92
operator<<
std::ostream & operator<<(std::ostream &os, const CSCTMBHeader &hdr)
Definition: CSCTMBHeader.cc:219
CSCDetId
Definition: CSCDetId.h:26
CSCTMBHeader2006
Definition: CSCTMBHeader2006.h:6
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
CSCTMBHeader
Definition: CSCTMBHeader.h:26
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CSCTMBHeader2007.h
CSCTMBHeader::theHeaderFormat
std::shared_ptr< CSCVTMBHeaderFormat > theHeaderFormat
Definition: CSCTMBHeader.h:117
Exception
Definition: hltDiff.cc:246
CSCTMBHeader.h
CSCTMBHeader2013
Definition: CSCTMBHeader2013.h:6
CSCCLCTDigi.h
CSCTMBHeader::add
void add(const std::vector< CSCCLCTDigi > &digis)
these methods need more brains to figure which one goes first
Definition: CSCTMBHeader.cc:114
mps_fire.result
result
Definition: mps_fire.py:311
CSCTMBHeader::data
unsigned short * data()
Definition: CSCTMBHeader.h:81
CSCTMBHeader::theFirmwareVersion
int theFirmwareVersion
Definition: CSCTMBHeader.h:118
CSCCorrelatedLCTDigi
Definition: CSCCorrelatedLCTDigi.h:19
CSCTMBHeader::selfTest
static void selfTest(int firmwwareVersion, int firmwareRevision)
tests that packing and unpacking give same results
Definition: CSCTMBHeader.cc:163
CSCTMBHeader2006.h