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 size_t framesPerBX, const size_t tmux, const size_t maxFramesPerFile, const ChannelMap_t &)
 
 BoardDataWriter (FileFormat, const std::string &filePath, 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 ()
 

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_
 
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 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 cond::impl::to_string().

17  filePathGen_([=](const size_t i) { return path + "_" + std::to_string(i) + ".txt"; }),
18  framesPerBX_(framesPerBX),
19  boardTMUX_(tmux),
20  maxFramesPerFile_(maxFramesPerFile),
22  eventIndex_(0),
23  pendingEvents_(0),
24  channelMap_(channelSpecs) {
25  if (channelMap_.empty())
26  throw std::runtime_error("BoardDataWriter channel map cannnot be empty");
27 
28  for (const auto& [id, value] : channelMap_) {
29  const auto& [spec, indices] = value;
30  for (const auto i : indices)
31  boardData_.add(i);
32 
33  if ((spec.tmux % boardTMUX_) != 0)
34  throw std::runtime_error("BoardDataWriter, link [" + id.interface + ", " + std::to_string(id.channel) +
35  "]: Specified TMUX period, " + std::to_string(spec.tmux) +
36  ", is not a multiple of the board TMUX, " + std::to_string(boardTMUX_));
37 
38  const size_t tmuxRatio(spec.tmux / boardTMUX_);
39  if (indices.size() != tmuxRatio)
40  throw std::runtime_error("BoardDataWriter, link [" + id.interface + ", " + std::to_string(id.channel) +
41  "]: Number of channel indices specified, " + std::to_string(indices.size()) +
42  ", does not match link:board TMUX ratio, " + std::to_string(tmuxRatio));
43 
45  ((maxFramesPerFile_ - spec.offset) / (framesPerBX_ * boardTMUX_)) - (tmuxRatio - 1));
46  }
47 
49  }
Channel & add(size_t)
Definition: BoardData.cc:25
std::string to_string(const V &value)
Definition: OMSAccess.h:71
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 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 51 of file BoardDataWriter.cc.

58  : BoardDataWriter(format, path, framesPerBX, tmux, maxFramesPerFile, mergeMaps(channelMap, channelSpecs)) {}
BoardDataWriter(FileFormat, const std::string &filePath, 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 60 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, maxEventsPerFile_, pendingEvents_, and cond::impl::to_string().

Referenced by L1CTJetFileWriter::analyze(), and GTTFileWriter::analyze().

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

◆ flush()

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

Definition at line 109 of file BoardDataWriter.cc.

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

Referenced by addEvent(), L1CTJetFileWriter::endJob(), and GTTFileWriter::endJob().

109  {
110  if (pendingEvents_ == 0)
111  return;
112 
113  // Pad any channels that aren't full with invalid frames
114  for (auto& x : boardData_)
115  x.second.resize(maxFramesPerFile_);
116 
117  // Write board data object to file
120  fileNames_.push_back(filePath);
121 
122  // Clear board data to be ready for next event
123  resetBoardData();
124  }
void write(const BoardData &, const std::string &filePath, const FileFormat)
Definition: utilities.cc:270
std::function< std::string(const size_t)> filePathGen_
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 126 of file BoardDataWriter.cc.

References x.

127  {
128  ChannelMap_t channelMap;
129  for (const auto& x : indexMap)
130  channelMap[x.first] = {specMap.at(x.first.interface), x.second};
131  return channelMap;
132  }
std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t

◆ resetBoardData()

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

Definition at line 134 of file BoardDataWriter.cc.

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

Referenced by flush().

134  {
135  for (auto& x : boardData_)
136  x.second.clear();
137 
138  for (const auto& [id, value] : channelMap_) {
139  const auto& [spec, indices] = value;
140  for (size_t tmuxIndex = 0; tmuxIndex < indices.size(); tmuxIndex++)
141  boardData_.at(indices.at(tmuxIndex)).resize(tmuxIndex * boardTMUX_ * framesPerBX_ + spec.offset);
142  }
143 
144  pendingEvents_ = 0;
145  }
Definition: value.py:1
Channel & at(size_t)
Definition: BoardData.cc:35

Member Data Documentation

◆ boardData_

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

Definition at line 70 of file BoardDataWriter.h.

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

◆ boardTMUX_

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

Definition at line 59 of file BoardDataWriter.h.

Referenced by addEvent(), and resetBoardData().

◆ channelMap_

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

Definition at line 73 of file BoardDataWriter.h.

Referenced by addEvent(), and resetBoardData().

◆ eventIndex_

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

Definition at line 65 of file BoardDataWriter.h.

Referenced by addEvent().

◆ fileFormat_

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

Definition at line 51 of file BoardDataWriter.h.

Referenced by flush().

◆ fileNames_

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

Definition at line 55 of file BoardDataWriter.h.

Referenced by flush().

◆ filePathGen_

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

Definition at line 53 of file BoardDataWriter.h.

Referenced by flush().

◆ framesPerBX_

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

Definition at line 57 of file BoardDataWriter.h.

Referenced by addEvent(), and resetBoardData().

◆ maxEventsPerFile_

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

Definition at line 63 of file BoardDataWriter.h.

Referenced by addEvent().

◆ maxFramesPerFile_

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

Definition at line 61 of file BoardDataWriter.h.

Referenced by flush().

◆ pendingEvents_

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

Definition at line 68 of file BoardDataWriter.h.

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