Jpp  18.0.0
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  JServer server;
31  string usr;
32  string pwd;
33  string cookie;
34  string inputFile;
35  string detid;
36  JPBS_t pbs;
37  JUPI_t upi;
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Example program to build detector from database.");
43 
44  zap['s'] = make_field(server) = getServernames();
45  zap['u'] = make_field(usr) = "";
46  zap['!'] = make_field(pwd) = "";
47  zap['C'] = make_field(cookie) = "";
48  zap['f'] = make_field(inputFile, "output of JPrintDB -q \"integration\" -c \";\" -W1") = "";
49  zap['D'] = make_field(detid);
50  zap['P'] = make_field(pbs) = JPBS_t();
51  zap['U'] = make_field(upi) = JUPI_t();
52  zap['d'] = make_field(debug) = 1;
53 
54  zap(argc, argv);
55  }
56  catch(const exception &error) {
57  FATAL(error.what() << endl);
58  }
59 
60 
61  JDetectorIntegration_t detector;
62 
63  if (inputFile != "") {
64 
65  detector.load(inputFile.c_str());
66 
67  } else {
68 
69  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << endl);
70 
71  try {
72 
73  JDB::reset(usr, pwd, cookie);
74 
75  detid = getDetector<string>(detid);
76 
77  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
78 
79  if (! (rs >> detector)) {
80  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
81  }
82  }
83  catch(const exception& error) {
84  FATAL(error.what() << endl);
85  }
86  }
87 
88  if (is_integer(detid)) {
89  FATAL("Detector identifier must be object identifier." << endl);
90  }
91 
92  detector.configure(detid);
93 
94 
95  if (pbs != JPBS_t()) {
96 
97  const JProductRouter router(detector, getPBSSequences(pbs));
98 
99  JDetectorIntegration_t::range_type range = detector.find(pbs);
100 
101  for (JDetectorIntegration_t::range_const_iterator i = range.first; i != range.second; ++i) {
102 
103  const JUPI_t upi = detector[i->second].content.getUPI();
104 
105  cout << LEFT(32) << upi << right << ' ' << router.getLocation(upi) << endl;
106  }
107 
108  } else if (upi != JUPI_t()) {
109 
110  const JProductRouter router(detector, getPBSSequences(upi.getPBS()));
111 
112  detector.print(cout, upi);
113 
114  const JLocation_t location = router.getLocation(upi);
115 
116  if (location.is_valid()) {
117  cout << location << endl;
118  }
119 
120  } else {
121 
122  cout << "Enter UPI." << endl;
123 
124  for ( ; ; ) {
125 
126  JUPI_t upi;
127 
128  cout << "> " << flush;
129  cin >> upi;
130 
131  const JProductRouter router(detector, getPBSSequences(upi.getPBS()));
132 
133  detector.print(cout, upi);
134 
135  const JLocation_t location = router.getLocation(upi);
136 
137  if (location.is_valid()) {
138  cout << location << endl;
139  }
140  }
141  }
142 }
Utility class to parse command line options.
Definition: JParser.hh:1514
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:1989
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:436
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:106
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62