Jpp
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/JProductRouter.hh"
10 #include "JDB/JDBToolkit.hh"
11 
12 #include "Jeep/JParser.hh"
13 #include "Jeep/JMessage.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Example program to build detector from database.
20  * \author mdejong
21  */
22 int main(int argc, char **argv)
23 {
24  using namespace std;
25  using namespace JPP;
26 
27  string usr;
28  string pwd;
29  string cookie;
30  string detid;
31  JPBS pbs;
32  JUPI upi;
33  int debug;
34 
35  try {
36 
37  JParser<> zap("Example program to build detector from database.");
38 
39  zap['u'] = make_field(usr) = "";
40  zap['!'] = make_field(pwd) = "";
41  zap['C'] = make_field(cookie) = "";
42  zap['D'] = make_field(detid);
43  zap['P'] = make_field(pbs) = JPBS();
44  zap['U'] = make_field(upi) = JUPI();
45  zap['d'] = make_field(debug) = 1;
46 
47  zap(argc, argv);
48  }
49  catch(const exception &error) {
50  FATAL(error.what() << endl);
51  }
52 
53 
54  JDetectorIntegration detector;
55 
56  DEBUG("Reading database table " << getTable<JDetectorIntegration>() << endl);
57 
58  try {
59 
60  JDB::reset(usr, pwd, cookie);
61 
62  if (is_integer(detid)) {
63  detid = getDetector(to_value<int>(detid));
64  }
65 
66  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>());
67 
68  if (! (rs >> detector)) {
69  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration>());
70  }
71  }
72  catch(const exception& error) {
73  FATAL(error.what() << endl);
74  }
75 
76 
77  detector.configure(detid);
78 
79  const JProductRouter router(detector);
80 
81  if (pbs != JPBS()) {
82 
83  JDetectorIntegration::range_type range = detector.find(pbs);
84 
85  for (JDetectorIntegration::range_const_iterator i = range.first; i != range.second; ++i) {
86 
87  const JUPI upi = detector[i->second].content.getUPI();
88 
89  cout << upi << ' ' << router.getLocation(upi) << endl;
90  }
91 
92  } else if (upi != JUPI()) {
93 
94  detector.print(cout, upi);
95 
96  cout << router.getLocation(upi) << endl;
97 
98  } else {
99 
100  cout << "Enter UPI." << endl;
101 
102  for ( ; ; ) {
103 
104  JUPI upi;
105 
106  cout << "> " << flush;
107  cin >> upi;
108 
109  detector.print(cout, upi);
110 
111  cout << router.getLocation(upi) << endl;
112  }
113  }
114 }
JProductRouter.hh
JMessage.hh
JLANG::is_integer
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
JSelector.hh
main
int main(int argc, char **argv)
Definition: JDetectorIntegration.cc:22
JDBToolkit.hh
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JDATABASE::getDetector
static const JDetectorsHelper & getDetector
Function object for mapping serial number and object identifier of detectors.
Definition: JDBToolkit.hh:131
JDATABASE::getResultSet
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:403
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDB.hh
debug
int debug
debug level
Definition: JSirene.cc:59
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:669
JDetectorIntegration.hh
JDETECTOR::reset
void reset(JCLBInput &data, size_t size)
Reset CLB buffers.
Definition: JCLBSimulator.hh:41
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JSelectorSupportkit.hh