Jpp  15.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 
5 #include "JDB/JDB.hh"
6 #include "JDB/JSelector.hh"
9 #include "JDB/JPBSSequence.hh"
10 #include "JDB/JProductRouter.hh"
11 #include "JDB/JDBToolkit.hh"
12 
13 #include "JLang/JLangToolkit.hh"
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Example program to build detector from database.
23  * \author mdejong
24  */
25 int main(int argc, char **argv)
26 {
27  using namespace std;
28  using namespace JPP;
29 
30  JServer server;
31  string usr;
32  string pwd;
33  string cookie;
34  string detid;
35  JPBS_t pbs;
36  JUPI_t upi;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Example program to build detector from database.");
42 
43  zap['s'] = make_field(server) = getServernames();
44  zap['u'] = make_field(usr) = "";
45  zap['!'] = make_field(pwd) = "";
46  zap['C'] = make_field(cookie) = "";
47  zap['D'] = make_field(detid);
48  zap['P'] = make_field(pbs) = JPBS_t();
49  zap['U'] = make_field(upi) = JUPI_t();
50  zap['d'] = make_field(debug) = 1;
51 
52  zap(argc, argv);
53  }
54  catch(const exception &error) {
55  FATAL(error.what() << endl);
56  }
57 
58 
59  JDetectorIntegration_t detector;
60 
61  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << endl);
62 
63  try {
64 
65  JDB::reset(usr, pwd, cookie);
66 
67  if (is_integer(detid)) {
68  detid = getDetector(to_value<int>(detid));
69  }
70 
71  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
72 
73  if (! (rs >> detector)) {
74  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
75  }
76  }
77  catch(const exception& error) {
78  FATAL(error.what() << endl);
79  }
80 
81 
82  detector.configure(detid);
83 
84 
85  if (pbs != JPBS_t()) {
86 
87  const JProductRouter router(detector, getPBSSequences(pbs));
88 
89  JDetectorIntegration_t::range_type range = detector.find(pbs);
90 
91  for (JDetectorIntegration_t::range_const_iterator i = range.first; i != range.second; ++i) {
92 
93  const JUPI_t upi = detector[i->second].content.getUPI();
94 
95  cout << LEFT(32) << upi << right << ' ' << router.getLocation(upi) << endl;
96  }
97 
98  } else if (upi != JUPI_t()) {
99 
100  const JProductRouter router(detector, getPBSSequences(upi.getPBS()));
101 
102  detector.print(cout, upi);
103 
104  const JLocation_t location = router.getLocation(upi);
105 
106  if (location.is_valid()) {
107  cout << location << endl;
108  }
109 
110  } else {
111 
112  cout << "Enter UPI." << endl;
113 
114  for ( ; ; ) {
115 
116  JUPI_t upi;
117 
118  cout << "> " << flush;
119  cin >> upi;
120 
121  const JProductRouter router(detector, getPBSSequences(upi.getPBS()));
122 
123  detector.print(cout, upi);
124 
125  const JLocation_t location = router.getLocation(upi);
126 
127  if (location.is_valid()) {
128  cout << location << endl;
129  }
130  }
131  }
132 }
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:670
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
#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