CMS 3D CMS Logo

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

#include <BoardDataReader.h>

Public Types

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

Public Member Functions

 BoardDataReader (FileFormat, const std::vector< std::string > &, const size_t framesPerBX, const size_t tmux, const size_t emptyFramesAtStart, const ChannelMap_t &)
 
 BoardDataReader (FileFormat, const std::vector< std::string > &, const size_t framesPerBX, const size_t tmux, const size_t emptyFramesAtStart, const std::map< LinkId, std::vector< size_t >> &, const std::map< std::string, ChannelSpec > &)
 
EventData getNextEvent ()
 

Static Private Member Functions

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

Private Attributes

size_t boardTMUX_
 
ChannelMap_t channelMap_
 
size_t emptyFramesAtStart_
 
std::vector< EventData >::const_iterator eventIt_
 
std::vector< EventDataevents_
 
FileFormat fileFormat_
 
std::vector< std::string > fileNames_
 
size_t framesPerBX_
 

Detailed Description

Definition at line 21 of file BoardDataReader.h.

Member Typedef Documentation

◆ ChannelMap_t

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

Definition at line 24 of file BoardDataReader.h.

Constructor & Destructor Documentation

◆ BoardDataReader() [1/2]

l1t::demo::BoardDataReader::BoardDataReader ( FileFormat  format,
const std::vector< std::string > &  fileNames,
const size_t  framesPerBX,
const size_t  tmux,
const size_t  emptyFramesAtStart,
const ChannelMap_t channelMap 
)

Definition at line 10 of file BoardDataReader.cc.

References l1t::demo::EventData::add(), l1t::demo::BoardData::at(), boardTMUX_, channelMap_, emptyFramesAtStart_, eventIt_, events_, fileFormat_, fileNames_, framesPerBX_, l1t::demo::BoardData::has(), mps_fire::i, dqmdumpme::indices, l1ctLayer2EG_cff::interface, dqmiolumiharvest::j, castor_dqm_sourceclient_file_cfg::path, l1t::demo::read(), cond::impl::to_string(), and relativeConstraints::value.

18  framesPerBX_(framesPerBX),
19  boardTMUX_(tmux),
20  emptyFramesAtStart_(emptyFramesAtStart),
21  channelMap_(channelMap),
22  events_() {
23  // TODO (long term): Move much of this to separate function, and only read files on demand
24 
25  // Verify that channel map/spec is self-consistent
26  for (const auto& [id, value] : channelMap_) {
27  const auto& [spec, indices] = value;
28  if ((spec.tmux % boardTMUX_) != 0)
29  throw std::runtime_error("Link [" + id.interface + ", " + std::to_string(id.channel) +
30  "]: Specified TMUX period, " + std::to_string(spec.tmux) +
31  ", is not a multiple of the board TMUX, " + std::to_string(boardTMUX_));
32 
33  const size_t tmuxRatio(spec.tmux / boardTMUX_);
34  if (indices.size() != tmuxRatio)
35  throw std::runtime_error("Link [" + id.interface + ", " + std::to_string(id.channel) +
36  "]: Number of channel indices specified, " + std::to_string(indices.size()) +
37  ", does not match link:board TMUX ratio");
38  }
39 
40  // Loop over input files
41  for (const auto& path : fileNames_) {
42  BoardData boardData(read(path, fileFormat_));
43 
44  // 1) Verify that all expected channels are present
45  for (const auto& [id, value] : channelMap_) {
46  const auto& [spec, indices] = value;
47  for (const auto i : indices) {
48  if (not boardData.has(i))
49  throw std::runtime_error("Channel " + std::to_string(i) + " was declared but is missing from file '" +
50  path + "'");
51  }
52  }
53 
54  // 2) Verify that packet structure is as expected
55  for (const auto& [id, value] : channelMap) {
56  const auto& [spec, indices] = value;
57  for (size_t tmuxIndex = 0; tmuxIndex < indices.size(); tmuxIndex++) {
58  const auto& chanData = boardData.at(indices.at(tmuxIndex));
59 
60  const size_t framesBeforeFirstPacket(emptyFramesAtStart_ + tmuxIndex * boardTMUX_ * framesPerBX_ +
61  spec.offset);
62  const size_t eventLength(spec.tmux * framesPerBX_);
63  const size_t packetLength(eventLength - spec.interpacketGap);
64 
65  for (size_t j = 0; j < framesBeforeFirstPacket; j++) {
66  if (chanData.at(j).valid)
67  throw std::runtime_error("Frame " + std::to_string(j) + " on channel " +
68  std::to_string(indices.at(tmuxIndex)) + " is valid, but first " +
69  std::to_string(framesBeforeFirstPacket) + "frames should be invalid");
70  }
71 
72  for (size_t j = framesBeforeFirstPacket; j < chanData.size(); j++) {
73  if ((j + (framesPerBX_ * spec.tmux)) >= chanData.size())
74  continue;
75 
76  bool expectValid(((j - framesBeforeFirstPacket) % eventLength) < packetLength);
77 
78  if (expectValid) {
79  if (not chanData.at(j).valid)
80  throw std::runtime_error("Frame " + std::to_string(j) + " on channel " +
81  std::to_string(indices.at(tmuxIndex)) +
82  " is invalid, but expected valid frame");
83  } else if (chanData.at(j).valid)
84  throw std::runtime_error("Frame " + std::to_string(j) + " on channel " +
85  std::to_string(indices.at(tmuxIndex)) + " is valid, but expected invalid frame");
86  }
87  }
88  }
89 
90  // 3) Extract the data for each event
91  bool eventIncomplete(false);
92  for (size_t eventIndex = 0;; eventIndex++) {
93  EventData eventData;
94 
95  for (const auto& [id, value] : channelMap) {
96  const auto& [spec, indices] = value;
97  const auto& chanData = boardData.at(indices.at(eventIndex % (spec.tmux / boardTMUX_)));
98 
99  // Extract the frames for this event
100  const size_t framesBeforeEvent(eventIndex * boardTMUX_ * framesPerBX_ + emptyFramesAtStart_ + spec.offset);
101  const size_t packetLength(spec.tmux * framesPerBX_ - spec.interpacketGap);
102 
103  if (chanData.size() < (framesBeforeEvent + spec.tmux * framesPerBX_)) {
104  eventIncomplete = true;
105  break;
106  }
107 
108  std::vector<ap_uint<64>> chanEventData(packetLength);
109  for (size_t j = 0; j < packetLength; j++)
110  chanEventData.at(j) = chanData.at(framesBeforeEvent + j).data;
111  eventData.add(id, chanEventData);
112  }
113 
114  if (eventIncomplete)
115  break;
116 
117  events_.push_back(eventData);
118  }
119  }
120 
121  eventIt_ = events_.begin();
122  }
std::string to_string(const V &value)
Definition: OMSAccess.h:77
Definition: value.py:1
std::vector< std::string > fileNames_
BoardData read(const std::string &filePath, const FileFormat)
Definition: utilities.cc:91
std::vector< EventData >::const_iterator eventIt_
std::vector< EventData > events_

