Jpp
Namespaces | Functions
JRoot.cc File Reference
#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  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 
88  writer.insert<JDAQTypes_t>();
89 
90 
91  JDAQPreamble preamble;
92  vector<char> buffer;
93 
94  Long64_t event_count = 0;
95 
96  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
97 
98  STATUS("File: " << *i << endl);
99 
100  ifstream in(i->c_str());
101 
102  for (JStreamReader is(in); event_count < numberOfEvents; ++event_count) {
103 
104  STATUS("event: " << setw(10) << event_count << '\r'); DEBUG(endl);
105 
106  if (!(is >> preamble)) {
107  break;
108  }
109 
110  DEBUG("length " << preamble.getLength() << endl);
111  DEBUG("type " << preamble.getDataType() << endl);
112 
113  if (preamble.getLength() < (int) getSizeof<JDAQPreamble>()) {
114 
115  ERROR("File " << *i << " invalid length " << preamble.getLength() << endl);
116 
117  break;
118  }
119 
120  JAutoTreeWriter<int>::iterator i = writer.find(preamble.getDataType());
121 
122  if (i != writer.end()) {
123 
124  buffer.resize(preamble.getLength());
125 
126  memcpy(buffer.data(), static_cast<JDAQAbstractPreamble*>(&preamble), getSizeof<JDAQPreamble>());
127 
128  is.read(buffer.data() + getSizeof<JDAQPreamble>(),
129  preamble.getLength() - getSizeof<JDAQPreamble>());
130 
131  JByteArrayReader bin(buffer.data(), buffer.size());
132 
133  i->second->copy(bin);
134 
135  } else {
136 
137  in.ignore((streamsize) (preamble.getLength() - getSizeof<JDAQPreamble>()));
138 
139  ERROR("Illegal data type, skip" << endl);
140  }
141  }
142  STATUS(endl);
143 
144  in.close();
145  }
146 
147  writer.close();
148 }
JSUPPORT::JAutoTreeWriter::open
virtual void open(const char *file_name)
Open file.
Definition: JAutoTreeWriter.hh:94
JSUPPORT::JAutoTreeWriter
Auxiliary class to copy input data to corresponding TTree.
Definition: JAutoTreeWriter.hh:31
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JIO::JByteArrayReader
Byte array binary input.
Definition: JByteArrayIO.hh:25
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
JSUPPORT::JAutoTreeWriter::close
virtual void close()
Close file.
Definition: JAutoTreeWriter.hh:109
JLANG::JTypeList
Type list.
Definition: JTypeList.hh:22
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JIO::JStreamReader
Binary input based on std::istream.
Definition: JStreamIO.hh:24
JSUPPORT::JAutoTreeWriter::iterator
map_type::iterator iterator
Definition: JAutoTreeWriter.hh:41
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
KM3NETDAQ::getSizeof< JDAQPreamble >
size_t getSizeof< JDAQPreamble >()
Get size of type.
Definition: JDAQPreambleIO.hh:19
JSUPPORT::JAutoTreeWriter::insert
void insert()
Insert (list of) data type(s).
Definition: JAutoTreeWriter.hh:83
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JROOT::JRootFile::is_open
virtual bool is_open() const
Check is file is open.
Definition: JRootFile.hh:76
KM3NETDAQ::JDAQPreamble
DAQ preamble.
Definition: JDAQPreamble.hh:26