CMS 3D CMS Logo

CSCComparatorData.h
Go to the documentation of this file.
1 #ifndef EventFilter_CSCRawToDigi_CSCComparatorData_h
2 #define EventFilter_CSCRawToDigi_CSCComparatorData_h
5 #include <vector>
6 #include <cassert>
7 
8 #ifndef LOCAL_UNPACK
9 #include <atomic>
10 #endif
11 
13  CSCComparatorDataWord(unsigned cfeb, unsigned tbin, unsigned data) : data_(data), tbin_(tbin), cfeb_(cfeb) {}
14  bool value(int distrip) { return (data_ >> distrip) & 0x1; }
16  void set(int distrip, bool value) { data_ |= (value << distrip); }
17  unsigned short data_ : 8;
18  unsigned short tbin_ : 4;
19  unsigned short cfeb_ : 4;
20 };
21 
22 class CSCTMBHeader;
23 
25 public:
26  explicit CSCComparatorData(const CSCTMBHeader *tmbHeader);
27  CSCComparatorData(int ncfebs, int ntbins, int firmware_version = 2007);
28  CSCComparatorData(int ncfebs, int ntbins, const unsigned short *e0bbuf, int firmware_version = 2007);
29 
31  static void setDebug(const bool value) { debug = value; };
32 
34  std::vector<CSCComparatorDigi> comparatorDigis(int layer);
35 
37  std::vector<CSCComparatorDigi> comparatorDigis(uint32_t idlayer, unsigned icfeb);
38 
39  unsigned short *data() { return theData; }
41  int sizeInWords() const { return size_; }
42  int nlines() const { return ncfebs_ * ntbins_ * 6; }
43 
45  void add(const CSCComparatorDigi &digi, int layer);
47  void add(const CSCComparatorDigi &digi, const CSCDetId &id);
48 
50 #ifdef ASSERTS
51  assert(iline < nlines());
52 #endif
53  union dataPtr {
54  const unsigned short *s;
56  } mptr;
57  mptr.s = theData + iline;
58  return *(mptr.d);
59  }
60 
61  CSCComparatorDataWord &dataWord(int cfeb, int tbin, int layer) const {
62  int iline = (layer - 1) + tbin * 6 + cfeb * 6 * ntbins_;
63  return dataWord(iline);
64  }
65 
66  bool bitValue(int cfeb, int tbin, int layer, int distrip) { return dataWord(cfeb, tbin, layer).value(distrip); }
67 
68  // checks that the CFEB number and time bins are correct
69  bool check() const;
70 
71  // hex dump
72  void dump() const;
73 
74  // checks packing and unpacking
75  static void selfTest();
76 
77 private:
78  // helper for constructors
79  void zero();
80 
81 #ifdef LOCAL_UNPACK
82  static bool debug;
83 #else
84  static std::atomic<bool> debug;
85 #endif
86 
87  int ncfebs_;
88  int ntbins_;
89  int size_;
90  unsigned short theData[7 * 6 * 32];
92 };
93 
94 #endif
int sizeInWords() const
in 16-bit words
bool bitValue(int cfeb, int tbin, int layer, int distrip)
CSCComparatorDataWord(unsigned cfeb, unsigned tbin, unsigned data)
assert(be >=bs)
static void selfTest()
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
static void setDebug(const bool value)
CSCComparatorDataWord & dataWord(int iline) const
Definition: value.py:1
d
Definition: ztail.py:151
bool value(int distrip)
CSCComparatorDataWord & dataWord(int cfeb, int tbin, int layer) const
void add(const CSCComparatorDigi &digi, int layer)
TODO for packing. Doesn&#39;t do flipping yet.
CSCComparatorData(const CSCTMBHeader *tmbHeader)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static std::atomic< bool > debug
std::vector< CSCComparatorDigi > comparatorDigis(int layer)
layers count from one
unsigned short theData[7 *6 *32]
unsigned short * data()