Project
Loading...
Searching...
No Matches
DigitIOV2.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 "DigitIOV2.h"
13#include <stdexcept>
14#include <vector>
17#include <iostream>
18#include <fmt/format.h>
19#include "DigitFileFormat.h"
21#include "IO.h"
22
23//
24// V2 was prior to the introduction of rofs, so the file format is
25// simply a set of consecutive [nofDigits|list of digits] blocks
26//
27
28namespace o2::mch::io::impl
29{
30void DigitSamplerV2::count(std::istream& in, size_t& ntfs, size_t& nrofs, size_t& ndigits)
31{
32 auto dff = digitFileFormats[2];
33 rewind(in);
34 ndigits = 0;
35 nrofs = 0;
36 ntfs = 0;
37 int ndig{0};
38
39 while ((ndig = advance(in, dff.digitSize, "digits")) >= 0) {
40 ndigits += ndig;
41 ++nrofs;
42 ++ntfs;
43 }
44 rewind(in);
45}
46
47bool DigitSamplerV2::read(std::istream& in,
48 std::vector<Digit>& digits,
49 std::vector<ROFRecord>& rofs)
50{
51 if (in.peek() == EOF) {
52 return false;
53 }
54 // note the input vectors are not cleared as this is the responsability
55 // of the calling class, if need be.
56 int ndigits = readNofItems(in, "digits");
57
58 for (int i = 0; i < ndigits; i++) {
59 uint32_t tfTime;
60 uint16_t nofSamples;
61 uint8_t sat;
62 uint32_t deID;
63 uint32_t padID;
64 uint32_t adc;
65 in.read(reinterpret_cast<char*>(&tfTime), sizeof(uint32_t));
66 in.read(reinterpret_cast<char*>(&nofSamples), sizeof(uint16_t));
67 in.read(reinterpret_cast<char*>(&sat), sizeof(uint8_t));
68 in.read(reinterpret_cast<char*>(&deID), sizeof(uint32_t));
69 in.read(reinterpret_cast<char*>(&padID), sizeof(uint32_t));
70 in.read(reinterpret_cast<char*>(&adc), sizeof(uint32_t));
71 digits.emplace_back(deID, padID, adc, tfTime, nofSamples, sat > 0);
72 }
73
74 rofs.emplace_back(o2::InteractionRecord(0, mCurrentROF), 0, ndigits);
75 ++mCurrentROF;
76 return !in.fail();
77}
78
79void DigitSamplerV2::rewind(std::istream& in)
80{
82 mCurrentROF = 0;
83}
84
85bool DigitSinkV2::write(std::ostream& out,
86 gsl::span<const Digit> digits,
87 gsl::span<const ROFRecord> rofs)
88{
89 // V2 format had no notion of rofs, so we strip them
90 for (auto r : rofs) {
91 writeNofItems(out, r.getNEntries());
92 for (int i = r.getFirstIdx(); i <= r.getLastIdx(); i++) {
93 const Digit& d = digits[i];
94 uint32_t tfTime = d.getTime();
95 uint16_t nofSamples = d.getNofSamples();
96 uint32_t deID = d.getDetID();
97 uint32_t padID = d.getPadID();
98 uint32_t adc = d.getADC();
99 uint8_t sat = d.isSaturated();
100 out.write(reinterpret_cast<const char*>(&tfTime), sizeof(uint32_t));
101 out.write(reinterpret_cast<const char*>(&nofSamples), sizeof(uint16_t));
102 out.write(reinterpret_cast<const char*>(&sat), sizeof(uint8_t));
103 out.write(reinterpret_cast<const char*>(&deID), sizeof(uint32_t));
104 out.write(reinterpret_cast<const char*>(&padID), sizeof(uint32_t));
105 out.write(reinterpret_cast<const char*>(&adc), sizeof(uint32_t));
106 }
107 }
108 return !out.fail();
109}
110
111} // namespace o2::mch::io::impl
int32_t i
Definition of the MCH ROFrame record.
MCH digit implementation.
Definition Digit.h:31
int getPadID() const
Definition Digit.h:54
int getDetID() const
Definition Digit.h:52
uint16_t getNofSamples() const
Definition Digit.cxx:39
bool isSaturated() const
Definition Digit.cxx:44
int32_t getTime() const
Definition Digit.h:44
uint32_t getADC() const
Definition Digit.h:57
void count(std::istream &in, size_t &ntfs, size_t &nrofs, size_t &ndigits) override
Definition DigitIOV2.cxx:30
bool read(std::istream &in, std::vector< Digit > &digits, std::vector< ROFRecord > &rofs) override
Definition DigitIOV2.cxx:47
void rewind(std::istream &in)
Definition DigitIOV2.cxx:79
GLboolean r
Definition glcorearb.h:1233
int advance(std::istream &in, size_t itemByteSize, const char *itemName)
Definition IO.cxx:35
void writeNofItems(std::ostream &out, uint32_t nofItems)
Definition IO.cxx:30
int readNofItems(std::istream &in, const char *itemName)
Definition IO.cxx:20
std::array< DigitFileFormat, 5 > digitFileFormats
bool write(std::ostream &out, gsl::span< const Digit > digits, gsl::span< const ROFRecord > rofs) override
Definition DigitIOV2.cxx:85
std::vector< Digit > digits
ArrayADC adc