Jpp - the software that should make you happy
 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/JPBSSequence.hh"
#include "JDB/JProductRouter.hh"
#include "JDB/JDBToolkit.hh"
#include "JLang/JLangToolkit.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 25 of file JDetectorIntegration.cc.

26 {
27  using namespace std;
28  using namespace JPP;
29 
30  string usr;
31  string pwd;
32  string cookie;
33  string detid;
34  JPBS_t pbs;
35  JUPI_t upi;
36  int debug;
37 
38  try {
39 
40  JParser<> zap("Example program to build detector from database.");
41 
42  zap['u'] = make_field(usr) = "";
43  zap['!'] = make_field(pwd) = "";
44  zap['C'] = make_field(cookie) = "";
45  zap['D'] = make_field(detid);
46  zap['P'] = make_field(pbs) = JPBS_t();
47  zap['U'] = make_field(upi) = JUPI_t();
48  zap['d'] = make_field(debug) = 1;
49 
50  zap(argc, argv);
51  }
52  catch(const exception &error) {
53  FATAL(error.what() << endl);
54  }
55 
56 
57  JDetectorIntegration_t detector;
58 
59  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << endl);
60 
61  try {
62 
63  JDB::reset(usr, pwd, cookie);
64 
65  if (is_integer(detid)) {
66  detid = getDetector(to_value<int>(detid));
67  }
68 
69  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
70 
71  if (! (rs >> detector)) {
72  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
73  }
74  }
75  catch(const exception& error) {
76  FATAL(error.what() << endl);
77  }
78 
79 
80  detector.configure(detid);
81 
82 
83  if (pbs != JPBS_t()) {
84 
85  const JProductRouter router(detector, getPBSSequences(pbs));
86 
87  JDetectorIntegration_t::range_type range = detector.find(pbs);
88 
89  for (JDetectorIntegration_t::range_const_iterator i = range.first; i != range.second; ++i) {
90 
91  const JUPI_t upi = detector[i->second].content.getUPI();
92 
93  cout << LEFT(32) << upi << right << ' ' << router.getLocation(upi) << endl;
94  }
95 
96  } else if (upi != JUPI_t()) {
97 
98  const JProductRouter router(detector, getPBSSequences(upi.getPBS()));
99 
100  detector.print(cout, upi);
101 
102  const JLocation_t location = router.getLocation(upi);
103 
104  if (location.is_valid()) {
105  cout << location << endl;
106  }
107 
108  } else {
109 
110  cout << "Enter UPI." << endl;
111 
112  for ( ; ; ) {
113 
114  JUPI_t upi;
115 
116  cout << "> " << flush;
117  cin >> upi;
118 
119  const JProductRouter router(detector, getPBSSequences(upi.getPBS()));
120 
121  detector.print(cout, upi);
122 
123  const JLocation_t location = router.getLocation(upi);
124 
125  if (location.is_valid()) {
126  cout << location << endl;
127  }
128  }
129  }
130 }
Utility class to parse command line options.
Definition: JParser.hh:1500
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
#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.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
do set_variable DETECTOR_TXT $WORKDIR detector
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62