Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JDetectorDB.cc File Reference

Auxiliary program to print detector from database. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JCLBMap.hh"
#include "JDB/JDBToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorSupportkit.hh"
#include "JLang/JComparator.hh"
#include "JLang/JPredicate.hh"
#include "JSupport/JMeta.hh"
#include "Jeep/JPrint.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

Auxiliary program to print detector from database.

Author
mdejong

Definition in file JDetectorDB.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file JDetectorDB.cc.

35 {
36  using namespace std;
37  using namespace JPP;
38 
39  JServer server;
40  string usr;
41  string pwd;
42  string cookie;
43  string id;
44  string tcalset;
45  string pcalset;
46  string rcalset;
47  string detectorFile;
48  string outputFile;
49  int run;
50  bool wizzard;
51  int debug;
52 
53  try {
54 
55  JParser<> zap("Auxiliary program to print detector from database.");
56 
57  zap['s'] = make_field(server) = getServernames();
58  zap['u'] = make_field(usr) = "";
59  zap['!'] = make_field(pwd) = "";
60  zap['C'] = make_field(cookie) = "";
61  zap['D'] = make_field(id, "detector identifier") = "";
62  zap['r'] = make_field(run, "run number") = -1;
63  zap['t'] = make_field(tcalset, "tcal: t0 (time offsets) calibration set from DB") = "";
64  zap['p'] = make_field(pcalset, "pcal: position (x,y,z) calibration set from DB") = "";
65  zap['q'] = make_field(rcalset, "rcal: orientation (quaterions) calibration set from DB") = "";
66  zap['a'] = make_field(detectorFile) = "";
67  zap['o'] = make_field(outputFile) = "";
68  zap['W'] = make_field(wizzard);
69  zap['d'] = make_field(debug) = 2;
70 
71  zap(argc, argv);
72  }
73  catch(const exception &error) {
74  FATAL(error.what() << endl);
75  }
76 
77 
78  const int file = ((detectorFile != "" ? 1 : 0));
79  const int calset = ((tcalset.empty() ? 0 : 1) +
80  (pcalset.empty() ? 0 : 1) +
81  (rcalset.empty() ? 0 : 1));
82  const int daq = ((run != -1 ? 1 : 0));
83 
84  if (file != 0 && (file != 1)) { FATAL("Inconsistent specificaton of detector file."); }
85  if (calset != 0 && (calset != 3 || id == "")) { FATAL("Inconsistent specificaton of detector identifier, tcal, pcal and rcal calibration sets."); }
86  if (daq != 0 && (daq != 1 || id == "")) { FATAL("Inconsistent specificaton of detector identifier and run number."); }
87 
88  int np = 0;
89 
90  if (file == 1) { ++np; }
91  if (calset == 3) { ++np; }
92  if (daq == 1) { ++np; }
93 
94  if (np != 1) { FATAL("Specify detector file; OR detector identifier, tcal, pcal and rcal calibration set; OR detector identifier and run number."); }
95 
96 
97  try {
98  JDB::reset(usr, pwd, cookie);
99  }
100  catch(const exception& error) {
101  FATAL(error.what() << endl);
102  }
103 
105 
106  try {
107 
108  if (file == 1)
109  load(detectorFile, detector);
110  else if (calset == 3)
111  *(JDB::get()->DetX)(id.c_str(), tcalset.c_str(), pcalset.c_str(), rcalset.c_str()) >> detector;
112  else if (daq == 1)
113  *(JDB::get()->DetX)(id.c_str(), run) >> detector;
114  }
115  catch(const exception& error) {
116  FATAL(error.what() << endl);
117  }
118 
119  detector.comment.add(JMeta(argc,argv));
120 
121  if (detector.setToLatestVersion()) {
122  NOTICE("Set detector version to " << detector.getVersion() << endl);
123  }
124 
125  if (wizzard) {
126 
127  vector<JCLBMap> clbmap;
128 
129  try {
130 
131  JSelector selector = getSelector<JCLBMap>(getDetector(detector.getID()));
132 
133  selector.add(&JCLBMap::FLOORID, 0);
134 
135  ResultSet& rs = getResultSet(getTable<JCLBMap>(), selector);
136 
137  rs >> clbmap;
138 
139  rs.Close();
140  }
141  catch(const exception& error) {
142  FATAL(error.what() << endl);
143  }
144 
146 
147  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
148  zmap[module->getString()][module->getFloor()] = module->getPosition();
149  }
150 
151  for (vector<JCLBMap>::const_iterator i = clbmap.begin(); i != clbmap.end(); ++i) {
152 
153  JDetector::iterator p = find_if(detector.begin(), detector.end(), make_predicate(&JModule::getID, i->DOMID, JComparison::eq()));
154 
155  if (i->FLOORID == 0 && p == detector.end()) {
156 
157  JModule module(i->DOMID, JLocation(i->DUID, i->FLOORID));
158 
159  module.setPosition(JPosition3D(zmap[i->DUID].begin()->second.getX(),
160  zmap[i->DUID].begin()->second.getY(),
163  0.0));
164 
165  const double t0 = 0.0;
166 
167  module.setCalibration(t0 - HYDROPHONE_DELAYTIME_US * 1.0e+3);
168 
169  NOTICE("Adding module " << module << endl);
170 
171  detector.push_back(module);
172  }
173  }
174  }
175 
176  if (outputFile != "")
178  else
179  cout << detector;
180 }
bool isORCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with that of ORCA.
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
Data structure for a composite optical module.
Definition: JModule.hh:66
static const double ARCA_TBARZ_M
ORCA T-bar position relative to seabed [m].
bool isARCADetector(const JDetectorHeader &header)
Check if given detector header is compatible with tat of ARCA.
static const double HYDROPHONE_DELAYTIME_US
Hydrophone delay time [us].
Detector data structure.
Definition: JDetector.hh:81
T get(const JHead &header)
Get object from header.
then usage $script< string identifier >< detectorfile > input file(toashort file)+" "\nNote that the input files and toashort files should be one-to-one related." fi if (( $
Auxiliary class for specifying selection of database data.
string outputFile
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
static const double ORCA_TBARZ_M
ORCA T-bar position relative to seabed [m].
Detector file.
Definition: JHead.hh:196
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
JSelector & add(const JSelector &selection)
Add selection.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
#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.
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
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
do set_variable DETECTOR_TXT $WORKDIR detector
Template definition for getting table specific selector.