Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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

◆ main()

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
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}
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#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
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition JDB.hh:438
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition JDB.hh:108
bool is_integer(const std::string &buffer)
Check if string is an integer.
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.
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