CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCALCTHeader.h
Go to the documentation of this file.
1 #ifndef EventFilter_CSCRawToDigi_CSCALCTHeader_h
2 #define EventFilter_CSCRawToDigi_CSCALCTHeader_h
3 
7 #include <bitset>
8 #include <vector>
9 #include <iosfwd>
10 #ifndef LOCAL_UNPACK
11 #include <atomic>
12 #endif
20 #include <boost/dynamic_bitset.hpp>
21 
23 public:
24  explicit CSCALCTHeader(int chamberType);
25 
26  explicit CSCALCTHeader(const unsigned short *buf);
27 
28  CSCALCTHeader(const CSCALCTStatusDigi &digi);
29 
31  static void setDebug(bool value) { debug = value; };
32 
33  void setEventInformation(const CSCDMBHeader &);
34  unsigned short int nLCTChipRead() const;
35 
36  std::vector<CSCALCTDigi> ALCTDigis() const;
37 
40 
42  unsigned short int FIFOMode() const { return header2006.fifoMode; }
43  unsigned short int NTBins() const {
44 #ifdef LOCAL_UNPACK
45  switch (firmwareVersion) {
46 #else
47  switch (firmwareVersion.load()) {
48 #endif
49  case 2006:
50  return header2006.nTBins;
51  case 2007:
52  return header2007.rawBins;
53  default:
54  edm::LogError("CSCALCTHeader|CSCRawToDigi")
55  << "trying to access NTBINs: ALCT firmware version is bad/not defined!";
56  return 0;
57  }
58  }
59  unsigned short int BoardID() const { return header2006.boardID; }
60  unsigned short int ExtTrig() const { return header2006.extTrig; }
61  unsigned short int CSCID() const { return header2006.cscID; }
62  unsigned short int BXNCount() const {
63 #ifdef LOCAL_UNPACK
64  switch (firmwareVersion) {
65 #else
66  switch (firmwareVersion.load()) {
67 #endif
68  case 2006:
69  return header2006.bxnCount;
70  case 2007:
71  return header2007.bxnCount;
72  default:
73  edm::LogError("CSCALCTHeader|CSCRawToDigi")
74  << "trying to access BXNcount: ALCT firmware version is bad/not defined!";
75  return 0;
76  }
77  }
78 
79  void setBXNCount(unsigned int bxn) {
80 #ifdef LOCAL_UNPACK
81  switch (firmwareVersion) {
82 #else
83  switch (firmwareVersion.load()) {
84 #endif
85  case 2006:
86  header2006.bxnCount = bxn % 0xFFF;
87  break;
88  case 2007:
89  header2007.bxnCount = bxn % 0xFFF;
90  break;
91  default:
92  edm::LogError("CSCALCTHeader|CSCRawToDigi")
93  << "trying to set BXNcount: ALCT firmware version is bad/not defined!";
94  break;
95  }
96  }
97 
98  unsigned short int L1Acc() const {
99 #ifdef LOCAL_UNPACK
100  switch (firmwareVersion) {
101 #else
102  switch (firmwareVersion.load()) {
103 #endif
104  case 2006:
105  return header2006.l1Acc;
106  case 2007:
107  return header2007.l1aCounter;
108  default:
109  edm::LogError("CSCALCTHeader|CSCRawToDigi")
110  << "trying to access L1Acc: ALCT firmware version is bad/not defined!";
111  return 0;
112  }
113  }
114 
115  void setL1Acc(unsigned int l1a) {
116 #ifdef LOCAL_UNPACK
117  switch (firmwareVersion) {
118 #else
119  switch (firmwareVersion.load()) {
120 #endif
121  case 2006:
122  header2006.l1Acc = l1a % 0xF;
123  break;
124  case 2007:
125  header2007.l1aCounter = l1a % 0xFFF;
126  break;
127  default:
128  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "trying to set L1Acc: ALCT firmware version is bad/not defined!";
129  break;
130  }
131  }
132 
133  unsigned short int L1AMatch() const { return header2006.l1aMatch; }
134  unsigned short int ActiveFEBs() const { return header2006.activeFEBs; }
135  unsigned short int Promote1() const { return header2006.promote1; }
136  unsigned short int Promote2() const { return header2006.promote2; }
137  unsigned short int LCTChipRead() const { return header2006.lctChipRead; }
138  unsigned short int alctFirmwareVersion() const { return firmwareVersion; }
139  unsigned short int alctFirmwareRevision() const {
140 #ifdef LOCAL_UNPACK
141  switch (firmwareVersion) {
142 #else
143  switch (firmwareVersion.load()) {
144 #endif
145  case 2006:
146  return 0;
147  case 2007:
149  default:
150  edm::LogError("CSCALCTHeader|CSCRawToDigi")
151  << "trying to access ALCT firmware revision bits: ALCT firmware version is bad/not defined!";
152  return 0;
153  }
154  }
155 
156  std::vector<CSCShowerDigi> alctShowerDigis() const {
157  std::vector<CSCShowerDigi> results;
158  results.clear();
159 #ifdef LOCAL_UNPACK
160  switch (firmwareVersion) {
161 #else
162  switch (firmwareVersion.load()) {
163 #endif
164  case 2006:
165  return results;
166  case 2007:
167  // if (alctFirmwareRevision() >= 0) // TODO: Need ALCT Run3 firmware revision to properly detect presense of HMT bits in data format
168  // {
169  if ((!theALCTs.empty()) && (theALCTs.size() == unsigned(header2007.lctBins * 2))) {
170  for (unsigned bx = 0; bx < header2007.lctBins; bx++) {
171  results.push_back(CSCShowerDigi(theALCTs[bx * 2].reserved & 0x3, 0, bx));
172  }
173  return results;
174  } else
175  return results;
176  // } else return results;
177  default:
178  edm::LogError("CSCALCTHeader|CSCRawToDigi")
179  << "trying to access ALCT HMT Shower Digis bits: ALCT firmware version is bad/not defined!";
180  return results;
181  }
182  }
183 
184  std::vector<unsigned short int> alctHMTs() const {
185  std::vector<unsigned short int> results;
186  results.clear();
187 #ifdef LOCAL_UNPACK
188  switch (firmwareVersion) {
189 #else
190  switch (firmwareVersion.load()) {
191 #endif
192  case 2006:
193  return results;
194  case 2007:
195  // if (alctFirmwareRevision() >= 0) // TODO: Need ALCT Run3 firmware revision to properly detect presense of HMT bits in data format
196  // {
197  if ((!theALCTs.empty()) && (theALCTs.size() == unsigned(header2007.lctBins * 2))) {
198  for (unsigned bx = 0; bx < header2007.lctBins; bx++) {
199  results.push_back(theALCTs[bx * 2].reserved & 0x3);
200  }
201  return results;
202  } else
203  return results;
204  // } else return results;
205  default:
206  edm::LogError("CSCALCTHeader|CSCRawToDigi")
207  << "trying to access ALCT HMT bits: ALCT firmware version is bad/not defined!";
208  return results;
209  }
210  }
211 
212  void setDAVForChannel(int wireGroup) {
213  if (firmwareVersion == 2006) {
214  header2006.setDAV((wireGroup - 1) / 16);
215  }
216  }
217 
220 
221  unsigned short int *data() { return theOriginalBuffer; }
222 
224  int sizeInWords() {
225 #ifdef LOCAL_UNPACK
226  switch (firmwareVersion) {
227 #else
228  switch (firmwareVersion.load()) {
229 #endif
230  case 2006:
231  return 8;
232  case 2007:
233  return sizeInWords2007_;
234  default:
235  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "SizeInWords(): ALCT firmware version is bad/not defined!";
236  return 0;
237  }
238  }
239 
240  bool check() const {
241 #ifdef LOCAL_UNPACK
242  switch (firmwareVersion) {
243 #else
244  switch (firmwareVersion.load()) {
245 #endif
246  case 2006:
247  return header2006.flag_0 == 0xC;
248  case 2007:
249  return header2007.flag1 == 0xDB0A;
250  default:
251  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "check(): ALCT firmware version is bad/not defined!";
252  return false;
253  }
254  }
255 
256  void add(const std::vector<CSCALCTDigi> &digis);
258  void addShower(const std::vector<CSCShowerDigi> &digis);
259 
260  boost::dynamic_bitset<> pack();
261 
263  static void selfTest(int firmware);
264 
265 private:
268  std::vector<CSCALCT> theALCTs;
272  std::vector<CSCCollisionMask> collisionMasks;
273  std::vector<CSCHotChannelMask> hotChannelMasks;
274 
275  //raw data also stored in this buffer
276  //maximum header size is 116 words
277  unsigned short int theOriginalBuffer[116];
278 
279 #ifdef LOCAL_UNPACK
280  static bool debug;
281  static unsigned short int firmwareVersion;
282 #else
283  static std::atomic<bool> debug;
284  static std::atomic<unsigned short int> firmwareVersion;
285 #endif
286 
288  unsigned short int sizeInWords2007_, bxn0, bxn1;
289 };
290 
291 std::ostream &operator<<(std::ostream &os, const CSCALCTHeader &header);
292 
293 #endif
std::vector< CSCShowerDigi > alctShowerDigis() const
unsigned short int L1AMatch() const
unsigned bxnCount
full bunch crossing number
unsigned fifoMode
see the FIFO_MODE enum
unsigned short int LCTChipRead() const
std::vector< CSCHotChannelMask > hotChannelMasks
std::vector< CSCCollisionMask > collisionMasks
unsigned promote1
promotion bit for 1st LCT pattern
CSCVirtexID virtexID
unsigned short int bxn1
unsigned short int nLCTChipRead() const
for packing
dictionary results
void setBXNCount(unsigned int bxn)
Definition: CSCALCTHeader.h:79
CSCConfigurationRegister configRegister
CSCALCTHeader(int chamberType)
bool check() const
CSCALCTs2006 alcts2006
Log< level::Error, false > LogError
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
void setEventInformation(const CSCDMBHeader &)
static std::atomic< unsigned short int > firmwareVersion
static void selfTest(int firmware)
tests that we unpack what we packed
unsigned extTrig
trigger source was external
CSCALCTHeader2007 alctHeader2007() const
unsigned short int CSCID() const
Definition: CSCALCTHeader.h:61
unsigned short int theOriginalBuffer[116]
unsigned short int ActiveFEBs() const
CSCALCTHeader2006 header2006
unsigned short int ExtTrig() const
Definition: CSCALCTHeader.h:60
ALCT Header consists of several modular units that are defined as structs below.
std::vector< CSCALCT > theALCTs
void add(const std::vector< CSCALCTDigi > &digis)
CSCALCTHeader2007 header2007
boost::dynamic_bitset pack()
unsigned nTBins
of 25 ns time bins in the raw dump
unsigned short int sizeInWords2007_
size of the 2007 header in words
unsigned short int Promote2() const
int sizeInWords()
in 16-bit words
std::vector< CSCALCTDigi > ALCTDigis() const
unsigned short int Promote1() const
unsigned short int alctFirmwareVersion() const
unsigned short int bxn0
static void setDebug(bool value)
to access data by via status digis
Definition: CSCALCTHeader.h:31
unsigned short int L1Acc() const
Definition: CSCALCTHeader.h:98
unsigned l1Acc
l1 accept counter
unsigned promote2
promotion bit for 2nd LCT pattern
unsigned short int FIFOMode() const
Definition: CSCALCTHeader.h:42
unsigned boardID
ALCT2000 board ID.
unsigned short int NTBins() const
Definition: CSCALCTHeader.h:43
unsigned lctChipRead
LCT chips read out in raw hit dump.
unsigned activeFEBs
LCT chips with ADB hits.
CSCALCTHeader2006 alctHeader2006() const
unsigned cscID
chamber ID number
void setDAV(int afebBoard)
for packing
unsigned short int alctFirmwareRevision() const
void addShower(const std::vector< CSCShowerDigi > &digis)
Add Run3 ALCT HMT shower bits.
unsigned short int BXNCount() const
Definition: CSCALCTHeader.h:62
unsigned l1aMatch
exteran L1A arrived in L1A window
unsigned short int BoardID() const
Definition: CSCALCTHeader.h:59
void setDAVForChannel(int wireGroup)
void setL1Acc(unsigned int l1a)
static std::atomic< bool > debug
std::vector< unsigned short int > alctHMTs() const
unsigned flag_0
should be &#39;01100&#39;, so it&#39;ll be a 6xxx in the ASCII dump
unsigned short int * data()