Rev 109 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 109 | Rev 110 | ||
---|---|---|---|
1 | #include <stdio.h> |
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
2 | #include <stdlib.h> |
3 | #include <string.h> |
3 | #include <string.h> |
4 | #include <unistd.h> |
4 | #include <unistd.h> |
5 | #include <sys/mman.h> |
5 | #include <sys/mman.h> |
6 | #include <sys/ioctl.h> |
6 | #include <sys/ioctl.h> |
7 | #include <errno.h> |
7 | #include <errno.h> |
8 | #include <signal.h> |
8 | #include <signal.h> |
9 | #include <ctype.h> |
9 | #include <ctype.h> |
10 | #include <time.h> |
10 | #include <time.h> |
11 | #include <sys/time.h> |
11 | #include <sys/time.h> |
12 | 12 | ||
13 | #include "wusbxx_dll.h" /* the header of the shared library */ |
13 | #include "wusbxx_dll.h" /* the header of the shared library */ |
14 | #include "daq.h" |
14 | #include "daq.h" |
15 | 15 | ||
16 | #define DEVICE_NAME "/dev/cc32_1" |
16 | #define DEVICE_NAME "/dev/cc32_1" |
17 | #define PRRES(X) printf(">>> %s -> %d\n",#X,(X)) |
17 | #define PRRES(X) printf(">>> %s -> %d\n",#X,(X)) |
18 | 18 | ||
19 | 19 | ||
20 | 20 | ||
21 | /* definiram lokacije enot*/ |
21 | /* definiram lokacije enot*/ |
22 | //#define NTDC 23 /* TDC LeCroy 2277*/ |
22 | //#define NTDC 23 /* TDC LeCroy 2277*/ |
23 | #define NTDC 16 /* TDC LeCroy 2277*/ |
23 | #define NTDC 16 /* TDC LeCroy 2277*/ |
24 | #define END_MARKER 0xFAF5 |
24 | #define END_MARKER 0xFAF5 |
25 | int ctrlc=0; |
25 | int ctrlc=0; |
26 | int timer_out=0; |
26 | int timer_out=0; |
27 | 27 | ||
28 | void SigInt (int sig) |
28 | void SigInt (int sig) |
29 | { |
29 | { |
30 | ctrlc = 1; |
30 | ctrlc = 1; |
31 | timer_out=1; |
31 | timer_out=1; |
32 | 32 | ||
33 | } |
33 | } |
34 | 34 | ||
35 | struct sigaction oact; |
35 | struct sigaction oact; |
36 | void timerast (int signumber) |
36 | void timerast (int signumber) |
37 | { |
37 | { |
38 | timer_out = 1; |
38 | timer_out = 1; |
39 | printf("->>> TIMEOUT !!!\n"); |
39 | printf("->>> TIMEOUT !!!\n"); |
40 | } |
40 | } |
41 | 41 | ||
42 | void tmlnk (int tout) |
42 | void tmlnk (int tout) |
43 | { |
43 | { |
44 | timer_out = 0; |
44 | timer_out = 0; |
45 | struct sigaction act; |
45 | struct sigaction act; |
46 | struct itimerval tdelay; |
46 | struct itimerval tdelay; |
47 | 47 | ||
48 | act.sa_handler = timerast; |
48 | act.sa_handler = timerast; |
49 | sigemptyset (&act.sa_mask); |
49 | sigemptyset (&act.sa_mask); |
50 | act.sa_flags = 0; |
50 | act.sa_flags = 0; |
51 | 51 | ||
52 | tdelay.it_value.tv_sec = tout / 100; |
52 | tdelay.it_value.tv_sec = tout / 100; |
53 | tdelay.it_value.tv_usec = 10000 * (tout % 100); |
53 | tdelay.it_value.tv_usec = 10000 * (tout % 100); |
54 | tdelay.it_interval.tv_sec = 0; |
54 | tdelay.it_interval.tv_sec = 0; |
55 | tdelay.it_interval.tv_usec = 0; |
55 | tdelay.it_interval.tv_usec = 0; |
56 | 56 | ||
57 | if (sigaction (SIGALRM, &act, &oact) < 0) |
57 | if (sigaction (SIGALRM, &act, &oact) < 0) |
58 | { |
58 | { |
59 | perror ("sigaction(tmlnk)"); |
59 | perror ("sigaction(tmlnk)"); |
60 | exit (EXIT_FAILURE); |
60 | exit (EXIT_FAILURE); |
61 | } |
61 | } |
62 | if (setitimer (ITIMER_REAL, &tdelay, NULL) < 0) |
62 | if (setitimer (ITIMER_REAL, &tdelay, NULL) < 0) |
63 | { |
63 | { |
64 | perror ("setitimer(tmlnk)"); |
64 | perror ("setitimer(tmlnk)"); |
65 | exit (EXIT_FAILURE); |
65 | exit (EXIT_FAILURE); |
66 | } |
66 | } |
67 | } |
67 | } |
68 | 68 | ||
69 | void tmulk () |
69 | void tmulk () |
70 | { |
70 | { |
71 | struct itimerval tdelay; |
71 | struct itimerval tdelay; |
72 | 72 | ||
73 | tdelay.it_value.tv_sec = 0; |
73 | tdelay.it_value.tv_sec = 0; |
74 | tdelay.it_value.tv_usec = 0; |
74 | tdelay.it_value.tv_usec = 0; |
75 | tdelay.it_interval.tv_sec = 0; |
75 | tdelay.it_interval.tv_sec = 0; |
76 | tdelay.it_interval.tv_usec = 0; |
76 | tdelay.it_interval.tv_usec = 0; |
77 | 77 | ||
78 | if (setitimer (ITIMER_REAL, &tdelay, NULL) < 0) |
78 | if (setitimer (ITIMER_REAL, &tdelay, NULL) < 0) |
79 | { |
79 | { |
80 | perror ("setitimer(tmulk)"); |
80 | perror ("setitimer(tmulk)"); |
81 | exit (EXIT_FAILURE); |
81 | exit (EXIT_FAILURE); |
82 | } |
82 | } |
83 | if (sigaction (SIGALRM, &oact, NULL) < 0) |
83 | if (sigaction (SIGALRM, &oact, NULL) < 0) |
84 | { |
84 | { |
85 | perror ("sigaction(tmulk)"); |
85 | perror ("sigaction(tmulk)"); |
86 | exit (EXIT_FAILURE); |
86 | exit (EXIT_FAILURE); |
87 | } |
87 | } |
88 | } |
88 | } |
89 | 89 | ||
90 | 90 | ||
91 | 91 | ||
92 | 92 | ||
93 | void CAMAC_status(void) |
93 | void CAMAC_status(void) |
94 | { |
94 | { |
95 | unsigned short id,fpga,modid,inhibit,lam; |
95 | unsigned short id,fpga,modid,inhibit,lam; |
96 | unsigned short dum; |
96 | unsigned short dum; |
97 | 97 | ||
98 | 98 | ||
99 | long cres; |
99 | long cres; |
100 | int q,x; |
100 | int q,x; |
101 | 101 | ||
102 | CSSA_RQX(0,0,0,&cres,&q,&x); |
102 | CSSA_RQX(0,0,0,&cres,&q,&x); |
103 | dum = cres; |
103 | dum = cres; |
104 | id = (dum & 0xF000) >> 12; |
104 | id = (dum & 0xF000) >> 12; |
105 | fpga = (dum & 0x0F00) >> 8; |
105 | fpga = (dum & 0x0F00) >> 8; |
106 | modid = (dum & 0x00F0) >> 4; |
106 | modid = (dum & 0x00F0) >> 4; |
107 | q = (dum & 0x0008) >> 3; |
107 | q = (dum & 0x0008) >> 3; |
108 | x = (dum & 0x0004) >> 2; |
108 | x = (dum & 0x0004) >> 2; |
109 | inhibit= (dum & 0x0002) >> 1; |
109 | inhibit= (dum & 0x0002) >> 1; |
110 | lam = (dum & 0x0001); |
110 | lam = (dum & 0x0001); |
111 | printf ("CC32 CSR ID=%x FPGA=%x modID=%x Q=%d X=%d INHIBIT=%d LAM=%d \n",id,fpga,modid, q,x,inhibit,lam); |
111 | printf ("CC32 CSR ID=%x FPGA=%x modID=%x Q=%d X=%d INHIBIT=%d LAM=%d \n",id,fpga,modid, q,x,inhibit,lam); |
112 | } |
112 | } |
113 | 113 | ||
114 | int daq::init(){ |
114 | int daq::init(){ |
115 | 115 | ||
116 | printf("DAQ init at 0x%x\n",(unsigned int *) udev); |
116 | printf("DAQ init at 0x%x\n",(unsigned int *) udev); |
117 | if (udev == NULL) connect(); |
117 | if (udev == NULL) connect(); |
118 | if (udev == NULL) printf("udev == NULL\n"); |
118 | if (udev == NULL) printf("udev == NULL\n"); |
119 | xxusb_register_write(udev,1,0x0); // Stop DAQ mode |
119 | xxusb_register_write(udev,1,0x0); // Stop DAQ mode |
120 | while (xxusb_usbfifo_read(udev, (int*) stackdump,BUFF_L,100)>0); |
120 | while (xxusb_usbfifo_read(udev, (int*) stackdump,BUFF_L,100)>0); |
121 | 121 | ||
122 | printf("DAQ init finished\n"); |
122 | printf("DAQ init finished\n"); |
123 | CCCZ; |
123 | CCCZ; |
124 | CCCC; |
124 | CCCC; |
125 | 125 | ||
126 | CREM_I; |
126 | CREM_I; |
127 | long cres; |
127 | long cres; |
128 | int q,x; |
128 | int q,x; |
129 | 129 | ||
130 | // set status registerdevices_find |
130 | // set status registerdevices_find |
131 | //int tdcreg2277=0x8C00; // status register common start (green LED),Front panel timeout ,leading+trailing |
131 | //int tdcreg2277=0x8C00; // status register common start (green LED),Front panel timeout ,leading+trailing |
132 | // tdcreg2277= 0xC00; // status register common stop (red LED) ,leading + trailing edge recording |
132 | // tdcreg2277= 0xC00; // status register common stop (red LED) ,leading + trailing edge recording |
133 | int tdcreg2277= 0xCC00; // status register common start (green LED),8192 ns timeout ,leading+trailing |
133 | int tdcreg2277= 0xCC00; // status register common start (green LED),8192 ns timeout ,leading+trailing |
134 | 134 | ||
135 | CSSA_WQX(NTDC,0,17,tdcreg2277,&q,&x); |
135 | CSSA_WQX(NTDC,0,17,tdcreg2277,&q,&x); |
136 | CSSA_RQX(NTDC,0,17,&cres,&q,&x); |
136 | CSSA_RQX(NTDC,0,17,&cres,&q,&x); |
137 | 137 | ||
138 | printf("LC2277 SetRegister 0x%04x GetRegister 0x%04x\n",tdcreg2277,(unsigned int)cres); |
138 | printf("LC2277 SetRegister 0x%04x GetRegister 0x%04x\n",tdcreg2277,(unsigned int)cres); |
139 | 139 | ||
140 | CAMAC_status(); |
140 | CAMAC_status(); |
141 | 141 | ||
142 | // listmode data ----------------------------------------------- |
142 | // listmode data ----------------------------------------------- |
143 | 143 | ||
144 | long k=1; |
144 | long k=1; |
145 | 145 | ||
146 | 146 | ||
147 | /* |
147 | /* |
148 | stackwrite[k++]=(NAF(NTDC,0,8))| 0x8000 ; // test lam |
148 | stackwrite[k++]=(NAF(NTDC,0,8))| 0x8000 ; // test lam |
149 | stackwrite[k++]=0x80 ; // wait for lam |
149 | stackwrite[k++]=0x80 ; // wait for lam |
150 | 150 | ||
151 | 151 | ||
152 | stackwrite[k++]=(NAF(NTDC,1,27))| 0x8000; // test buffering |
152 | stackwrite[k++]=(NAF(NTDC,1,27))| 0x8000; // test buffering |
153 | stackwrite[k++]=0x10 | 0x8000 ; //until Q=0 |
153 | stackwrite[k++]=0x10 | 0x8000 ; //until Q=0 |
154 | stackwrite[k++]=0xF ; //max repetitions |
154 | stackwrite[k++]=0xF ; //max repetitions |
155 | 155 | ||
156 | stackwrite[k++]=NAFS(0,0,16); |
156 | stackwrite[k++]=NAFS(0,0,16); |
157 | stackwrite[k++]=0xbeef; |
157 | stackwrite[k++]=0xbeef; |
158 | 158 | ||
159 | stackwrite[k++]=(NAF(NTDC,9,27))| 0x8000; // test buffering |
159 | stackwrite[k++]=(NAF(NTDC,9,27))| 0x8000; // test buffering |
160 | stackwrite[k++]=0x10 | 0x8000 ; //until Q=0 |
160 | stackwrite[k++]=0x10 | 0x8000 ; //until Q=0 |
161 | stackwrite[k++]=0xFF ; //max repetitions |
161 | stackwrite[k++]=0xFF ; //max repetitions |
162 | 162 | ||
163 | stackwrite[k++]=NAFS(0,0,16); |
163 | stackwrite[k++]=NAFS(0,0,16); |
164 | stackwrite[k++]=0xbeef; |
164 | stackwrite[k++]=0xbeef; |
165 | */ |
165 | */ |
166 | 166 | ||
167 | 167 | ||
168 | stackwrite[k++]=(NAF(NTDC,0,0))| 0x8000; // read TDC |
168 | stackwrite[k++]=(NAF(NTDC,0,0))| 0x8000; // read TDC |
169 | stackwrite[k++]=0x10 | 0x8000 ; //until Q=0 |
169 | stackwrite[k++]=0x10 | 0x8000 ; //until Q=0 |
170 | stackwrite[k++]=0xF ; //max repetitions |
170 | stackwrite[k++]=0xF ; //max repetitions |
171 | 171 | ||
172 | stackwrite[k++]=NAF(NTDC,0,9) ; // clear tdc |
172 | stackwrite[k++]=NAF(NTDC,0,9) ; // clear tdc |
173 | 173 | ||
174 | stackwrite[k++]=NAF(NTDC,0,10) ; // clear lam |
174 | stackwrite[k++]=NAF(NTDC,0,10) ; // clear lam |
175 | 175 | ||
176 | 176 | ||
177 | // stackwrite[k++]=NAF(NTDC,0,1); // read status register |
177 | // stackwrite[k++]=NAF(NTDC,0,1); // read status register |
178 | stackwrite[k++]=NAFS(0,0,16); |
178 | stackwrite[k++]=NAFS(0,0,16); |
179 | stackwrite[k++]=END_MARKER; |
179 | stackwrite[k++]=END_MARKER; |
180 | stackwrite[0]=k-1; |
180 | stackwrite[0]=k-1; |
181 | 181 | ||
182 | for(unsigned int i=0;i<stackwrite[0];i++) printf("0x%04lx\n",stackwrite[i+1]); |
182 | for(unsigned int i=0;i<stackwrite[0];i++) printf("0x%04lx\n",stackwrite[i+1]); |
183 | 183 | ||
184 | CAMAC_LED_settings(udev, 1,1,0,0); |
184 | CAMAC_LED_settings(udev, 1,1,0,0); |
185 | xxusb_stack_write(udev,0x2,(long int *)stackwrite); |
185 | xxusb_stack_write(udev,0x2,(long int *)stackwrite); |
186 | PRRES(xxusb_stack_read(udev,0x2,(long int *) stackdata)); |
186 | PRRES(xxusb_stack_read(udev,0x2,(long int *) stackdata)); |
187 | for(int i=0;i<13;i++) printf("0x%04lx\n",stackdata[i]); |
187 | for(int i=0;i<13;i++) printf("0x%04lx\n",stackdata[i]); |
188 | 188 | ||
189 | PRRES(CAMAC_register_read(udev,0,&k)); |
189 | PRRES(CAMAC_register_read(udev,0,&k)); |
190 | char tbline[300]; |
190 | char tbline[300]; |
191 | sprintf(tbline,"Firmware ID -> 0x%08lX",k); |
191 | sprintf(tbline,"Firmware ID -> 0x%08lX",k); |
192 | printf("%s\n",tbline); |
192 | printf("%s\n",tbline); |
193 | 193 | ||
194 | CAMAC_register_read(udev,1,&k); |
194 | CAMAC_register_read(udev,1,&k); |
195 | sprintf(tbline,"Global Mode -> 0x%08lX",k); |
195 | sprintf(tbline,"Global Mode -> 0x%08lX",k); |
196 | printf("%s\n",tbline); |
196 | printf("%s\n",tbline); |
197 | k=(k&0xF000)|0x0006; |
197 | k=(k&0xF000)|0x0006; |
198 | // k=0x0002; |
198 | // k=0x0002; |
199 | k=7;// Start DAQ mode Buffopt=7 single event |
199 | k=7;// Start DAQ mode Buffopt=7 single event |
200 | CAMAC_register_write(udev,1,k); |
200 | CAMAC_register_write(udev,1,k); |
201 | CAMAC_register_write(udev,2,0x80); // wait 0x80 us |
201 | CAMAC_register_write(udev,2,0x80); // wait 0x80 us |
202 | CAMAC_register_write(udev,3,0x0); |
202 | CAMAC_register_write(udev,3,0x0); |
203 | CAMAC_register_write(udev,9,0x0); |
203 | CAMAC_register_write(udev,9,0x0); |
204 | CAMAC_register_write(udev,14,0x0); |
204 | CAMAC_register_write(udev,14,0x0); |
205 | 205 | ||
206 | return 0; |
206 | return 0; |
207 | } |
207 | } |
208 | 208 | ||
209 | int daq::connect(){ |
209 | int daq::connect(){ |
210 | /*xxusb_device_type devices[100]; |
210 | /*xxusb_device_type devices[100]; |
211 | struct usb_device *dev; |
211 | struct usb_device *dev; |
212 | dev = devices[0].usbdev; |
212 | dev = devices[0].usbdev; |
213 | udev = xxusb_device_open(dev);*/ |
213 | udev = xxusb_device_open(dev);*/ |
214 | WUSBXX_load (NULL); |
214 | WUSBXX_load (NULL); |
215 | // WUSBXX_open ((char *)"CC0126"); |
215 | // WUSBXX_open ((char *)"CC0126"); |
216 | WUSBXX_open ((char *)"CC0130"); |
216 | WUSBXX_open ((char *)"CC0130"); |
217 | printf("daq::connect()\n"); |
217 | printf("daq::connect()\n"); |
218 | return 0; |
218 | return 0; |
219 | } |
219 | } |
220 | 220 | ||
221 | int daq::disconnect(){ |
221 | int daq::disconnect(){ |
222 | /* zakljuci */ |
222 | /* zakljuci */ |
223 | 223 | ||
224 | printf("daq::disconnect()\n"); |
224 | printf("daq::disconnect()\n"); |
225 | return 0; |
225 | return 0; |
226 | } |
226 | } |
227 | 227 | ||
228 | 228 | ||
229 | int daq::event(unsigned int *data, int maxn){ |
229 | int daq::event(unsigned int *data, int maxn){ |
230 | 230 | ||
231 | //int events=0; |
231 | //int events=0; |
232 | 232 | ||
233 | short ret; |
233 | short ret; |
234 | 234 | ||
235 | 235 | ||
236 | 236 | ||
237 | //while ((events==0)&&(!fStop)){ |
237 | //while ((events==0)&&(!fStop)){ |
238 | int tout=100; /* 1/100 of a second */ |
238 | int tout=100; /* 1/100 of a second */ |
239 | tmlnk (tout); |
239 | tmlnk (tout); |
240 | 240 | ||
241 | ret=xxusb_usbfifo_read(udev,(int *) data,BUFF_L,500); |
241 | ret=xxusb_usbfifo_read(udev,(int *) data,BUFF_L,500); |
242 | tmulk(); |
242 | tmulk(); |
243 | 243 | ||
244 | 244 | ||
245 | // printf("ret=%d,events=0x%08x\n",ret,data[0]); |
245 | // printf("ret=%d,events=0x%08x\n",ret,data[0]); |
246 | //} |
246 | //} |
247 | 247 | ||
248 | 248 | ||
249 | return ret*2; |
249 | return ret*2; |
250 | } |
250 | } |
251 | 251 | ||
252 | 252 | ||
253 | 253 | ||
254 | daq::daq(){ |
254 | daq::daq(){ |
255 | // intercept routine |
255 | // intercept routine |
256 | if (signal (SIGINT, SigInt) == SIG_ERR) perror ("sigignore"); |
256 | if (signal (SIGINT, SigInt) == SIG_ERR) perror ("sigignore"); |
257 | 257 | ||
258 | fStop=0; |
258 | fStop=0; |
259 | connect(); |
259 | connect(); |
260 | init(); |
260 | init(); |
261 | xxusb_register_write(udev,1,0x1); // Start DAQ mode |
261 | xxusb_register_write(udev,1,0x1); // Start DAQ mode |
262 | } |
262 | } |
263 | 263 | ||
264 | daq::~daq(){ |
264 | daq::~daq(){ |
265 | xxusb_register_write(udev,1,0x0); // Stop DAQ mode |
265 | xxusb_register_write(udev,1,0x0); // Stop DAQ mode |
266 | while (xxusb_usbfifo_read(udev,(int *)stackdump,BUFF_L,30)>0); |
266 | while (xxusb_usbfifo_read(udev,(int *)stackdump,BUFF_L,30)>0); |
267 | 267 | ||
268 | disconnect(); |
268 | disconnect(); |
269 | } |
269 | } |
270 | 270 | ||
271 | #ifdef MAIN |
271 | #ifdef MAIN |
272 | 272 | ||
273 | 273 | ||
274 | 274 | ||
275 | int main (int argc, char **argv){ |
275 | int main (int argc, char **argv){ |
276 | 276 | ||
277 | int debug=0; |
277 | int debug=0; |
278 | int neve=1000000; |
278 | int neve=1000000; |
279 | char fname[0xFF]; |
279 | char fname[0xFF]; |
280 | sprintf(fname, "test.dat"); |
280 | sprintf(fname, "test.dat"); |
281 | if (argc==1) { |
281 | if (argc==1) { |
282 | printf("Uporaba: %s stevilo_dogodkov ime_datoteke\n",argv[0]); |
282 | printf("Uporaba: %s stevilo_dogodkov ime_datoteke\n",argv[0]); |
283 | printf("Meritev prekini s Ctrl-C, ce je nabranih dogodkov ze dovolj\n"); |
283 | printf("Meritev prekini s Ctrl-C, ce je nabranih dogodkov ze dovolj\n"); |
284 | exit(0); |
284 | exit(0); |
285 | } |
285 | } |
286 | if (argc>1) neve = atoi(argv[1]); |
286 | if (argc>1) neve = atoi(argv[1]); |
287 | if (argc>2) sprintf(fname,"%s", argv[2]); |
287 | if (argc>2) sprintf(fname,"%s", argv[2]); |
288 | if (argc>3) debug = atoi(argv[3]); |
288 | if (argc>3) debug = atoi(argv[3]); |
289 | 289 | ||
290 | 290 | ||
291 | 291 | ||
292 | // odpremo datoteko za pisanje |
292 | // odpremo datoteko za pisanje |
293 | FILE *fp=fopen(fname,"w"); |
293 | FILE *fp=fopen(fname,"w"); |
294 | 294 | ||
295 | int hdr[4]={1}; |
295 | int hdr[4]={1}; |
296 | 296 | ||
297 | #define BSIZE 10000 |
297 | #define BSIZE 10000 |
298 | unsigned int data[BSIZE]; |
298 | unsigned int data[BSIZE]; |
299 | daq *d= new daq(); |
299 | daq *d= new daq(); |
300 | 300 | ||
301 | for (int ieve=0;ieve!=neve && !ctrlc ;ieve++){ |
301 | for (int ieve=0;ieve!=neve && !ctrlc ;ieve++){ |
302 | //int tout=100; /* 1/100 of a second */ |
302 | //int tout=100; /* 1/100 of a second */ |
303 | //tmlnk (tout); |
303 | //tmlnk (tout); |
304 | int nb=d->event(data,BSIZE); |
304 | int nb=d->event(data,BSIZE); |
305 | //tmulk(); |
305 | //tmulk(); |
306 | // zapis v datoteko |
306 | // zapis v datoteko |
- | 307 | if (nb<0){ |
|
- | 308 | ieve--; |
|
- | 309 | continue; |
|
- | 310 | } |
|
307 | hdr[1]=nb+4*sizeof(int); |
311 | hdr[1]=nb+4*sizeof(int); |
308 | hdr[2]=time(NULL); |
312 | hdr[2]=time(NULL); |
309 | hdr[3]=ieve; |
313 | hdr[3]=ieve; |
310 | 314 | ||
311 | fwrite(hdr, sizeof(int),4 , fp); |
315 | fwrite(hdr, sizeof(int),4 , fp); |
312 | fwrite(data, sizeof(int),nb, fp); |
316 | fwrite(data, sizeof(int),nb, fp); |
313 | //***************** |
317 | //***************** |
314 | int evsize=0; |
318 | int evsize=0; |
315 | int events=0; |
319 | int events=0; |
316 | int ib=1,count=0; |
320 | int ib=1,count=0; |
317 | events = data[0]; |
321 | events = data[0]; |
318 | evsize = data[ib++]&0xffff; |
322 | evsize = data[ib++]&0xffff; |
319 | if (ieve %100 == 0) printf("nb=%d Event:%d events=%d EvSize:%d\n",nb, ieve, events, evsize); |
323 | if (ieve %100 == 0) printf("nb=%d Event:%d events=%d EvSize:%d\n",nb, ieve, events, evsize); |
- | 324 | if (evsize<2) { |
|
- | 325 | ieve--; |
|
- | 326 | continue; |
|
- | 327 | } |
|
320 | for (int i=0;i<evsize;i++) { |
328 | for (int i=0;i<evsize;i++) { |
321 | //if (debug) printf("%d\t%08x\n", ib, data[ib]); |
329 | //if (debug) printf("%d\t%08x\n", ib, data[ib]); |
322 | if (data[ib]== END_MARKER) break; |
330 | if (data[ib]== END_MARKER) break; |
323 | if ( |
331 | if (ib%2==0) { |
324 | unsigned short word1 =data[ib ]&0xFFFF; |
332 | unsigned short word1 =data[ib ]&0xFFFF; |
325 | unsigned short word2 =data[ib+1]&0xFFFF; |
333 | unsigned short word2 =data[ib+1]&0xFFFF; |
326 | unsigned short tdc = word1; |
334 | unsigned short tdc = word1; |
327 | unsigned short ch = (word2 >> 1 ) &0x1F; |
335 | unsigned short ch = (word2 >> 1 ) &0x1F; |
328 | unsigned short edge = word2 & 0x1; |
336 | unsigned short edge = word2 & 0x1; |
329 | unsigned short q = (word2 >> 8) &0x1; |
337 | unsigned short q = (word2 >> 8) &0x1; |
330 | unsigned short x = (word2 >> 9) &0x1; |
338 | unsigned short x = (word2 >> 9) &0x1; |
331 | if (debug) printf("%d. [ch=%2d] edge=%d data=%d q=%d x=%d\n",count,ch,edge,tdc, q, x); |
339 | if (debug) printf("%d. [ch=%2d] edge=%d data=%d q=%d x=%d\n",count,ch,edge,tdc, q, x); |
332 | count++; |
340 | count++; |
333 | } |
341 | } |
334 | ib++; |
342 | ib++; |
335 | } |
343 | } |
336 | if (data[evsize+1]!=END_MARKER) printf("Error! END_MARKER not found\n"); |
344 | if (data[evsize+1]!=END_MARKER) printf("Error! END_MARKER not found\n"); |
337 | //***************** |
345 | //***************** |
338 | 346 | ||
339 | 347 | ||
340 | } |
348 | } |
341 | fclose(fp); |
349 | fclose(fp); |
342 | printf("Podatki so v datoteki %s\n", fname); |
350 | printf("Podatki so v datoteki %s\n", fname); |
343 | 351 | ||
344 | 352 | ||
345 | delete d; |
353 | delete d; |
346 | 354 | ||
347 | return 0; |
355 | return 0; |
348 | } |
356 | } |
349 | #endif |
357 | #endif |
350 | 358 |