◆ BoardDataReader() [2/2]

l1t::demo::BoardDataReader::BoardDataReader ( FileFormat  format,
const std::vector< std::string > &  fileNames,
const size_t  framesPerBX,
const size_t  tmux,
const size_t  emptyFramesAtStart,
const std::map< LinkId, std::vector< size_t >> &  channelMap,
const std::map< std::string, ChannelSpec > &  channelSpecs 
)

Definition at line 124 of file BoardDataReader.cc.

131  : BoardDataReader(format, fileNames, framesPerBX, tmux, emptyFramesAtStart, mergeMaps(channelMap, channelSpecs)) {
132  }
BoardDataReader(FileFormat, const std::vector< std::string > &, const size_t framesPerBX, const size_t tmux, const size_t emptyFramesAtStart, const ChannelMap_t &)
static ChannelMap_t mergeMaps(const std::map< LinkId, std::vector< size_t >> &, const std::map< std::string, ChannelSpec > &)

Member Function Documentation

◆ getNextEvent()

EventData l1t::demo::BoardDataReader::getNextEvent ( )

Definition at line 134 of file BoardDataReader.cc.

References eventIt_, and events_.

Referenced by GTTFileReader::produce().

134  {
135  if (eventIt_ == events_.end())
136  throw std::runtime_error("Board data reader ran out of events");
137 
138  return *(eventIt_++);
139  }
std::vector< EventData >::const_iterator eventIt_
std::vector< EventData > events_

◆ mergeMaps()

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

Definition at line 141 of file BoardDataReader.cc.

References x.

142  {
143  ChannelMap_t channelMap;
144  for (const auto& x : indexMap)
145  channelMap.at(x.first) = {specMap.at(x.first.interface), x.second};
146  return channelMap;
147  }
std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t

Member Data Documentation

◆ boardTMUX_

size_t l1t::demo::BoardDataReader::boardTMUX_
private

Definition at line 53 of file BoardDataReader.h.

Referenced by BoardDataReader().

◆ channelMap_

ChannelMap_t l1t::demo::BoardDataReader::channelMap_
private

Definition at line 58 of file BoardDataReader.h.

Referenced by BoardDataReader().

◆ emptyFramesAtStart_

size_t l1t::demo::BoardDataReader::emptyFramesAtStart_
private

Definition at line 55 of file BoardDataReader.h.

Referenced by BoardDataReader().

◆ eventIt_

std::vector<EventData>::const_iterator l1t::demo::BoardDataReader::eventIt_
private

Definition at line 62 of file BoardDataReader.h.

Referenced by BoardDataReader(), and getNextEvent().

◆ events_

std::vector<EventData> l1t::demo::BoardDataReader::events_
private

Definition at line 60 of file BoardDataReader.h.

Referenced by BoardDataReader(), and getNextEvent().

◆ fileFormat_

FileFormat l1t::demo::BoardDataReader::fileFormat_
private

Definition at line 47 of file BoardDataReader.h.

Referenced by BoardDataReader().

◆ fileNames_

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

Definition at line 49 of file BoardDataReader.h.

Referenced by BoardDataReader().

◆ framesPerBX_

size_t l1t::demo::BoardDataReader::framesPerBX_
private

Definition at line 51 of file BoardDataReader.h.

Referenced by BoardDataReader().