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 
131 void CSCTMBHeader::add(const std::vector<CSCShowerDigi> &digis) {
132  if (!digis.empty())
133  theHeaderFormat->addShower(digis[0]);
134 }
135 
137  CSCTMBHeader2007 *result = dynamic_cast<CSCTMBHeader2007 *>(theHeaderFormat.get());
138  if (result == nullptr) {
139  throw cms::Exception("Could not get 2007 TMB header format");
140  }
141  return *result;
142 }
143 
145  CSCTMBHeader2007_rev0x50c3 *result = dynamic_cast<CSCTMBHeader2007_rev0x50c3 *>(theHeaderFormat.get());
146  if (result == nullptr) {
147  throw cms::Exception("Could not get 2007 rev0x50c3 TMB header format");
148  }
149  return *result;
150 }
151 
153  CSCTMBHeader2013 *result = dynamic_cast<CSCTMBHeader2013 *>(theHeaderFormat.get());
154  if (result == nullptr) {
155  throw cms::Exception("Could not get 2013 TMB header format");
156  }
157  return *result;
158 }
159 
161  CSCTMBHeader2006 *result = dynamic_cast<CSCTMBHeader2006 *>(theHeaderFormat.get());
162  if (result == nullptr) {
163  throw cms::Exception("Could not get 2006 TMB header format");
164  }
165  return *result;
166 }
167 
168 void CSCTMBHeader::selfTest(int firmwareVersion, int firmwareRevision) {
169  constexpr bool debug = false;
170 
171  // tests packing and unpacking
172  for (int station = 1; station <= 4; ++station) {
173  for (int iendcap = 1; iendcap <= 2; ++iendcap) {
174  CSCDetId detId(iendcap, station, 1, 1, 0);
175 
176  // the next-to-last is the BX, which only gets
177  // saved in two bits and must be the same for clct0 and clct1.
178  //CSCCLCTDigi clct0(1, 1, 4, 0, 0, 30, 3, 0, 1); // valid for 2006
179  // In 2007 firmware, there are no distrips, so the 4th argument (strip
180  // type) should always be set to 1 (halfstrips).
181  CSCCLCTDigi clct0(1, 1, 4, 1, 0, 30, 4, 2, 1); // valid for 2007
182  CSCCLCTDigi clct1(1, 1, 3, 1, 1, 31, 1, 2, 2);
183 
184  // BX of LCT (8th argument) is 1-bit word (the least-significant bit
185  // of ALCT's bx).
186  CSCCorrelatedLCTDigi lct0(1, 1, 2, 10, 98, 5, 0, 1, 0, 0, 0, 0);
187  CSCCorrelatedLCTDigi lct1(2, 1, 2, 20, 15, 9, 1, 0, 0, 0, 0, 0);
188 
189  CSCTMBHeader tmbHeader(firmwareVersion, firmwareRevision);
190  tmbHeader.addCLCT0(clct0);
191  tmbHeader.addCLCT1(clct1);
192  tmbHeader.addCorrelatedLCT0(lct0);
193  tmbHeader.addCorrelatedLCT1(lct1);
194  std::vector<CSCCLCTDigi> clcts = tmbHeader.CLCTDigis(detId.rawId());
195  // guess they got reordered
196  assert(cscPackerCompare(clcts[0], clct0));
197  assert(cscPackerCompare(clcts[1], clct1));
198  if (debug) {
199  std::cout << "Match for: " << clct0 << "\n";
200  std::cout << " " << clct1 << "\n \n";
201  }
202 
203  std::vector<CSCCorrelatedLCTDigi> lcts = tmbHeader.CorrelatedLCTDigis(detId.rawId());
204  assert(cscPackerCompare(lcts[0], lct0));
205  assert(cscPackerCompare(lcts[1], lct1));
206  if (debug) {
207  std::cout << "Match for: " << lct0 << "\n";
208  std::cout << " " << lct1 << "\n";
209  }
210 
211  // try packing and re-packing, to make sure they're the same
212  unsigned short int *data = tmbHeader.data();
213  CSCTMBHeader newHeader(data);
214  clcts = newHeader.CLCTDigis(detId.rawId());
215  assert(cscPackerCompare(clcts[0], clct0));
216  assert(cscPackerCompare(clcts[1], clct1));
217  lcts = newHeader.CorrelatedLCTDigis(detId.rawId());
218  assert(cscPackerCompare(lcts[0], lct0));
219  assert(cscPackerCompare(lcts[1], lct1));
220  }
221  }
222 }
223 
224 std::ostream &operator<<(std::ostream &os, const CSCTMBHeader &hdr) {
225  hdr.theHeaderFormat->print(os);
226  return os;
227 }
MessageLogger.h
CSCTMBHeader::CorrelatedLCTDigis
std::vector< CSCCorrelatedLCTDigi > CorrelatedLCTDigis(uint32_t idlayer) const
returns CorrelatedLCT digis
Definition: CSCTMBHeader.h:72
CSCTMBHeader::debug
static std::atomic< bool > debug
Definition: CSCTMBHeader.h:116
relativeConstraints.station
station
Definition: relativeConstraints.py:67
CSCTMBHeader::tmbHeader2013
CSCTMBHeader2013 tmbHeader2013() const
Definition: CSCTMBHeader.cc:152
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:160
CSCCorrelatedLCTDigi.h
CSCTMBHeader::CLCTDigis
std::vector< CSCCLCTDigi > CLCTDigis(uint32_t idlayer)
returns CLCT digis
Definition: CSCTMBHeader.h:69
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:136
CSCDMBHeader.h
CSCTMBHeader::addCorrelatedLCT0
void addCorrelatedLCT0(const CSCCorrelatedLCTDigi &digi)
Definition: CSCTMBHeader.h:97
CSCTMBHeader2013.h
CSCTMBHeader::tmbHeader2007_rev0x50c3
CSCTMBHeader2007_rev0x50c3 tmbHeader2007_rev0x50c3() const
Definition: CSCTMBHeader.cc:144
CSCTMBHeader::addCorrelatedLCT1
void addCorrelatedLCT1(const CSCCorrelatedLCTDigi &digi)
Definition: CSCTMBHeader.h:98
CSCTMBHeader::addCLCT1
void addCLCT1(const CSCCLCTDigi &digi)
Definition: CSCTMBHeader.h:94
CSCTMBHeader::addCLCT0
void addCLCT0(const CSCCLCTDigi &digi)
Needed before data packing.
Definition: CSCTMBHeader.h:93
operator<<
std::ostream & operator<<(std::ostream &os, const CSCTMBHeader &hdr)
Definition: CSCTMBHeader.cc:224
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:160
CSCTMBHeader
Definition: CSCTMBHeader.h:27
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:119
Exception
Definition: hltDiff.cc:245
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:82
CSCTMBHeader::theFirmwareVersion
int theFirmwareVersion
Definition: CSCTMBHeader.h:120
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:168
CSCTMBHeader2006.h