Jpp  16.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDetectorIntegration.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <fstream>
5 
6 #include "JDB/JDB.hh"
7 #include "JDB/JSelector.hh"
10 #include "JDB/JPBSSequence.hh"
11 #include "JDB/JProductRouter.hh"
12 #include "JDB/JDBToolkit.hh"
13 
14 #include "JLang/JLangToolkit.hh"
15 
16 #include "Jeep/JParser.hh"
17 #include "Jeep/JMessage.hh"
18 
19 
20 /**
21  * \file
22  *
23  * Example program to build detector from database.
24  * \author mdejong
25  */
26 int main(int argc, char **argv)
27 {
28  using namespace std;
29  using namespace JPP;
30 
31  JServer server;
32  string usr;
33  string pwd;
34  string cookie;
35  string inputFile;
36  string detid;
37  JPBS_t pbs;
38  JUPI_t upi;
39  int debug;
40 
41  try {
42 
43  JParser<> zap("Example program to build detector from database.");
44 
45  zap['s'] = make_field(server) = getServernames();
46  zap['u'] = make_field(usr) = "";
47  zap['!'] = make_field(pwd) = "";
48  zap['C'] = make_field(cookie) = "";
49  zap['f'] = make_field(inputFile, "output of JPrintDB -q \"integration\" -c \";\" -W1") = "";
50  zap['D'] = make_field(detid);
51  zap['P'] = make_field(pbs) = JPBS_t();
52  zap['U'] = make_field(upi) = JUPI_t();
53  zap['d'] = make_field(debug) = 1;
54 
55  zap(argc, argv);
56  }
57  catch(const exception &error) {
58  FATAL(error.what() << endl);
59  }
60 
61 
62  JDetectorIntegration_t detector;
63 
64  if (inputFile != "") {
65 
66  ifstream in(inputFile.c_str());
67 
68  in >> detector;
69 
70  in.close();
71 
72  } else {
73 
74  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << endl);
75 
76  try {
77 
78  JDB::reset(usr, pwd, cookie);
79 
80  detid = getDetector<string>(detid);
81 
82  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
83 
84  if (! (rs >> detector)) {
85  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
86  }
87  }
88  catch(const exception& error) {
89  FATAL(error.what() << endl);
90  }
91  }
92 
93  if (is_integer(detid)) {
94  FATAL("Detector identifier must be object identifier." << endl);
95  }
96 
97  detector.configure(detid);
98 
99 
100  if (pbs != JPBS_t()) {
101 
102  const JProductRouter router(detector, getPBSSequences(pbs));
103 
104  JDetectorIntegration_t::range_type range = detector.find(pbs);
105 
106  for (JDetectorIntegration_t::range_const_iterator i = range.first; i != range.second; ++i) {
107 
108  const JUPI_t upi = detector[i->second].content.getUPI();
109 
110  cout << LEFT(32) << upi << right << ' ' << router.getLocation(upi) << endl;
111  }
112 
113  } else if (upi != JUPI_t()) {
114 
115  const JProductRouter router(detector, getPBSSequences(upi.getPBS()));
116 
117  detector.print(cout, upi);
118 
119  const JLocation_t location = router.getLocation(upi);
120 
121  if (location.is_valid()) {
122  cout << location << endl;
123  }
124 
125  } else {
126 
127  cout << "Enter UPI." << endl;
128 
129  for ( ; ; ) {
130 
131  JUPI_t upi;
132 
133  cout << "> " << flush;
134  cin >> upi;
135 
136  const JProductRouter router(detector, getPBSSequences(upi.getPBS()));
137 
138  detector.print(cout, upi);
139 
140  const JLocation_t location = router.getLocation(upi);
141 
142  if (location.is_valid()) {
143  cout << location << endl;
144  }
145  }
146  }
147 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
static JGetPBSSequences getPBSSequences
Function object to get PBS sequences as a function of PBS.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
void reset(T &value)
Reset value.
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:432
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:98
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42