CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
l1t::demo::BoardDataWriter Class Reference

#include <BoardDataWriter.h>

Public Types

typedef std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t
 

Public Member Functions

void addEvent (const EventData &data)
 
 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 &)
 
 BoardDataWriter (FileFormat, const std::string &filePath, const std::string &fileExt, const size_t framesPerBX, const size_t tmux, const size_t maxFramesPerFile, const std::map< LinkId, std::vector< size_t >> &, const std::map< std::string, ChannelSpec > &)
 
void flush ()
 
void setBoardDataFileID (const std::string &)
 

Private Member Functions

void resetBoardData ()
 

Static Private Member Functions

static ChannelMap_t mergeMaps (const std::map< LinkId, std::vector< size_t >> &, const std::map< std::string, ChannelSpec > &)
 

Private Attributes

BoardData boardData_
 
std::string boardDataFileID_
 
size_t boardTMUX_
 
ChannelMap_t channelMap_
 
size_t eventIndex_
 
FileFormat fileFormat_
 
std::vector< std::string > fileNames_
 
std::function< std::string(const size_t)> filePathGen_
 
size_t framesPerBX_
 
size_t maxEventsPerFile_
 
size_t maxFramesPerFile_
 
size_t pendingEvents_
 

Detailed Description

Definition at line 20 of file BoardDataWriter.h.

Member Typedef Documentation

◆ ChannelMap_t

typedef std::map<LinkId, std::pair<ChannelSpec, std::vector<size_t> > > l1t::demo::BoardDataWriter::ChannelMap_t

Definition at line 23 of file BoardDataWriter.h.

Constructor & Destructor Documentation

◆ BoardDataWriter() [1/2]

l1t::demo::BoardDataWriter::BoardDataWriter ( FileFormat  format,
const std::string &  filePath,
const std::string &  fileExt,
const size_t  framesPerBX,
const size_t  tmux,
const size_t  maxFramesPerFile,
const ChannelMap_t channelSpecs 
)

Definition at line 10 of file BoardDataWriter.cc.

References mps_fire::i, castor_dqm_sourceclient_file_cfg::path, and to_string().

18  boardDataFileID_("CMSSW"),
19  filePathGen_([=](const size_t i) { return path + "_" + std::to_string(i) + "." + fileExt; }),
20  framesPerBX_(framesPerBX),
21  boardTMUX_(tmux),
22  maxFramesPerFile_(maxFramesPerFile),
24  eventIndex_(0),
25  pendingEvents_(0),
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");
31 
32  for (const auto& [id, value] : channelMap_) {
33  const auto& [spec, indices] = value;
34  for (const auto i : indices)
35  boardData_.add(i);
36 
37  if ((spec.tmux % boardTMUX_) != 0)
38  throw std::runtime_error("BoardDataWriter, link [" + id.interface + ", " + std::to_string(id.channel) +
39  "]: Specified TMUX period, " + std::to_string(spec.tmux) +
40  ", is not a multiple of the board TMUX, " + std::to_string(boardTMUX_));
41 
42  const size_t tmuxRatio(spec.tmux / boardTMUX_);
43  if (indices.size() != tmuxRatio)
44  throw std::runtime_error("BoardDataWriter, link [" + id.interface + ", " + std::to_string(id.channel) +
45  "]: Number of channel indices specified, " + std::to_string(indices.size()) +
46  ", does not match link:board TMUX ratio, " + std::to_string(tmuxRatio));
47 
49  ((maxFramesPerFile_ - spec.offset) / (framesPerBX_ * boardTMUX_)) - (tmuxRatio - 1));
50  }
51 
53  }
Channel & add(size_t)
Definition: BoardData.cc:27
static std::string to_string(const XMLCh *ch)
std::function< std::string(const size_t)> filePathGen_
Definition: value.py:1

◆ BoardDataWriter() [2/2]

l1t::demo::BoardDataWriter::BoardDataWriter ( FileFormat  format,
const std::string &  filePath,
const std::string &  fileExt,
const size_t  framesPerBX,
const size_t  tmux,
const size_t  maxFramesPerFile,
const std::map< LinkId, std::vector< size_t >> &  channelMap,
const std::map< std::string, ChannelSpec > &  channelSpecs 
)

Definition at line 55 of file BoardDataWriter.cc.

64  format, path, fileExt, framesPerBX, tmux, maxFramesPerFile, mergeMaps(channelMap, channelSpecs)) {}
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 &)
static ChannelMap_t mergeMaps(const std::map< LinkId, std::vector< size_t >> &, const std::map< std::string, ChannelSpec > &)

Member Function Documentation

