Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
getModule.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JDetector/JDetector.hh"
8 
9 #include "Jeep/JParser.hh"
10 #include "Jeep/JMessage.hh"
11 
12 
13 /**
14  * \file
15  *
16  * Auxiliary program to print module identifier for a given module location.
17  * \author mdejong
18  */
19 int main(int argc, char **argv)
20 {
21  using namespace std;
22  using namespace JPP;
23 
24  string detectorFile;
25  JLocation location;
26  bool fatal;
27  int debug;
28 
29  try {
30 
31  JParser<> zap("Auxiliary program to print module identifier for a given module location."
32  "\nInteractive mode in absence of option -L <location>.");
33 
34  zap['a'] = make_field(detectorFile, "Detector file");
35  zap['L'] = make_field(location, "Module location") = JLocation();
36  zap['F'] = make_field(fatal, "Make error fatal");
37  zap['d'] = make_field(debug) = 1;
38 
39  zap(argc, argv);
40  }
41  catch(const exception &error) {
42  FATAL(error.what() << endl);
43  }
44 
45 
47 
48  try {
49  load(detectorFile, detector);
50  }
51  catch(const JException& error) {
52  FATAL(error);
53  }
54 
55  const JLocationRouter router(detector);
56 
57  if (location != JLocation()) {
58 
59  if (router.hasLocation(location))
60  cout << router.getModule(location).getID() << endl;
61  else if (fatal)
62  FATAL("Missing location " << location << endl);
63  else
64  cout << getUndefinedObjectID() << endl;
65 
66  } else {
67 
68  while (cin >> location && location != JLocation()) {
69 
70  if (router.hasLocation(location))
71  cout << router.getModule(location).getID() << endl;
72  else if (fatal)
73  FATAL("Missing location " << location << endl);
74  else
75  cout << getUndefinedObjectID() << endl;
76  }
77  }
78 
79  return 0;
80 }
Data structure for detector geometry and calibration.
Direct access to location in detector data structure.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Detector data structure.
Definition: JDetector.hh:96
Router for direct addressing of location data in detector data structure.
bool hasLocation(const JLocation &location) const
Has module.
const JModule & getModule(const JLocation &location) const
Get module parameters.
Logical location of module.
Definition: JLocation.hh:40
General exception.
Definition: JException.hh:24
int getID() const
Get identifier.
Definition: JObjectID.hh:50
Utility class to parse command line options.
Definition: JParser.hh:1698
int main(int argc, char **argv)
Definition: getModule.cc:19
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
const JObjectID & getUndefinedObjectID()
Get undefined object identifier.
Definition: JObjectID.hh:149
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Detector file.
Definition: JHead.hh:227