Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JCLB.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <limits>
5#include <vector>
6#include <map>
7#include <algorithm>
8
10
14
16
18#include "JSupport/JSupport.hh"
19#include "JSupport/JMeta.hh"
20
21#include "Jeep/JParser.hh"
22#include "Jeep/JMessage.hh"
23
24
25namespace {
26
27 const uint32_t TDC = 1414808643; //!< TDC data type
28
30
31 typedef std::vector<char> buffer_type; //!< UDP packet
32 typedef std::vector<buffer_type> collection_type; //!< collection of UDP packets
33 typedef std::map<int, collection_type> timeslice_type; //!< module identifier -> collection of UDP packets
34
35
36 /**
37 * Auxiliary data structure to organise CLB data.
38 */
39 struct map_type :
40 public std::map<uint64_t, timeslice_type> // UTC time -> time slice data
41 {
42 /**
43 * Constructor.
44 *
45 * \param detector detector identifier
46 */
47 map_type(int detector) :
49 frame_index(0)
50 {}
51
52
53 /**
54 * Convert first element in container and remove it.
55 *
56 * \return time slice
57 */
58 const JDAQTimeslice& pop()
59 {
60 using namespace std;
61 using namespace KM3NETDAQ;
62
63 frame_index += 1;
64
65 timeslice.clear();
66
67 for (timeslice_type::iterator collection = this->begin()->second.begin(); collection != this->begin()->second.end(); ++collection) {
68
69 sort(collection->second.begin(), collection->second.end(), compare);
70
71 const CLBCommonHeader* header = (const CLBCommonHeader*) collection->second.rbegin()->data();
72
73 const JDAQChronometer chronometer(detector,
74 header->runNumber(),
75 frame_index,
76 JDAQUTCExtended(header->timeStamp().sec(), header->timeStamp().tics()));
77
78 if (timeslice.empty()) {
79 timeslice = JDAQTimeslice(chronometer);
80 }
81
82 const uint32_t number_of_packets = collection->second.size();
83 const uint32_t sequence_number = header->udpSequenceNumber();
84
85 const JDAQFrameStatus status(DAQ_UDP_RECEIVED_PACKETS.write(number_of_packets) | //
86 DAQ_UDP_SEQUENCE_NUMBER .write(sequence_number), // DAQ status
87 header->domStatus(1), // TDC status
88 header->domStatus(2) | //
89 DAQ_UDP_TRAILER.write(sequence_number + 1 == number_of_packets)); // FIFO status
90
91 JDAQSuperFrame frame(JDAQSuperFrameHeader(chronometer, collection->first, status));
92
93 for (collection_type::const_iterator i = collection->second.begin(); i != collection->second.end(); ++i) {
94
95 const size_t size = (i->size() - sizeof(CLBCommonHeader)) / sizeof(JDAQHit);
96 const JDAQHit* data = (const JDAQHit*) (i->data() + sizeof(CLBCommonHeader));
97
98 frame.add(size, data);
99 }
100
101 timeslice.push_back(frame);
102 }
103
104 this->erase(this->begin());
105
106 return timeslice;
107 }
108
109
110 /**
111 * Compare two frames by UDP sequence number.
112 *
113 * \param first first UDP packet
114 * \param second second UDP packet
115 * \return true if first packet before second; else false
116 */
117 static inline bool compare(const buffer_type& first,const buffer_type& second)
118 {
119 return (((const CLBCommonHeader*) first .data())->udpSequenceNumber() <
120 ((const CLBCommonHeader*) second.data())->udpSequenceNumber());
121 }
122
123 private:
124 int detector;
125 int frame_index;
126 JDAQTimeslice timeslice;
127 };
128}
129
130
131/**
132 * \file
133 *
134 * Auxiliary program to convert raw CLB data to KM3NETDAQ::JDAQTimeslice data.
135 * \author mdejong
136 */
137int main(int argc, char **argv)
138{
139 using namespace std;
140 using namespace JPP;
141 using namespace KM3NETDAQ;
142
143
144 string inputFile;
145 int numberOfEvents;
147 int detector;
148 size_t queue;
149 int debug;
150
151 try {
152
153 JParser<> zap("Auxiliary program to convert raw CLB data to KM3NETDAQ::JDAQTimeslice data.");
154
155 zap['f'] = make_field(inputFile, "input file).");
156 zap['o'] = make_field(outputFile, "output file.") = "clb.root";
157 zap['n'] = make_field(numberOfEvents) = numeric_limits<int>::max();
158 zap['Q'] = make_field(queue, "queue depth") = 1000;
159 zap['D'] = make_field(detector, "detector identifier") = 1;
160 zap['d'] = make_field(debug, "debug.") = 1;
161
162 zap(argc, argv);
163 }
164 catch(const exception& error) {
165 FATAL(error.what() << endl);
166 }
167
168
169 outputFile.open();
170
171 if (!outputFile.is_open()) {
172 FATAL("Error opening file " << outputFile << endl);
173 }
174
175 outputFile.put(JMeta(argc, argv));
176
177 map_type data(detector);
178
179 uint32_t run = numeric_limits<uint32_t>::max();
180 uint32_t size;
181
182 ifstream in(inputFile.c_str(), ios::binary);
183
184 for (int count = 0; count != numberOfEvents && in.read((char*) &size, sizeof(uint32_t)); ++count) {
185
186 STATUS(setw(8) << count << '\r'); DEBUG(endl);
187
188 buffer_type buffer(size);
189
190 if (in.read(buffer.data(), size)) {
191
192 if (size >= sizeof(CLBCommonHeader)) {
193
194 const CLBCommonHeader* header = (const CLBCommonHeader*) buffer.data();
195
196 if (run == numeric_limits<uint32_t>::max()) {
197 run = header->runNumber();
198 }
199
200 DEBUG("data: "
201 << setw(8) << header->runNumber() << ' '
202 << setw(9) << header->domIdentifier() << ' '
203 << setw(2) << header->udpSequenceNumber() << endl);
204
205 if (header->dataType() == TDC) {
206
207 if (header->runNumber() == run) {
208
209 data[header->timeStamp().inMilliSeconds()][header->domIdentifier()].push_back(buffer);
210
211 while (data.size() > queue) {
212 outputFile.put(data.pop());
213 }
214
215 } else {
216
217 WARNING("Run numbers differ " << run << ' ' << header->runNumber() << " -> skip data." << endl);
218 }
219 }
220 }
221 }
222 }
223 STATUS(endl);
224
225 in.close();
226
227 while (!data.empty()) {
228 outputFile.put(data.pop());
229 }
230
231 outputFile.close();
232}
int main(int argc, char **argv)
Definition JCLB.cc:137
string outputFile
Recording of objects on file according a format that follows from the file name extension.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define WARNING(A)
Definition JMessage.hh:65
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:2142
ROOT TTree parameter settings of various packages.
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
Hit data structure.
Definition JDAQHit.hh:35
Data frame of one optical module.
Data structure for UTC time.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< JHitW0 > buffer_type
hits
Definition JPerth.cc:70
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
static const JBits DAQ_UDP_RECEIVED_PACKETS(0, 15)
Mask of UDP received packets.
static const JBits DAQ_UDP_SEQUENCE_NUMBER(16, 31)
Mask of UDP sequence number.
static const JBit DAQ_UDP_TRAILER(31)
UDP trailer.
std::map< int, range_type > map_type
uint32_t dataType() const
uint32_t udpSequenceNumber() const
UTCTime timeStamp() const
uint32_t runNumber() const
uint32_t domIdentifier() const
uint32_t domStatus(int n=1) const
Detector file.
Definition JHead.hh:227
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
int write(const int value) const
Write given value as bit mask.
Definition JDAQ.hh:115
int write(const int value) const
Write given value as bit mask.
Definition JDAQ.hh:238
uint32_t sec() const
Definition utctime.hh:17
uint32_t tics() const
Definition utctime.hh:22
uint64_t inMilliSeconds() const
Definition utctime.hh:27