Project
Loading...
Searching...
No Matches
DigitIOV0.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 "DigitIOV0.h"
13#include "DigitD0.h"
14#include <stdexcept>
15#include <vector>
18#include <iostream>
19#include <fmt/format.h>
20#include "DigitFileFormat.h"
22#include "IOStruct.h"
23
24//
25// V0 was prior to the introduction of rofs, so the file format is
26// simply a set of consecutive [nofDigits|list of digits] blocks
27//
28
29namespace o2::mch::io::impl
30{
31void DigitSamplerV0::count(std::istream& in, size_t& ntfs, size_t& nrofs, size_t& ndigits)
32{
33 rewind(in);
34 ndigits = 0;
35 nrofs = 0;
36 ntfs = 0;
37 int ndig{0};
38 auto dff = digitFileFormats[0];
39
40 while ((ndig = advance(in, dff.digitSize, "digits")) >= 0) {
41 ndigits += ndig;
42 ++nrofs;
43 ++ntfs;
44 }
45 rewind(in);
46}
47
48bool DigitSamplerV0::read(std::istream& in,
49 std::vector<Digit>& digits,
50 std::vector<ROFRecord>& rofs)
51{
52 // note the input vectors are not cleared as this is the responsability
53 // of the calling class, if need be.
54 std::vector<DigitD0> digitsd0;
55 bool ok = readBinaryStruct(in, digitsd0, "digits");
56 if (!ok) {
57 return false;
58 }
59
60 for (auto d0 : digitsd0) {
61 Digit d(d0.detID, d0.padID, d0.adc, d0.tfTime, d0.getNofSamples(), d0.isSaturated());
62 digits.push_back(d);
63 }
64
65 rofs.emplace_back(o2::InteractionRecord(0, mCurrentROF), 0, digits.size());
66 ++mCurrentROF;
67 return true;
68}
69
70void DigitSamplerV0::rewind(std::istream& in)
71{
73 mCurrentROF = 0;
74}
75
76bool DigitSinkV0::write(std::ostream& out,
77 gsl::span<const Digit> digits,
78 gsl::span<const ROFRecord> rofs)
79{
80 // V0 format had no notion of rofs, so we strip them
81 for (auto r : rofs) {
82 std::vector<DigitD0> digitsd0;
83 for (int i = r.getFirstIdx(); i <= r.getLastIdx(); i++) {
84 const Digit& d = digits[i];
85 digitsd0.push_back(DigitD0{d.getTime(), d.getNofSamples(), d.getDetID(), d.getPadID(), d.getADC()});
86 digitsd0.back().setSaturated(d.isSaturated());
87 }
88 gsl::span<const DigitD0> d0(digitsd0);
89 bool ok = writeBinaryStruct(out, d0);
90 if (!ok) {
91 return false;
92 }
93 }
94 return true;
95}
96
97} // 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
void setSaturated(bool sat)
Definition Digit.cxx:58
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 rewind(std::istream &in)
Definition DigitIOV0.cxx:70
bool read(std::istream &in, std::vector< Digit > &digits, std::vector< ROFRecord > &rofs) override
Definition DigitIOV0.cxx:48
void count(std::istream &in, size_t &ntfs, size_t &nrofs, size_t &ndigits) override
Definition DigitIOV0.cxx:31
GLboolean r
Definition glcorearb.h:1233
bool readBinaryStruct(std::istream &in, std::vector< T > &items, const char *itemName)
Definition IOStruct.h:35
int advance(std::istream &in, size_t itemByteSize, const char *itemName)
Definition IO.cxx:35
bool writeBinaryStruct(std::ostream &os, gsl::span< const T > items)
Definition IOStruct.h:23
std::array< DigitFileFormat, 5 > digitFileFormats
bool write(std::ostream &out, gsl::span< const Digit > digits, gsl::span< const ROFRecord > rofs) override
Definition DigitIOV0.cxx:76
std::vector< Digit > digits