Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JDetectorIntegration.cc File Reference

Example program to build detector from database. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDetectorIntegration_t.hh"
#include "JDB/JProductRouter.hh"
#include "JDB/JDBToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to build detector from database.

Author
mdejong

Definition in file JDetectorIntegration.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file JDetectorIntegration.cc.

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_t detector;
55 
56  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << 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_t>());
67 
68  if (! (rs >> detector)) {
69  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
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_t::range_type range = detector.find(pbs);
84 
85  for (JDetectorIntegration_t::range_const_iterator i = range.first; i != range.second; ++i) {
86 
87  const JUPI upi = detector[i->second].content.getUPI();
88 
89  cout << LEFT(24) << upi << right << ' ' << 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 }
Utility class to parse command line options.
Definition: JParser.hh:1493
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
static const JDetectorsHelper & getDetector
Function object for mapping serial number and object identifier of detectors.
Definition: JDBToolkit.hh:131
void reset(T &value)
Reset value.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62