-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmmef.cpp
117 lines (105 loc) · 4.26 KB
/
vmmef.cpp
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
#include <iostream>
#include <tclap/CmdLine.h>
#include "SRSRawFile.h"
#include "vmmef.h"
#include "event.h"
#include "Pedestal.h"
#include "HDF5File.h"
int verbose = 0; // global verbosity level
void buildDAQMap(std::string str, std::vector<size_t >& daqMap) {
std::stringstream ss(str); // Turn the string into a stream.
std::string idx;
while(std::getline(ss, idx, ','))
{
size_t i = std::stoi(idx);
daqMap.push_back(i);
}
}
int main(int argc, char** argv)
{
// A few safety measures against DATE's event.h
assert(sizeof(uint32_t) == sizeof(long32));
assert(sizeof(eventHeaderStruct) == EVENT_HEAD_BASE_SIZE);
Histogram* histogram = NULL;
Pedestal* pedestal = NULL;
HDF5File* hdf5File = NULL;
std::vector<size_t > daqMap;
try
{
// Setting up the command line perser
TCLAP::CmdLine cmd("Event formation proto type for the VMM3", ' ', "0.001");
TCLAP::ValueArg<std::string> dataFile_("d","data","Name of raw data file",false,"","filename",cmd);
TCLAP::ValueArg<int> numEvents_("n","nevent","Number of events to read from file",false,-1,"int",cmd);
TCLAP::ValueArg<int> numPedEvents_("N","nped","Number of events to read from pedestal file",false,-1,"int",cmd);
TCLAP::ValueArg<std::string> pedFile_("p","pedestal","Name of file containing pedestal data", false,"","filename",cmd);
TCLAP::ValueArg<std::string> aggFile_("a","aggregate","Aggregate the data in file in the same manner as the pedestal", false,"","filename",cmd);
TCLAP::ValueArg<std::string> hdf5File_("o","hdf5","Write output to HDF5 file <filename>", false,"","filename",cmd);
TCLAP::ValueArg<std::string> x_("x","Xmap","Comma separated list of DAQ indexes mapping to the X projection", false,"1,0","int,int",cmd);
TCLAP::ValueArg<std::string> y_("y","Ymap","Comma separated list of DAQ indexes mapping to the Y projection", false,"3,2","int,int",cmd);
TCLAP::ValueArg<int> verbose_("v","verbose","Level of verbosity [0-1]",false,0,"int",cmd);
// Parsing commandline paramneters
cmd.parse(argc, argv);
std::string dataFileName = dataFile_.getValue();
std::string pedestalFileName = pedFile_.getValue();
std::string aggregateFileName = aggFile_.getValue();
std::string hdf5FileName = hdf5File_.getValue();
int numEvents = numEvents_.getValue();
int numPedEvents = numPedEvents_.getValue();
verbose = verbose_.getValue();
buildDAQMap(x_.getValue(),daqMap);
if (daqMap.size() != DAQ_CHANNELS/2)
{
std::cerr << "Xmap must consist of " << DAQ_CHANNELS/2 << " elements." << std::endl;
return 1;
}
buildDAQMap(y_.getValue(),daqMap);
if (daqMap.size() != DAQ_CHANNELS)
{
std::cerr << "Ymap must consist of " << DAQ_CHANNELS/2 << " elements." << std::endl;
return 1;
}
if (!hdf5FileName.empty())
{
hdf5File = new HDF5File(hdf5FileName);
}
// Start processing
if (!pedestalFileName.empty())
{
SRSRawFile pedFile(pedestalFileName,daqMap);
histogram = new Histogram(pedFile, numPedEvents);
pedestal = new Pedestal(*histogram);
if (hdf5File)
hdf5File->addAggregate(pedestal,histogram, "/pedestal");
}
if (!aggregateFileName.empty())
{
SRSRawFile aggFile(aggregateFileName,daqMap);
histogram = new Histogram(aggFile, numPedEvents);
pedestal = new Pedestal(*histogram);
if (hdf5File)
hdf5File->addAggregate(pedestal,histogram,"/aggregate");
}
if (!dataFileName.empty())
{
SRSRawFile dataFile(dataFileName,daqMap);
if (hdf5File)
hdf5File->addEvents(dataFile,numEvents);
}
}
catch (TCLAP::ArgException &e)
{
std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
}
catch (std::exception e)
{
std::cerr << "error: " << e.what() << std::endl;
}
// Clean up
if (pedestal)
delete pedestal;
if (histogram)
delete histogram;
if (hdf5File)
delete hdf5File;
return 0;
}