◆ addEvent()

void l1t::demo::BoardDataWriter::addEvent ( const EventData data)

Definition at line 68 of file BoardDataWriter.cc.

References l1t::demo::BoardData::at(), boardData_, boardTMUX_, channelMap_, eventIndex_, flush(), framesPerBX_, l1t::demo::EventData::has(), dqmdumpme::indices, info(), l1ctLayer2EG_cff::interface, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, maxEventsPerFile_, pendingEvents_, and to_string().

Referenced by L1GTAlgoBoardWriter::analyze(), L1GTFinOrBoardWriter::analyze(), L1CTJetFileWriter::analyze(), GTTFileWriter::analyze(), L1GTOutputObjectWriter::analyze(), L1GTFinOrBoardWriter::endJob(), L1GTAlgoBoardWriter::endJob(), and L1GTEvaluationProducer::writeInputPatterns().

68  {
69  // Check that data is supplied for each channel
70  for (const auto& [id, info] : channelMap_) {
71  if (not eventData.has(id))
72  throw std::runtime_error("Event data for link [" + id.interface + ", " + std::to_string(id.channel) +
73  "] is missing.");
74  }
75 
76  for (const auto& [id, channelData] : eventData) {
77  // Check that each channel was declared to constructor
78  if (channelMap_.count(id) == 0)
79  throw std::runtime_error("Event data for link [" + id.interface + ", " + std::to_string(id.channel) +
80  "] was given to BoardDataWriter, but its structure was not defined");
81 
82  const auto& [spec, indices] = channelMap_.at(id);
83  const size_t chanIndex(indices.at(pendingEvents_ % (spec.tmux / boardTMUX_)));
84 
85  // Check that that expected amount of data has been provided
86  if (channelData.size() > (spec.tmux * framesPerBX_ - spec.interpacketGap))
87  throw std::runtime_error("Event data for link [" + id.interface + ", " + std::to_string(id.channel) +
88  "] (TMUX " + std::to_string(spec.tmux) + ", " + std::to_string(spec.interpacketGap) +
89  " cycles between packets) is too long (" + std::to_string(channelData.size()) +
90  " 64-bit words)");
91 
92  if (channelData.empty())
93  throw std::runtime_error("Event data for link [" + id.interface + ", " + std::to_string(id.channel) +
94  "] is empty");
95 
96  // Copy event data for this channel to board data object
97  boardData_.at(chanIndex).insert(boardData_.at(chanIndex).end(), channelData.begin(), channelData.end());
98 
99  // Override flags for start & end of event
100  BoardData::Channel::iterator it(boardData_.at(chanIndex).end() - 1);
101  it->endOfPacket = true;
102  it -= (channelData.size() - 1);
103  it->startOfPacket = true;
104 
105  // Pad link with non-valid frames
106  boardData_.at(chanIndex).insert(
107  boardData_.at(chanIndex).end(), spec.tmux * framesPerBX_ - channelData.size(), Frame());
108  }
109 
110  eventIndex_++;
111  pendingEvents_++;
112 
114  flush();
115  }
std::bitset< TTBV::S_ > Frame
Definition: TTTypes.h:58
static const TGPicture * info(bool iBackgroundIsBlack)
static std::string to_string(const XMLCh *ch)
Channel & at(size_t)
Definition: BoardData.cc:37

◆ flush()

void l1t::demo::BoardDataWriter::flush ( )

Definition at line 117 of file BoardDataWriter.cc.

References boardData_, boardDataFileID_, fileFormat_, fileNames_, dt4ml_dqm_sourceclient-live_cfg::filePath, filePathGen_, maxFramesPerFile_, l1t::demo::BoardData::name(), pendingEvents_, resetBoardData(), AlCaHLTBitMon_QueryRunRegistry::string, l1t::demo::write(), and x.

Referenced by addEvent(), L1GTFinOrBoardWriter::endJob(), L1GTAlgoBoardWriter::endJob(), L1CTJetFileWriter::endJob(), L1GTEvaluationProducer::endJob(), GTTFileWriter::endJob(), and L1GTOutputObjectWriter::endJob().

117  {
118  if (pendingEvents_ == 0)
119  return;
120 
121  // Pad any channels that aren't full with invalid frames
122  for (auto& x : boardData_)
123  x.second.resize(maxFramesPerFile_);
124 
125  // For each channel: Assert start_of_orbit for first clock cycle that start is asserted
126  for (auto& x : boardData_) {
127  for (auto& frame : x.second) {
128  if (frame.startOfPacket) {
129  frame.startOfOrbit = true;
130  break;
131  }
132  }
133  }
134 
135  // Set ID field for board data files
137 
138  // Write board data object to file
141  fileNames_.push_back(filePath);
142 
143  // Clear board data to be ready for next event
144  resetBoardData();
145  }
void write(const BoardData &, const std::string &filePath, const FileFormat)
Definition: utilities.cc:372
std::function< std::string(const size_t)> filePathGen_
const std::string & name() const
Definition: BoardData.cc:15
std::vector< std::string > fileNames_

