Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /* -*- C++ -*- */
0002 #ifndef CastorMergerData_H
0003 #define CastorMergerData_H
0004 
0005 /**  \class CastorMergerData
0006  *
0007  *  Interpretive class for CastorMergerData
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 CastorMergerData {
0015 public:
0016   CastorMergerData();
0017   ~CastorMergerData() {
0018     if (m_ownData != nullptr)
0019       delete[] m_ownData;
0020   }
0021   CastorMergerData(int version_to_create);
0022   CastorMergerData(const unsigned short* data, int length);
0023   CastorMergerData(const CastorMergerData&);
0024 
0025   CastorMergerData& operator=(const CastorMergerData&);
0026   void allocate(int version_to_create = 0);
0027   void adoptData(const unsigned short* data, int length);
0028   /** \brief Get the Merger firmware version */
0029   unsigned int getFirmwareRevision() const;
0030 
0031   /** \brief Get the errors word */
0032   inline unsigned int getErrorsWord() const { return m_rawConst[2] & 0xFFFF; }
0033 
0034   /** \brief Get the version number of this event */
0035   inline int getFormatVersion() const { return m_formatVersion; }
0036 
0037   /** \brief Get a pointer to the raw data */
0038   inline const unsigned short* getRawData() const { return m_rawConst; }
0039 
0040   /** \brief Get the length of the raw data */
0041   inline const int getRawLength() const { return m_rawLength; }
0042 
0043   /** \brief Check for a good event
0044       Requires a minimum length, matching wordcount and length, not an
0045       empty event */
0046   bool check() const;
0047 
0048   /** \brief Unpack the HTR data into TP and DAQ data sorted by channel
0049       \param daq_lengths unsigned char[24] of lengths.  High bit set
0050       indicates error with this channel
0051       \param daq_samples unsigned short [24*20] of data
0052       \param tp_lengths  unsigned char[24] of lengths
0053       \param tp_samples  unsigned short [24*20] of data
0054   */
0055   void unpack(unsigned char* tp_lengths, unsigned short* tp_samples) const;
0056 
0057   /** \brief Unpack the HTR data into TP and DAQ data sorted by channel
0058       \param daq_lengths unsigned char[24] of lengths
0059       \param daq_samples unsigned short [24*20] of data
0060       \param tp_lengths  unsigned char[24] of lengths
0061       \param tp_samples  unsigned short [24*20] of data
0062   */
0063   void pack(unsigned char* tp_lengths, unsigned short* tp_samples);
0064   /** \brief pack header and trailer (call _after_ pack)*/
0065   void packHeaderTrailer(
0066       int L1Anumber, int bcn, int submodule, int orbitn, int pipeline, int ndd, int nps, int firmwareRev = 0);
0067 
0068   /** \brief Get the HTR event number */
0069   inline unsigned int getL1ANumber() const { return (m_rawConst[0] & 0xFF) + (m_rawConst[1] << 8); }
0070   /** \brief Get the HTR bunch number */
0071   inline unsigned int getBunchNumber() const { return (m_rawConst[4] & 0xFFF); }
0072   /** \brief Get the HTR orbit number */
0073   unsigned int getOrbitNumber() const;
0074 
0075   /** \brief Get the Merger Ext Header words*/
0076   inline unsigned int getExtHdr1() const { return (m_rawConst[0]); }
0077   inline unsigned int getExtHdr2() const { return (m_rawConst[1]); }
0078   inline unsigned int getExtHdr3() const { return (m_rawConst[2]); }
0079   inline unsigned int getExtHdr4() const { return (m_rawConst[3]); }
0080   inline unsigned int getExtHdr5() const { return (m_rawConst[4]); }
0081   inline unsigned int getExtHdr6() const { return (m_rawConst[5]); }
0082   inline unsigned int getExtHdr7() const { return (m_rawConst[6]); }
0083   inline unsigned int getExtHdr8() const { return (m_rawConst[7]); }
0084 
0085 protected:
0086   void determineSectionLengths(int& tpWords, int& headerWords, int& trailerWords) const;
0087   void determineStaticLengths(int& headerWords, int& trailerWords) const;
0088 
0089   int m_formatVersion;
0090   int m_rawLength;
0091   const unsigned short* m_rawConst;  // pointer to actual raw data
0092   unsigned short* m_ownData;         // local block in raw data format
0093   unsigned short* m_unpackedData;    // local data in usable format
0094 };
0095 
0096 #endif