forked from CMSROMA/VMEDAQ
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_acquisition.c
789 lines (664 loc) · 22.1 KB
/
main_acquisition.c
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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <time.h>
//I'd like to get rid of those!!!
#include "my_vmeio.h"
#include "my_vmeint.h"
//Bridge!
#include "vme_bridge.h"
#include "main_acquisition.h"
#include "tdc1190_lib.h"
#include "adc265_lib.h"
#include "adc792_lib.h"
//#include "v495_lib.h"
#include "tdcV488A_lib.h"
#include "scaler560_lib.h"
#include "v1718_lib.h"
#include "V513.h"
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char** argv)
{
unsigned long max_evts=9000;
int nevent = 0;
short daq_status, status_init;
int i;
double rate;
int32_t BHandle(0);
int n_value = 0; int p_value = 50;
//float b_value = 0.0;
char* f_value = "dumb";
ofstream myOut;
int d_value = 0;
//a.out -a 3 -b 5.6 -c "I am a string" -d 222 111
for (i = 1; i < argc; i++) {
/* Check for a switch (leading "-"). */
if (argv[i][0] == '-') {
/* Use the next character to decide what to do. */
switch (argv[i][1]) {
case 'n':n_value = atoi(argv[++i]);
break;
case 'p':p_value = atoi(argv[++i]);
break;
case 'f':f_value = argv[++i];
break;
case 'd':d_value = atoi(argv[++i]);
break;
}
}
}
double tempo_last=0., time_start=0., time_last=0., delta_seconds=0., time_now=0., tempo_aftwr=0.;
double tempo_start=0., tempo_now =0., tempo_last_event=0.;
double elapsed_seconds=0., elapsed_seconds_dt=0.;
int n_microseconds = 0, n_microseconds_dt = 0;
int tempo_now_int = 0;
struct timeval tv;
struct timeval tempo1;
printf("n_evts(max) = %d\n", n_value);
if (f_value != NULL) printf("file = \"%s\"\n", f_value);
if(n_value) max_evts = n_value;
/* Bridge VME initialization */
status_init = bridge_init(BHandle);
bridge_deinit(BHandle);
status_init = bridge_init(BHandle);
/* VME deinitialization */
printf("\n\n VME initialization\n");
if (status_init != 1)
{
printf("VME Initialization error ... STOP!\n");
return(1);
}
/* Modules initialization */
if(V1718)
{
printf("\n Bridge initialization and trigger vetoed\n");
status_init *= init_1718(BHandle);
status_init *= init_pulser_1718(BHandle) ;
status_init *= set_configuration_1718(BHandle);
status_init *= print_configuration_1718(BHandle);
status_init *= init_scaler_1718(BHandle) ;
/* status_init *= setbusy_1718(BHandle,DAQ_BUSY_ON); */
if (status_init != 1) { return(1); }
}
else {
printf("\n No TRIGGER module is present:: EXIT!\n");
return(1);
}
if(IO513)
{
printf("\n IO register initialization and trigger vetoed\n");
status_init *= init_V513(BHandle);
status_init *= busy_V513(BHandle,DAQ_BUSY_ON);
if (status_init != 1) { return(1); }
}
/* Scaler560 Initialisation */
if(SCALER560) {
printf("\n Initialization of SCALER 560\n");
status_init *= init_scaler560(BHandle);
if (status_init != 1)
{
printf("Error in SCALER 560 initialization... STOP!\n");
return(1);
}
}
/*
Fast TDC initialization
Initializes ALL the TDC 1190 boards specified in tdc1190_lib.h header
*/
if(TDC1190 || TDC1190_2)
{
printf("\n Initialization of TDC1190 \n");
status_init *= init_tdc1190(BHandle);
if(status_init!=1)
{
printf("Error in tdc1190 initialization.... STOP!\n");
return(0);
}
}
/* ADC 265 initialization */
if(ADC265) {
printf("\n Initialization of ADC 265\n");
status_init *= init_adc265(BHandle);
if (status_init != 1)
{
printf("Error in ADC 265 initialization... STOP!\n");
return(1);
}
}
/* Fast TDC initialization */
if(TDC488A) {
printf("\n Initialization of TDCV488A \n");
status_init *= init_tdcV488A(BHandle);
if(status_init!=1) {
printf("Error in tdcV488A initialization.... STOP!\n");
return(0);
}
}
/* ADC 792 initialization */
if(ADC792) {
printf("\n Initialization of ADC 792\n");
status_init *= init_adc792(BHandle,0); //Initialize the first card
if (status_init != 1)
{
printf("Error in ADC 792 initialization... STOP!\n");
return(1);
}
}
printf("\n VME and modules initialization completed \n\n Start data acquisition\n");
/* Output file initialization */
int start, end;
int start_adc792, end_adc792;
int start_adc792_2, end_adc792_2;
int start_adc792_3, end_adc792_3;
int start_tdc2, end_tdc2;
int start_v488, end_v488;
int start_v560, end_v560;
int start_hea, end_hea;
int tdcWords, tdc2Words, board_num, adcWords, adc792Words, headWords;
int scalWords;
int adc792Words_2, adc792Words_3, v488Words;
bool trigger = false;
vector<int> myOE;
vector<int> my_tdc_OD, my_tdc_WD;
vector<int> my_tdc2_OD, my_tdc2_WD;
vector<int> my_v488_OD, my_v488_WD; //
vector<int> my_adc_OD;
vector<int> my_adc792_OD, my_adc792_WD;
vector<int> my_adc792_2_OD, my_adc792_2_WD;
vector<int> my_adc792_3_OD, my_adc792_3_WD;
vector<uint32_t> my_scal_OD, my_scal_WD, tmpscaD;
vector<int> my_header_OD;
myOut.open(f_value,ios::out);
/* Start counting: check that the scaler's channels are empty */
gettimeofday(&tempo1, NULL);
tempo_start = ((double)tempo1.tv_sec) + ((double)tempo1.tv_usec)/1000000;
tempo_last_event = tempo_start;
tempo_last = tempo_start;
time_start = tempo_start;
time_last = tempo_start;
int in_evt_read = 10;
bool read_boards,read_scaler;
int hm_evt_read;
bool hiScale = true;
//Clear of header info
my_header_OD.clear();
status_init *= reset_nim_scaler_1718(BHandle) ;
int nreadout=0;
/* Start of the event collection cycle */
while(nevent<(int)max_evts)
{
board_num = 0;
daq_status = 1;
hm_evt_read = in_evt_read;
// hm_evt_read = 1;
hiScale = true;
trigger = false;
//nasty...
if(nevent<in_evt_read) {hm_evt_read = 1; hiScale = false;}
/* START of data acquisition */
if (V1718 && !IO513) {
daq_status *= read_scaler_1718(BHandle); //reset scaler
daq_status *= setbusy_1718(BHandle,DAQ_BUSY_OFF); //busy off to latch the busy bit
if (daq_status != 1)
{
printf("\n Trigger enable(v1718) problems.. STOP!\n");
return(1);
}
} else if (V1718 && IO513) {
daq_status *= clear_strobe_V513(BHandle);
daq_status *= reset_daq(BHandle);
daq_status *= busy_V513(BHandle, DAQ_BUSY_OFF);
if (daq_status != 1)
{
printf("\n Problem in V513 trigger enable\n");
return(1);
}
}
/* Wait for the trigger signal from the IO */
if (V1718 && !IO513) {
while(!trigger)
{
daq_status = trigger_scaler_1718(BHandle,&trigger);
}
if(daq_status==999){
printf("Consider setting a reset...\n");
}
else if(daq_status!=1){
printf("\nError %d while on polling... STOP!\n",daq_status);
return(1);
}
daq_status *= setbusy_1718(BHandle,DAQ_TRIG_ACK); //acknowledge of the trigger to latch the trigger bit
} else if (V1718 && IO513) {
while(!trigger)
{
trigger = trigger_V513(BHandle);
}
}
/* measure the daq time */
gettimeofday(&tv, NULL);
tempo_now = ((double)tv.tv_sec) + ((double)tv.tv_usec)/1000000;
tempo_now_int = (tv.tv_sec)*1000000 + (tv.tv_usec);
elapsed_seconds = tempo_now - tempo_last_event;
n_microseconds =( (int) (elapsed_seconds*1000000));
n_microseconds_dt =( (int) (elapsed_seconds_dt*1000000));
tempo_last_event = tempo_now;
my_header_OD.push_back(n_microseconds);
my_header_OD.push_back(n_microseconds_dt);
if(d_value) cout<<"Dist btw evts:: "<<n_microseconds<<" Dist btw start/end:: "<<n_microseconds_dt<<endl;
my_header_OD.push_back(tempo_now_int);
headWords = my_header_OD.size();
read_boards = false;
read_scaler = false;
nevent++;
if(!(nevent%hm_evt_read)) {
if((nevent != hm_evt_read) || !hiScale)
read_boards = true;
}
if(read_boards) {
nreadout++;
/* read the TDC 1190 */
if(TDC1190) {
my_tdc_OD.clear();
my_tdc_WD.clear();
// my_tdc_OD = readNEventsTDC(BHandle,0,daq_status,hm_evt_read,my_tdc_WD);
my_tdc_OD = readFastNEventsTDC(BHandle,0,daq_status,hm_evt_read,my_tdc_WD,false);
if(d_value)
cout<<"Filled Word Vector:: "<<my_tdc_WD.size()<<" "<<my_tdc_OD.size()<<endl;
if(daq_status!=1){
printf("\nError reading the TDC 1190... STOP!\n");
return(1);
}
board_num ++;
tdcWords = my_tdc_OD.size();
}
/* read the TDC 1290 */
if(TDC1190_2) {
my_tdc2_OD.clear();
my_tdc2_WD.clear();
my_tdc2_OD = readFastNEventsTDC(BHandle,1,daq_status,hm_evt_read,my_tdc2_WD,true);
if(daq_status!=1){
printf("\nError reading the TDC 1290... STOP!\n");
return(1);
}
cout<<"Filled Word Vector:: "<<my_tdc2_WD.size()<<" "<<my_tdc2_OD.size()<<endl;
board_num += 2;
tdc2Words = my_tdc2_OD.size();
}
/* read the TDC V488A */
if(TDC488A) {
my_v488_OD.clear();
my_v488_WD.clear();
my_v488_OD = readBltNEventV488A(BHandle,daq_status,hm_evt_read,my_v488_WD);
if(daq_status!=1){
printf("\nEvent= %d Error reading the TDC V488A... STOP!\n",nevent);
return(1);
}
board_num += 4;
v488Words = my_v488_OD.size();
/*
for(int i=0; i<my_v488_OD.size(); i++) {
cout<<" content:: "<<nevent<<" "<<i<<" "<<my_v488_OD.at(i)<<endl;
}
*/
}
/* read the ADC 265*/
if(ADC265) {
my_adc_OD.clear();
//here we should improve the readomg pf n_events in a single event
my_adc_OD = read_adc265(BHandle,daq_status);
if (daq_status != 1)
{
printf("\nError reading ADC 265... STOP!\n");
return(1);
}
board_num += 8;
adcWords = my_adc_OD.size();
}
/* read the ADC 792*/
if(ADC792) {
my_adc792_OD.clear();
my_adc792_WD.clear();
//my_adc792_OD = read_adc792(BHandle,daq_status);
// my_adc792_OD = readFastadc792(BHandle,0,daq_status);
my_adc792_OD = readFastNadc792(BHandle,0,daq_status,hm_evt_read,my_adc792_WD);
// if(!my_adc792_OD.size()) cout<<" Warning:: QDC0 Read :: "<< my_adc792_OD.size()<<" "<< my_adc792_WD.size()<<endl;
if (daq_status != 1)
{
printf("\nError reading ADC 792... STOP!\n");
return(1);
}
board_num += 16;
adc792Words = my_adc792_OD.size();
if (d_value) std::cout << "ADC 792:: WORDS " << adc792Words << std::endl;
}
/* read the ADC 792 n.2*/
if(ADC792_2) {
my_adc792_2_OD.clear();
my_adc792_2_WD.clear();
my_adc792_2_OD = readFastNadc792(BHandle,1,daq_status,hm_evt_read,my_adc792_2_WD);
if(!my_adc792_2_OD.size()) cout<<" Warning:: Read :: "<< my_adc792_2_OD.size()<<" "<< my_adc792_2_WD.size()<<endl;
if (daq_status != 1)
{
printf("\nError reading ADC 792 n.2... STOP!\n");
return(1);
}
board_num += 32;
adc792Words_2 = my_adc792_2_OD.size();
if (d_value) std::cout << "ADC 792 n.2:: WORDS " << adc792Words_2 << std::endl;
}
/* read the ADC 792 n.3*/
if(ADC792_3) {
my_adc792_3_OD.clear();
my_adc792_3_WD.clear();
my_adc792_3_OD = readFastNadc792(BHandle,2,daq_status,hm_evt_read,my_adc792_3_WD);
if(!my_adc792_3_OD.size()) cout<<" Warning:: Read :: "<< my_adc792_3_OD.size()<<" "<< my_adc792_3_WD.size()<<endl;
if (daq_status != 1)
{
printf("\nError reading ADC 792 n.3... STOP!\n");
return(1);
}
board_num += 64;
adc792Words_3 = my_adc792_3_OD.size();
if (d_value) std::cout << "ADC 792 n.3:: WORDS " << adc792Words_3 << std::endl;
}
/* read the SCALER 560 EACH event*/
if(SCALER560) {
my_scal_OD.clear();
my_scal_WD.clear();
//Needed only if you read each event. In this implementation the
//tmp Vector is no longer needed.
//read the SCALER 1 in 100 times
if (nreadout%100==0)
read_scaler=true;
if (read_scaler)
{
my_scal_WD.push_back(V560_CHANNEL);
tmpscaD.clear();
tmpscaD = read_scaler560Vec(BHandle,daq_status);
my_scal_OD.insert( my_scal_OD.end(), tmpscaD.begin(), tmpscaD.end() );
board_num += 128;
scalWords = my_scal_OD.size();
// cout<<my_scal_OD.at(0)<<" "<<my_scal_OD.at(1)<<" "<<my_scal_OD.at(2)<<" "<<my_scal_OD.at(3)<<" "<<my_scal_OD.at(4)<<endl;
if(!my_scal_OD.size()) cout<<" Warning:: Scaler Read :: "<< my_scal_OD.size()<<" "<< my_scal_WD.size()<<endl;
if (daq_status != 1)
{
printf("\nError reading SCALER 560... STOP!\n");
return(1);
}
}
}
//HEADER with timing will be always present
board_num += 256;
start = 0;
start_adc792 = 0;
start_adc792_2 = 0;
start_adc792_3 = 0;
start_tdc2 = 0;
start_v488 = 0;
start_v560 = 0;
start_hea = 0;
/* if(hm_evt_read == 1) { */
/* myOE.clear(); */
/* //Write the event in unformatted style */
/* myOE.push_back(nevent); */
/* //What boards? */
/* myOE.push_back(board_num); */
/* if(TDC1190) myOE.push_back(tdcWords); */
/* if(TDC1190_2) myOE.push_back(tdc2Words); */
/* if(TDC488A) { */
/* myOE.push_back(v488Words); */
/* } */
/* if(ADC265) myOE.push_back(adcWords); */
/* if(ADC792) myOE.push_back(adc792Words); */
/* if(ADC792_2) myOE.push_back(adc792Words_2); */
/* if(ADC792_3) myOE.push_back(adc792Words_3); */
/* if(SCALER560) myOE.push_back(scalWords); */
/* myOE.push_back(headWords); */
/* if(TDC1190) myOE.insert( myOE.end(), my_tdc_OD.begin(), my_tdc_OD.end() ); */
/* if(TDC1190_2) myOE.insert( myOE.end(), my_tdc2_OD.begin(), my_tdc2_OD.end() ); */
/* if(TDC488A) myOE.insert( myOE.end(), my_v488_OD.begin(), my_v488_OD.end() ); */
/* if(ADC265) myOE.insert( myOE.end(), my_adc_OD.begin(), my_adc_OD.end() ); */
/* if(ADC792) myOE.insert( myOE.end(), my_adc792_OD.begin(), my_adc792_OD.end() ); */
/* if(ADC792_2) myOE.insert( myOE.end(), my_adc792_2_OD.begin(), my_adc792_2_OD.end() ); */
/* if(ADC792_3) myOE.insert( myOE.end(), my_adc792_3_OD.begin(), my_adc792_3_OD.end() ); */
/* if(SCALER560) myOE.insert( myOE.end(), my_scal_OD.begin(), my_scal_OD.end() ); */
/* myOE.insert( myOE.end(), my_header_OD.begin(), my_header_OD.end() ); */
/* //Clears the HEADER after writing the EVENT */
/* my_header_OD.clear(); */
/* daq_status *= writeFastEvent(myOE,&myOut); */
/* } else { */
for(int ie=0; ie<hm_evt_read; ie++) {
myOE.clear();
//Write the event in unformatted style
myOE.push_back(nevent-hm_evt_read+ie+1);
//What boards?
myOE.push_back(board_num);
if(TDC1190) {
if(ie<(int)my_tdc_WD.size()) {
myOE.push_back(my_tdc_WD.at(ie));
}
}
if(TDC1190_2) {
if(ie<(int)my_tdc2_WD.size()) {
myOE.push_back(my_tdc2_WD.at(ie));
}
}
if(TDC488A) {
if(ie<(int)my_v488_WD.size()) {
myOE.push_back(my_v488_WD.at(ie));
} else {
cout<<"nWords:: We are missing an event!!! "<<ie<<" "<<my_v488_WD.size()<<endl;
myOE.push_back(1);
}
}
// if(ADC265) myOE.push_back(adcWords);
int eventSize_adc792=0;
int eventSize_adc792_2=0;
int eventSize_adc792_3=0;
if(ADC792) {
eventSize_adc792=find_adc792_eventSize(my_adc792_OD,start_adc792);
if(eventSize_adc792) {
if(d_value) cout<<"This ADC evt has "<<eventSize_adc792<<" words"<<endl;
myOE.push_back(eventSize_adc792);
}
}
if(ADC792_2) {
eventSize_adc792_2=find_adc792_eventSize(my_adc792_2_OD,start_adc792_2);
if(eventSize_adc792_2) {
if(d_value) cout<<"This 2nd ADC evt has "<<eventSize_adc792_2<<" words"<<endl;
myOE.push_back(eventSize_adc792_2);
}
}
if(ADC792_3) {
eventSize_adc792_3=find_adc792_eventSize(my_adc792_3_OD,start_adc792_3);
if(eventSize_adc792_3) {
if(d_value) cout<<"This 3rd ADC evt has "<<eventSize_adc792_3<<" words"<<endl;
myOE.push_back(eventSize_adc792_3);
}
}
if(SCALER560) {
//Only dump the scaler on the of the event readout'
if(my_scal_WD.size()) {
if(d_value) cout<<" This scaler evt has "<<my_scal_WD.at(0)<<" words"<<endl;
if(ie == hm_evt_read-1) myOE.push_back(my_scal_WD.at(0));
else myOE.push_back(0);
}
else
myOE.push_back(0);
}
if(headWords/hm_evt_read != 3) {
cout<<"Problem with the HEADER!! "<<endl;
cout<<"HEADER words in the multiple events"<<headWords<<" "<<hm_evt_read<<endl;
}
myOE.push_back(headWords/hm_evt_read);
//Ok, finished writing the Number of words.
//Now writing the events
if(TDC1190 && my_tdc_WD.size()) {
end = start + my_tdc_WD.at(ie);
for(int idum = start; idum<end; idum++) {
if(d_value)
cout<<" TDC loop:: "<<ie<<" "<<idum<<" "<<my_tdc_OD.at(idum)<<endl;
myOE.push_back(my_tdc_OD.at(idum));
}
start = end; //Reset the start position to the end of previuos write
}
if(TDC1190_2 && my_tdc2_WD.size()) {
end_tdc2 = start_tdc2 + my_tdc2_WD.at(ie);
for(int idum = start_tdc2; idum<end_tdc2; idum++) {
if(d_value)
cout<<" TDC 2 loop:: "<<ie<<" "<<idum<<" "<<my_tdc2_OD.at(idum)<<endl;
myOE.push_back(my_tdc2_OD.at(idum));
}
start_tdc2 = end_tdc2; //Reset the start position to the end of previuos write
}
if(TDC488A) {
if(d_value)
cout<<" TDC488:: "<<ie<<" "<<my_v488_WD.size()<<endl;
if(ie<(int)my_v488_WD.size()){
end_v488 = start_v488 + my_v488_WD.at(ie);
for(int idum = start_v488; idum<end_v488; idum++) {
if(d_value)
cout<<" V488 loop:: "<<ie<<" "<<idum<<" "<<my_v488_OD.at(idum)<<endl;
myOE.push_back(my_v488_OD.at(idum));
}
start_v488 = end_v488; //Reset the start position to the end of previuos write
} else {
cout<<" eWords:: We are missing an event!!! "<<ie<<" "<<my_v488_WD.size()<<endl;
myOE.push_back(40000);
}
}
// if(ADC265) myOE.insert( myOE.end(), my_adc_OD.begin(), my_adc_OD.end() );
if(ADC792) {
end_adc792 = start_adc792 + eventSize_adc792;
for(int idum = start_adc792; idum<end_adc792; idum++) {
myOE.push_back(my_adc792_OD.at(idum));
}
start_adc792 = end_adc792; //Reset the start position to the end of previuos write
}
if(ADC792_2 && my_adc792_2_WD.size()) {
end_adc792_2 = start_adc792_2 + eventSize_adc792_2;
for(int idum = start_adc792_2; idum<end_adc792_2; idum++) {
myOE.push_back(my_adc792_2_OD.at(idum));
}
start_adc792_2 = end_adc792_2; //Reset the start position to the end of previuos write
}
if(ADC792_3 && my_adc792_3_WD.size()) {
end_adc792_3 = start_adc792_3 + eventSize_adc792_3;
for(int idum = start_adc792_3; idum<end_adc792_3; idum++) {
myOE.push_back(my_adc792_3_OD.at(idum));
}
start_adc792_3 = end_adc792_3; //Reset the start position to the end of previuos write
}
if(SCALER560 && my_scal_OD.size()) {
//Only dump the scaler on the 'FIRST set of events'
if(ie == hm_evt_read-1) {
end_v560 = start_v560 + my_scal_WD.at(0);
for(int idum = start_v560; idum<end_v560; idum++) {
myOE.push_back(my_scal_OD.at(idum));
}
start_v560 = end_v560; //Reset the start position to the end of previuos write
}
}
//ADD the header info
end_hea = start_hea + 3;
for(int idum = start_hea; idum<end_hea; idum++) {
myOE.push_back( my_header_OD.at(idum) );
}
start_hea = end_hea;
daq_status *= writeFastEvent(myOE,&myOut);
}
//Clears the HEADER after writing the EVENT
my_header_OD.clear();
}
if(daq_status!=1){
printf("\nError writing the Event... STOP!\n");
return(1);
}
// if(IO513) daq_status = read_V513_old(BHandle, IO_value);
if((nevent-(p_value*((int)(nevent/p_value))))==0)
{
gettimeofday(&tempo1, NULL);
time_now = ((double)tempo1.tv_sec) +
((double)tempo1.tv_usec)/1000000;
elapsed_seconds = time_now-time_start;
delta_seconds = time_now-time_last;
time_last = time_now;
if(delta_seconds) rate = ((double)p_value)/delta_seconds;
printf("_____ Event number: %d El time (s): %f Freq (Hz): %lf ______\n",
nevent,delta_seconds,rate);
if(!access("acq.stop",F_OK)) {
cout<<"Stopped run from acq.stop : deleting acq.stop file"<<endl;
nevent = max_evts;
remove("acq.stop");
}
}
/* /\* Reset the strobe bit and send the reset to the DAQ *\/ */
/* if (V1718 && !IO513) { */
/* daq_status *= clearbusy_1718(BHandle); */
/* if (daq_status != 1) */
/* { */
/* printf("\nerror resetting V1718 -> exiting\n"); */
/* return(1); */
/* } */
/* } else if (V1718 && IO513) { */
/* /\* */
/* reset the strobe bit and send the reset to the DAQ */
/* *\/ */
/* if (daq_status != 1) */
/* { */
/* printf("\nerror resetting IO -> exiting\n"); */
/* return(1); */
/* } */
/* } */
gettimeofday(&tv, NULL);
tempo_aftwr = ((double)tv.tv_sec) + ((double)tv.tv_usec)/1000000;
elapsed_seconds_dt = tempo_aftwr - tempo_now;
}
std::cout << "++++++ Final run statistics +++++++" << std::endl;
tmpscaD.clear();
tmpscaD = read_scaler560Vec(BHandle,daq_status);
if(!tmpscaD.size()) cout<<" Warning:: Scaler Read :: "<< tmpscaD.size() << std::endl;
if (daq_status != 1)
{
printf("\nError reading SCALER 560... STOP!\n");
return(1);
}
/* Output File finalization */
printf("\n Closing output file!\n");
myOut.close();
/* VME deinitialization */
bridge_deinit(BHandle);
printf("\n VME and modules deinitialization completed \n\n Data acquisition stopped\n");
return(0);
}
// Read FAST (no decoding)
unsigned short writeFastEvent(vector<int> wriD, ofstream *Fouf)
{
/*
Event FORMAT:
Evt Size
Channel Mask
Evt number
Trigger time
And for the non zero channels
N. of ch words (+1, tot charge)
*/
unsigned short status = 1;
int size = wriD.size();
int myD[size];
// cout<<"++++++++ New Event of size " << size <<endl;
for(int dum=0; dum<size; dum++) {
myD[dum] = wriD[dum];
// cout<<dum << "\t" << myD[dum] <<endl;
}
Fouf->write((char *) &size,sizeof(int));
Fouf->write((char *) myD,wriD.size()*sizeof(int));
return (status);
}