Functions
webevd.cxx File Reference
#include <iostream>
#include <string>
#include <vector>
#include "canvas/Utilities/InputTag.h"
#include "gallery/Event.h"
#include "webevd/ArtSupport/ArtServiceHelper.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "larcore/Geometry/Geometry.h"
#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
#include "webevd/WebEVD/WebEVDServer.h"
#include "webevd/WebEVD/ThreadsafeGalleryEvent.h"

Go to the source code of this file.

Functions

void usage ()
 
int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file webevd.cxx.

25 {
26  if(argc == 1) usage();
27  --argc;
28  ++argv;
29 
30  bool detKnown = false;
31  bool isFD = false;
32 
33  int tgt_run = -1, tgt_subrun = -1, tgt_evt = -1;
34 
35  while(argc >= 1 && argv[0][0] == '-'){
36  if(std::string(argv[0]) == "-d"){
37  if(argc < 2) usage();
38 
39  const std::string d(argv[1]);
40 
41  detKnown = true;
42 
43  if(d == "fd" || d == "fardet" || d == "dune10kt") isFD = true;
44  else if(d == "pd" || d == "protodune" || d == "np04") isFD = false;
45  else{
46  std::cout << "Unrecognized detector '" << d << "'" << std::endl;
47  return 1;
48  }
49 
50  argc -= 2;
51  argv += 2;
52  continue;
53  }
54 
55  if(std::string(argv[0]) == "-e"){
56  if(argc < 2) usage();
57 
58  std::vector<int> toks;
59 
60  char* ptok = strtok(argv[1], ":");
61  while(ptok){
62  toks.push_back(atoi(ptok));
63  ptok = strtok(0, ":");
64  }
65 
66  if(toks.empty() || toks.size() > 3) usage();
67 
68  tgt_evt = toks[toks.size()-1];
69  std::cout << "Will look for event " << tgt_evt;
70  if(toks.size() > 1){
71  tgt_subrun = toks[toks.size()-2];
72  std::cout << " in subrun " << tgt_subrun;
73  }
74  if(toks.size() > 2){
75  tgt_run = toks[toks.size()-3];
76  std::cout << " in run " << tgt_run;
77  }
78  std::cout << std::endl;
79 
80  argc -= 2;
81  argv += 2;
82  continue;
83  }
84 
85  if(std::string(argv[0]) == "--help" ||
86  std::string(argv[0]) == "-h") usage();
87 
88  // Didn't match any of the conditions above
89  std::cout << "Unknown argument " << argv[0] << std::endl;
90  usage();
91  } // end while options remain
92 
93  if(argc == 0){
94  std::cout << "Must specify at least one input file" << std::endl;
95  usage();
96  }
97 
98  const std::vector<std::string> filenames(argv, argv + argc);
99 
100  if(!detKnown){
101  if(filenames[0].find("dune10kt") != std::string::npos ||
102  filenames[0].find("1x2x6") != std::string::npos){
103  isFD = true;
104  detKnown = true;
105  }
106  else if(filenames[0].find("np04") != std::string::npos){
107  isFD = false;
108  detKnown = true;
109  }
110  else{
111  std::cout << "Unable to auto-detect detector from filename. Please specify it explicitly with -d" << std::endl;
112  return 1;
113  }
114 
115  std::cout << "Auto-detected geometry as ";
116  if(isFD) std::cout << "far detector"; else std::cout << "ProtoDUNE SP";
117  std::cout << std::endl;
118  }
119 
120  // Prototype for automatically configuring the geometry below. Dumps the
121  // input file geometry configuration. Don't know how to do this in code yet
122  // system(("config_dumper -S -f Geometry "+filenames[0]).c_str());
123 
125 
126  std::string fclConfig = "#include \"services_dune.fcl\"\n";
127  if(isFD){
128  fclConfig +=
129  "@table::dunefd_services\n"
130  "Geometry.GDML: \"dune10kt_v1_1x2x6.gdml\"\n";
131  // TODO why is it necessary to manually specify the GDML?
132  }
133  else{
134  fclConfig +=
135  "@table::protodune_services\n";
136  }
137 
138  fclConfig +=
139  "BackTrackerService: @erase \n"
140  "PhotonBackTrackerService: @erase \n"
141  "LArFFT: @erase \n"
142  "TFileService: @erase \n";
143 
145 
148 
149  std::cout << geom->GDMLFile() << std::endl;
150 
151  std::cout << "Filling index of event numbers..." << std::endl;
152  std::map<art::EventID, std::pair<long long, long long>> seek_index;
153  for(gallery::Event evt(filenames); !evt.atEnd(); evt.next()){
154  seek_index[evt.eventAuxiliary().eventID()] = std::make_pair(evt.fileEntry(), evt.eventEntry());
155  }
156  std::cout << "Done" << std::endl;
157 
158  for(gallery::Event evt(filenames); !evt.atEnd();){
159  const art::EventAuxiliary& aux = evt.eventAuxiliary();
160 
161  if(tgt_run >= 0 || tgt_subrun >= 0 || tgt_evt >= 0){
162  if((tgt_run >= 0 && int(aux.run()) != tgt_run ) ||
163  (tgt_subrun >= 0 && int(aux.subRun()) != tgt_subrun) ||
164  (tgt_evt >= 0 && int(aux.event()) != tgt_evt )){
165  evt.next();
166  continue;
167  }
168  }
169  else{
170  // We must have arrived, stop seeking
171  tgt_run = tgt_subrun = tgt_evt = -1;
172  }
173 
174  std::cout << "\nDisplaying event " << aux.run() << ":" << aux.subRun() << ":" << aux.event() << std::endl << std::endl;
175 
177  const evd::Result res = server.serve(tsevt, geom, detprop);
178 
179  switch(res.code){
180  case evd::kNEXT:
181  std::cout << "Next event" << std::endl;
182  evt.next();
183  break;
184 
185  case evd::kPREV:
186  std::cout << "Previous event" << std::endl;
187  evt.previous();
188  break;
189 
190  case evd::kSEEK:
191  std::cout << "User requested seek to " << res.run << ":"<< res.subrun << ":" << res.event << std::endl;
192  {
193  const art::EventID tgt(res.run, res.subrun, res.event);
194  if(seek_index.find(tgt) == seek_index.end()){
195  std::cout << tgt << " not found in event index! Abort." << std::endl;
196  return 1;
197  }
198 
199  while(std::make_pair(evt.fileEntry(), evt.eventEntry()) < seek_index[tgt]) evt.next();
200  while(std::make_pair(evt.fileEntry(), evt.eventEntry()) > seek_index[tgt]) evt.previous();
201  }
202  continue;
203 
204  case evd::kQUIT:
205  std::cout << "Quit" << std::endl;
206  return 0;
207 
208  case evd::kERROR:
209  std::cout << "Error" << std::endl;
210  return 1;
211 
212  default:
213  std::cout << "Unrecognized result code " << res.code << "!" << std::endl;
214  abort();
215  }
216  }
217 
218  std::cout << "End of file" << std::endl;
219  return 0;
220 }
SubRunNumber_t subRun() const noexcept
std::string string
Definition: nybbler.cc:12
EventNumber_t event() const noexcept
virtual const provider_type * provider() const override
void usage()
Definition: webevd.cxx:17
static void load_services(std::string const &config)
RunNumber_t run() const noexcept
std::string GDMLFile() const
Returns the full directory path to the GDML file source.
Description of geometry of one entire detector.
EResult code
Definition: WebEVDServer.h:21
Result serve(const T &evt, const geo::GeometryCore *geom, const detinfo::DetectorPropertiesData &detprop)
TCEvent evt
Definition: DataStructs.cxx:7
QTextStream & endl(QTextStream &s)
void usage ( )

Definition at line 17 of file webevd.cxx.

18 {
19  std::cout << "Usage: webevd [-d DET] [-e [[RUN:]SUBRUN:]EVT] events.root [more_events.root...]" << std::endl;
20  exit(1);
21 }
QTextStream & endl(QTextStream &s)