Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:30

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   /// Returns the CRC, for non-reversed TOTEM T2.
0058   VFATFrame::word getCRCT2() const { return data[11]; }
0059 
0060   /// Sets presence flags.
0061   void setPresenceFlags(uint8_t v) { presenceFlags = v; }
0062 
0063   /// Returns true if the BC word is present in the frame.
0064   bool isBCPresent() const { return presenceFlags & 0x1; }
0065 
0066   /// Returns true if the EC word is present in the frame.
0067   bool isECPresent() const { return presenceFlags & 0x2; }
0068 
0069   /// Returns true if the ID word is present in the frame.
0070   bool isIDPresent() const { return presenceFlags & 0x4; }
0071 
0072   /// Returns true if the CRC word is present in the frame.
0073   bool isCRCPresent() const { return presenceFlags & 0x8; }
0074 
0075   /// Returns true if the CRC word is present in the frame.
0076   bool isNumberOfClustersPresent() const { return presenceFlags & 0x10; }
0077 
0078   /// Sets DAQ error flags.
0079   void setDAQErrorFlags(uint8_t v) { daqErrorFlags = v; }
0080 
0081   void setNumberOfClusters(uint8_t v) { numberOfClusters = v; }
0082 
0083   /// Returns the number of clusters as given by the "0xD0 frame".
0084   /// Returns 0, if not available.
0085   uint8_t getNumberOfClusters() const { return numberOfClusters; }
0086 
0087   /// Checks the fixed bits in the frame.
0088   /// Returns false if any of the groups (in BC, EC and ID words) is present but wrong.
0089   bool checkFootprint() const;
0090 
0091   /// Checks the fixed bits in the frame, for the TOTEM T2 non-inverse word ordering.
0092   /// Returns false if any of the groups (in BC, EC and ID words) is present but wrong.
0093   bool checkFootprintT2() const;
0094 
0095   /// Checks the validity of frame (CRC and daqErrorFlags).
0096   /// Returns false if daqErrorFlags is non-zero.
0097   /// Returns false if the CRC is present and invalid.
0098   virtual bool checkCRC() const;
0099 
0100   /// Checks the validity of Totem T2 non-reversed CRC.
0101   /// Returns false if the CRC is present and invalid.
0102   virtual bool checkCRCT2() const;
0103 
0104   /// Checks if channel number 'channel' was active.
0105   /// Returns positive number if it was active, 0 otherwise.
0106   virtual bool channelActive(unsigned char channel) const {
0107     return (data[1 + (channel / 16)] & (1 << (channel % 16))) ? true : false;
0108   }
0109 
0110   /// Returns list  of active channels.
0111   /// It's more efficient than the channelActive(char) for events with low channel occupancy.
0112   virtual std::vector<unsigned char> getActiveChannels() const;
0113 
0114   /// Prints the frame.
0115   /// If binary is true, binary format is used.
0116   void Print(bool binary = false) const;
0117 
0118   //Follow the VFAT2 manual format, not reversed
0119   void PrintT2(bool binary = false) const;
0120 
0121   /// internaly used to check CRC
0122   static word calculateCRC(word crc_in, word dato);
0123 
0124 protected:
0125   /** Raw data frame as sent by electronics.
0126     * The container is organized as follows (reversed Figure 8 at page 23 of VFAT2 manual):
0127     * \verbatim
0128     * buffer index   content       size
0129     * ---------------------------------------------------------------
0130     *   0            CRC           16 bits
0131     *   1->8         Channel data  128 bits, channel 0 first
0132     *   9            ChipID        4 constant bits (1110) + 12 bits
0133     *   10           EC, Flags     4 constant bits (1100) + 8, 4 bits
0134     *   11           BC            4 constant bits (1010) + 12 bits
0135     * \endverbatim
0136     **/
0137   word data[12];
0138 
0139 private:
0140   /// Flag indicating the presence of various components.
0141   ///   bit 1: "BC word" (buffer index 11)
0142   ///   bit 2: "EC word" (buffer index 10)
0143   ///   bit 3: "ID word" (buffer index 9)
0144   ///   bit 4: "CRC word" (buffer index 0)
0145   ///   bit 5: "number of clusters word" (prefix 0xD0)
0146   uint8_t presenceFlags;
0147 
0148   /// Error flag as given by certain versions of DAQ.
0149   uint8_t daqErrorFlags;
0150 
0151   /// Number of clusters.
0152   /// Only available in cluster mode and if the number of clusters exceeds a limit (10).
0153   uint8_t numberOfClusters;
0154 };
0155 
0156 #endif