-
Notifications
You must be signed in to change notification settings - Fork 0
/
daqana.cc
93 lines (81 loc) · 2.73 KB
/
daqana.cc
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
#include "TApplication.h"
#include <string>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include "driver.hh"
#include "daq.hh"
#include "event.hh"
#include "rootdriver.hh"
#include <TCanvas.h>
using namespace std;
//
// MAIN program
//
int main(int argc, char **argv)
{
// switches
int c = 0;
string DriverFilename;
bool graphics = false, longRoot = false, slowOn = false;
// parse switches
while((c = getopt(argc,argv,"glsi:")) != -1)
{
switch(c) {
case 'i': // name of binary file from Labview
DriverFilename = optarg;
break;
case 'g':
graphics = true;
break;
case 'l':
longRoot = true;
break;
case 's':
slowOn = true;
break;
default:
exit(-1);
}
}
// driver for the daq processing..... provided from the python script
cout << "daqana:: DriverFilename: " << DriverFilename << endl;
driver* myDriver = new driver(DriverFilename, slowOn);
// TApplication is needed to plot a canvas with an event
TApplication *theApp;
if(graphics) theApp = new TApplication("tapp", &argc, argv);
TCanvas *canv = new TCanvas("c1","c1",500,300);
// create an instance of teh daq datatype: controls all the binary file handling
daq myDaq(myDriver);
// root management
rootdriver myRoot(myDriver, longRoot, slowOn);
// loop over the events
int totalnumberofevents = myDriver->getNEvent();
cout << "daqana:: number of events = " <<totalnumberofevents << endl;
event *ev = NULL;
for(int iEvent=0; iEvent<totalnumberofevents; iEvent++){
if(iEvent%100000==0) cout << " processed "<<iEvent<<" events"<<endl;
// read the next event
ev = myDaq.readEvent(myDriver);
// write the event to the root tree
myRoot.FastFill(ev, myDriver);
// if you want plot the event
Double_t pk = ev->getPeak();
Int_t ich = ev->getChannel();
Double_t rms = ev->calculateBaselineRMS();
//if(graphics && ( (ev->getErrorCode()&0x04) != 0) ) ev->Plot(canv);
if(graphics && ((ev->getErrorCode()&0x02) != 0 && ev->getChannel()%100 == 3 ) ) ev->Plot(canv);
// free event
myDaq.endEvent();
ev = NULL;
}
cout <<"daqana:: Finished processing .... terminating daqana" <<endl;
if(graphics) delete theApp;
// write run parameters to file
myRoot.writeParameters(myDriver);
myRoot.Close();
//delete myDriver;
cout <<"daqana:: Finished processing .... done" <<endl;
return 0;
}