Jpp  17.2.1-pre0
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 <fstream>
#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 26 of file JDetectorIntegration.cc.

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:1517
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:1993
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
#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: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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62