StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_dta.h
1 #ifndef _DAQ_DTA_H_
2 #define _DAQ_DTA_H_
3 
4 
5 
6 
7 #include <rts.h> // for swaps
8 #include <sys/types.h> // for u_int
9 
10 #include "daq_dta_structs.h"
11 
12 
13 struct daq_store {
14 // u_char sec ;
15 // u_char row ;
16 // u_char pad ;
17 // char type ; // 'r' raw; 'a' adc; 'c' clusters; 'p' pedestals; 'g' gains
18 
19  u_int sec ;
20  u_int row ;
21  u_int pad ;
22  char type ; // 'r' raw; 'a' adc; 'c' clusters; 'p' pedestals; 'g' gains
23 
24  u_int nitems ; // usually 1 for raw; <512 for adc; <32 for clusters; 512 for pedestals; 1 for gains
25 } ;
26 
27 
28 struct daq_store_hdr {
29 // this MUST NOT change!
30  int hdr_bytes ;
31  int hdr_version ;
32  u_int endianess ;
33  int obj_bytes ;
34  char obj_name[32] ;
35  u_int bytes_used ;
36  char describe[128] ; // string for humans...
37 //extend after this line
38 } ;
39 
40 
41 
42 #define DAQ_DTA_STRUCT(expr) __STRING(expr),sizeof(expr)
43 #define DAQ_DTA_ENDIANESS 0x04030201
44 #define DAQ_DTA_C_VERSION 0
45 #define DAQ_DTA_H_VERSION 0
46 
47 
48 
49 class daq_dta {
50 private:
51 
52  daq_store *store_cur ;
53  daq_store_hdr *hdr ;
54 
55  u_int bytes_alloced ; // in store!
56  u_int nitems ;
57 
58  int do_swap ; // for endianess conversion
59  char type ; // type of structure stored; used for endianess conversion only!
60 
61  inline void sw(u_int &x) {
62  x = swap32(x) ;
63  }
64  inline void sw(int &x) {
65  x = swap32(x) ;
66  }
67  inline void sw(u_short &x) {
68  x = swap16(x) ;
69  }
70  inline void sw(short &x) {
71  x = swap16(x) ;
72  }
73 
74 
75 
76  inline void psw(u_int &x) {
77  if(do_swap) x = swap32(x) ;
78  }
79  inline void psw(int &x) {
80  if(do_swap) x = swap32(x) ;
81  }
82  inline void psw(u_short &x) {
83  if(do_swap) x = swap16(x) ;
84  }
85  inline void psw(short &x) {
86  if(do_swap) x = swap16(x) ;
87  }
88 
89 
90 
91  inline u_int tsw(u_int x) {
92  if(do_swap) return swap32(x) ;
93  return x ;
94  }
95  inline int tsw(int x) {
96  if(do_swap) return swap32(x) ;
97  return x ;
98  }
99  inline u_short tsw(u_short x) {
100  if(do_swap) return swap16(x) ;
101  return x ;
102  }
103  inline short tsw(short x) {
104  if(do_swap) return swap16(x) ;
105  return x ;
106  }
107 
108 
109  inline short l2h(short x) { return l2h16(x) ; } ;
110  inline u_short l2h(u_short x) { return l2h16(x) ; } ;
111  inline int l2h(int x) { return l2h32(x) ; } ;
112  inline u_int l2h(u_int x) { return l2h32(x) ; } ;
113 
114  inline short b2h(short x) { return b2h16(x) ; } ;
115  inline u_short b2h(u_short x) { return b2h16(x) ; } ;
116  inline int b2h(int x) { return b2h32(x) ; } ;
117  inline u_int b2h(u_int x) { return b2h32(x) ; } ;
118 
119  daq_store *get(u_int obj_cou=0) ;
120 
121  void clear() ; // clears counters so it can be reused...
122 
123  void release() ; // releases memory
124 
125 
126 
127  void commit(u_int bytes=0) ;
128 
129  daq_store *store ;
130 public:
131 
132 
133  daq_dta() ;
134  virtual ~daq_dta() ;
135 
136  // used for writing!
137  daq_store *create(u_int bytes, const char *name, int rts_id, const char *o_name, u_int obj_size) ;
138 
139  void *request(u_int obj_cou) ;
140  void finalize(u_int obj_cou, int s=0, int row=0, int pad=0) ;
141  void rewind() ; // rewinds at the beggining
142 
143 
144  int is_empty() ;
145 
146  int iterate() ;
147 
148  inline size_t get_size_t() {
149  return hdr->obj_bytes ;
150  }
151 
152  virtual const char *GetCVS() const { // Offline
153  static const char cvs[]="Tag $Name: $: $Id: daq_dta.h,v 1.10 2018/04/10 12:13:31 tonko Exp $: built " __DATE__ " " __TIME__ ;
154  return cvs;
155  }
156 
157 
158 
159 
160 
161  union { // UNION of pointers!!!! ONLY!!!! ;
162  // the following are system so DO NOT change foolishly
163  void *Void ;
164  unsigned char *Byte ;
165  unsigned short *Short ;
166  unsigned int *Int32 ;
167  unsigned long long *Int64 ;
168 
169  // current specifics:
170  daq_trg_word *trg_word ;
171 
172  // timebin based zero-suppressed dets:TPX, TPC, FTPC, SVT, SSD maybe
173  daq_adc_tb *adc ;
174 
175  // TPC/TPX cluster data
176  daq_cld *cld ;
177 
178  // TPC/TPX simulated data
179  daq_sim_adc_tb *sim_adc ;
180  // TPC/TPX output of simulated clusters...
181  daq_sim_cld *sim_cld ;
182 
183  // TPC/TPX gain
184  daq_det_gain *gain ;
185 
186 
187  /* commented: to be deleted
188  // older EVP_READER structures...
189  struct svt_t *svt ;
190  struct trg_t *trg ;
191  struct ssd_t *ssd ;
192  struct tof_t *tof ;
193  struct pp2pp_t *pp2pp ;
194 
195  // special fixed arrays for misc dets...
196  unsigned short (*etow)[160] ; // X 6 i.e. etow[6][160]
197  unsigned short (*etow_pre)[4] ;
198 
199  unsigned short (*esmd)[192] ; // X 48 i.e. esmd[48][192]
200  unsigned short (*esmd_pre)[4] ;
201 
202  unsigned short (*btow)[160] ; // X 30 i.e. btow[30][160]
203  unsigned short (*btow_pre)[4] ;
204 
205  unsigned short (*bsmd)[4800] ; // X 12 i.e. bsmd[12][4800]
206  unsigned char *bsmd_cap ;
207 
208  */
209  } ;
210 
211 
212 
213 
214 
215  // from subsequent data
216  int sec ;
217  union {
218  int row ;
219  int rdo ;
220  } ;
221 
222  int pad ;
223 
224  void *meta ; // detector specific info bank...
225 
226  u_int ncontent ;
227 
228  u_int mode ; // bank/detector specific; can be error, can be something else...
229 } ;
230 
231 
232 #endif