Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
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/JPBSSequence.hh"
10#include "JDB/JProductRouter.hh"
11#include "JDB/JDBToolkit.hh"
12
13#include "JLang/JLangToolkit.hh"
14
15#include "Jeep/JParser.hh"
16#include "Jeep/JMessage.hh"
17
18
19/**
20 * \file
21 *
22 * Example program to build detector from database.
23 * \author mdejong
24 */
25int main(int argc, char **argv)
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
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
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}
int main(int argc, char **argv)
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Database exception.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Detector file.
Definition JHead.hh:227
map_type::const_iterator range_const_iterator
Auxiliary data structure for location of product in detector.
bool is_valid() const
Check validity of location.
Product breakdown structure (PBS).
Definition JPBS_t.hh:29
const JPBS_t & getPBS() const
Get PBS.
Definition JPBS_t.hh:101
Auxiliary class to map UPI to location in detector.
JLocation_t getLocation(const JUPI_t &upi) const
Get location of product with given UPI.
Wrapper class for server name.
Definition JDB.hh:54
Universal product identifier (UPI).
Definition JUPI_t.hh:32
Auxiliary data structure for alignment of data.
Definition JManip.hh:266