Jpp
JRoot.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <fstream>
5 #include <iomanip>
6 #include <vector>
7 #include <limits>
8 #include <string.h>
9 
10 #include "TROOT.h"
11 #include "TFile.h"
12 
13 #include "JDAQ/JDAQEvent.hh"
14 #include "JDAQ/JDAQTimeslice.hh"
15 #include "JDAQ/JDAQSummaryslice.hh"
16 
17 #include "JROOT/JTreeReader.hh"
18 #include "JIO/JStreamIO.hh"
19 #include "JIO/JByteArrayIO.hh"
20 #include "JSupport/JSupport.hh"
22 
23 #include "Jeep/JParser.hh"
24 #include "Jeep/JMessage.hh"
25 
26 
27 namespace JSUPPORT {
28 
29  /**
30  * Get key for given DAQ data type.
31  *
32  * \param type data type
33  * \return map element
34  */
35  template<>
36  template<class T>
38  {
39  return KM3NETDAQ::getDataType<T>();
40  }
41 }
42 
43 
44 /**
45  * \file
46  * Auxiliary program to convert binary data to ROOT formatted data.
47  * \author mdejong
48  */
49 int main(int argc, char **argv)
50 {
51  using namespace std;
52 
53  vector<string> inputFile;
54  string outputFile;
55  Long64_t numberOfEvents;
56  int debug;
57 
58  try {
59 
60  JParser<> zap("Auxiliary program to convert binary data to ROOT formatted data.");
61 
62  zap['f'] = make_field(inputFile);
63  zap['o'] = make_field(outputFile);
64  zap['n'] = make_field(numberOfEvents) = numeric_limits<Long64_t>::max();
65  zap['d'] = make_field(debug) = 1;
66 
67  zap(argc, argv);
68  }
69  catch(const exception &error) {
70  FATAL(error.what() << endl);
71  }
72 
73 
74  cout.tie(&cerr);
75 
76  using namespace KM3NETDAQ;
77  using namespace JPP;
78 
79 
80  JAutoTreeWriter<int> writer;
81 
82  writer.open(outputFile.c_str());
83 
84  if (!writer.is_open())
85  FATAL("Error opening file " << outputFile << endl);
86 
87  writer.insert<JDAQTypes_t>();
88 
89 
90  JDAQPreamble preamble;
91  vector<char> buffer;
92 
93  Long64_t event_count = 0;
94 
95  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
96 
97  STATUS("File: " << *i << endl);
98 
99  ifstream in(i->c_str());
100 
101  for (JStreamReader is(in); event_count < numberOfEvents; ++event_count) {
102 
103  STATUS("event: " << setw(10) << event_count << '\r'); DEBUG(endl);
104 
105  if (!(is >> preamble))
106  break;
107 
108  DEBUG("length " << preamble.getLength() << endl);
109  DEBUG("type " << preamble.getDataType() << endl);
110 
111  if (preamble.getLength() < JDAQPreamble::sizeOf()) {
112 
113  ERROR("File " << *i << " invalid length " << preamble.getLength() << endl);
114 
115  break;
116  }
117 
118  JAutoTreeWriter<int>::iterator i = writer.find(preamble.getDataType());
119 
120  if (i != writer.end()) {
121 
122  buffer.resize(preamble.getLength());
123 
124  memcpy(buffer.data(), static_cast<JDAQAbstractPreamble*>(&preamble), JDAQPreamble::sizeOf());
125 
126  is.read(buffer.data() + JDAQPreamble::sizeOf(),
127  preamble.getLength() - JDAQPreamble::sizeOf());
128 
129  JByteArrayReader bin(buffer.data(), buffer.size());
130 
131  i->second->copy(bin);
132 
133  } else {
134 
135  in.ignore((streamsize) (preamble.getLength() - JDAQPreamble::sizeOf()));
136 
137  ERROR("Illegal data type, skip" << endl);
138  }
139  }
140  STATUS(endl);
141 
142  in.close();
143  }
144 
145  writer.close();
146 }
JStreamIO.hh
JLANG::JType
Auxiliary class for a type holder.
Definition: JType.hh:19
JMessage.hh
JTreeReader.hh
main
int main(int argc, char **argv)
Definition: JRoot.cc:49
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JDAQTimeslice.hh
JDAQSummaryslice.hh
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
ERROR
#define ERROR(A)
Definition: JMessage.hh:66
debug
int debug
debug level
Definition: JSirene.cc:59
JLANG::JTypeList
Type list.
Definition: JTypeList.hh:22
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JParser.hh
JByteArrayIO.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JSUPPORT::JAutoTreeWriter::getKey
static JKey_t getKey(JType< T > type)
Get key.
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
JAutoTreeWriter.hh
std
Definition: jaanetDictionary.h:36
JSUPPORT
Support classes and methods for experiment specific I/O.
Definition: JDataWriter.cc:38
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JDAQEvent.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
KM3NETDAQ::JDAQPreamble
DAQ preamble.
Definition: JDAQPreamble.hh:39