14#define BOOST_TEST_MODULE Test MCHRaw Closure
15#define BOOST_TEST_MAIN
16#define BOOST_TEST_DYN_LINK
18#include <boost/test/unit_test.hpp>
19#include <boost/property_tree/ptree.hpp>
27#include <boost/mpl/list.hpp>
28#include <fmt/format.h>
34 "S728-J1-DS0-CH3-ts-24-bc-0-cs-14-q-13",
35 "S728-J1-DS0-CH13-ts-24-bc-0-cs-134-q-133",
36 "S728-J1-DS0-CH23-ts-24-bc-0-cs-164-q-163",
38 "S361-J0-DS4-CH0-ts-24-bc-0-cs-11-q-10",
39 "S361-J0-DS4-CH1-ts-24-bc-0-cs-21-q-20",
40 "S361-J0-DS4-CH2-ts-24-bc-0-cs-31-q-30",
41 "S361-J0-DS4-CH3-ts-24-bc-0-cs-41-q-40",
43 "S448-J6-DS2-CH22-ts-24-bc-0-cs-421-q-420",
44 "S448-J6-DS2-CH23-ts-24-bc-0-cs-431-q-430",
45 "S448-J6-DS2-CH24-ts-24-bc-0-cs-441-q-440",
46 "S448-J6-DS2-CH25-ts-24-bc-0-cs-451-q-450",
47 "S448-J6-DS2-CH26-ts-24-bc-0-cs-461-q-460",
48 "S448-J6-DS2-CH42-ts-24-bc-0-cs-421-q-420"};
51 "S728-J1-DS0-CH3-ts-24-bc-0-cs-3-q-13-15-17",
52 "S728-J1-DS0-CH13-ts-24-bc-0-cs-3-q-133-135-137",
53 "S728-J1-DS0-CH23-ts-24-bc-0-cs-2-q-163-165",
55 "S361-J0-DS4-CH0-ts-24-bc-0-cs-3-q-10-12-14",
56 "S361-J0-DS4-CH1-ts-24-bc-0-cs-3-q-20-22-24",
57 "S361-J0-DS4-CH2-ts-24-bc-0-cs-3-q-30-32-34",
58 "S361-J0-DS4-CH3-ts-24-bc-0-cs-3-q-40-42-44",
60 "S448-J6-DS2-CH22-ts-24-bc-0-cs-3-q-420-422-424",
61 "S448-J6-DS2-CH23-ts-24-bc-0-cs-3-q-430-432-434",
62 "S448-J6-DS2-CH24-ts-24-bc-0-cs-3-q-440-442-444",
63 "S448-J6-DS2-CH25-ts-24-bc-0-cs-3-q-450-452-454",
64 "S448-J6-DS2-CH26-ts-24-bc-0-cs-3-q-460-462-464",
65 "S448-J6-DS2-CH42-ts-24-bc-0-cs-5-q-420-422-424-426-428"};
67template <
typename ELECMAP,
typename FORMAT,
typename CHARGESUM,
int VERSION>
68std::vector<std::byte>
paginate(gsl::span<const std::byte>
buffer,
const std::string& tmpbasename)
70 fair::Logger::SetConsoleSeverity(
"nolog");
76 auto solar2LinkInfo = createSolar2LinkInfo<ELECMAP, FORMAT, CHARGESUM, VERSION>();
80 std::set<LinkInfo> links;
81 for (
auto solarId : {361, 448, 728}) {
82 links.insert(solar2LinkInfo(solarId).value());
91 auto filename = fmt::format(
"{:s}.raw", tmpbasename);
92 std::ifstream in(
filename, std::ifstream::binary);
94 throw std::runtime_error(fmt::format(
"could not open ",
filename));
100 std::vector<std::byte> pages(
length);
103 in.read(
reinterpret_cast<char*
>(&pages[0]),
length);
121 auto index = d.find(
"ts-");
122 auto ts = std::stoi(d.substr(
index + 3));
123 index = d.find(
"bc-");
124 auto bc = std::stoi(d.substr(
index + 3));
125 index = d.find(
"cs-");
126 auto cs = std::stoi(d.substr(
index + 3));
127 index = d.find(
"q-");
128 auto q = d.substr(
index + 2);
130 if (
index != std::string::npos) {
131 std::vector<uint10_t> charges;
132 std::istringstream ss(q);
134 while (std::getline(ss,
adc,
'-')) {
135 charges.emplace_back(std::stoi(
adc) & 0x3FF);
146 std::set<DsElecId> dsids;
147 for (
auto d :
data) {
150 std::cout <<
"Could not get dsElecId for " << d <<
"\n";
153 dsids.insert(dsElecId.value());
167template <
typename ELECMAP,
typename FORMAT,
typename CHARGESUM,
int VERSION>
169 uint32_t
orbit = 12345, uint16_t
bc = 678)
172 o2::conf::ConfigurableParam::setValue<uint32_t>(
"HBFUtils",
"orbitFirst",
orbit);
173 o2::conf::ConfigurableParam::setValue<uint32_t>(
"HBFUtils",
"orbitFirstSampled",
orbit);
178 encoder->startHeartbeatFrame(
orbit,
bc);
179 std::set<DsElecId> dsElecIds =
getDs(
data);
180 encoder->addHeartbeatHeaders(dsElecIds);
181 for (
auto d :
data) {
184 std::cout <<
"Could not get dsElecId for " << d <<
"\n";
188 std::cout <<
"Could not get channel for " << d <<
"\n";
191 encoder->addChannelData(dsElecId.value(), channel.value(), sampaClusters);
193 std::vector<std::byte>
buffer;
194 encoder->moveToBuffer(
buffer);
196 o2::conf::ConfigurableParam::setValue<uint32_t>(
"HBFUtils",
"orbitFirst",
orbit);
197 o2::conf::ConfigurableParam::setValue<uint32_t>(
"HBFUtils",
"orbitFirstSampled",
orbit);
199 std::vector<std::byte> out =
200 paginate<ELECMAP, FORMAT, CHARGESUM, VERSION>(
buffer,
201 fmt::format(
"mch-closure-codec-{}-{}.raw",
215template <
typename ELECMAP>
218 std::vector<std::string>
result;
223 createFeeLink2SolarMapper<ELECMAP>());
226 parser(testBuffer, pageDecoder);
233 std::cout <<
"Got " <<
result.size() <<
" results:\n";
235 std::cout << s <<
"\n";
237 std::cout <<
"Expected " <<
expected.size() <<
":\n";
239 std::cout << s <<
"\n";
250 static constexpr int version = 0;
256 static constexpr int version = 0;
262 static constexpr int version = 1;
268 static constexpr int version = 0;
274 static constexpr int version = 0;
280 static constexpr int version = 1;
283typedef boost::mpl::list<BareGen, UserLogicGen, UserLogicGen1, BareDummy, UserLogicDummy, UserLogicDummy1>
testTypes;
Utility class to write detectors data to (multiple) raw data file(s) respecting CRU format.
static const HBFUtils & Instance()
void setDontFillEmptyHBF(bool v)
GLuint GLsizei GLsizei * length
PageParser createPageParser()
void paginate(o2::raw::RawFileWriter &rawFileWriter, gsl::span< const std::byte > buffer, const std::set< LinkInfo > &links, Solar2LinkInfo solar2LinkInfo)
std::optional< uint8_t > decodeChannelId(std::string rep)
void registerLinks(o2::raw::RawFileWriter &rawFileWriter, std::string outputBase, const std::set< LinkInfo > &links, bool filePerLink, bool filePerCru)
std::function< void(DsElecId dsId, DualSampaChannelId channel, SampaCluster)> SampaChannelHandler
uint6_t DualSampaChannelId
PageDecoder createPageDecoder(RawBuffer rdhBuffer, DecodedDataHandlers decodedDataHandlers)
will be called for each decoded Sampa packet and in case of decoding errors
std::string asString(const SampaCluster &sc)
std::optional< DsElecId > decodeDsElecId(uint32_t code)
std::unique_ptr< PayloadEncoder > createPayloadEncoder(Solar2FeeLinkMapper solar2feelink, bool userLogic, int version, bool chargeSumMode)
bool sameSize(T0 const &first, Ts const &... rest)
static constexpr int version
static constexpr int version
static constexpr int version
static constexpr int version
static constexpr int version
static constexpr int version
SampaChannelHandler sampaChannelHandler
Piece of data for one Sampa channel.
std::vector< std::string > chargeSumInput
constexpr const char * sampaClusterFormat
boost::mpl::list< BareGen, UserLogicGen, UserLogicGen1, BareDummy, UserLogicDummy, UserLogicDummy1 > testTypes
bool testDecode(gsl::span< const std::byte > testBuffer, gsl::span< std::string > expected)
std::vector< SampaCluster > getSampaClusters(const std::string &d)
std::vector< std::byte > createBuffer(gsl::span< std::string > data, uint32_t orbit=12345, uint16_t bc=678)
std::vector< std::string > sampleInput
SampaChannelHandler handlePacketStoreAsVec(std::vector< std::string > &result)
BOOST_AUTO_TEST_CASE_TEMPLATE(ClosureChargeSum, T, testTypes)
std::set< DsElecId > getDs(gsl::span< std::string > data)
std::map< std::string, ID > expected
boost::mpl::list< o2::dcs::DataPointIdentifier, o2::dcs::DataPointValue, o2::dcs::DataPointCompositeObject > testTypes
std::vector< Cluster > clusters
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())