Jpp  17.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMTSwapDB.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <limits>
5 #include <vector>
6 #include <map>
7 
8 #include "JDB/JDB.hh"
9 #include "JDB/JSelector.hh"
11 #include "JDB/JDBToolkit.hh"
13 #include "JDB/JLocation_t.hh"
14 
15 #include "JDetector/JDetector.hh"
17 
18 #include "Jeep/JPrint.hh"
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 
23 /**
24  * \file
25  *
26  * Auxiliary program to check HV.
27  * \author mdejong
28  */
29 int main(int argc, char **argv)
30 {
31  using namespace std;
32  using namespace JPP;
33 
34  JServer server;
35  string usr;
36  string pwd;
37  string cookie;
38  string detectorFile;
39  string outputFile;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to check HV.");
45 
46  zap['s'] = make_field(server) = getServernames();
47  zap['u'] = make_field(usr) = "";
48  zap['!'] = make_field(pwd) = "";
49  zap['C'] = make_field(cookie) = "";
50  zap['a'] = make_field(detectorFile);
51  zap['o'] = make_field(outputFile) = "";
52  zap['d'] = make_field(debug) = 2;
53 
54  zap(argc, argv);
55  }
56  catch(const exception &error) {
57  FATAL(error.what() << endl);
58  }
59 
60 
61  JDetector detectorA;
62 
63  try {
64  load(detectorFile, detectorA);
65  }
66  catch(const JException& error) {
67  FATAL(error);
68  }
69 
70 
71  try {
72 
73  JDB::reset(usr, pwd, cookie);
74 
75  const string detid = getDetector(detectorA.getID());
76 
77  typedef map<int, JDetectorIntegration> detector_type;
78 
79  detector_type detectorB;
80 
81  {
82  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(detectorA.getID()));
83 
85 
86  if (parameters.PMTUPI.getPBS() == PBS::PMT) {
87  detectorB[parameters.PMTSER] = parameters;
88  }
89  }
90 
91  rs.Close();
92  }
93 
94  for (JDetector::iterator module = detectorA.begin(); module != detectorA.end(); ++module) {
95 
96  vector<JPMT> buffer(module->begin(), module->end());
97 
98  for (size_t i = 0; i != module->size(); ++i) {
99 
100  const int pmt = (*module)[i].getID();
101 
102  if (detectorB.count(pmt) == 1) {
103 
104  const JDetectorIntegration& parameters = detectorB[pmt];
105 
106  const JLocation location(parameters.DUID, parameters.FLOORID);
107 
108  if (module->getLocation() != location) {
109  FATAL("Wrong location " << left << setw(5) << pmt << " " << module->getLocation() << " != " << location << endl);
110  }
111 
112  if (parameters.PMTID != parameters.CABLEPOS) {
113 
114  NOTICE("Swap PMT " << right << setw(10) << module->getID() << ' '
115  << JLocation_t(parameters.DUID, parameters.FLOORID, parameters.CABLEPOS) << " <- "
116  << JLocation_t(parameters.DUID, parameters.FLOORID, parameters.PMTID) << endl);
117 
118  buffer[parameters.CABLEPOS] = (*module)[parameters.PMTID];
119  }
120 
121  } else {
122 
123  ERROR("Missing PMT " << left << setw(5) << pmt << right << setw(10) << module->getID() << "." << FILL(2,'0') << i << FILL() << endl);
124  }
125  }
126 
127  module->swap(buffer);
128  }
129  }
130  catch(const exception& error) {
131  FATAL(error.what() << endl);
132  }
133 
134 
135  if (outputFile != "") {
136  try {
137  store(outputFile, detectorA);
138  }
139  catch(const JException& error) {
140  FATAL(error);
141  }
142  }
143 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
static const JPBS_t PMT(3, 4, 2, 3)
PBS of photo-multiplier tube (PMT)
Detector data structure.
Definition: JDetector.hh:89
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
string outputFile
Data structure for detector geometry and calibration.
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
Definition: JDBToolkit.hh:365
I/O formatting auxiliaries.
Logical location of module.
Definition: JLocation.hh:37
Auxiliary data structure for location of product in detector.
Definition: JLocation_t.hh:24
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:66
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
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
Wrapper class for server name.
Definition: JDB.hh:42
Template definition for getting table specific selector.