CMS 3D CMS Logo

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