Jpp  debug
the software that should make you happy
software/JAcoustics/JToA.cc
Go to the documentation of this file.
1 #include "JAcoustics/JToA.hh"
2 
3 #include <iomanip>
4 #include <iostream>
5 
6 #include "JAcoustics/JSupport.hh"
7 #include "JDB/JDB.hh"
8 #include "JDB/JDBToolkit.hh"
10 #include "JDB/JSelector.hh"
11 #include "JDB/JSupport.hh"
12 #include "JDB/JToAshort.hh"
14 #include "JSupport/JMeta.hh"
15 #include "Jeep/JMessage.hh"
16 #include "Jeep/JParser.hh"
17 #include "dbclient/KM3NeTDBClient.h"
18 
19 
20 /**
21  * \file
22  *
23  * Auxiliary program to convert acoustics data from data base into ROOT format.
24  *
25  * Example usage :
26  *
27  * JToA -@ "minrun=16514" \
28  * -@ "maxrun=16514" \
29  * -@ "detid=D1ORCA015" \
30  * -o KM3NeT_00000146_00016514_toa.root
31  *
32  * \author mdejong
33  */
34 int main(int argc, char** argv)
35 {
36  using namespace std;
37  using namespace JPP;
38 
40 
41  JServer server;
42  string usr;
43  string pwd;
44  string cookie;
45  JSelector selection;
46  int debug;
47 
48  try {
49 
50  JParser<> zap("Auxiliary program to convert acoustics data from data base into ROOT format.");
51 
52  // clang-format off
53  zap['o'] = make_field(outputFile);
54  zap['s'] = make_field(server) = getServernames();
55  zap['u'] = make_field(usr) = "";
56  zap['!'] = make_field(pwd) = "";
57  zap['C'] = make_field(cookie) = "";
58  zap['@'] = make_field(selection) = JPARSER::initialised();
59  zap['d'] = make_field(debug) = 1;
60  // clang-format on
61 
62  zap(argc, argv);
63  }
64  catch (const exception& error) {
65  FATAL(error.what() << endl);
66  }
67 
68 
69  try {
70 
71  JDB::reset(usr, pwd, cookie);
72 
73  JDBToolkit::initialise(getDetector);
74 
75  outputFile.open();
76 
77  outputFile.put(JMeta(argc, argv));
78 
79  outputFile.close();
80 
81  auto ofile = std::unique_ptr<TFile>(TFile::Open(outputFile.getFilename().c_str(), "UPDATE"));
82 
83  auto toa_tree = std::unique_ptr<TTree>(new TTree("TOA", "Time Of Arrival (Acoustic Data)"));
84 
85  toa_tree->SetAutoSave(0);
86 
87  JToA toa;
88 
89  toa_tree->Branch("RUN", &toa.RUN);
90  toa_tree->Branch("DOMID", &toa.DOMID);
91  toa_tree->Branch("WAVEFORMID", &toa.WAVEFORMID);
92  toa_tree->Branch("DETID", &toa.DETID);
93  toa_tree->Branch("TOA_NS", &toa.TOA_NS);
94  toa_tree->Branch("SECONDS", &toa.SECONDS);
95  toa_tree->Branch("TICKS", &toa.TICKS);
96  toa_tree->Branch("QUALITYFACTOR", &toa.QUALITYFACTOR);
97  toa_tree->Branch("QUALITYNORMALISATION", &toa.QUALITYNORMALISATION);
98 
99  for (JDatabaseObjectIterator<JToAshort> in(JToAshort::getName(), selection); in.hasNext();) {
100 
101  const JToAshort* p = in.next();
102 
103  toa.DETID = getDetector(p->DETID);
104  toa.RUN = p->RUN;
105  toa.DOMID = p->DOMID;
106  toa.WAVEFORMID = p->EMITTERID;
107  toa.TOA_NS = p->getAbsoluteToA_ns();
108  toa.SECONDS = p->getDAQFrameSeconds();
109  toa.TICKS = p->getDAQFrameTicks();
110  toa.QUALITYFACTOR = p->QUALITYFACTOR;
112 
113  toa_tree->Fill();
114  }
115 
116  toa_tree->Write();
117  }
118  catch (const exception& error) {
119  FATAL(error.what() << endl);
120  }
121 }
ROOT TTree parameter settings.
string outputFile
ROOT TTree parameter settings.
Recording of objects on file according a format that follows from the file name extension.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Acoustic event.
Object iteration from database.
Auxiliary class for specifying selection of database data.
virtual bool hasNext() override
Check availability of next element.
Utility class to parse command line options.
Definition: JParser.hh:1714
Object writing to file.
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
Definition: JDBToolkit.hh:378
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:106
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const char * getName()
Get ROOT name of given data type.
Definition: JRootToolkit.hh:62
void reset(T &value)
Reset value.
Definition: JSTDTypes.hh:14
int main(int argc, char **argv)
Time-of-arrival data from acoustic piezo sensor or hydrophone.
Definition: JToA.hh:26
uint32_t SECONDS
Time of Arrival, in ns (relative to Unix epoch, 1 January 1970 00:00:00 UTC)
Definition: JToA.hh:35
uint32_t DOMID
DAQ run number.
Definition: JToA.hh:32
int64_t TOA_NS
Unique ID of the waveform that best described the signal around TOA_NS.
Definition: JToA.hh:34
uint32_t QUALITYFACTOR
The ticks (16ns) part of the DAQ frame timestamp.
Definition: JToA.hh:37
uint32_t QUALITYNORMALISATION
A measure of how good the waveform match was to the signal.
Definition: JToA.hh:38
int32_t WAVEFORMID
DOM unique identifeir.
Definition: JToA.hh:33
int32_t DETID
Definition: JToA.hh:30
int32_t RUN
detector identifier
Definition: JToA.hh:31
uint32_t TICKS
The seconds part of the DAQ frame timestamp.
Definition: JToA.hh:36
Wrapper class for server name.
Definition: JDB.hh:52
uint32_t getDAQFrameSeconds() const
get the number of seconds (since Unix epoch) of the DAQ Frame start time
Definition: JToAshort.hh:52
int EMITTERID
waveform identifier
Definition: JToAshort.hh:29
uint32_t getDAQFrameTicks() const
get the number of ticks (16 ns) of the DAQ Frame start time
Definition: JToAshort.hh:58
std::string DETID
constraint
Definition: JToAshort.hh:24
int64_t getAbsoluteToA_ns() const
return the absolute Time Of Arrival, in nanoseconds (since Unix epoch 1 January 1970 00:00:00 UTC)
Definition: JToAshort.hh:40
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:84
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72