Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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