Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:36

0001 #ifndef EventFilter_CSCRawToDigi_CSCComparatorData_h
0002 #define EventFilter_CSCRawToDigi_CSCComparatorData_h
0003 #include "DataFormats/CSCDigi/interface/CSCComparatorDigi.h"
0004 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0005 #include <vector>
0006 #include <cassert>
0007 
0008 #ifndef LOCAL_UNPACK
0009 #include <atomic>
0010 #endif
0011 
0012 struct CSCComparatorDataWord {
0013   CSCComparatorDataWord(unsigned cfeb, unsigned tbin, unsigned data) : data_(data), tbin_(tbin), cfeb_(cfeb) {}
0014   bool value(int distrip) { return (data_ >> distrip) & 0x1; }
0015   ///@@ not right! doesn't set zero
0016   void set(int distrip, bool value) { data_ |= (value << distrip); }
0017   unsigned short data_ : 8;
0018   unsigned short tbin_ : 4;
0019   unsigned short cfeb_ : 4;
0020 };
0021 
0022 class CSCTMBHeader;
0023 
0024 class CSCComparatorData {
0025 public:
0026   explicit CSCComparatorData(const CSCTMBHeader *tmbHeader);
0027   CSCComparatorData(int ncfebs, int ntbins, int firmware_version = 2007);
0028   CSCComparatorData(int ncfebs, int ntbins, const unsigned short *e0bbuf, int firmware_version = 2007);
0029 
0030   /** turns on/off debug flag for this class */
0031   static void setDebug(const bool value) { debug = value; };
0032 
0033   /// layers count from one
0034   std::vector<CSCComparatorDigi> comparatorDigis(int layer);
0035 
0036   /// layers count from one
0037   std::vector<CSCComparatorDigi> comparatorDigis(uint32_t idlayer, unsigned icfeb);
0038 
0039   unsigned short *data() { return theData; }
0040   /// in 16-bit words
0041   int sizeInWords() const { return size_; }
0042   int nlines() const { return ncfebs_ * ntbins_ * 6; }
0043 
0044   ///TODO for packing.  Doesn't do flipping yet
0045   void add(const CSCComparatorDigi &digi, int layer);
0046   ///TODO for packing.  Doesn't do flipping yet
0047   void add(const CSCComparatorDigi &digi, const CSCDetId &id);
0048 
0049   CSCComparatorDataWord &dataWord(int iline) const {
0050 #ifdef ASSERTS
0051     assert(iline < nlines());
0052 #endif
0053     union dataPtr {
0054       const unsigned short *s;
0055       CSCComparatorDataWord *d;
0056     } mptr;
0057     mptr.s = theData + iline;
0058     return *(mptr.d);
0059   }
0060 
0061   CSCComparatorDataWord &dataWord(int cfeb, int tbin, int layer) const {
0062     int iline = (layer - 1) + tbin * 6 + cfeb * 6 * ntbins_;
0063     return dataWord(iline);
0064   }
0065 
0066   bool bitValue(int cfeb, int tbin, int layer, int distrip) { return dataWord(cfeb, tbin, layer).value(distrip); }
0067 
0068   // checks that the CFEB number and time bins are correct
0069   bool check() const;
0070 
0071   // hex dump
0072   void dump() const;
0073 
0074   // checks packing and unpacking
0075   static void selfTest();
0076 
0077 private:
0078   // helper for constructors
0079   void zero();
0080 
0081 #ifdef LOCAL_UNPACK
0082   static bool debug;
0083 #else
0084   static std::atomic<bool> debug;
0085 #endif
0086 
0087   int ncfebs_;
0088   int ntbins_;
0089   int size_;
0090   unsigned short theData[7 * 6 * 32];
0091   int theFirmwareVersion;
0092 };
0093 
0094 #endif