Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:49

0001 #ifndef __ONCSSUB_IDTPCFEEV4_H__
0002 #define __ONCSSUB_IDTPCFEEV4_H__
0003 
0004 #include "oncsSubevent.h"
0005 #include <vector>
0006 #include <set>
0007 #include <bitset>
0008 #include <algorithm>
0009 #include <functional>
0010 #include <limits>
0011 
0012 #ifndef __CINT__
0013 class WINDOWSEXPORT oncsSub_idtpcfeev4 : public  oncsSubevent_w2 {
0014 #else
0015 class  oncsSub_idtpcfeev4 : public  oncsSubevent_w2 {
0016 #endif
0017 
0018 public:
0019   oncsSub_idtpcfeev4( subevtdata_ptr);
0020   ~oncsSub_idtpcfeev4();
0021 
0022   //! SAMPA waveform interfaces
0023   int    iValue(const int ch, const int sample);
0024   int    iValue(const int ,const char * what);
0025 
0026   //! Expose the Level 1 trigger and endat taggers
0027   long long  lValue(const int channel, const char *what) ;
0028 
0029   void  dump ( OSTREAM& os = COUT) ;
0030 
0031 
0032 protected:
0033   int tpc_decode();
0034   int tpc_gtm_decode();
0035 
0036   static const unsigned short  MAGIC_KEY_0 {0xfe};
0037 //  static const unsigned short  MAGIC_KEY_1 = 0x00;
0038   static const unsigned short  MAGIC_KEY_1 {0xed};
0039 
0040   static const unsigned short FEE_MAGIC_KEY {0xba00};
0041   static const unsigned short GTM_MAGIC_KEY {0xbb00};
0042   static const unsigned short GTM_LVL1_ACCEPT_MAGIC_KEY {0xbbf0};
0043   static const unsigned short GTM_ENDAT_MAGIC_KEY {0xbbf1};
0044   static const unsigned short GTM_MODEBIT_MAGIC_KEY {0xbbf2};
0045 
0046   static const unsigned short  MAX_FEECOUNT {26};   // that many FEEs
0047   static const unsigned short  MAX_CHANNELS   {8*32}; // that many channels per FEE
0048 //  static const unsigned short  HEADER_LENGTH  = 5;
0049   static const unsigned short  HEADER_LENGTH  {7};
0050   
0051   unsigned short reverseBits(const unsigned short x) const;
0052   unsigned short crc16(const unsigned int fee, const unsigned int index, const int  l) const;
0053   unsigned short check_data_parity(const unsigned int fee, const unsigned int index, const int  l) const;
0054 
0055   //  int find_header ( std::vector<unsigned short>::const_iterator &itr,  const std::vector<unsigned short> &orig);
0056   int find_header ( const unsigned int xx,  const std::vector<unsigned short> &orig);
0057   int decode_gtm_data(unsigned short gtm[16]);
0058   
0059 //  int _broken;
0060   unsigned long NR_VALIDFEE = 0;
0061   
0062   int _is_decoded{0};
0063   int _is_gtm_decoded{0};
0064 
0065   struct sampa_waveform {
0066     unsigned short fee {std::numeric_limits<unsigned short>::max()};
0067     unsigned short pkt_length {std::numeric_limits<unsigned short>::max()};
0068     unsigned short channel {std::numeric_limits<unsigned short>::max()};
0069     unsigned short sampa_channel {std::numeric_limits<unsigned short>::max()};
0070     unsigned short sampa_address {std::numeric_limits<unsigned short>::max()};
0071     unsigned int bx_timestamp {0};
0072     std::vector<unsigned short> waveform;
0073     unsigned short adc_length {std::numeric_limits<unsigned short>::max()};
0074     unsigned short checksum {std::numeric_limits<unsigned short>::max()};
0075     unsigned short user_word {std::numeric_limits<unsigned short>::max()};
0076     unsigned short type {std::numeric_limits<unsigned short>::max()};
0077     unsigned short data_parity {std::numeric_limits<unsigned short>::max()};
0078     bool     valid {false};
0079     bool     parity_valid {false};
0080   };
0081 
0082   struct gtm_payload {
0083       unsigned short pkt_type;
0084       bool is_endat;
0085       bool is_lvl1;
0086       bool is_modebit;
0087       unsigned long long bco;
0088       unsigned int lvl1_count;
0089       unsigned int endat_count;
0090       unsigned long long last_bco;
0091       unsigned char modebits;
0092       unsigned char userbits;
0093   };
0094   
0095   // once vector per possible channel 16 cards * 256 channels
0096   //std::vector<sampa_waveform *> waveform_vector[MAX_FEECOUNT * MAX_CHANNELS];
0097 
0098   // our sort functional
0099 
0100 struct bco_compare {
0101     bool operator() (const sampa_waveform *lhs, const sampa_waveform *rhs) const
0102     {
0103       return  ( lhs->bx_timestamp <= rhs->bx_timestamp );
0104     }
0105 };
0106 
0107 
0108   
0109   typedef std::multiset< sampa_waveform* , bco_compare> waveform_set;
0110   //typedef waveform_set::iterator wf_iter;
0111   
0112   waveform_set waveforms;
0113   //  waveform_set waveforms[MAX_FEECOUNT * MAX_CHANNELS];
0114 
0115   std::vector<sampa_waveform*> waveform_vector;
0116   
0117   int cacheIterator(const int n);
0118   
0119   int _last_requested_element {-1}; // impossible value to mark "unused"
0120   sampa_waveform* _last_requested_waveform {nullptr};
0121   
0122   std::vector<unsigned short> fee_data[MAX_FEECOUNT];
0123 
0124   std::vector<gtm_payload *> gtm_data;
0125 
0126 };
0127 
0128  
0129 #endif /* __ONCSSUB_IDTPCFEEV4_H__ */