◆ mergeMaps()

BoardDataWriter::ChannelMap_t l1t::demo::BoardDataWriter::mergeMaps ( const std::map< LinkId, std::vector< size_t >> &  indexMap,
const std::map< std::string, ChannelSpec > &  specMap 
)
staticprivate

Definition at line 147 of file BoardDataWriter.cc.

References x.

148  {
149  ChannelMap_t channelMap;
150  for (const auto& x : indexMap)
151  channelMap[x.first] = {specMap.at(x.first.interface), x.second};
152  return channelMap;
153  }
std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t

◆ resetBoardData()

void l1t::demo::BoardDataWriter::resetBoardData ( )
private

Definition at line 155 of file BoardDataWriter.cc.

References l1t::demo::BoardData::at(), boardData_, boardTMUX_, channelMap_, framesPerBX_, dqmdumpme::indices, pendingEvents_, relativeConstraints::value, and x.

Referenced by flush().

155  {
156  for (auto& x : boardData_)
157  x.second.clear();
158 
159  for (const auto& [id, value] : channelMap_) {
160  const auto& [spec, indices] = value;
161  for (size_t tmuxIndex = 0; tmuxIndex < indices.size(); tmuxIndex++)
162  boardData_.at(indices.at(tmuxIndex)).resize(tmuxIndex * boardTMUX_ * framesPerBX_ + spec.offset);
163  }
164 
165  pendingEvents_ = 0;
166  }
Definition: value.py:1
Channel & at(size_t)
Definition: BoardData.cc:37

◆ setBoardDataFileID()

void l1t::demo::BoardDataWriter::setBoardDataFileID ( const std::string &  aId)

Definition at line 66 of file BoardDataWriter.cc.

References boardDataFileID_.

66 { boardDataFileID_ = aId; }

Member Data Documentation

◆ boardData_

BoardData l1t::demo::BoardDataWriter::boardData_
private

Definition at line 78 of file BoardDataWriter.h.

Referenced by addEvent(), flush(), and resetBoardData().

◆ boardDataFileID_

std::string l1t::demo::BoardDataWriter::boardDataFileID_
private

Definition at line 59 of file BoardDataWriter.h.

Referenced by flush(), and setBoardDataFileID().

◆ boardTMUX_

size_t l1t::demo::BoardDataWriter::boardTMUX_
private

Definition at line 67 of file BoardDataWriter.h.

Referenced by addEvent(), and resetBoardData().

◆ channelMap_

ChannelMap_t l1t::demo::BoardDataWriter::channelMap_
private

Definition at line 81 of file BoardDataWriter.h.

Referenced by addEvent(), and resetBoardData().

◆ eventIndex_

size_t l1t::demo::BoardDataWriter::eventIndex_
private

Definition at line 73 of file BoardDataWriter.h.

Referenced by addEvent().

◆ fileFormat_

FileFormat l1t::demo::BoardDataWriter::fileFormat_
private

Definition at line 56 of file BoardDataWriter.h.

Referenced by flush().

◆ fileNames_

std::vector<std::string> l1t::demo::BoardDataWriter::fileNames_
private

Definition at line 63 of file BoardDataWriter.h.

Referenced by flush().

◆ filePathGen_

std::function<std::string(const size_t)> l1t::demo::BoardDataWriter::filePathGen_
private

Definition at line 61 of file BoardDataWriter.h.

Referenced by flush().

◆ framesPerBX_

size_t l1t::demo::BoardDataWriter::framesPerBX_
private

Definition at line 65 of file BoardDataWriter.h.

Referenced by addEvent(), and resetBoardData().

◆ maxEventsPerFile_

size_t l1t::demo::BoardDataWriter::maxEventsPerFile_
private

Definition at line 71 of file BoardDataWriter.h.

Referenced by addEvent().

◆ maxFramesPerFile_

size_t l1t::demo::BoardDataWriter::maxFramesPerFile_
private

Definition at line 69 of file BoardDataWriter.h.

Referenced by flush().

◆ pendingEvents_

size_t l1t::demo::BoardDataWriter::pendingEvents_
private

Definition at line 76 of file BoardDataWriter.h.

Referenced by addEvent(), flush(), and resetBoardData().