~ajdobbs/maus/event-viewer

« back to all changes in this revision

Viewing changes to src/utilities/event-viewer/EVSimpleExporter.cc

  • Committer: Adam Dobbs
  • Date: 2016-05-10 17:37:19 UTC
  • Revision ID: phuccj@gmail.com-20160510173719-7r79ffxdzhuq9m2t
Added event viewer

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
2
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 */
 
17
 
 
18
/* Simple code used to open a reconstructed MAUS ROOT file,
 
19
 * iterate through spills and pass a spill to EVExporter 
 
20
 */
 
21
 
 
22
#include <iostream>
 
23
#include <vector>
 
24
#include <string>
 
25
 
 
26
#include "DataStructure/Spill.hh"
 
27
#include "DataStructure/Data.hh"
 
28
#include "JsonCppStreamer/IRStream.hh"
 
29
 
 
30
#include "src/utilities/event-viewer/EVExporter.hh"
 
31
 
 
32
int ParseArguments(int argc, char* argv[]);
 
33
void ShowUsage(std::string arg);
 
34
 
 
35
std::string FILE_NAME;
 
36
int SPILL_NUM;
 
37
int SPILL_RANGE[2];
 
38
int EVENT_SELECTION;
 
39
bool VERBOSE;
 
40
 
 
41
int main(int argc, char* argv[]) {
 
42
  SPILL_NUM = 0;
 
43
  SPILL_RANGE[0] = 0;
 
44
  SPILL_RANGE[1] = 0;
 
45
  EVENT_SELECTION = 0;
 
46
  VERBOSE = false;
 
47
 
 
48
  if (!ParseArguments(argc, argv))
 
49
    return 1;
 
50
 
 
51
  // - start reading data:
 
52
  MAUS::Data data;
 
53
  irstream infile(FILE_NAME.c_str(), "Spill");
 
54
 
 
55
  // - iterate over spills:
 
56
  while (infile >> readEvent != NULL) {
 
57
    infile >> branchName("data") >> data;
 
58
    MAUS::Spill *spill = data.GetSpill();
 
59
 
 
60
    if (spill != NULL && spill->GetDaqEventType() == "physics_event") {
 
61
      int spillNumber = spill->GetSpillNumber();
 
62
 
 
63
      // - instantiate EVExported and pass spill to it
 
64
      if (SPILL_NUM != 0) {
 
65
        if (spillNumber == SPILL_NUM) {
 
66
          EventViewer::EVExporter *exp = new EventViewer::EVExporter(spill);
 
67
          exp->ReadAllEvents(EVENT_SELECTION, VERBOSE);
 
68
          return 0;
 
69
        }
 
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]) {
 
76
            return 0;
 
77
          }
 
78
        } else {
 
79
          std::cerr << std::endl << "ERROR: Invalid spill range!" << std::endl << std::endl;
 
80
          return 2;
 
81
        }
 
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);
 
85
      }
 
86
    }
 
87
  }
 
88
  infile.close();
 
89
  return 0;
 
90
}
 
91
 
 
92
int ParseArguments(int argc, char* argv[]) {
 
93
  FILE_NAME = "";
 
94
 
 
95
  if (argc < 2) {
 
96
    ShowUsage(argv[0]);
 
97
    return 0;
 
98
  }
 
99
 
 
100
  for (int i = 1; i < argc; ++i) {
 
101
    std::string arg = argv[i];
 
102
    if (arg == "-h" || arg == "--help") {
 
103
      ShowUsage(argv[0]);
 
104
      return 0;
 
105
    }
 
106
    if (arg == "-v" || arg == "--verbose") {
 
107
      VERBOSE = true;
 
108
    }
 
109
    if (arg == "-f" || arg == "--file")
 
110
      FILE_NAME = argv[i+1];
 
111
    if (arg == "-s" || arg == "--spill") {
 
112
      if (i+1 < argc) {
 
113
        SPILL_NUM = atoi(argv[i+1]);
 
114
      } else {
 
115
        std::cerr << "\n" << "WARNING: You must provide argument to --spill option" << "\n\n";
 
116
        return 0;
 
117
      }
 
118
    }
 
119
    if (arg == "-sr" || arg == "--spill_range") {
 
120
      if (i+1 < argc) {
 
121
        SPILL_RANGE[0] = atoi(argv[i+1]);
 
122
      } else {
 
123
        std::cerr << "\n" << "WARNING: You must provide argument to --spill_range option" << "\n\n";
 
124
        return 0;
 
125
      }
 
126
      if (i+2 < argc) {
 
127
        SPILL_RANGE[1] = atoi(argv[i+2]);
 
128
      } else {
 
129
        std::cerr << "\n" << "WARNING: You must provide second argument to --spill_range option"
 
130
                  << "\n\n";
 
131
        return 0;
 
132
      }
 
133
    }
 
134
    if (arg == "-es" || arg == "--event_selection")
 
135
      if (i+1 < argc) {
 
136
        EVENT_SELECTION = atoi(argv[i+1]);
 
137
      } else {
 
138
        std::cerr << "\n" << "WARNING: You must provide argument to --event_selection option"
 
139
                  << "\n\n";
 
140
        return 0;
 
141
      }
 
142
  }
 
143
 
 
144
  if (FILE_NAME == "") {
 
145
    std::cerr << "\n" << "ERROR! You must provide INPUT_FILE argument!" << "\n\n";
 
146
    ShowUsage(argv[0]);
 
147
    return 0;
 
148
  }
 
149
 
 
150
  return 1;
 
151
}
 
152
 
 
153
void ShowUsage(std::string progName) {
 
154
  std::cerr << "\n" << "USAGE: " << progName << " <option(s)> SOURCES\n"
 
155
    << " Options:\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"
 
173
    << "\n\n";
 
174
}