Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-11 02:22:05

0001 /**********************************************************
0002 *
0003 * This is a part of the TOTEM offline software.
0004 * Authors:
0005 *    Jan Kaspar (jan.kaspar@gmail.com)
0006 *
0007 **********************************************************/
0008 
0009 #ifndef EventFilter_CTPPSRawToDigi_VFATFrame
0010 #define EventFilter_CTPPSRawToDigi_VFATFrame
0011 
0012 #include <vector>
0013 #include <cstddef>
0014 #include <cstdint>
0015 
0016 /**
0017  * Representation of VFAT frame plus extra info added by DAQ.
0018 **/
0019 class VFATFrame {
0020 public:
0021   typedef uint16_t word;
0022 
0023 public:
0024   VFATFrame(const word* _data = nullptr);
0025 
0026   VFATFrame(const VFATFrame& copy) {
0027     setData(copy.data);
0028     presenceFlags = copy.presenceFlags;
0029     daqErrorFlags = copy.daqErrorFlags;
0030     numberOfClusters = copy.numberOfClusters;
0031   }
0032 
0033   virtual ~VFATFrame() {}
0034 
0035   /// Copies a memory block to data buffer.
0036   void setData(const word* _data);
0037 
0038   VFATFrame::word* getData() { return data; }
0039 
0040   const VFATFrame::word* getData() const { return data; }
0041 
0042   /// Returns Bunch Crossing number (BC<11:0>).
0043   VFATFrame::word getBC() const { return data[11] & 0x0FFF; }
0044 
0045   /// Returns Event Counter (EV<7:0>).
0046   VFATFrame::word getEC() const { return (data[10] & 0x0FF0) >> 4; }
0047 
0048   /// Returns flags.
0049   VFATFrame::word getFlags() const { return data[10] & 0x000F; }
0050 
0051   /// Returns ChipID (ChipID<11:0>).
0052   VFATFrame::word getChipID() const { return data[9] & 0x0FFF; }
0053 
0054   /// Returns the CRC.
0055   VFATFrame::word getCRC() const { return data[0]; }
0056 
0057   /// Sets presence flags.
0058   void setPresenceFlags(uint8_t v) { presenceFlags = v; }
0059 
0060   /// Returns true if the BC word is present in the frame.
0061   bool isBCPresent() const { return presenceFlags & 0x1; }
0062 
0063   /// Returns true if the EC word is present in the frame.
0064   bool isECPresent() const { return presenceFlags & 0x2; }
0065 
0066   /// Returns true if the ID word is present in the frame.
0067   bool isIDPresent() const { return presenceFlags & 0x4; }
0068 
0069   /// Returns true if the CRC word is present in the frame.
0070   bool isCRCPresent() const { return presenceFlags & 0x8; }
0071 
0072   /// Returns true if the CRC word is present in the frame.
0073   bool isNumberOfClustersPresent() const { return presenceFlags & 0x10; }
0074 
0075   /// Sets DAQ error flags.
0076   void setDAQErrorFlags(uint8_t v) { daqErrorFlags = v; }
0077 
0078   void setNumberOfClusters(uint8_t v) { numberOfClusters = v; }
0079 
0080   /// Returns the number of clusters as given by the "0xD0 frame".
0081   /// Returns 0, if not available.
0082   uint8_t getNumberOfClusters() const { return numberOfClusters; }
0083 
0084   /// Checks the fixed bits in the frame.
0085   /// Returns false if any of the groups (in BC, EC and ID words) is present but wrong.
0086   bool checkFootprint() const;
0087 
0088   /// Checks the validity of frame (CRC and daqErrorFlags).
0089   /// Returns false if daqErrorFlags is non-zero.
0090   /// Returns false if the CRC is present and invalid.
0091   virtual bool checkCRC() const;
0092 
0093   /// Checks if channel number 'channel' was active.
0094   /// Returns positive number if it was active, 0 otherwise.
0095   virtual bool channelActive(unsigned char channel) const {
0096     return (data[1 + (channel / 16)] & (1 << (channel % 16))) ? true : false;
0097   }
0098 
0099   /// Returns list  of active channels.
0100   /// It's more efficient than the channelActive(char) for events with low channel occupancy.
0101   virtual std::vector<unsigned char> getActiveChannels() const;
0102 
0103   /// Prints the frame.
0104   /// If binary is true, binary format is used.
0105   void Print(bool binary = false) const;
0106 
0107   //Follow the VFAT2 manual format, not reversed
0108   void PrintT2(bool binary = false) const;
0109 
0110   /// internaly used to check CRC
0111   static word calculateCRC(word crc_in, word dato);
0112 
0113 protected:
0114   /** Raw data frame as sent by electronics.
0115     * The container is organized as follows (reversed Figure 8 at page 23 of VFAT2 manual):
0116     * \verbatim
0117     * buffer index   content       size
0118     * ---------------------------------------------------------------
0119     *   0            CRC           16 bits
0120     *   1->8         Channel data  128 bits, channel 0 first
0121     *   9            ChipID        4 constant bits (1110) + 12 bits
0122     *   10           EC, Flags     4 constant bits (1100) + 8, 4 bits
0123     *   11           BC            4 constant bits (1010) + 12 bits
0124     * \endverbatim
0125     **/
0126   word data[12];
0127 
0128 private:
0129   /// Flag indicating the presence of various components.
0130   ///   bit 1: "BC word" (buffer index 11)
0131   ///   bit 2: "EC word" (buffer index 10)
0132   ///   bit 3: "ID word" (buffer index 9)
0133   ///   bit 4: "CRC word" (buffer index 0)
0134   ///   bit 5: "number of clusters word" (prefix 0xD0)
0135   uint8_t presenceFlags;
0136 
0137   /// Error flag as given by certain versions of DAQ.
0138   uint8_t daqErrorFlags;
0139 
0140   /// Number of clusters.
0141   /// Only available in cluster mode and if the number of clusters exceeds a limit (10).
0142   uint8_t numberOfClusters;
0143 };
0144 
0145 #endif