Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef __ONCSSUB_IDTPCFEEV5_H__
0002 #define __ONCSSUB_IDTPCFEEV5_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_idtpcfeev5 : public  oncsSubevent_w2 {
0014 #else
0015 class  oncsSub_idtpcfeev5 : public  oncsSubevent_w2 {
0016 #endif
0017 
0018 public:
0019   oncsSub_idtpcfeev5( subevtdata_ptr);
0020   ~oncsSub_idtpcfeev5();
0021 
0022   //! SAMPA waveform interfaces
0023   int    iValue(const int ch, const int sample);
0024   int    iValue(const int ,const char * what);
0025 
0026   //! FEE digital current interfaces
0027   int    iValue(const int, const int, const char *what);
0028 
0029   //! Expose the Level 1 trigger and endat taggers
0030   long long  lValue(const int channel, const char *what) ;
0031 
0032   void  dump ( OSTREAM& os = COUT) ;
0033 
0034 
0035 protected:
0036   int tpc_decode();
0037   int tpc_gtm_decode();
0038 
0039   static const unsigned short  MAGIC_KEY_0 {0xfe};
0040 //  static const unsigned short  MAGIC_KEY_1 = 0x00;
0041   static const unsigned short  MAGIC_KEY_1 {0xed};
0042   static const unsigned short  MAGIC_KEY_2 {0xdcdc};
0043 
0044   static const unsigned short FEE_MAGIC_KEY {0xba00};
0045   static const unsigned short GTM_MAGIC_KEY {0xbb00};
0046   static const unsigned short GTM_LVL1_ACCEPT_MAGIC_KEY {0xbbf0};
0047   static const unsigned short GTM_ENDAT_MAGIC_KEY {0xbbf1};
0048   static const unsigned short GTM_MODEBIT_MAGIC_KEY {0xbbf2};
0049 
0050   static const unsigned short  MAX_FEECOUNT {26};   // that many FEEs
0051   static const unsigned short  MAX_CHANNELS   {8*32}; // that many channels per FEE
0052 //  static const unsigned short  HEADER_LENGTH  = 5;
0053   static const unsigned short  HEADER_LENGTH  {7};
0054   
0055   unsigned short reverseBits(const unsigned short x) const;
0056   unsigned short crc16(const unsigned int fee, const unsigned int index, const int  l) const;
0057   unsigned short check_data_parity(const unsigned int fee, const unsigned int index, const int  l) const;
0058 
0059   //  int find_header ( std::vector<unsigned short>::const_iterator &itr,  const std::vector<unsigned short> &orig);
0060   int find_header ( const unsigned int xx,  const std::vector<unsigned short> &orig);
0061   int decode_gtm_data(unsigned short gtm[16]);
0062   
0063 //  int _broken;
0064   unsigned long NR_VALIDFEE = 0;
0065   
0066   int _is_decoded{0};
0067   int _is_gtm_decoded{0};
0068 
0069   struct sampa_waveform {
0070     unsigned short fee {std::numeric_limits<unsigned short>::max()};
0071     unsigned short pkt_length {std::numeric_limits<unsigned short>::max()};
0072     unsigned short channel {std::numeric_limits<unsigned short>::max()};
0073     unsigned short sampa_channel {std::numeric_limits<unsigned short>::max()};
0074     unsigned short sampa_address {std::numeric_limits<unsigned short>::max()};
0075     unsigned int bx_timestamp {0};
0076     std::vector<unsigned short> waveform;
0077     unsigned short adc_length {std::numeric_limits<unsigned short>::max()};
0078     unsigned short checksum {std::numeric_limits<unsigned short>::max()};
0079     unsigned short user_word {std::numeric_limits<unsigned short>::max()};
0080     unsigned short type {std::numeric_limits<unsigned short>::max()};
0081     unsigned short data_parity {std::numeric_limits<unsigned short>::max()};
0082     bool     valid {false};
0083     bool     parity_valid {false};
0084   };
0085 
0086   struct digital_current {
0087     unsigned short fee {std::numeric_limits<unsigned short>::max()};
0088     unsigned short pkt_length {std::numeric_limits<unsigned short>::max()};
0089     unsigned short channel {std::numeric_limits<unsigned short>::max()};
0090     unsigned short sampa_max_channel {std::numeric_limits<unsigned short>::max()};
0091     unsigned short sampa_address {std::numeric_limits<unsigned short>::max()};
0092     unsigned int bx_timestamp {0};
0093     unsigned int current[8];
0094     unsigned int nsamples[8];
0095     unsigned short checksum {std::numeric_limits<unsigned short>::max()};
0096     unsigned short type {std::numeric_limits<unsigned short>::max()};
0097     bool     valid {false};
0098   };
0099 
0100   struct gtm_payload {
0101       unsigned short pkt_type;
0102       bool is_endat;
0103       bool is_lvl1;
0104       bool is_modebit;
0105       unsigned long long bco;
0106       unsigned int lvl1_count;
0107       unsigned int endat_count;
0108       unsigned long long last_bco;
0109       unsigned char modebits;
0110       unsigned char userbits;
0111   };
0112   
0113   // once vector per possible channel 16 cards * 256 channels
0114   //std::vector<sampa_waveform *> waveform_vector[MAX_FEECOUNT * MAX_CHANNELS];
0115 
0116   // our sort functional
0117 
0118 struct bco_compare {
0119     bool operator() (const sampa_waveform *lhs, const sampa_waveform *rhs) const
0120     {
0121       return  ( lhs->bx_timestamp <= rhs->bx_timestamp );
0122     }
0123 };
0124 
0125 struct bco_dc_compare {
0126     bool operator() (const digital_current *lhs, const digital_current *rhs) const
0127     {
0128       return  ( lhs->bx_timestamp <= rhs->bx_timestamp );
0129     }
0130 };
0131 
0132   
0133   typedef std::multiset< sampa_waveform* , bco_compare> waveform_set;
0134   typedef std::multiset< digital_current* , bco_dc_compare> current_set;
0135 
0136   //typedef waveform_set::iterator wf_iter;
0137   
0138   waveform_set waveforms;
0139   current_set currentforms;
0140   //  waveform_set waveforms[MAX_FEECOUNT * MAX_CHANNELS];
0141 
0142   std::vector<sampa_waveform*> waveform_vector;
0143   std::vector<digital_current*> current_vector;
0144   
0145   int cacheIterator(const int n);
0146   int DCcacheIterator(const int n);
0147 
0148   int normal_packet(unsigned short[],int,unsigned int,unsigned int);
0149   int current_packet(unsigned short[],int,unsigned int,unsigned int);
0150   
0151   int _last_requested_element {-1}; // impossible value to mark "unused"
0152   int _last_requested_dcelement {-1}; // impossible value to mark "unused"
0153   sampa_waveform* _last_requested_waveform {nullptr};
0154   digital_current* _last_requested_currentform {nullptr};
0155   
0156   std::vector<unsigned short> fee_data[MAX_FEECOUNT];
0157 
0158   std::vector<gtm_payload *> gtm_data;
0159 
0160 };
0161 
0162  
0163 #endif /* __ONCSSUB_IDTPCFEEV5_H__ */