Jpp  15.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JTDC.cc File Reference

Auxiliary program to determine TDC constraints (input to JFitK40.cc) according HV settings from the database. More...

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JDetectorIntegration.hh"
#include "JDB/JPMTHV.hh"
#include "JDetector/JPMTIdentifier.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (const int argc, const char *const argv[])
 

Detailed Description

Auxiliary program to determine TDC constraints (input to JFitK40.cc) according HV settings from the database.

Author
mdejong

Definition in file JTDC.cc.

Function Documentation

int main ( const int  argc,
const char *const  argv[] 
)

Definition at line 25 of file JTDC.cc.

26 {
27  using namespace std;
28  using namespace JPP;
29 
30  typedef pair<int, int> run_type;
31 
32  JServer server;
33  string usr;
34  string pwd;
35  string cookie;
36  string detid;
37  run_type runs;
38  string outputFile;
39  bool usePMTID; // option for old data for which correction for PMT cable swaps does not apply
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to determine TDC constraints (input to JFitK40.cc) according HV settings from the database.");
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['D'] = make_field(detid, "Detector identifier");
51  zap['r'] = make_field(runs, "Pair of data taking runs");
52  zap['o'] = make_field(outputFile, "TDC file") = "";
53  zap['U'] = make_field(usePMTID);
54  zap['d'] = make_field(debug) = 1;
55 
56  zap(argc, argv);
57  }
58  catch(const exception& error) {
59  FATAL(error.what() << endl);
60  }
61 
62 
63  try {
64 
65  JDB::reset(usr, pwd, cookie);
66 
67  int ID = -1;
68 
69  if (is_integer(detid)) {
70  ID = to_value<int>(detid);
71  detid = getDetector(ID);
72  } else {
73  ID = getDetector(detid);
74  }
75 
76  typedef vector<JDetectorIntegration> detector_type;
77 
78  detector_type detector;
79 
80  {
81  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(ID));
82 
83  for (JDetectorIntegration parameters; rs >> parameters; ) {
84  detector.push_back(parameters);
85  }
86 
87  rs.Close();
88  }
89 
90  const JPMTHV pmt_hv[] = {
91  JPMTHV(ID, runs.first),
92  JPMTHV(ID, runs.second)
93  };
94 
95  filebuf buffer;
96 
97  if (outputFile != "") {
98  buffer.open(outputFile.c_str(), ios::out);
99  }
100 
101  ostream os(buffer.is_open() ? &buffer : cout.rdbuf());
102 
103  for (detector_type::const_iterator i = detector.begin(); i != detector.end(); ++i) {
104  if (i->PMTUPI.getPBS() == PBS::PMT) {
105  if (pmt_hv[0](i->PMTUPI).value == pmt_hv[1](i->PMTUPI).value) {
106  if (usePMTID)
107  os << setw(10) << i->DOMID << ' ' << setw(2) << i->PMTID << endl;
108  else
109  os << setw(10) << i->DOMID << ' ' << setw(2) << i->CABLEPOS << endl;
110  }
111  }
112  }
113 
114  buffer.close();
115  }
116  catch(const exception& error) {
117  FATAL(error.what() << endl);
118  }
119 }
Utility class to parse command line options.
Definition: JParser.hh:1500
static const JPBS_t PMT(3, 4, 2, 3)
PBS of photo-multiplier tube (PMT)
*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
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
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
do set_variable DETECTOR_TXT $WORKDIR detector