Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /* -*- C++ -*- */
0002 #ifndef HcalHTRData_H
0003 #define HcalHTRData_H
0004 
0005 #include <cstdint>
0006 
0007 /**  \class HcalHTRData
0008  *
0009  *  Interpretive class for HcalHTRData
0010  *  Since this class requires external specification of the length of the data, it is implemented
0011  *  as an interpreter, rather than a cast-able header class.
0012  *
0013  *  \author J. Mans - UMD
0014  */
0015 
0016 class HcalHTRData {
0017 public:
0018   static const int CHANNELS_PER_SPIGOT = 24;
0019   static const int MAXIMUM_SAMPLES_PER_CHANNEL = 20;
0020   static const int FORMAT_VERSION_COMPACT_DATA = 6;
0021 
0022   HcalHTRData();
0023   ~HcalHTRData() {
0024     if (m_ownData != nullptr)
0025       delete[] m_ownData;
0026   }
0027   HcalHTRData(int version_to_create);
0028   HcalHTRData(const unsigned short* data, int length);
0029   HcalHTRData(const HcalHTRData&);
0030 
0031   HcalHTRData& operator=(const HcalHTRData&);
0032   void allocate(int version_to_create = 0);
0033   void adoptData(const unsigned short* data, int length);
0034 
0035   /** \brief Get the version number of this event */
0036   inline int getFormatVersion() const { return m_formatVersion; }
0037 
0038   /** \brief Get a pointer to the raw data */
0039   inline const unsigned short* getRawData() const { return m_rawConst; }
0040 
0041   /** \brief Get the length of the raw data */
0042   inline const int getRawLength() const { return m_rawLength; }
0043 
0044   /** \brief Check for a good event
0045       Requires a minimum length, matching wordcount and length, not an
0046       empty event */
0047   bool check() const;
0048 
0049   bool isEmptyEvent() const;
0050   bool isOverflowWarning() const;
0051   bool isBusy() const;
0052 
0053   /** \brief Obtain the starting and ending pointers for external
0054      unpacking of the data
0055       \param daq_first Pointer to a pointer to the start of the DAQ data
0056       \param daq_last Pointer to a pointer to the end of the DAQ data
0057       \param tp_first Pointer to a pointer to the start of the TP data
0058       \param tp_last Pointer to a pointer to the end of the TP data
0059   */
0060   void dataPointers(const unsigned short** daq_first,
0061                     const unsigned short** daq_last,
0062                     const unsigned short** tp_first,
0063                     const unsigned short** tp_last) const;
0064 
0065   /** \brief Unpack the HTR data into TP and DAQ data sorted by channel
0066       \param daq_lengths unsigned char[24] of lengths.  High bit set
0067       indicates error with this channel
0068       \param daq_samples unsigned short [24*20] of data
0069       \param tp_lengths  unsigned char[24] of lengths
0070       \param tp_samples  unsigned short [24*20] of data
0071   */
0072   void unpack(unsigned char* daq_lengths,
0073               unsigned short* daq_samples,
0074               unsigned char* tp_lengths,
0075               unsigned short* tp_samples) const;
0076 
0077   /** \brief Unpack special histogramming mode data
0078       \param fiber
0079       \param fiberchan
0080       \param capid Capacitor id for which to extract a histogram
0081       \param histogram unsigned int[32] into which the data should be
0082       deposited
0083   */
0084   bool unpackHistogram(int fiber, int fiberchan, int capid, unsigned short* histogram) const;
0085 
0086   /** \brief Unpack a per-channel header word (compact format)
0087    */
0088   static bool unpack_per_channel_header(unsigned short, int& flav, int& error_flags, int& capid0, int& channelid);
0089 
0090   /** \brief check top bit to see if this is a compact format channel header word
0091    */
0092   static bool is_channel_header(unsigned short value) { return (value & 0x8000) != 0; }
0093 
0094   /** \brief Unpack the HTR data into TP and DAQ data sorted by channel
0095       \param daq_lengths unsigned char[24] of lengths
0096       \param daq_samples unsigned short [24*20] of data
0097       \param tp_lengths  unsigned char[24] of lengths
0098       \param tp_samples  unsigned short [24*20] of data
0099   */
0100   void pack(unsigned char* daq_lengths,
0101             unsigned short* daq_samples,
0102             unsigned char* tp_lengths,
0103             unsigned short* tp_samples,
0104             bool do_capid = false);
0105   /** \brief pack header and trailer (call _after_ pack)*/
0106   void packHeaderTrailer(int L1Anumber,
0107                          int bcn,
0108                          int submodule,
0109                          int orbitn,
0110                          int pipeline,
0111                          int ndd,
0112                          int nps,
0113                          int firmwareRev = 0,
0114                          int firmwareFlav = 0);
0115 
0116   /** \brief pack trailer with Mark and Pass bits */
0117   void packUnsuppressed(const bool* mp);
0118 
0119   /** \brief Get the HTR event number */
0120   inline unsigned int getL1ANumber() const { return (m_rawConst[0] & 0xFF) + (m_rawConst[1] << 8); }
0121   /** \brief Get the HTR bunch number */
0122   inline unsigned int getBunchNumber() const { return (m_rawConst[4] & 0xFFF); }
0123   /** \brief Get the HTR orbit number */
0124   unsigned int getOrbitNumber() const;
0125   /** \brief Get the HTR submodule number */
0126   unsigned int getSubmodule() const;
0127   /** \brief HcalElectronicsId-style HTR slot */
0128   // get the htr slot
0129   unsigned int htrSlot() const;
0130   /** \brief HcalElectronicsId-style HTR top/bottom (1=top/0=bottom) */
0131   // get the htr top/bottom (1=top/0=bottom)
0132   unsigned int htrTopBottom() const;
0133   /** \brief HcalElectronicsId-style VME crate number */
0134   // get the readout VME crate number
0135   unsigned int readoutVMECrateId() const;
0136   /** \brief Is this event a calibration-stream event? */
0137   bool isCalibrationStream() const;
0138   /** \brief Is this event an unsuppresed event? */
0139   bool isUnsuppressed() const;
0140   /** \brief Was this channel passed as part of Mark&Pass ZS?*/
0141   bool wasMarkAndPassZS(int fiber, int fiberchan) const;
0142   /** \brief Was this channel passed as part of Mark&Pass ZS?*/
0143   bool wasMarkAndPassZSTP(int slb, int slbchan) const;
0144   /** \brief ZS Bunch Mask (if available) */
0145   uint32_t zsBunchMask() const;
0146 
0147   /** \brief Is this event a pattern-ram event? */
0148   bool isPatternRAMEvent() const;
0149   /** \brief Is this event a histogram event? (do not call standard
0150       unpack in this case!!!!!) */
0151   bool isHistogramEvent() const;
0152   /** \brief Get the fiber numbers for the data present in this event
0153       (only in histogram mode!) */
0154   void getHistogramFibers(int& a, int& b) const;
0155   /** \brief Get the pipeline length used for this event */
0156   unsigned int getPipelineLength() const;
0157   /** \brief Get the HTR firmware version */
0158   unsigned int getFirmwareRevision() const;
0159   /** \brief Get the HTR firmware flavor */
0160   int getFirmwareFlavor() const;
0161   /** \brief Get the errors word */
0162   inline unsigned int getErrorsWord() const { return m_rawConst[2] & 0xFFFF; }
0163   /** \brief Get the total number of precision data 16-bit words */
0164   int getNPrecisionWords() const;
0165   /** \brief Get the number of daq data samples per channel when not zero-suppressed */
0166   int getNDD() const;
0167   /** \brief Get the number of trigger data samples when not
0168       zero-suppressed (not available after FW 4)*/
0169   int getNTP() const;
0170   /** \brief Get the number of presamples in daq data */
0171   int getNPS() const;
0172 
0173   /** \brief Get DLLunlock bits */
0174   inline unsigned int getDLLunlock() const { return (m_rawConst[5] >> 1) & 0x3; }
0175 
0176   /** \brief Get TTCready bit */
0177   inline unsigned int getTTCready() const { return m_rawConst[5] & 0x1; }
0178 
0179   /** \brief Get the BCN of the Fiber Orbit Messages */
0180   inline unsigned int getFibOrbMsgBCN(int fiber) const {
0181     return (m_formatVersion == -1 || fiber < 1 || fiber > 8) ? (0)
0182                                                              : (m_rawConst[m_rawLength - 12 + (fiber - 1)] & 0xFFF);
0183   }
0184 
0185   /** \brief Get the BCN of the Fiber Orbit Messages */
0186   inline unsigned int getFib1OrbMsgBCN() const {
0187     return (m_formatVersion == -1) ? (0) : (m_rawConst[m_rawLength - 12] & 0xFFF);
0188   }
0189   inline unsigned int getFib2OrbMsgBCN() const {
0190     return (m_formatVersion == -1) ? (0) : (m_rawConst[m_rawLength - 11] & 0xFFF);
0191   }
0192 
0193   inline unsigned int getFib3OrbMsgBCN() const {
0194     return (m_formatVersion == -1) ? (0) : (m_rawConst[m_rawLength - 10] & 0xFFF);
0195   }
0196 
0197   inline unsigned int getFib4OrbMsgBCN() const {
0198     return (m_formatVersion == -1) ? (0) : (m_rawConst[m_rawLength - 9] & 0xFFF);
0199   }
0200 
0201   inline unsigned int getFib5OrbMsgBCN() const {
0202     return (m_formatVersion == -1) ? (0) : (m_rawConst[m_rawLength - 8] & 0xFFF);
0203   }
0204 
0205   inline unsigned int getFib6OrbMsgBCN() const {
0206     return (m_formatVersion == -1) ? (0) : (m_rawConst[m_rawLength - 7] & 0xFFF);
0207   }
0208 
0209   inline unsigned int getFib7OrbMsgBCN() const {
0210     return (m_formatVersion == -1) ? (0) : (m_rawConst[m_rawLength - 6] & 0xFFF);
0211   }
0212 
0213   inline unsigned int getFib8OrbMsgBCN() const {
0214     return (m_formatVersion == -1) ? (0) : (m_rawConst[m_rawLength - 5] & 0xFFF);
0215   }
0216 
0217   /** \brief Get the HTR Ext Header words*/
0218   inline unsigned int getExtHdr1() const { return (m_rawConst[0]); }
0219   inline unsigned int getExtHdr2() const { return (m_rawConst[1]); }
0220   inline unsigned int getExtHdr3() const { return (m_rawConst[2]); }
0221   inline unsigned int getExtHdr4() const { return (m_rawConst[3]); }
0222   inline unsigned int getExtHdr5() const { return (m_rawConst[4]); }
0223   inline unsigned int getExtHdr6() const { return (m_rawConst[5]); }
0224   inline unsigned int getExtHdr7() const { return (m_rawConst[6]); }
0225   inline unsigned int getExtHdr8() const { return (m_rawConst[7]); }
0226 
0227   /* unsigned int getFib1OrbMsgBCN() const;
0228   unsigned int getFib2OrbMsgBCN() const;
0229   unsigned int getFib3OrbMsgBCN() const;
0230   unsigned int getFib4OrbMsgBCN() const;
0231   unsigned int getFib5OrbMsgBCN() const;
0232   unsigned int getFib6OrbMsgBCN() const;
0233   unsigned int getFib7OrbMsgBCN() const;
0234   unsigned int getFib8OrbMsgBCN() const;
0235   */
0236 
0237   /** \brief Was there an error on the given fiber for this event (only
0238       in histogram mode!) */
0239   bool wasHistogramError(int ifiber) const;
0240 
0241 protected:
0242   void determineSectionLengths(int& tpWords, int& daqWords, int& headerWords, int& trailerWords) const;
0243   void determineStaticLengths(int& headerWords, int& trailerWords) const;
0244   int m_formatVersion;
0245   int m_rawLength;
0246   const unsigned short* m_rawConst;
0247   unsigned short* m_ownData;
0248 };
0249 
0250 #endif