Skip to content

Commit

Permalink
Merge pull request #41768 from tswilliams/demonstrator-tools-new-emp-…
Browse files Browse the repository at this point in the history
…format-cmsswMaster

L1T demonstrator tools: Support for EMP v0.7.x buffer file format
  • Loading branch information
cmsbuild authored May 30, 2023
2 parents e4ab0e7 + 5a2215b commit 850b70c
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 45 deletions.
2 changes: 2 additions & 0 deletions L1Trigger/DemonstratorTools/interface/BoardData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace l1t::demo {

const std::string& name() const;

void name(const std::string& aName);

std::map<size_t, Channel>::const_iterator begin() const;

std::map<size_t, Channel>::iterator begin();
Expand Down
6 changes: 6 additions & 0 deletions L1Trigger/DemonstratorTools/interface/BoardDataWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ namespace l1t::demo {
const std::map<LinkId, std::vector<size_t>>&,
const std::map<std::string, ChannelSpec>&);

// Set ID string that's written at start of board data files
void setBoardDataFileID(const std::string&);

void addEvent(const EventData& data);

// If there are events that have not been written to file, forces creation of a board data file containing them
Expand All @@ -50,6 +53,9 @@ namespace l1t::demo {

FileFormat fileFormat_;

// ID string that's written at start of board data files
std::string boardDataFileID_;

std::function<std::string(const size_t)> filePathGen_;

std::vector<std::string> fileNames_;
Expand Down
7 changes: 6 additions & 1 deletion L1Trigger/DemonstratorTools/interface/FileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

namespace l1t::demo {

enum class FileFormat { APx, EMP, X20 };
enum class FileFormat {
APx,
EMPv1, //< Format used in EMP until version 0.6.x
EMPv2, //< Format used in EMP from verison 0.7.0
X2O
};

std::ostream& operator<<(std::ostream&, FileFormat);

Expand Down
5 changes: 3 additions & 2 deletions L1Trigger/DemonstratorTools/interface/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ namespace l1t::demo {
ap_uint<64> data{0};
bool valid{false};
bool strobe{true};
bool start{false};
bool end{false};
bool startOfOrbit{false};
bool startOfPacket{false};
bool endOfPacket{false};
};

} // namespace l1t::demo
Expand Down
2 changes: 2 additions & 0 deletions L1Trigger/DemonstratorTools/src/BoardData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace l1t::demo {

const std::string& BoardData::name() const { return name_; }

void BoardData::name(const std::string& aName) { name_ = aName; }

std::map<size_t, BoardData::Channel>::const_iterator BoardData::begin() const { return data_.begin(); }

std::map<size_t, BoardData::Channel>::iterator BoardData::begin() { return data_.begin(); }
Expand Down
22 changes: 19 additions & 3 deletions L1Trigger/DemonstratorTools/src/BoardDataWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace l1t::demo {
const size_t maxFramesPerFile,
const ChannelMap_t& channelSpecs)
: fileFormat_(format),
boardDataFileID_("CMSSW"),
filePathGen_([=](const size_t i) { return path + "_" + std::to_string(i) + ".txt"; }),
framesPerBX_(framesPerBX),
boardTMUX_(tmux),
Expand Down Expand Up @@ -57,6 +58,8 @@ namespace l1t::demo {
const std::map<std::string, ChannelSpec>& channelSpecs)
: BoardDataWriter(format, path, framesPerBX, tmux, maxFramesPerFile, mergeMaps(channelMap, channelSpecs)) {}

void BoardDataWriter::setBoardDataFileID(const std::string& aId) { boardDataFileID_ = aId; }

void BoardDataWriter::addEvent(const EventData& eventData) {
// Check that data is supplied for each channel
for (const auto& [id, info] : channelMap_) {
Expand Down Expand Up @@ -90,9 +93,9 @@ namespace l1t::demo {

// Override flags for start & end of event
BoardData::Channel::iterator it(boardData_.at(chanIndex).end() - 1);
it->end = true;
it->endOfPacket = true;
it -= (channelData.size() - 1);
it->start = true;
it->startOfPacket = true;

// Pad link with non-valid frames
boardData_.at(chanIndex).insert(
Expand All @@ -114,6 +117,19 @@ namespace l1t::demo {
for (auto& x : boardData_)
x.second.resize(maxFramesPerFile_);

// For each channel: Assert start_of_orbit for first clock cycle that start is asserted
for (auto& x : boardData_) {
for (auto& frame : x.second) {
if (frame.startOfPacket) {
frame.startOfOrbit = true;
break;
}
}
}

// Set ID field for board data files
boardData_.name(boardDataFileID_);

// Write board data object to file
const std::string filePath = filePathGen_(fileNames_.size());
write(boardData_, filePath, fileFormat_);
Expand Down Expand Up @@ -144,4 +160,4 @@ namespace l1t::demo {
pendingEvents_ = 0;
}

} // namespace l1t::demo
} // namespace l1t::demo
11 changes: 7 additions & 4 deletions L1Trigger/DemonstratorTools/src/FileFormat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ namespace l1t::demo {
case FileFormat::APx:
os << "APx";
break;
case FileFormat::EMP:
os << "EMP";
case FileFormat::EMPv1:
os << "EMPv1";
break;
case FileFormat::X20:
os << "X20";
case FileFormat::EMPv2:
os << "EMPv2";
break;
case FileFormat::X2O:
os << "X2O";
}
return os;
}
Expand Down
Loading

0 comments on commit 850b70c

Please sign in to comment.