Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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   /// internaly used to check CRC
0108   static word calculateCRC(word crc_in, word dato);
0109 
0110 protected:
0111   /** Raw data frame as sent by electronics.
0112     * The container is organized as follows (reversed Figure 8 at page 23 of VFAT2 manual):
0113     * \verbatim
0114     * buffer index   content       size
0115     * ---------------------------------------------------------------
0116     *   0            CRC           16 bits
0117     *   1->8         Channel data  128 bits, channel 0 first
0118     *   9            ChipID        4 constant bits (1110) + 12 bits
0119     *   10           EC, Flags     4 constant bits (1100) + 8, 4 bits
0120     *   11           BC            4 constant bits (1010) + 12 bits
0121     * \endverbatim
0122     **/
0123   word data[12];
0124 
0125 private:
0126   /// Flag indicating the presence of various components.
0127   ///   bit 1: "BC word" (buffer index 11)
0128   ///   bit 2: "EC word" (buffer index 10)
0129   ///   bit 3: "ID word" (buffer index 9)
0130   ///   bit 4: "CRC word" (buffer index 0)
0131   ///   bit 5: "number of clusters word" (prefix 0xD0)
0132   uint8_t presenceFlags;
0133 
0134   /// Error flag as given by certain versions of DAQ.
0135   uint8_t daqErrorFlags;
0136 
0137   /// Number of clusters.
0138   /// Only available in cluster mode and if the number of clusters exceeds a limit (10).
0139   uint8_t numberOfClusters;
0140 };
0141 
0142 #endif