CMS 3D CMS Logo

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  //CSCID is set to be 0
172  //ALCTshower, showerType_= 1, wireNHits and ComparatorNHits are not available in data
173  results.push_back(
174  CSCShowerDigi(theALCTs[bx * 2].reserved & 0x3, 0, 0, bx, CSCShowerDigi::ShowerType::kALCTShower, 0, 0));
175  }
176  return results;
177  } else
178  return results;
179  // } else return results;
180  default:
181  edm::LogError("CSCALCTHeader|CSCRawToDigi")
182  << "trying to access ALCT HMT Shower Digis bits: ALCT firmware version is bad/not defined!";
183  return results;
184  }
185  }
186 
187  std::vector<unsigned short int> alctHMTs() const {
188  std::vector<unsigned short int> results;
189  results.clear();
190 #ifdef LOCAL_UNPACK
191  switch (firmwareVersion) {
192 #else
193  switch (firmwareVersion.load()) {
194 #endif
195  case 2006:
196  return results;
197  case 2007:
198  // if (alctFirmwareRevision() >= 0) // TODO: Need ALCT Run3 firmware revision to properly detect presense of HMT bits in data format
199  // {
200  if ((!theALCTs.empty()) && (theALCTs.size() == unsigned(header2007.lctBins * 2))) {
201  for (unsigned bx = 0; bx < header2007.lctBins; bx++) {
202  results.push_back(theALCTs[bx * 2].reserved & 0x3);
203  }
204  return results;
205  } else
206  return results;
207  // } else return results;
208  default:
209  edm::LogError("CSCALCTHeader|CSCRawToDigi")
210  << "trying to access ALCT HMT bits: ALCT firmware version is bad/not defined!";
211  return results;
212  }
213  }
214 
215  void setDAVForChannel(int wireGroup) {
216  if (firmwareVersion == 2006) {
217  header2006.setDAV((wireGroup - 1) / 16);
218  }
219  }
220 
223 
224  unsigned short int *data() { return theOriginalBuffer; }
225 
227  int sizeInWords() {
228 #ifdef LOCAL_UNPACK
229  switch (firmwareVersion) {
230 #else
231  switch (firmwareVersion.load()) {
232 #endif
233  case 2006:
234  return 8;
235  case 2007:
236  return sizeInWords2007_;
237  default:
238  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "SizeInWords(): ALCT firmware version is bad/not defined!";
239  return 0;
240  }
241  }
242 
243  bool check() const {
244 #ifdef LOCAL_UNPACK
245  switch (firmwareVersion) {
246 #else
247  switch (firmwareVersion.load()) {
248 #endif
249  case 2006:
250  return header2006.flag_0 == 0xC;
251  case 2007:
252  return header2007.flag1 == 0xDB0A;
253  default:
254  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "check(): ALCT firmware version is bad/not defined!";
255  return false;
256  }
257  }
258 
259  void add(const std::vector<CSCALCTDigi> &digis);
261  void addShower(const std::vector<CSCShowerDigi> &digis);
262 
263  boost::dynamic_bitset<> pack();
264 
266  static void selfTest(int firmware);
267 
268 private:
271  std::vector<CSCALCT> theALCTs;
275  std::vector<CSCCollisionMask> collisionMasks;
276  std::vector<CSCHotChannelMask> hotChannelMasks;
277 
278  //raw data also stored in this buffer
279  //maximum header size is 116 words
280  unsigned short int theOriginalBuffer[116];
281 
282 #ifdef LOCAL_UNPACK
283  static bool debug;
284  static unsigned short int firmwareVersion;
285 #else
286  static std::atomic<bool> debug;
287  static std::atomic<unsigned short int> firmwareVersion;
288 #endif
289 
291  unsigned short int sizeInWords2007_, bxn0, bxn1;
292 };
293 
294 std::ostream &operator<<(std::ostream &os, const CSCALCTHeader &header);
295 
296 #endif
unsigned short int LCTChipRead() const
unsigned bxnCount
full bunch crossing number
std::vector< unsigned short int > alctHMTs() const
unsigned fifoMode
see the FIFO_MODE enum
std::vector< CSCHotChannelMask > hotChannelMasks
std::vector< CSCCollisionMask > collisionMasks
unsigned promote1
promotion bit for 1st LCT pattern
CSCVirtexID virtexID
unsigned short int bxn1
bool check() const
std::ostream & operator<<(std::ostream &os, const CSCALCTHeader &header)
unsigned short int FIFOMode() const
Definition: CSCALCTHeader.h:42
void setBXNCount(unsigned int bxn)
Definition: CSCALCTHeader.h:79
CSCConfigurationRegister configRegister
CSCALCTHeader(int chamberType)
CSCALCTs2006 alcts2006
Log< level::Error, false > LogError
unsigned short int BoardID() const
Definition: CSCALCTHeader.h:59
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
unsigned short int theOriginalBuffer[116]
CSCALCTHeader2006 header2006
unsigned short int NTBins() const
Definition: CSCALCTHeader.h:43
unsigned short int L1Acc() const
Definition: CSCALCTHeader.h:98
unsigned short int ExtTrig() const
Definition: CSCALCTHeader.h:60
ALCT Header consists of several modular units that are defined as structs below.
unsigned short int CSCID() const
Definition: CSCALCTHeader.h:61
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
CSCALCTHeader2006 alctHeader2006() const
Definition: value.py:1
unsigned short int sizeInWords2007_
size of the 2007 header in words
int sizeInWords()
in 16-bit words
unsigned short int BXNCount() const
Definition: CSCALCTHeader.h:62
unsigned short int Promote2() const
CSCALCTHeader2007 alctHeader2007() 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 l1Acc
l1 accept counter
unsigned promote2
promotion bit for 2nd LCT pattern
std::vector< CSCALCTDigi > ALCTDigis() const
unsigned boardID
ALCT2000 board ID.
unsigned short int ActiveFEBs() const
unsigned lctChipRead
LCT chips read out in raw hit dump.
unsigned activeFEBs
LCT chips with ADB hits.
unsigned short int alctFirmwareRevision() const
unsigned short int Promote1() const
unsigned cscID
chamber ID number
void setDAV(int afebBoard)
for packing
unsigned short int L1AMatch() const
void addShower(const std::vector< CSCShowerDigi > &digis)
Add Run3 ALCT HMT shower bits.
unsigned l1aMatch
exteran L1A arrived in L1A window
void setDAVForChannel(int wireGroup)
std::vector< CSCShowerDigi > alctShowerDigis() const
void setL1Acc(unsigned int l1a)
static std::atomic< bool > debug
unsigned flag_0
should be &#39;01100&#39;, so it&#39;ll be a 6xxx in the ASCII dump
unsigned short int * data()
unsigned short int nLCTChipRead() const
for packing