All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Enumerations | 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.

Enumerations

enum  EDetector {
  EDetector::kUnknown, EDetector::kDUNEFDHD, EDetector::kDUNEFDVD, EDetector::kProtoDUNESP,
  EDetector::kSBND, EDetector::kIcarus
}
 

Functions

void usage ()
 
std::ostream & operator<< (std::ostream &os, EDetector det)
 
EDetector DetectorFromArgument (const std::string &d)
 
EDetector DetectorFromFilename (const std::string &fname)
 
std::string FCLConfigForDetector (EDetector det)
 
int main (int argc, char **argv)
 

Enumeration Type Documentation

enum EDetector
strong
Enumerator
kUnknown 
kDUNEFDHD 
kDUNEFDVD 
kProtoDUNESP 
kSBND 
kIcarus 

Definition at line 23 of file webevd.cxx.

Function Documentation

EDetector DetectorFromArgument ( const std::string &  d)

Definition at line 47 of file webevd.cxx.

48 {
49  if(d == "fd" ||
50  d == "fardet" ||
51  d == "dune10kt") return EDetector::kDUNEFDHD;
52 
53  if(d == "fdvd" ||
54  d == "vd") return EDetector::kDUNEFDVD;
55 
56  if(d == "pd" ||
57  d == "protodune" ||
58  d == "np04") return EDetector::kProtoDUNESP;
59 
60  if(d == "sbnd") return EDetector::kSBND;
61 
62  if(d == "icarus") return EDetector::kIcarus;
63 
64  return EDetector::kUnknown;
65 }
EDetector DetectorFromFilename ( const std::string &  fname)

Definition at line 67 of file webevd.cxx.

68 {
69  const std::map<std::string, EDetector> auto_fname_mapping = {
70  {"dune10kt", EDetector::kDUNEFDHD},
71  {"1x2x6", EDetector::kDUNEFDHD},
72  // TODO what to use to autodetect DUNE VD filenames?
73  {"np04", EDetector::kProtoDUNESP},
74  {"sbnd", EDetector::kSBND},
75  {"icarus", EDetector::kIcarus}
76  };
77 
78  for(auto it: auto_fname_mapping){
79  if(fname.find(it.first) != std::string::npos) return it.second;
80  }
81 
82  return EDetector::kUnknown;
83 }
string fname
Definition: demo.py:5
std::string FCLConfigForDetector ( EDetector  det)

Definition at line 85 of file webevd.cxx.

86 {
87  std::string fclConfig;
88 
89  switch(det){
91  fclConfig +=
92  "#include \"services_dune.fcl\"\n"
93  "@table::dunefd_services\n"
94  "Geometry.GDML: \"dune10kt_v1_1x2x6.gdml\"\n";
95  // TODO why is it necessary to manually specify the GDML?
96  break;
97 
99  fclConfig +=
100  "#include \"services_dune.fcl\"\n"
101  "@table::protodunedphase_simulation_services\n";
102  break;
103 
105  fclConfig +=
106  "#include \"services_dune.fcl\"\n"
107  "@table::protodune_services\n";
108  break;
109 
110  case EDetector::kSBND:
111  fclConfig +=
112  "#include \"services_sbnd.fcl\"\n"
113  "@table::sbnd_services\n";
114  break;
115 
116  case EDetector::kIcarus:
117  fclConfig +=
118  "#include \"services_common_icarus.fcl\"\n"
119  "@table::icarus_common_services\n";
120  break;
121 
122  default:
123  std::cout << "Don't know how to configure services for " << det << std::endl;
124  abort();
125  }
126 
127  fclConfig +=
128  "message: @erase \n"
129  "scheduler: @erase \n"
130  "BackTrackerService: @erase \n"
131  "PhotonBackTrackerService: @erase \n"
132  "LArFFT: @erase \n"
133  "TFileService: @erase \n";
134 
135  return fclConfig;
136 }
BEGIN_PROLOG could also be cout
int main ( int  argc,
char **  argv 
)

Definition at line 139 of file webevd.cxx.

