Project
Loading...
Searching...
No Matches
DigitRawEncoder.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
13
16#include "Framework/Logger.h"
17#include "Headers/DAQID.h"
22#include <filesystem>
23#include <fmt/format.h>
24#include <iostream>
25#include <set>
26
27namespace o2::mch::raw
28{
38void setupRawFileWriter(o2::raw::RawFileWriter& fw, const std::set<LinkInfo>& links, DigitRawEncoderOptions opt)
39{
42
43 bool continuous = true;
44 if (!opt.noGRP) {
45 std::string inputGRP = o2::base::NameConf::getGRPFileName();
46 std::unique_ptr<o2::parameters::GRPObject> grp{o2::parameters::GRPObject::loadFrom(inputGRP)};
48 }
49 fw.setContinuousReadout(continuous); // must be set explicitly
50
51 if (opt.noEmptyHBF) {
52 fw.setDontFillEmptyHBF(true);
53 }
54
55 if (!std::filesystem::exists(opt.outputDir)) {
56 if (!std::filesystem::create_directories(opt.outputDir)) {
57 LOGP(fatal, "could not create output directory {}", opt.outputDir);
58 } else {
59 LOGP(info, "created output directory {}", opt.outputDir);
60 }
61 }
62
63 std::string output = fmt::format("{:s}/MCH", opt.outputDir);
64
65 // Register the corresponding links (might have several solars for 1 link)
66 registerLinks(fw, output, links,
69}
70
71Solar2LinkInfo getSolar2LinkInfo(bool userLogic, bool dummyElecMap, int userLogicVersion)
72{
73 // the following cascade is not pretty, but the non-negociable intent is
74 // to avoid exposing templates to the DigitRawEncoder interface, hence
75 // this bool to template argument dance.
76
77 if (dummyElecMap) {
78 if (userLogic) {
79 if (userLogicVersion == 0) {
81 } else if (userLogicVersion == 1) {
83 } else {
84 throw std::invalid_argument("Version can only be 0 or 1");
85 }
86 } else {
88 }
89 }
90 if (userLogic) {
91 if (userLogicVersion == 0) {
93 } else if (userLogicVersion == 1) {
95 } else {
96 throw std::invalid_argument("Version can only be 0 or 1");
97 }
98 } else {
100 }
101}
102
110
111std::set<uint16_t> getSolarUIDs(bool dummyElecMap)
112{
113 if (dummyElecMap) {
115 }
117}
118
119std::set<o2::mch::raw::LinkInfo> getLinks(Solar2LinkInfo solar2LinkInfo, bool dummyElecMap)
120{
121 // Get the list of solarIds and convert it to a list of unique RDH(Any)s
122 //
123 // Note that there's not necessarily a one to one correspondence
124 // between solarIds and FEEID (hence RDH) :
125 // the most probable format is UserLogic and in that case several
126 // solars end up in the same RDH/FEEID (readout is basically
127 // gathering solars per CRU endpoint)
128 auto solarIds = getSolarUIDs(dummyElecMap);
129 std::set<LinkInfo> links;
130 for (auto solarId : solarIds) {
131 auto li = solar2LinkInfo(solarId);
132 if (!li.has_value()) {
133 LOGP(fatal, "Could not find information about solarId {:d}", solarId);
134 }
135 links.insert(li.value());
136 }
137
138 LOGP(info, "MCH: registered {:d} links for {:d} solars",
139 links.size(),
140 solarIds.size());
141 return links;
142}
143
151
152std::ostream& operator<<(std::ostream& os, const DigitRawEncoderOptions& opt)
153{
154 os << fmt::format("output dir {} filePerLink {} filePerCruEndpoint {} userLogic {} dummyElecMap {} ulVersion {}\n",
155 opt.outputDir,
159 return os;
160}
161
163 : mOptions{opts},
164 mRawFileWriter{o2::header::DAQID(o2::header::DAQID::MCH).getO2Origin()},
165 mSolar2LinkInfo{getSolar2LinkInfo(opts.userLogic, opts.dummyElecMap, opts.userLogicVersion)},
166 mLinks{getLinks(mSolar2LinkInfo, opts.dummyElecMap)},
167 mPayloadEncoder{createPayloadEncoder(
168 getSolar2FeeLink(opts.dummyElecMap),
169 opts.userLogic,
170 opts.userLogicVersion,
171 opts.chargeSumMode)},
172 mDigitPayloadEncoder{getDigit2Elec(opts.dummyElecMap), *(mPayloadEncoder.get())}
173{
174 setupRawFileWriter(mRawFileWriter, mLinks, opts);
175}
176
177void DigitRawEncoder::addHeartbeats(std::set<DsElecId> dsElecIds, uint32_t orbit)
178{
179 LOGP(info, "Adding heartbeats for orbit={}", orbit);
180 mPayloadEncoder->startHeartbeatFrame(orbit, 0);
181 mPayloadEncoder->addHeartbeatHeaders(dsElecIds);
182}
183
184void DigitRawEncoder::encodeDigits(gsl::span<o2::mch::Digit> digits, uint32_t orbit, uint16_t bc)
185{
186 LOGP(info, "Encoding {} MCH digits for orbit {} bc {}", digits.size(), orbit, bc);
187 std::vector<std::byte> buffer;
188 mDigitPayloadEncoder.encodeDigits(digits, orbit, bc, buffer);
189 paginate(mRawFileWriter, buffer, mLinks, mSolar2LinkInfo);
190}
191
193{
194 mRawFileWriter.writeConfFile("MCH", "RAWDATA", fmt::format("{:s}/MCHraw.cfg", mOptions.outputDir));
195}
196
197} // namespace o2::mch::raw
uint64_t orbit
Definition RawEventData.h:6
uint64_t bc
Definition RawEventData.h:5
Header of the General Run Parameters object.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of the Names Generator class.
static std::string getGRPFileName(const std::string_view prefix=STANDARDSIMPREFIX)
Definition NameConf.cxx:58
static constexpr ID MCH
Definition DetID.h:72
void encodeDigits(gsl::span< o2::mch::Digit > digits, uint32_t orbit, uint16_t bc, std::vector< std::byte > &buffer)
DigitRawEncoder(DigitRawEncoderOptions opt={})
void encodeDigits(gsl::span< o2::mch::Digit > digits, uint32_t orbit, uint16_t bc)
void addHeartbeats(std::set< DsElecId > dsElecIds, uint32_t orbit)
bool isDetContinuousReadOut(DetID id) const
test if detector is read out
Definition GRPObject.h:127
static GRPObject * loadFrom(const std::string &grpFileName="")
void setDontFillEmptyHBF(bool v)
void writeConfFile(std::string_view origin="FLP", std::string_view description="RAWDATA", std::string_view cfgname="raw.cfg", bool fullPath=true) const
GLuint buffer
Definition glcorearb.h:655
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperDummy, UserLogicFormat, ChargeSumMode, 1 >()
std::function< std::optional< DsElecId >(DsDetId)> createDet2ElecMapper< ElectronicMapperDummy >()
std::function< std::optional< std::pair< DsElecId, int > >(const o2::mch::Digit &digit)> Digit2ElecMapper
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperDummy, UserLogicFormat, ChargeSumMode, 0 >()
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperGenerated, UserLogicFormat, ChargeSumMode, 1 >()
void paginate(o2::raw::RawFileWriter &rawFileWriter, gsl::span< const std::byte > buffer, const std::set< LinkInfo > &links, Solar2LinkInfo solar2LinkInfo)
Solar2LinkInfo getSolar2LinkInfo(bool userLogic, bool dummyElecMap, int userLogicVersion)
std::function< std::optional< DsElecId >(DsDetId)> createDet2ElecMapper< ElectronicMapperGenerated >()
Solar2FeeLinkMapper getSolar2FeeLink(bool dummyElecMap)
void registerLinks(o2::raw::RawFileWriter &rawFileWriter, std::string outputBase, const std::set< LinkInfo > &links, bool filePerLink, bool filePerCru)
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperGenerated, BareFormat, ChargeSumMode, 0 >()
Digit2ElecMapper createDigit2ElecMapper(Det2ElecMapper det2elec)
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperGenerated, UserLogicFormat, ChargeSumMode, 0 >()
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperDummy, BareFormat, ChargeSumMode, 0 >()
std::set< uint16_t > getSolarUIDs< ElectronicMapperGenerated >()
std::function< std::optional< LinkInfo >(uint16_t)> Solar2LinkInfo
Digit2ElecMapper getDigit2Elec(bool dummyElecMap)
std::function< std::optional< FeeLinkId >(uint16_t solarId)> Solar2FeeLinkMapper
From solarId to (feeId,linkId)
Definition Mapper.h:57
std::function< std::optional< FeeLinkId >(uint16_t)> createSolar2FeeLinkMapper< ElectronicMapperDummy >()
std::set< o2::mch::raw::LinkInfo > getLinks(Solar2LinkInfo solar2LinkInfo, bool dummyElecMap)
std::set< uint16_t > getSolarUIDs< ElectronicMapperDummy >()
std::set< uint16_t > getSolarUIDs()
List of Solar Unique Ids for all MCH.
std::function< std::optional< FeeLinkId >(uint16_t)> createSolar2FeeLinkMapper< ElectronicMapperGenerated >()
void setupRawFileWriter(o2::raw::RawFileWriter &fw, const std::set< LinkInfo > &links, DigitRawEncoderOptions opt)
std::unique_ptr< PayloadEncoder > createPayloadEncoder(Solar2FeeLinkMapper solar2feelink, bool userLogic, int version, bool chargeSumMode)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
std::vector< Digit > digits