Jpp  19.1.0
the software that should make you happy
Namespaces | Functions
JRoot.cc File Reference

Auxiliary program to convert binary data to ROOT formatted data. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <limits>
#include <string.h>
#include "TROOT.h"
#include "TFile.h"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JROOT/JTreeReader.hh"
#include "JIO/JStreamIO.hh"
#include "JIO/JByteArrayIO.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JAutoTreeWriter.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Namespaces

 JSUPPORT
 Support classes and methods for experiment specific I/O.
 

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to convert binary data to ROOT formatted data.

Author
mdejong

Definition in file JRoot.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file JRoot.cc.

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 
75  using namespace KM3NETDAQ;
76  using namespace JPP;
77 
78 
79  JAutoTreeWriter<int> writer;
80 
81  writer.open(outputFile.c_str());
82 
83  if (!writer.is_open()) {
84  FATAL("Error opening file " << outputFile << endl);
85  }
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 
109  DEBUG("length " << preamble.getLength() << endl);
110  DEBUG("type " << preamble.getDataType() << endl);
111 
112  if (preamble.getLength() < (int) getSizeof<JDAQPreamble>()) {
113 
114  ERROR("File " << *i << " invalid length " << preamble.getLength() << endl);
115 
116  break;
117  }
118 
119  JAutoTreeWriter<int>::iterator i = writer.find(preamble.getDataType());
120 
121  if (i != writer.end()) {
122 
123  buffer.resize(preamble.getLength());
124 
125  memcpy(buffer.data(), static_cast<JDAQAbstractPreamble*>(&preamble), getSizeof<JDAQPreamble>());
126 
127  is.read(buffer.data() + getSizeof<JDAQPreamble>(),
128  preamble.getLength() - getSizeof<JDAQPreamble>());
129 
130  JByteArrayReader bin(buffer.data(), buffer.size());
131 
132  i->second->copy(bin);
133 
134  } else {
135 
136  in.ignore((streamsize) (preamble.getLength() - getSizeof<JDAQPreamble>()));
137 
138  ERROR("Illegal data type, skip" << endl);
139  }
140  }
141  STATUS(endl);
142 
143  in.close();
144  }
145 
146  writer.close();
147 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Byte array binary input.
Definition: JByteArrayIO.hh:27
Binary input based on std::istream.
Definition: JStreamIO.hh:26
Utility class to parse command line options.
Definition: JParser.hh:1698
virtual bool is_open() const override
Check is file is open.
Definition: JRootFile.hh:77
Auxiliary class to copy input data to corresponding TTree.
virtual void open(const char *file_name) override
Open file.
map_type::iterator iterator
void insert()
Insert (list of) data type(s).
virtual void close() override
Close file.
Simple data structure for the DAQ preamble required for a correct calculation of the object size for ...
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
size_t getSizeof< JDAQPreamble >()
Get size of type.
Definition: JSTDTypes.hh:14
Type list.
Definition: JTypeList.hh:23