Project
Loading...
Searching...
No Matches
DigitIOV4.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include "DigitIOV4.h"
15#include "DigitFileFormat.h"
16#include "DigitSampler.h"
17#include "IO.h"
18#include "IOStruct.h"
19#include <iostream>
20
21namespace o2::mch::io::impl
22{
23
24void DigitSamplerV4::count(std::istream& in, size_t& ntfs, size_t& nrofs, size_t& ndigits)
25{
26 rewind(in);
27 ndigits = 0;
28 nrofs = 0;
29 ntfs = 0;
30 std::pair<int, int> pairs;
31 std::pair<int, int> invalid{-1, -1};
32
33 while ((pairs = advanceOneEvent(in, 4)) != invalid) {
34 ndigits += pairs.second;
35 nrofs += pairs.first;
36 ++ntfs;
37 }
38 rewind(in);
39}
40
41bool DigitSamplerV4::read(std::istream& in,
42 std::vector<Digit>& digits,
43 std::vector<ROFRecord>& rofs)
44{
45 if (in.peek() == EOF) {
46 return false;
47 }
48 // note the input vectors are not cleared as this is the responsability
49 // of the calling class, if need be.
50
51 int nrofs = readNofItems(in, "rofs");
52 if (in.fail()) {
53 return false;
54 }
55
56 for (auto i = 0; i < nrofs; i++) {
59 uint32_t firstIdx;
60 uint32_t nentries;
61 uint32_t bcWidth;
62 in.read(reinterpret_cast<char*>(&bc), sizeof(uint16_t));
63 in.read(reinterpret_cast<char*>(&orbit), sizeof(uint32_t));
64 in.read(reinterpret_cast<char*>(&firstIdx), sizeof(uint32_t));
65 in.read(reinterpret_cast<char*>(&nentries), sizeof(uint32_t));
66 in.read(reinterpret_cast<char*>(&bcWidth), sizeof(uint32_t));
67 rofs.emplace_back(o2::InteractionRecord{bc, orbit}, firstIdx, nentries, bcWidth);
68 if (in.fail()) {
69 return false;
70 }
71 }
72
73 int ndigits = readNofItems(in, "digits");
74 if (in.fail()) {
75 return false;
76 }
77
78 for (int i = 0; i < ndigits; i++) {
79 uint32_t tfTime;
80 uint16_t nofSamples;
81 uint32_t deID;
82 uint32_t padID;
84 uint8_t sat;
85 in.read(reinterpret_cast<char*>(&tfTime), sizeof(uint32_t));
86 in.read(reinterpret_cast<char*>(&nofSamples), sizeof(uint16_t));
87 in.read(reinterpret_cast<char*>(&sat), sizeof(uint8_t));
88 in.read(reinterpret_cast<char*>(&deID), sizeof(uint32_t));
89 in.read(reinterpret_cast<char*>(&padID), sizeof(uint32_t));
90 in.read(reinterpret_cast<char*>(&adc), sizeof(uint32_t));
91 digits.emplace_back(deID, padID, adc, tfTime, nofSamples, sat > 0);
92 if (in.fail()) {
93 return false;
94 }
95 }
96 return true;
97}
98
99void DigitSamplerV4::rewind(std::istream& in)
100{
102}
103
104bool DigitSinkV4::write(std::ostream& out,
105 gsl::span<const Digit> digits,
106 gsl::span<const ROFRecord> rofs)
107{
108 if (rofs.empty()) {
109 return false;
110 }
111 writeNofItems(out, rofs.size());
112 if (out.fail()) {
113 return false;
114 }
115 for (auto r : rofs) {
116 uint16_t bc = r.getBCData().bc;
117 uint32_t orbit = r.getBCData().orbit;
118 uint32_t firstIdx = r.getFirstIdx();
119 uint32_t nentries = r.getNEntries();
120 uint32_t bcWidth = r.getBCWidth();
121 out.write(reinterpret_cast<const char*>(&bc), sizeof(uint16_t));
122 out.write(reinterpret_cast<const char*>(&orbit), sizeof(uint32_t));
123 out.write(reinterpret_cast<const char*>(&firstIdx), sizeof(uint32_t));
124 out.write(reinterpret_cast<const char*>(&nentries), sizeof(uint32_t));
125 out.write(reinterpret_cast<const char*>(&bcWidth), sizeof(uint32_t));
126 if (out.fail()) {
127 return false;
128 }
129 }
130
131 writeNofItems(out, digits.size());
132 if (out.fail()) {
133 return false;
134 }
135 for (const auto& d : digits) {
136 uint32_t tfTime = d.getTime();
137 uint16_t nofSamples = d.getNofSamples();
138 uint32_t deID = d.getDetID();
139 uint32_t padID = d.getPadID();
140 uint32_t adc = d.getADC();
141 uint8_t sat = d.isSaturated();
142 out.write(reinterpret_cast<const char*>(&tfTime), sizeof(uint32_t));
143 out.write(reinterpret_cast<const char*>(&nofSamples), sizeof(uint16_t));
144 out.write(reinterpret_cast<const char*>(&sat), sizeof(uint8_t));
145 out.write(reinterpret_cast<const char*>(&deID), sizeof(uint32_t));
146 out.write(reinterpret_cast<const char*>(&padID), sizeof(uint32_t));
147 out.write(reinterpret_cast<const char*>(&adc), sizeof(uint32_t));
148 if (out.fail()) {
149 return false;
150 }
151 }
152 return true;
153}
154
155} // namespace o2::mch::io::impl
uint64_t orbit
Definition RawEventData.h:6
uint64_t bc
Definition RawEventData.h:5
unsigned char uint8_t
unsigned short int uint16_t
unsigned int uint32_t
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
Definition of the MCH ROFrame record.
void count(std::istream &in, size_t &ntfs, size_t &nrofs, size_t &ndigits) override
Definition DigitIOV4.cxx:24
bool read(std::istream &in, std::vector< Digit > &digits, std::vector< ROFRecord > &rofs) override
Definition DigitIOV4.cxx:41
void rewind(std::istream &in)
Definition DigitIOV4.cxx:99
std::pair< int, int > advanceOneEvent(std::istream &in, int fileFormatVersion)
Definition IO.cxx:48
void writeNofItems(std::ostream &out, uint32_t nofItems)
Definition IO.cxx:30
int readNofItems(std::istream &in, const char *itemName)
Definition IO.cxx:20
bool write(std::ostream &out, gsl::span< const Digit > digits, gsl::span< const ROFRecord > rofs) override
std::vector< Digit > digits
ArrayADC adc