Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-07 05:50:16

0001 #ifndef EventFilter_CSCRawToDigi_CSCEventData_h
0002 #define EventFilter_CSCRawToDigi_CSCEventData_h
0003 
0004 class CSCCFEBData;
0005 class CSCTMBHeader;
0006 class CSCComparatorData;
0007 class CSCWireDigi;
0008 class CSCStripDigi;
0009 #include <map>
0010 #include <vector>
0011 #ifndef LOCAL_UNPACK
0012 #include <atomic>
0013 #endif
0014 #include "EventFilter/CSCRawToDigi/interface/CSCDMBHeader.h"
0015 #include "EventFilter/CSCRawToDigi/interface/CSCDMBTrailer.h"
0016 #include "EventFilter/CSCRawToDigi/interface/CSCALCTHeader.h"
0017 #include "EventFilter/CSCRawToDigi/interface/CSCAnodeData.h"
0018 #include "EventFilter/CSCRawToDigi/interface/CSCALCTTrailer.h"
0019 #include "EventFilter/CSCRawToDigi/interface/CSCTMBData.h"
0020 #include "EventFilter/CSCRawToDigi/interface/CSCDMBTrailer.h"
0021 #include "DataFormats/CSCDigi/interface/CSCRPCDigi.h"
0022 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0023 #include "DataFormats/MuonDetId/interface/GEMDetId.h"
0024 #include <boost/dynamic_bitset.hpp>
0025 
0026 class CSCEventData {
0027 public:
0028   explicit CSCEventData(int chamberType, uint16_t format_version = 2005);
0029   /// should make const input soon
0030   CSCEventData(const uint16_t *buf, uint16_t format_version = 2005);
0031   CSCEventData() {}
0032   /// since we need deep copies, need the Big Three
0033   /// (destructor, copy ctor, op=)
0034   ~CSCEventData();
0035   CSCEventData(const CSCEventData &data);
0036   CSCEventData operator=(const CSCEventData &data);
0037 
0038   /// size of the data buffer used, in bytes
0039   unsigned short size() const { return size_; }
0040 
0041   /** turns on/off debug flag for this class */
0042   static void setDebug(const bool value) { debug = value; }
0043 
0044   ///if dealing with ALCT data
0045   bool isALCT(const uint16_t *buf);
0046 
0047   ///if dealing with TMB data
0048   bool isTMB(const uint16_t *buf);
0049 
0050   /// unpacked in long mode: has overflow and error bits decoded
0051   const CSCCFEBData *cfebData(unsigned icfeb) const;
0052 
0053   /// returns all the strip digis in the chamber, with the comparator information.
0054   std::vector<CSCStripDigi> stripDigis(const CSCDetId &idlayer) const;
0055 
0056   /// returns all the strip digis in the chamber's cfeb
0057   std::vector<CSCStripDigi> stripDigis(unsigned idlayer, unsigned icfeb) const;
0058 
0059   /// deprecated.  Use the above methods instead
0060   std::vector<std::vector<CSCStripDigi> > stripDigis() const;
0061 
0062   std::vector<CSCWireDigi> wireDigis(unsigned ilayer) const;
0063   /// deprecated.  Use the above method instead.
0064   std::vector<std::vector<CSCWireDigi> > wireDigis() const;
0065 
0066   /// the flag for existence of ALCT data
0067   int nalct() const { return theDMBHeader.nalct(); }
0068 
0069   /// the number of CLCTs
0070   int nclct() const { return theDMBHeader.nclct(); }
0071 
0072   /// the DAQ motherboard header.  A good place for event and chamber info
0073   const CSCDMBHeader *dmbHeader() const { return &theDMBHeader; }
0074   CSCDMBHeader *dmbHeader() { return &theDMBHeader; }
0075 
0076   /// user must check if nalct > 0
0077   CSCALCTHeader *alctHeader() const;
0078 
0079   /// user must check if nalct > 0
0080   CSCALCTTrailer *alctTrailer() const;
0081 
0082   /// user must check if nalct > 0
0083   CSCAnodeData *alctData() const;
0084 
0085   ///user must check in nclct > 0
0086   CSCTMBData *tmbData() const;
0087 
0088   /// user must check if nclct > 0
0089   CSCTMBHeader *tmbHeader() const;
0090 
0091   /// user must check if nclct > 0
0092   CSCComparatorData *comparatorData() const;
0093 
0094   /// DMB trailer
0095   const CSCDMBTrailer *dmbTrailer() const { return &theDMBTrailer; }
0096   /// routines to add digis to the data
0097   void add(const CSCStripDigi &, int layer);
0098   void add(const CSCWireDigi &, int layer);
0099   void add(const CSCComparatorDigi &, int layer);
0100   void add(const CSCComparatorDigi &, const CSCDetId &);
0101   /// these go in as vectors, so they get sorted right away
0102   void add(const std::vector<CSCALCTDigi> &);
0103   void add(const std::vector<CSCCLCTDigi> &);
0104   void add(const std::vector<CSCCorrelatedLCTDigi> &);
0105   /// Run3 CSC Shower HMT objects
0106   void addShower(const std::vector<CSCShowerDigi> &);           // add LCT CSCShower
0107   void addAnodeShower(const std::vector<CSCShowerDigi> &);      // add Anode CSCShower
0108   void addCathodeShower(const std::vector<CSCShowerDigi> &);    // add Cathode CSCShower
0109   void addAnodeALCTShower(const std::vector<CSCShowerDigi> &);  // add Anode ALCT CSCShower
0110   /// Run3 GEM Pad Clusters obecjts
0111   void add(const std::vector<GEMPadDigiCluster> &, const GEMDetId &);
0112 
0113   /// this will fill the DMB header, and change all related fields in
0114   /// the DMBTrailer, ALCTHeader, and TMBHeader
0115   void setEventInformation(int bxnum, int lvl1num);
0116 
0117   /// returns the packed event data.
0118   boost::dynamic_bitset<> pack();
0119 
0120   /// adds an empty ALCTHeader, trailer, and anode data
0121   void addALCTStructures();
0122 
0123   /// might not be set in real data
0124   int chamberType() const { return theChamberType; }
0125 
0126   uint16_t getFormatVersion() const { return theFormatVersion; }
0127 
0128   unsigned int calcALCTcrc(std::vector<std::pair<unsigned int, unsigned short *> > &vec);
0129 
0130 #ifdef LOCAL_UNPACK
0131   static bool debug;
0132 #else
0133   static std::atomic<bool> debug;
0134 #endif
0135   //uint16_t dataPresent; // 7 bit word which will tell if alct, clct, and 5 cfebs are present
0136   static void selfTest();
0137 
0138 private:
0139   /// helpers for ctors, dtor, and op=
0140   /// zeroes all pointers
0141   void init();
0142   void unpack_data(const uint16_t *buf);
0143   void copy(const CSCEventData &);
0144   void destroy();
0145 
0146   /// makes new ALCT classes, if needed
0147   void checkALCTClasses();
0148   /// makes new TMB classes, if needed
0149   void checkTMBClasses();
0150 
0151   /// adds the comparators to the strip digis
0152   void addComparatorInformation(std::vector<CSCStripDigi> &, int layer) const;
0153 
0154   CSCDMBHeader theDMBHeader;
0155   //these are empty data objects unless filled in CSCEventData.cc
0156   /// these may or may not be present.  I decided to make them
0157   /// dynamic because most CSC chambers don't have LCTs,
0158   /// therefore don't have data, except for DMB headers and trailers.
0159   CSCALCTHeader *theALCTHeader;
0160   CSCAnodeData *theAnodeData;
0161   CSCALCTTrailer *theALCTTrailer;
0162   CSCTMBData *theTMBData;
0163 
0164   /// for up to MAX_CFEB CFEB boards
0165   CSCCFEBData *theCFEBData[CSCConstants::MAX_CFEBS_RUN2];
0166 
0167   CSCDMBTrailer theDMBTrailer;
0168 
0169   int size_;
0170   /// this won't be filled when real data is read it.  It's only used when packing
0171   /// simulated data, so we know how many wire and strip channels to make.
0172   int theChamberType;
0173 
0174   /// Auxiliary bufer to recove the ALCT raw payload from zero suppression
0175   unsigned short *alctZSErecovered;
0176   int zseEnable;
0177 
0178   /// Output Format Version (2005, 2013)
0179   uint16_t theFormatVersion;
0180 };
0181 
0182 std::ostream &operator<<(std::ostream &os, const CSCEventData &evt);
0183 #endif