Project
Loading...
Searching...
No Matches
PayloadPaginator.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#include <optional>
17#include "Headers/RDHAny.h"
18#include <iostream>
21#include "Framework/Logger.h"
22
23namespace o2::mch::raw
24{
25
26uint64_t encode(const LinkInfo& li)
27{
28 return static_cast<uint64_t>(li.endPoint) |
29 static_cast<uint64_t>(li.linkId) << 8 |
30 static_cast<uint64_t>(li.cruId) << 24 |
31 static_cast<uint64_t>(li.feeId) << 40;
32}
33
34bool operator<(const LinkInfo& li1, const LinkInfo& li2)
35{
36 return encode(li1) < encode(li2);
37}
38
39std::ostream& operator<<(std::ostream& os, const LinkInfo& li)
40{
41 os << fmt::format("FEEID {:6d} CRU {:4d} LINK {:4d} EP {:1d}",
42 li.feeId, li.cruId, li.linkId, li.endPoint);
43 return os;
44}
45
46template <typename ELECMAP, typename FORMAT, typename CHARGESUM, int VERSION>
48{
49 auto s2f = createSolar2FeeLinkMapper<ELECMAP>();
50 return [s2f](uint16_t solarId) -> std::optional<LinkInfo> {
51 auto f = s2f(solarId);
52 if (!f.has_value()) {
53 return std::nullopt;
54 };
55 LinkInfo li;
56 li.endPoint = f->feeId() % 2;
57 li.cruId = (f->feeId() - li.endPoint) / 2;
58 li.feeId = f->feeId() | extraFeeIdChargeSumMask<CHARGESUM>() | extraFeeIdVersionMask<VERSION>();
59 li.linkId = linkRemapping<FORMAT>(f->linkId());
60 return li;
61 };
62}
63
73
74std::string flpName(LinkInfo li)
75{
76 static std::array<int, 33> cru2flp = {
77 148, 148, 148, // 0, 1, 2 // FIXME: to be x-checked for St12
78 149, 149, 149, // 3, 4, 5 // FIXME: to be x-checked for St12
79 150, 150, 150, // 6, 7, 8 // FIXME: to be x-checked for St12
80 151, 151, 151, // 9,10,11 CH5
81 152, 152, 152, // 12,13,14 CH6
82 153, 153, 153, // 15,16,17 CH7o+CH8o (L)
83 154, 154, 154, // 18,19,20 CH7i+CH8i (R)
84 155, 155, 155, // 21,22,23 CH8i+CH9i (L)
85 156, 156, 156, // 24,25,26 CH8o+CH9o (R)
86 157, 157, 0, // 27,28,xx CH10o (L)
87 158, 158, 0 // 30,31,xx CH10i (R)
88 };
89 if (li.cruId > 32) {
90 throw std::invalid_argument("cruId should be <= 32");
91 }
92 return fmt::format("alio2-cr1-flp{}", cru2flp[li.cruId]);
93}
94
96 std::string outputBase,
97 const std::set<LinkInfo>& links,
98 bool filePerLink,
99 bool filePerCru)
100{
101 std::string output = fmt::format("{:s}.raw", outputBase);
102 for (auto li : links) {
103 if (filePerLink || filePerCru) {
104 output = fmt::format("{:s}_{:s}_cru{:d}_{:d}", outputBase, flpName(li), li.cruId, li.endPoint);
105 if (filePerLink) {
106 output += fmt::format("_feedid{:d}", li.feeId);
107 }
108 output += ".raw";
109 }
110 rawFileWriter.registerLink(rdhFromLinkInfo(li), output);
111 }
112}
113
115 gsl::span<const std::byte> buffer,
116 const std::set<LinkInfo>& links,
117 Solar2LinkInfo solar2LinkInfo)
118{
119 std::set<DataBlockRef> dataBlockRefs;
121 buffer, [&](const DataBlockRef& ref) {
122 dataBlockRefs.insert(ref);
123 });
124
125 std::map<o2::InteractionRecord, std::set<LinkInfo>> filled;
126
127 // fill output buffer with actual data
128 for (auto r : dataBlockRefs) {
129 auto& b = r.block;
130 auto& h = b.header;
131 auto solarId = r.block.header.solarId;
132 auto li = solar2LinkInfo(solarId);
133 if (!li.has_value()) {
134 throw std::runtime_error(fmt::format("Could not get fee,cru,link,endpoint for solarId {}", solarId));
135 }
136 filled[o2::InteractionRecord{h.bc, h.orbit}].insert(li.value());
137 rawFileWriter.addData(rdhFromLinkInfo(li.value()),
138 {h.bc, h.orbit},
139 gsl::span<char>(const_cast<char*>(reinterpret_cast<const char*>(&b.payload[0])),
140 b.payload.size()));
141 }
142
143 // loop over the used interaction records and ensure that we call
144 // addData for each link where it was not already called.
145
146 static std::array<char, 64> nothing;
147
148 for (auto p : filled) {
149 auto ir = p.first;
150 auto& filledLinks = p.second;
151 std::set<LinkInfo> addDataNotAlreadyCalled;
152 std::set_difference(links.begin(), links.end(), filledLinks.begin(), filledLinks.end(),
153 std::inserter(addDataNotAlreadyCalled, addDataNotAlreadyCalled.end()));
154 for (auto li : addDataNotAlreadyCalled) {
155 rawFileWriter.addData(rdhFromLinkInfo(li), ir, nothing);
156 }
157 }
158}
159
160// instanciate only the specializations that actually make sense.
163
168
171
176
177} // namespace o2::mch::raw
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Utility class to write detectors data to (multiple) raw data file(s) respecting CRU format.
Class for time synchronization of RawReader instances.
void addData(uint16_t feeid, uint16_t cru, uint8_t lnk, uint8_t endpoint, const IR &ir, const gsl::span< char > data, bool preformatted=false, uint32_t trigger=0, uint32_t detField=0)
LinkData & registerLink(uint16_t fee, uint16_t cru, uint8_t link, uint8_t endpoint, std::string_view outFileName)
GLuint buffer
Definition glcorearb.h:655
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean r
Definition glcorearb.h:1233
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperDummy, UserLogicFormat, SampleMode, 0 >()
Solar2LinkInfo createSolar2LinkInfo()
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperDummy, UserLogicFormat, ChargeSumMode, 1 >()
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperGenerated, UserLogicFormat, SampleMode, 0 >()
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperDummy, BareFormat, SampleMode, 0 >()
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)
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperGenerated, UserLogicFormat, SampleMode, 1 >()
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 >()
o2::header::RDHAny rdhFromLinkInfo(LinkInfo li)
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperGenerated, UserLogicFormat, ChargeSumMode, 0 >()
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperDummy, BareFormat, ChargeSumMode, 0 >()
std::function< std::optional< LinkInfo >(uint16_t)> Solar2LinkInfo
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperDummy, UserLogicFormat, SampleMode, 1 >()
int forEachDataBlockRef(gsl::span< const std::byte > buffer, std::function< void(DataBlockRef ref)> f)
Definition DataBlock.cxx:23
template Solar2LinkInfo createSolar2LinkInfo< ElectronicMapperGenerated, BareFormat, SampleMode, 0 >()
std::string flpName(LinkInfo li)
uint32_t encode(const DsDetId &id)
Create an integer code for the given id.
Definition DsDetId.cxx:28
bool operator<(const observer_ptr< W1 > &p1, const observer_ptr< W2 > &p2)
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
a DataBlockRef is a pair (DataBlock,offset) The offset is an offset into some external buffer
Definition DataBlock.h:45
static void setLinkID(H &rdh, uint8_t v, NOTPTR(H))
Definition RDHUtils.h:256
static void setEndPointID(H &rdh, uint8_t v, NOTPTR(H))
Definition RDHUtils.h:304
static void setFEEID(RDHv4 &rdh, uint16_t v)
Definition RDHUtils.h:146
static void setCRUID(H &rdh, uint16_t v, NOTPTR(H))
Definition RDHUtils.h:288
o2::InteractionRecord ir(0, 0)