-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtdc1190_lib.c
More file actions
657 lines (543 loc) · 19.2 KB
/
tdc1190_lib.c
File metadata and controls
657 lines (543 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <time.h>
#include <iostream>
#include "CAENVMElib.h"
#include "CAENVMEtypes.h"
#include "CAENVMEoslib.h"
#include "tdc1190_lib.h"
using namespace std;
std::vector<unsigned long> addrs;
/*------------------------------------------------------------------*/
unsigned short init_tdc1190(int32_t BHandle)
{
unsigned long address;
unsigned short data;
short status; int caenst;
int WindowWidth = 0x8; /* Value * 25ns : 0x8 --> 200ns*/
int WindowOffset = -0x4; /* Time Window Offset 100ns, TDC Gate is [-100,100] ns*/
unsigned long trMode = 0x0000;
addrs.clear();
addrs.push_back(TDC1190_ADDRESS);
if(NUMBOARDS >1) addrs.push_back(TDC1190_ADDRESS2);
//Initialize all the boards
for(int iBo = 0; iBo<NUMBOARDS; iBo++) {
status = 1;
/* 0 passo: card reset*/
/* Edge detection rising by default after reset*/
//software Clear
address = addrs.at(iBo) + 0x1016;
data = 0x0;
// status *= vme_write_dt(address,&data,AD32,D16);
caenst = CAENVME_WriteCycle(BHandle,address,&data,cvA24_U_DATA,cvD16);
status *= 1-caenst;
if(td1190_debug) printf("Issued a Software Clear. Status:%d\n",status);
sleep(1); /* wait until the inizialization is complete */
/* 0 step: debugging. Printout the status register */
/* //Load defaults */
/* status *=opwriteTDC(BHandle, addrs.at(iBo), 0x0500); */
/* I step: set TRIGGER Matching mode via OPCODE 00xx */
if(td1190_debug) printf("Going to set Tr mode :%d\n",(int)trMode);
status *=opwriteTDC(BHandle, addrs.at(iBo), trMode);
printf("TDC1290::Setting trigger matching. Status:%d\n",status);
/* I step: set Edge detection via OPCODE 22xx */
data = 0x2200;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
data = 0x2;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
/* I step: set Time Reso via OPCODE 24xx */
data = 0x2400;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
data = 0x3; //25 ps resolution
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
printf("TDC1290::Setting Time Reso 25ps. Status:%d\n",status);
/* II step: set TRIGGER Window Width to value n */
data = 0x1000;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
status *=opwriteTDC(BHandle, addrs.at(iBo), WindowWidth);
/* III step: set TRIGGER Window Offset to value -n */
data = 0x1100;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
status *=opwriteTDC(BHandle, addrs.at(iBo), WindowOffset);
printf("TDC1290::Setting Time Window Width %d and Offset %d (values in 25ns bins). Status:%d\n",WindowWidth, WindowOffset,status);
/* IV step: enable channels*/
data = 0x4300;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
unsigned int enabledChannels=0;
data = 0x4000;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
enabledChannels |= ( 1 << (data & 0xFF) );
data = 0x4001;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
enabledChannels |= ( 1 << (data & 0xFF) );
data = 0x4002;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
enabledChannels |= ( 1 << (data & 0xFF) );
data = 0x4003;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
enabledChannels |= ( 1 << (data & 0xFF) );
data = 0x4004;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
enabledChannels |= ( 1 << (data & 0xFF) );
data = 0x4005;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
enabledChannels |= ( 1 << (data & 0xFF) );
data = 0x4006;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
enabledChannels |= ( 1 << (data & 0xFF) );
data = 0x4007;
status *=opwriteTDC(BHandle, addrs.at(iBo), data);
enabledChannels |= ( 1 << (data & 0xFF) );
printf("TDC1290::Channels %X are enabled. Status:%d\n", enabledChannels, status);
//Max 128 hits per event
/* data = 0x3300; */
/* status *=opwriteTDC(BHandle, addrs.at(iBo), data); */
/* data = 0x8; */
/* status *=opwriteTDC(BHandle, addrs.at(iBo), data); */
/* III-bis step: enable BLT mode */
/* data = 0x1100; */
/* status *=opwriteTDC(BHandle, addrs.at(iBo), 0x1100); */
/* status *=opwriteTDC(BHandle, addrs.at(iBo), WindowOffset); */
/* IV step: Enable trigger time subtraction */
data = 0x1400;
status *=opwriteTDC(BHandle, addrs.at(iBo), 0x1400);
//Disable tr time subtr
// status *=opwriteTDC(BHandle,0x1500);
/* //Setting Event Aligned at 1 events */
/* address = addrs.at(iBo) + 0x1018; data=0x1; */
/* // status *= vme_write_dt(address,&data,AD32,D16); */
/* caenst = CAENVME_WriteCycle(BHandle,address,&data,cvA24_U_DATA,cvD16); */
/* status = 1-caenst; */
if(td1190_debug) printf("Settings Status:: %d\n",status);
/* //status *= vme_read_dt(address,&data,AD32,D16); */
address = addrs.at(iBo) + 0x1000;
/* caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD16); */
/* status = 1-caenst; */
/* data |= 0x0001; */
/* data |= 0x0010; */
/* caenst = CAENVME_WriteCycle(BHandle,address,&data,cvA24_U_DATA,cvD16); */
/* status = 1-caenst; */
/* if(td1190_debug) printf("Let's see..:%d\n",status); */
/* address = addrs.at(iBo) + 0x1024; */
/* data = 0x1; */
/* caenst = CAENVME_WriteCycle(BHandle,address,&data,cvA24_U_DATA,cvD16); */
/* status = 1-caenst; */
/* if(td1190_debug) printf("Let's see again..:%d\n",status); */
caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD16);
status *= 1-caenst;
printf("TDC1290:: Reading status register. Status:%u\t%X\n",status,(unsigned int)data);
/* /\* TDC Event Reset *\/ */
/* address = addrs.at(iBo) + 0x1018; data=0x1; */
/* // status *= vme_write_dt(address,&data,AD32,D16); */
/* caenst = CAENVME_WriteCycle(BHandle,address,&data,cvA24_U_DATA,cvD16); */
/* status = 1-caenst; */
if(td1190_debug) printf("Setup Done :: %d\t. Ready for acquisition.\n",status);
}
return (status);
}
/*------------------------------------------------------------*/
short opwriteTDC(int32_t BHandle, unsigned long addr, unsigned short data)
/* It allows to write an opcode or an operand */
{
unsigned long address;
unsigned short rdata;
unsigned long time=0;
short status=1; int caenst;
const int TIMEOUT = 10000;
/* Check the Write OK bit */
do {
address = addr + MICROHANDREG;
//status *= vme_read_dt(address, &rdata,AD32,D16);
caenst = CAENVME_ReadCycle(BHandle,address,&rdata,cvA24_U_DATA,cvD16);
status = 1-caenst;
time++;
} while ((rdata != 0x1) && ((int)time < TIMEOUT));
if ((int)time == TIMEOUT) {
printf("\n TDC opwrite failed: TIMEOUT! \n");
status = 0;
return(status);
}
/* usleep(10000); /\* 10ms sleep before sending real data *\/ */
address = addr + MICROREG; /* OPCODE register */
//status *= vme_write_dt(address, &data,AD32,D16);
caenst = CAENVME_WriteCycle(BHandle,address,&data,cvA24_U_DATA,cvD16);
status = 1-caenst;
return (status);
}
/*----------------------------------------------------------------------*/
unsigned short opreadTDC(int32_t BHandle, unsigned long addr,
unsigned short *p2data)
/* It allows to read the data; CAEN MANUAL like */
{
unsigned long address;
unsigned short rdata;
int time=0;
unsigned short status=1; int caenst;
const int TIMEOUT = 10000;
/* Wait the DATA READY bit set to 1 */
do {
address = addr + MICROHANDREG;
//status *= vme_read_dt(address, &rdata,AD32,D16);
caenst = CAENVME_ReadCycle(BHandle,address,&rdata,cvA24_U_DATA,cvD16);
status = 1-caenst ;
time++;
} while (!(rdata & 0x2) && (time < TIMEOUT));
if (time == TIMEOUT) {
printf("\n TDC opread failed: TIMEOUT! \n");
status = 0;
return(status);
}
address = addr + MICROREG; /* OPCODE register */
//status *= vme_read_dt(address,p2data,AD32,D16);
caenst = CAENVME_ReadCycle(BHandle,address,p2data,cvA24_U_DATA,cvD16);
status = 1-caenst;
return(status);
}
/*-------------------------------------------------------------*/
vector<int> readEventTDC(int32_t BHandle, int idB, int status) {
unsigned long data,address,geo_add,measurement,channel,trailing;
double tdc_time;
int dataReady = 0; int TRG_matched = 0, evt_num = 0, tra_stat = 0;
int caenst; int TIMEOUT = 50000;
vector<int> outD;
/*
Events Words
1) Header
2) Tdc evt, ch, time
3) Trailer + error
*/
int tdc_hea = 0; int tdc_mea = 0;
int tdc_tra = 0; int glb_hea = 0, glb_tra = 0;
int nTry (0);
if(idB<0 || idB>NUMBOARDS-1) {
cout<<" Accssing Board number"<<idB<<" while only "<<NUMBOARDS<<" are initialized!!! Check your configuration!"<<endl;
status = 0;
return outD;
}
/*
First of all check the Status Register to see
if there's Data Ready
*/
status = 1;
do {
address = addrs.at(idB) + STATUSREGADD;
//status *= vme_read_dt(address,&data,AD32,D16);
caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD16);
status = 1-caenst;
if((data>>0) & 0x1) {
dataReady = 1;
}
if((data>>3) & 0x1) { TRG_matched = 1; }
nTry++;
} while (!dataReady && nTry<TIMEOUT);
if(nTry > TIMEOUT-10) printf("Timeout!!!! :%d\n",nTry);
/* Wait the DATA READY bit set to 1 */
if(dataReady) {
address= addrs.at(idB) + 0x0;
//status *= vme_read_dt(address,&data,AD32,D32);
caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD32);
status = 1-caenst;
if(td1190_debug) printf("Read New event!\n");
if( (data>>27) & 0x8 ) {
glb_hea = 1;
geo_add = data>>27;
evt_num = data>>5 & 0x3fffff;
outD.push_back((int) evt_num);
}
/*Check if trailer is found. Then loop until trailer is found and
start over*/
if( (data>>27) & 0x10 ) glb_tra = 1;
while(status && !glb_tra)
{
//status *= vme_read_dt(address,&data,AD32,D32);
caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD32);
status = 1-caenst;
glb_tra = (data>>27) & 0x10 ;
tdc_tra = (data>>27) & 0x3 ;
tdc_hea = (data>>27) & 0x1 ;
tdc_mea = (data>>27) & 0x0 ;
if(glb_tra == 0x10) {
/* Global Trailer!*/
if(td1190_debug) printf("Global trailer:: %X\n",(unsigned int)data);
tra_stat = data>>24 & 0x1;
outD.push_back((int) tra_stat);
} else if(tdc_tra == 0x3) {
/* TDC Trailer!*/
if(td1190_debug) printf("TDC trailer:: %X\n",(unsigned int)data);
} else if(tdc_hea) {
/* TDC Header!*/
if(td1190_debug) printf("TDC header:: %X\n",(unsigned int)data);
} else if(!tdc_mea) {
/* TDC measurement!*/
measurement = data & 0x3ffff;
channel = (data>>19) & 0x7f;
trailing = (data>>26) & 0x1;
tdc_time = (double)measurement/10;
// if(td1190_debug)
if(td1190_debug)
printf("TDC header:: %d %d %d\n",(int)evt_num,(int)channel,(int)measurement);
outD.push_back((int) evt_num);
outD.push_back((int) channel);
outD.push_back((int) measurement);
}
}
}
return outD;
}
/*-------------------------------------------------------------*/
vector<int> readNEventsTDC(int32_t BHandle, int idB, int status, int nevents, vector<int> &outW) {
unsigned int address,geo_add,measurement,channel,trailing;
int data;
double tdc_time;
int dataReady = 0; int TRG_matched = 0, evt_num = 0, tra_stat = 0;
int caenst; int TIMEOUT = 10000;
vector<int> outD;
/*
Events Words
1) Header
2) Tdc evt, ch, time
3) Trailer + error
*/
int tdc_hea = 0; int tdc_mea = 0;
int tdc_tra = 0; int glb_hea = 0, glb_tra = 0;
int nTry (0);
if(idB<0 || idB>NUMBOARDS-1) {
cout<<" Accssing Board number"<<idB<<" while only "<<NUMBOARDS<<" are initialized!!! Check your configuration!"<<endl;
status = 0;
return outD;
}
/*Access to control REGISTER
address= addrs.at(idB) + CONREGADD;
status *= vme_read_dt(address,&data,AD32,D16);
if(td1190_debug) printf("Access to control register. Status:%d\n",status);
*/
/*
First of all check the Status Register to see
if there's Data Ready
*/
status = 1;
do {
address = addrs.at(idB) + STATUSREGADD;
//status *= vme_read_dt(address,&data,AD32,D16);
caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD16);
status = 1-caenst;
if((data>>0) & 0x1) {
dataReady = 1;
}
if((data>>3) & 0x1) { TRG_matched = 1; }
nTry++;
} while (!dataReady && nTry<TIMEOUT);
if(nTry > TIMEOUT-10) printf("Timeout!!!! :%d\n",nTry);
/* Wait the DATA READY bit set to 1 */
int tmpev(0),tmpW(0);
if(dataReady) {
while(tmpev<nevents) {
tmpW = 0;
address= addrs.at(idB);
//status *= vme_read_dt(address,&data,AD32,D32);
caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD32);
status = 1-caenst;
/* std::cout << "GGG " << (data>>27) << std::endl; */
/* glb_hea = 0; */
/* if( (data>>27) & 0x8 ) { */
glb_hea = 1;
geo_add = data & 0x1F;
evt_num = data>>5 & 0x3fffff;
outD.push_back( (0xA << 28) | ((int) evt_num & 0xFFFFFFF ));
tmpW++;
if(td1190_debug) printf("Read new event %d\n",evt_num);
/* } */
// cout<<"First read:: "<<glb_hea<<" "<<evt_num<<endl;
/*Check if trailer is found. Then loop until trailer is found and
start over*/
glb_tra = 0;
if( (data>>27) & 0x10 ) glb_tra = 1;
while(status && !glb_tra)
{
//status *= vme_read_dt(address,&data,AD32,D32);
caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD32);
status = 1-caenst;
glb_tra = (data>>27) & 0x10 ;
tdc_tra = (data>>27) & 0x3 ;
tdc_hea = (data>>27) & 0x1 ;
tdc_mea = (data>>27) & 0x0 ;
if(glb_tra == 0x10) {
/* Global Trailer!*/
if(td1190_debug) printf("Global trailer:: %X\n",(unsigned int)data);
tra_stat = data>>24 & 0x1;
outD.push_back(data);
tmpW++;
} else if(tdc_tra == 0x3) {
/* TDC Trailer!*/
if(td1190_debug) printf("TDC trailer:: %X\n",(unsigned int)data);
} else if(tdc_hea) {
/* TDC Header!*/
if(td1190_debug) printf("TDC header:: %X\n",(unsigned int)data);
} else if(!tdc_mea) {
/* TDC measurement!*/
measurement = data & 0x1fffff;
channel = (data>>21) & 0x1f;
trailing = (data>>26) & 0x1;
tdc_time = (double)measurement/10;
// if(td1190_debug)
if(td1190_debug) printf("TDC measurement:: %d %d %d\n",(int)evt_num,(int)channel,(int)measurement);
/* outD.push_back((int) evt_num); tmpW++; */
/* outD.push_back((int) channel); tmpW++; */
/* outD.push_back((int) measurement); tmpW++; */
outD.push_back(data);
tmpW++;
}
}
outW.push_back(tmpW);
tmpev++;
}//multiple events block
}
return outD;
}
/*-------------------------------------------------------------*/
vector<int> readFastNEventsTDC(int32_t BHandle, int idB, int status, int nevents, vector<int> &outW, bool t1290) {
unsigned long data,address,geo_add,measurement,channel,trailing;
double tdc_time;
int dataReady = 0; int TRG_matched = 0, evt_num = 0, tra_stat = 0;
int caenst; int TIMEOUT = 10000;
vector<int> outD;
/*
Events Words
1) Header
2) Tdc evt, ch, time
3) Trailer + error
*/
int nbytes_tran = 99999;
int tdc_tst = 0;
int glb_tra = 0;
int nTry (0);
int wr; int maxW = 75;
/* if(idB == 1) maxW = 75; //Second TDC has only 16 channels */
int dataV[maxW*nevents];
if(idB<0 || idB>NUMBOARDS-1) {
cout<<" Accssing Board number"<<idB<<" while only "<<NUMBOARDS<<" are initialized!!! Check your configuration!"<<endl;
status = 0;
return outD;
}
/*Access to control REGISTER
address= addrs.at(idB) + CONREGADD;
status *= vme_read_dt(address,&data,AD32,D16);
if(td1190_debug) printf("Access to control register. Status:%d\n",status);
*/
/*
First of all check the Status Register to see
if there's Data Ready
*/
status = 1;
/* do { */
address = addrs.at(idB) + STATUSREGADD;
//status *= vme_read_dt(address,&data,AD32,D16);
caenst = CAENVME_ReadCycle(BHandle,address,&data,cvA24_U_DATA,cvD16);
status = 1-caenst;
if((data>>0) & 0x1) {
dataReady = 1;
}
if((data>>3) & 0x1) { TRG_matched = 1; }
if (td1190_debug)
std::cout << "TDC trigger matched:" << TRG_matched << std::endl;
/* Wait the DATA READY bit set to 1 */
int tmpW(0), idV(0);
if(dataReady) {
if (td1190_debug)
std::cout << "TDC DREADY 1"<< std::endl;
tmpW = 0;
address= addrs.at(idB) + 0x0;
//Vector reset
idV = 0; while(idV<(maxW)*nevents) { dataV[idV] = 0; idV++; }
// wr = maxW*4*nevents;
wr = sizeof(dataV);
//Performing BLT access (assuming BERR is enabled, check nbytes_transf=0 to exit the read cycle
int nWordsRead=0;
while(nbytes_tran>0 && nWordsRead<wr)
{
caenst = CAENVME_FIFOBLTReadCycle(BHandle,address,dataV+nWordsRead,wr,
cvA24_U_DATA,cvD32,&nbytes_tran);
status *= (1-caenst);
if(td1190_debug) printf("Read events with size %d %d %X\n",nbytes_tran,sizeof(dataV),dataV[nWordsRead]);
nWordsRead+=nbytes_tran/4;
}
//Vector dump into output
idV = 0; while(idV<std::min(nWordsRead,wr)) {
/* if (td1190_debug) */
/* std::cout << "TDC MEB word " << idV << ":" << dataV[idV] << std::endl; */
geo_add = dataV[idV]>>27;
tdc_tst = geo_add & 0x1f ;
std::cout << "TDC WORD TYPE " << tdc_tst << std::endl;
if(tdc_tst == 0x18) {
idV++;
continue;
}
/* if(td1190_debug) */
/* printf("Found word: %d %lx :: %lx %d\n",idV,dataV[idV],geo_add,tdc_tst); */
if(tdc_tst == 0x8 ) {
tmpW = 0;
evt_num = dataV[idV]>>5 & 0x3fffff;
/* if(td1190_debug) */
/* printf("Found GLB header: %d %d %lx :: %d\n",idB,idV,dataV[idV],evt_num); */
outD.push_back((int) evt_num);
if(td1190_debug)
cout<<evt_num<<endl;
tmpW++;
}
/*
Check if trailer is found. Then loop until trailer is found and
start over
*/
if(tdc_tst == 0x10) {
/* Global Trailer!*/
if(td1190_debug)
printf("Global trailer:: %d %X\n",idB,(unsigned int)dataV[idV]);
tra_stat = dataV[idV]>>24 & 0x1;
outD.push_back((int) tra_stat);
if(td1190_debug)
cout<<"trail "<<tra_stat<<endl;
tmpW++;
outW.push_back(tmpW);
}
if(tdc_tst == 0x3) {
/* TDC Trailer!*/
if(td1190_debug)
printf("TDC trailer:: %d %X\n",idB,(unsigned int)dataV[idV]);
}
if(tdc_tst == 0x1) {
/* TDC Header!*/
if(td1190_debug)
printf("TDC header:: %d %X\n",idB,(unsigned int)dataV[idV]);
}
if(tdc_tst == 0x0) {
/* TDC measurement!*/
trailing = (dataV[idV]>>26) & 0x1; //1190 & 1290
if(!t1290) {
measurement = dataV[idV] & 0x3ffff;
channel = (dataV[idV]>>19) & 0x7f;
} else {
measurement = dataV[idV] & 0x1fffff;
channel = (dataV[idV]>>21) & 0x1f;
}
tdc_time = (double)measurement/10;
if(td1190_debug)
printf("TDC %d Measurement:: %d %d %d\n",(int)idB,(int)evt_num,(int)channel,(int)measurement);
/* outD.push_back((int) evt_num); tmpW++; */
/* outD.push_back((int) channel); tmpW++; */
/* outD.push_back((int) measurement); tmpW++; */
if(td1190_debug)
cout<<"eve:: "<<evt_num<<" "<<channel<<" "<<measurement<<endl;
}
outD.push_back((int)dataV[idV]);
idV++;
}
}
//Protection against timeout.
/* usleep(20); */
return outD;
}