Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tpc_pool.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file tpc_pool.h
1 #ifndef __TPC_POOL_H__
2 #define __TPC_POOL_H__
3 
4 #include <vector>
5 #include <set>
6 #include <algorithm>
7 #include <functional>
8 #include <iostream>
9 
10 class Packet;
11 
12 class tpc_pool {
13 
14 public:
15  tpc_pool( const unsigned int required_depth, const unsigned int low_mark =1000000);
16  virtual ~tpc_pool();
17 
18  virtual int addPacket( Packet *);
19 
20  int next();
21 
22 
24  int iValue(const int ch, const int sample);
25  int iValue(const int ,const char * what);
26 
28  long long lValue(const int channel, const char *what) ;
29 
30  void dump ( std::ostream& os = std::cout) ;
31 
32  virtual bool depth_ok() const;
33  virtual void drain() { _low_mark = 0;};
34  virtual unsigned int min_depth() const { return _thebuffer.size(); };
35 
36 
37 protected:
38  int tpc_decode ();
39 
40  static const unsigned short MAGIC_KEY_0 = 0xfe;
41  static const unsigned short MAGIC_KEY_1 = 0x00;
42 
43  static const unsigned short FEE_MAGIC_KEY = 0xba00;
44  static const unsigned short GTM_MAGIC_KEY = 0xbb00;
45  static const unsigned short GTM_LVL1_ACCEPT_MAGIC_KEY = 0xbbf0;
46  static const unsigned short GTM_ENDAT_MAGIC_KEY = 0xbbf1;
47 
48  static const unsigned short MAX_FEECOUNT = 26; // that many FEEs
49  static const unsigned short MAX_CHANNELS = 8*32; // that many channels per FEE
50  static const unsigned short HEADER_LENGTH = 7;
51 
52  unsigned short reverseBits(const unsigned short x) const;
53  unsigned short crc16(const unsigned int fee, const unsigned int index, const int l) const;
54 
55  // int find_header ( std::vector<unsigned short>::const_iterator &itr, const std::vector<unsigned short> &orig);
56  int find_header ( const unsigned int xx, const std::vector<unsigned short> &orig);
57  int decode_gtm_data(unsigned short gtm[16]);
58 
59 // int _broken {0};
60 
62 
63  unsigned int _required_depth;
64  unsigned int _low_mark;
65 
66  unsigned int _progress_index;
67 
68 
69 
70 
71  std::vector<unsigned short> _thebuffer;
72 
73  struct sampa_waveform {
74  unsigned short fee;
75  unsigned short pkt_length;
76  unsigned short channel;
77  unsigned short sampa_channel;
78  unsigned short sampa_address;
79  unsigned int bx_timestamp;
80  std::vector<unsigned short> waveform;
81  unsigned short adc_length;
82  unsigned short checksum;
83  bool valid;
84  };
85 
86  struct gtm_payload {
87  unsigned short pkt_type;
88  bool is_endat;
89  bool is_lvl1;
90  unsigned long long bco;
91  unsigned int lvl1_count;
92  unsigned int endat_count;
93  unsigned long long last_bco;
94  unsigned char modebits;
95  };
96 
97  // once vector per possible channel 16 cards * 256 channels
98  //std::vector<sampa_waveform *> waveform_vector[MAX_FEECOUNT * MAX_CHANNELS];
99 
100  // our sort functional
101 
102 struct bco_compare {
103  bool operator() (const sampa_waveform *lhs, const sampa_waveform *rhs) const
104  {
105  return ( lhs->bx_timestamp <= rhs->bx_timestamp );
106  }
107 };
108 
109 
110 
111  typedef std::multiset< sampa_waveform* , bco_compare> waveform_set;
112  //typedef waveform_set::iterator wf_iter;
113 
115  // waveform_set waveforms[MAX_FEECOUNT * MAX_CHANNELS];
116 
117  int cacheIterator(const int n);
118 
119  waveform_set::iterator _cached_iter;
121 
122  std::vector<unsigned short> fee_data[MAX_FEECOUNT];
123 
124  std::vector<gtm_payload *> gtm_data;
125 
126 };
127 
128 
129 #endif