1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
18
/* Simple code used to open a reconstructed MAUS ROOT file,
19
* iterate through spills and pass a spill to EVExporter
26
#include "DataStructure/Spill.hh"
27
#include "DataStructure/Data.hh"
28
#include "JsonCppStreamer/IRStream.hh"
30
#include "src/utilities/event-viewer/EVExporter.hh"
32
int ParseArguments(int argc, char* argv[]);
33
void ShowUsage(std::string arg);
35
std::string FILE_NAME;
41
int main(int argc, char* argv[]) {
48
if (!ParseArguments(argc, argv))
51
// - start reading data:
53
irstream infile(FILE_NAME.c_str(), "Spill");
55
// - iterate over spills:
56
while (infile >> readEvent != NULL) {
57
infile >> branchName("data") >> data;
58
MAUS::Spill *spill = data.GetSpill();
60
if (spill != NULL && spill->GetDaqEventType() == "physics_event") {
61
int spillNumber = spill->GetSpillNumber();
63
// - instantiate EVExported and pass spill to it
65
if (spillNumber == SPILL_NUM) {
66
EventViewer::EVExporter *exp = new EventViewer::EVExporter(spill);
67
exp->ReadAllEvents(EVENT_SELECTION, VERBOSE);
70
} else if (SPILL_RANGE[1] != 0) { // can not pass both --spill and --spill_range arguments
71
if (SPILL_RANGE[1] > SPILL_RANGE[0]) {
72
if (spillNumber >= SPILL_RANGE[0] && spillNumber <= SPILL_RANGE[1]) {
73
EventViewer::EVExporter *exp = new EventViewer::EVExporter(spill);
74
exp->ReadAllEvents(EVENT_SELECTION, VERBOSE);
75
} else if (spillNumber > SPILL_RANGE[1]) {
79
std::cerr << std::endl << "ERROR: Invalid spill range!" << std::endl << std::endl;
82
} else if (SPILL_NUM == 0 && SPILL_RANGE[0] == 0 && SPILL_RANGE[1] == 0) {
83
EventViewer::EVExporter *exp = new EventViewer::EVExporter(spill);
84
exp->ReadAllEvents(EVENT_SELECTION, VERBOSE);
92
int ParseArguments(int argc, char* argv[]) {
100
for (int i = 1; i < argc; ++i) {
101
std::string arg = argv[i];
102
if (arg == "-h" || arg == "--help") {
106
if (arg == "-v" || arg == "--verbose") {
109
if (arg == "-f" || arg == "--file")
110
FILE_NAME = argv[i+1];
111
if (arg == "-s" || arg == "--spill") {
113
SPILL_NUM = atoi(argv[i+1]);
115
std::cerr << "\n" << "WARNING: You must provide argument to --spill option" << "\n\n";
119
if (arg == "-sr" || arg == "--spill_range") {
121
SPILL_RANGE[0] = atoi(argv[i+1]);
123
std::cerr << "\n" << "WARNING: You must provide argument to --spill_range option" << "\n\n";
127
SPILL_RANGE[1] = atoi(argv[i+2]);
129
std::cerr << "\n" << "WARNING: You must provide second argument to --spill_range option"
134
if (arg == "-es" || arg == "--event_selection")
136
EVENT_SELECTION = atoi(argv[i+1]);
138
std::cerr << "\n" << "WARNING: You must provide argument to --event_selection option"
144
if (FILE_NAME == "") {
145
std::cerr << "\n" << "ERROR! You must provide INPUT_FILE argument!" << "\n\n";
153
void ShowUsage(std::string progName) {
154
std::cerr << "\n" << "USAGE: " << progName << " <option(s)> SOURCES\n"
156
<< " -h, --help\t\t\t\t\tShow this message\n"
157
<< " -v, --verbose\t\t\t\tverbose mode\n"
158
<< " -f, --file INPUT_FILE\t\t\tSpecify ROOT input file (has to be provided)\n"
159
<< " -s, --spill SPILL_NUMBER\t\t\tSpecify spill to export\n"
160
<< " -sr, --spill_range FIRST_SPILL LAST_SPILL\tSpecify range of spills to be exported\n"
161
<< " (if no spills are selected the whole run will be processed)\n\n"
162
<< " -es, --event_selection EVENT_SELECTION\tNumber describing combination "
163
<< "of detectors hit in an event:\n"
164
<< " \t0\t\texport all events (default value)\n"
165
<< " \t1\t\tno detectors hit\n"
166
<< " \t+2\t\tTOF0 hit\n"
167
<< " \t+4\t\tTOF1 hit\n"
168
<< " \t+8\t\tat least one hit in US tracker\n"
169
<< " \t+16\t\tat least one hit in DS tracker\n"
170
<< " \t+32\t\tTOF2 hit\n"
171
<< " (only events that have this combination of detectors hit will be exported "
172
<< "(e.g. 62 for all detectors hit))\n\n"