13 const size_t framesPerBX,
15 const size_t maxFramesPerFile,
18 boardDataFileID_(
"CMSSW"),
20 framesPerBX_(framesPerBX),
22 maxFramesPerFile_(maxFramesPerFile),
23 maxEventsPerFile_(maxFramesPerFile_),
26 channelMap_(channelSpecs) {
27 if (channelMap_.empty())
28 throw std::runtime_error(
"BoardDataWriter channel map cannnot be empty");
29 if (fileExt !=
"txt" && fileExt !=
"txt.gz" && fileExt !=
"txt.xz")
30 throw std::runtime_error(
"BoardDataWriter fileExt must be one of txt, txt.gz, txt.xz");
32 for (
const auto& [
id,
value] : channelMap_) {
37 if ((spec.tmux % boardTMUX_) != 0)
40 ", is not a multiple of the board TMUX, " +
std::to_string(boardTMUX_));
42 const size_t tmuxRatio(spec.tmux / boardTMUX_);
43 if (
indices.size() != tmuxRatio)
46 ", does not match link:board TMUX ratio, " +
std::to_string(tmuxRatio));
48 maxEventsPerFile_ =
std::min(maxEventsPerFile_,
49 ((maxFramesPerFile_ - spec.offset) / (framesPerBX_ * boardTMUX_)) - (tmuxRatio - 1));
58 const size_t framesPerBX,
60 const size_t maxFramesPerFile,
62 const std::map<std::string, ChannelSpec>& channelSpecs)
64 format,
path, fileExt, framesPerBX, tmux, maxFramesPerFile, mergeMaps(channelMap, channelSpecs)) {}
71 if (not eventData.
has(
id))
76 for (
const auto& [
id, channelData] : eventData) {
80 "] was given to BoardDataWriter, but its structure was not defined");
86 if (channelData.size() > (spec.tmux *
framesPerBX_ - spec.interpacketGap))
89 " cycles between packets) is too long (" +
std::to_string(channelData.size()) +
92 if (channelData.empty())
100 BoardData::Channel::iterator
it(
boardData_.
at(chanIndex).end() - 1);
101 it->endOfPacket =
true;
102 it -= (channelData.size() - 1);
103 it->startOfPacket =
true;
127 for (
auto&
frame :
x.second) {
128 if (
frame.startOfPacket) {
129 frame.startOfOrbit =
true;
148 const std::map<std::string, ChannelSpec>& specMap) {
150 for (
const auto&
x : indexMap)
151 channelMap[
x.first] = {specMap.at(
x.first.interface),
x.second};
161 for (
size_t tmuxIndex = 0; tmuxIndex <
indices.size(); tmuxIndex++)
std::bitset< TTBV::S_ > Frame
Logical ID for link within any given time slice (e.g. ["tracks", 0] -> ["tracks", 17] for links from ...
BoardDataWriter(FileFormat, const std::string &filePath, const std::string &fileExt, const size_t framesPerBX, const size_t tmux, const size_t maxFramesPerFile, const ChannelMap_t &)
void addEvent(const EventData &data)
static std::string to_string(const XMLCh *ch)
void write(const BoardData &, const std::string &filePath, const FileFormat)
std::function< std::string(const size_t)> filePathGen_
static ChannelMap_t mergeMaps(const std::map< LinkId, std::vector< size_t >> &, const std::map< std::string, ChannelSpec > &)
filePath
CUSTOMIZE FOR ML.
std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t
const std::string & name() const
std::string boardDataFileID_
std::vector< std::string > fileNames_
void setBoardDataFileID(const std::string &)
Class representing information phase-2 ATCA I/O data corresponding to a single event, with logical channel IDs (essentially string-uint pairs, e.g. tracks-0 to tracks-17).
bool has(const LinkId &) const