140 {
141  if(argc == 1) usage();
142  --argc;
143  ++argv;
144 
146 
147  int tgt_run = -1, tgt_subrun = -1, tgt_evt = -1;
148 
149  while(argc >= 1 && argv[0][0] == '-'){
150  if(std::string(argv[0]) == "-d"){
151  if(argc < 2) usage();
152 
153  const std::string d(argv[1]);
154 
155  det = DetectorFromArgument(argv[1]);
156 
157  if(det == EDetector::kUnknown){
158  std::cout << "Unrecognized detector '" << d << "'" << std::endl;
159  return 1;
160  }
161 
162  argc -= 2;
163  argv += 2;
164  continue;
165  }
166 
167  if(std::string(argv[0]) == "-e"){
168  if(argc < 2) usage();
169 
170  std::vector<int> toks;
171 
172  char* ptok = strtok(argv[1], ":");
173  while(ptok){
174  toks.push_back(atoi(ptok));
175  ptok = strtok(0, ":");
176  }
177 
178  if(toks.empty() || toks.size() > 3) usage();
179 
180  tgt_evt = toks[toks.size()-1];
181  std::cout << "Will look for event " << tgt_evt;
182  if(toks.size() > 1){
183  tgt_subrun = toks[toks.size()-2];
184  std::cout << " in subrun " << tgt_subrun;
185  }
186  if(toks.size() > 2){
187  tgt_run = toks[toks.size()-3];
188  std::cout << " in run " << tgt_run;
189  }
190  std::cout << std::endl;
191 
192  argc -= 2;
193  argv += 2;
194  continue;
195  }
196 
197  if(std::string(argv[0]) == "--help" ||
198  std::string(argv[0]) == "-h") usage();
199 
200  // Didn't match any of the conditions above
201  std::cout << "Unknown argument " << argv[0] << std::endl;
202  usage();
203  } // end while options remain
204 
205  if(argc == 0){
206  std::cout << "Must specify at least one input file" << std::endl;
207  usage();
208  }
209 
210  const std::vector<std::string> filenames(argv, argv + argc);
211 
212  if(det == EDetector::kUnknown){
213  det = DetectorFromFilename(filenames[0]);
214 
215  if(det == EDetector::kUnknown){
216  std::cout << "Unable to auto-detect detector from filename. Please specify it explicitly with -d" << std::endl;
217  return 1;
218  }
219 
220  std::cout << "Auto-detected geometry as " << det << std::endl;
221  }
222 
223  // Prototype for automatically configuring the geometry below. Dumps the
224  // input file geometry configuration. Don't know how to do this in code yet
225  // system(("config_dumper -S -f Geometry "+filenames[0]).c_str());
226 
228 
230 
231  const geo::GeometryCore* geom = art::ServiceHandle<geo::Geometry>()->provider();
232  const detinfo::DetectorPropertiesData detprop = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataForJob();
233 
234  std::cout << geom->GDMLFile() << std::endl;
235 
236  std::cout << "Filling index of event numbers..." << std::endl;
237  std::map<art::EventID, std::pair<long long, long long>> seek_index;
238  for(gallery::Event evt(filenames); !evt.atEnd(); evt.next()){
239  seek_index[evt.eventAuxiliary().eventID()] = std::make_pair(evt.fileEntry(), evt.eventEntry());
240  }
241  std::cout << "Done" << std::endl;
242 
243  for(gallery::Event evt(filenames); !evt.atEnd();){
244  const art::EventAuxiliary& aux = evt.eventAuxiliary();
245 
246  if(tgt_run >= 0 || tgt_subrun >= 0 || tgt_evt >= 0){
247  if((tgt_run >= 0 && int(aux.run()) != tgt_run ) ||
248  (tgt_subrun >= 0 && int(aux.subRun()) != tgt_subrun) ||
249  (tgt_evt >= 0 && int(aux.event()) != tgt_evt )){
250  evt.next();
251  continue;
252  }
253  }
254  else{
255  // We must have arrived, stop seeking
256  tgt_run = tgt_subrun = tgt_evt = -1;
257  }
258 
259  std::cout << "\nDisplaying event " << aux.run() << ":" << aux.subRun() << ":" << aux.event() << std::endl << std::endl;
260 
262  const evd::Result res = server.serve(tsevt, geom, detprop);
263 
264  switch(res.code){
265  case evd::kNEXT:
266  std::cout << "Next event" << std::endl;
267  evt.next();
268  break;
269 
270  case evd::kPREV:
271  std::cout << "Previous event" << std::endl;
272  evt.previous();
273  break;
274 
275  case evd::kSEEK:
276  std::cout << "User requested seek to " << res.run << ":"<< res.subrun << ":" << res.event << std::endl;
277  {
278  const art::EventID tgt(res.run, res.subrun, res.event);
279  if(seek_index.find(tgt) == seek_index.end()){
280  std::cout << tgt << " not found in event index! Abort." << std::endl;
281  return 1;
282  }
283 
284  while(std::make_pair(evt.fileEntry(), evt.eventEntry()) < seek_index[tgt]) evt.next();
285  while(std::make_pair(evt.fileEntry(), evt.eventEntry()) > seek_index[tgt]) evt.previous();
286  }
287  continue;
288 
289  case evd::kQUIT:
290  std::cout << "Quit" << std::endl;
291  return 0;
292 
293  case evd::kERROR:
294  std::cout << "Error" << std::endl;
295  return 1;
296 
297  default:
298  std::cout << "Unrecognized result code " << res.code << "!" << std::endl;
299  abort();
300  }
301  }
302 
303  std::cout << "End of file" << std::endl;
304  return 0;
305 }
EDetector
Definition: webevd.cxx:23
std::string FCLConfigForDetector(EDetector det)
Definition: webevd.cxx:85
static void load_services(std::string const &config)
usage
Definition: doGit.sh:21
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
EDetector DetectorFromArgument(const std::string &d)
Definition: webevd.cxx:47
Result serve(const T &evt, const geo::GeometryCore *geom, const detinfo::DetectorPropertiesData &detprop)
EDetector DetectorFromFilename(const std::string &fname)
Definition: webevd.cxx:67
TCEvent evt
Definition: DataStructs.cxx:8
BEGIN_PROLOG could also be cout
std::ostream& operator<< ( std::ostream &  os,
EDetector  det 
)

Definition at line 32 of file webevd.cxx.

33 {
34  switch(det){
35  case EDetector::kUnknown: os << "unknown"; return os;
36  case EDetector::kDUNEFDHD: os << "DUNE far detector HD"; return os;
37  case EDetector::kDUNEFDVD: os << "DUNE far detector VD"; return os;
38  case EDetector::kProtoDUNESP: os << "ProtoDUNE SP"; return os;
39  case EDetector::kSBND: os << "SBND"; return os;
40  case EDetector::kIcarus: os << "ICARUS"; return os;
41  default:
42  std::cerr << "Unknown detector enum " << int(det) << std::endl;
43  abort();
44  }
45 }
BEGIN_PROLOG could also be cerr
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 }
BEGIN_PROLOG could also be cout