CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
amc13::Packet Class Reference

#include <AMC13Spec.h>

Public Member Functions

void add (unsigned int amc_no, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector< uint64_t > &load, unsigned int user=0)
 
unsigned int blocks () const
 
 Packet ()
 
bool parse (const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
 
std::vector< amc::Packetpayload () const
 
unsigned int size () const
 
bool write (const edm::Event &ev, unsigned char *ptr, unsigned int skip, unsigned int size) const
 

Private Attributes

Header header_
 
std::vector< amc::Packetpayload_
 

Detailed Description

Definition at line 69 of file AMC13Spec.h.

Constructor & Destructor Documentation

◆ Packet()

amc13::Packet::Packet ( )
inline

Definition at line 71 of file AMC13Spec.h.

71 {};

Member Function Documentation

◆ add()

void Packet::add ( unsigned int  amc_no,
unsigned int  board,
unsigned int  lv1id,
unsigned int  orbit,
unsigned int  bx,
const std::vector< uint64_t > &  load,
unsigned int  user = 0 
)

Definition at line 47 of file AMC13Spec.cc.

References simKBmtfDigis_cfi::bx, svgfig::load(), payload_, and EnviromentSettings::user.

Referenced by counter.Counter::register(), SequenceTypes._TaskBase::remove(), and SequenceTypes._TaskBase::replace().

53  {
54  edm::LogInfo("AMC") << "Adding board " << board << " with payload size " << load.size() << " as payload #"
55  << amc_no;
56  // Start by indexing with 1
57  payload_.push_back(amc::Packet(amc_no, board, lv1id, orbit, bx, load, user));
58  }
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:96
Log< level::Info, false > LogInfo
def load(fileName)
Definition: svgfig.py:547

◆ blocks()

unsigned int Packet::blocks ( ) const

Definition at line 177 of file AMC13Spec.cc.

References SiStripPI::max, and payload_.

Referenced by size(), and write().

177  {
178  unsigned int maxblocks = 0;
179 
180  for (const auto& amc : payload_)
181  maxblocks = std::max(maxblocks, amc.blocks());
182 
183  return maxblocks;
184  }
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:96
Definition: AMCSpec.h:8

◆ parse()

bool Packet::parse ( const uint64_t *  start,
const uint64_t *  data,
unsigned int  size,
unsigned int  lv1,
unsigned int  bx,
bool  legacy_mc = false,
bool  mtf7_mode = false 
)

Definition at line 60 of file AMC13Spec.cc.

References b, simKBmtfDigis_cfi::bx, amc13::Header::check(), RPCNoise_example::check, cms::CRC32Calculator::checksum(), data, TauDecayModes::dec, amc13::Header::getFormatVersion(), amc13::Header::getNumberOfAMCs(), header_, getRunAppsInfo::headers, mps_fire::i, LogDebug, SiStripPI::max, payload_, size(), AlCaHLTBitMon_QueryRunRegistry::string, and submitPVValidationJobs::t.

Referenced by L1TMP7ZeroSupp::analyze(), L1UpgradeTfMuonTreeProducer::getAlgoFwVersion(), dqmBmtfAlgoSelector::L1TBMTFAlgoSelector::produce(), l1t::L1TRawToDigi::produce(), and omtf::OmtfUnpacker::produce().

66  {
67  // Need at least a header and trailer
68  // TODO check if this can be removed
69  if (size < 2) {
70  edm::LogError("AMC") << "AMC13 packet size too small";
71  return false;
72  }
73 
74  std::map<int, int> amc_index;
75 
76  header_ = Header(data++);
77 
78  if (!header_.check()) {
79  edm::LogError("AMC") << "Invalid header for AMC13 packet: "
80  << "format version " << header_.getFormatVersion() << ", " << header_.getNumberOfAMCs()
81  << " AMC packets";
82  return false;
83  }
84 
85  if (size < 2 + header_.getNumberOfAMCs())
86  return false;
87 
88  // Initial filling of AMC payloads. First, get the headers. The
89  // first payload follows afterwards.
90  for (unsigned int i = 0; i < header_.getNumberOfAMCs(); ++i) {
91  payload_.push_back(amc::Packet(data++));
92  amc_index[payload_.back().blockHeader().getAMCNumber()] = i;
93  }
94 
95  unsigned int tot_size = 0; // total payload size
96  unsigned int tot_nblocks = 0; // total blocks of payload
97  unsigned int maxblocks = 0; // counting the # of amc13 header/trailers (1 ea per block)
98 
99  bool check_crc = false;
100  for (const auto& amc : payload_) {
101  tot_size += amc.blockHeader().getSize();
102  tot_nblocks += amc.blockHeader().getBlocks();
103  maxblocks = std::max(maxblocks, amc.blockHeader().getBlocks());
104 
105  if (amc.blockHeader().validCRC())
106  check_crc = true;
107  }
108 
109  unsigned int words = tot_size + // payload size
110  tot_nblocks + // AMC headers
111  2 * maxblocks; // AMC13 headers
112 
113  if (size < words) {
114  edm::LogError("L1T") << "Encountered AMC 13 packet with " << size << " words, "
115  << "but expected " << words << " words: " << tot_size << " payload words, " << tot_nblocks
116  << " AMC header words, and 2 AMC 13 header words.";
117  return false;
118  }
119 
120  // Read in the first AMC block and append the payload to the
121  // corresponding AMC packet.
122  for (auto& amc : payload_) {
123  amc.addPayload(data, amc.blockHeader().getBlockSize());
124  data += amc.blockHeader().getBlockSize();
125  }
126 
127  Trailer t(data++);
128 
129  int crc = 0;
130  if (check_crc) {
131  std::string check(reinterpret_cast<const char*>(start), reinterpret_cast<const char*>(data) - 4);
133 
134  LogDebug("L1T") << "checking data checksum of " << std::hex << crc << std::dec;
135  }
136 
137  t.check(crc, 0, lv1, bx);
138 
139  // Read in remaining AMC blocks
140  for (unsigned int b = 1; b < maxblocks; ++b) {
141  Header block_h(data++);
142  std::vector<amc::BlockHeader> headers;
143 
144  for (unsigned int i = 0; i < block_h.getNumberOfAMCs(); ++i)
145  headers.push_back(amc::BlockHeader(data++));
146 
147  check_crc = false;
148  for (const auto& amc : headers) {
149  payload_[amc_index[amc.getAMCNumber()]].addPayload(data, amc.getBlockSize());
150  data += amc.getBlockSize();
151 
152  if (amc.validCRC())
153  check_crc = true;
154  }
155 
156  t = Trailer(data++);
157 
158  if (check_crc) {
159  std::string check(reinterpret_cast<const char*>(start), reinterpret_cast<const char*>(data) - 4);
161 
162  LogDebug("L1T") << "checking data checksum of " << std::hex << crc << std::dec;
163  } else {
164  crc = 0;
165  }
166 
167  t.check(crc, b, lv1, bx);
168  }
169 
170  for (auto& amc : payload_) {
171  amc.finalize(lv1, bx, legacy_mc, mtf7_mode);
172  }
173 
174  return true;
175  }
Definition: start.py:1
Header header_
Definition: AMC13Spec.h:92
bool check() const
Definition: AMC13Spec.cc:19
Log< level::Error, false > LogError
unsigned int size() const
Definition: AMC13Spec.cc:186
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:96
unsigned int getFormatVersion() const
Definition: AMC13Spec.h:24
double b
Definition: hdecay.h:118
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::uint32_t checksum()
Definition: AMCSpec.h:8
unsigned int getNumberOfAMCs() const
Definition: AMC13Spec.h:25
#define LogDebug(id)

◆ payload()

std::vector<amc::Packet> amc13::Packet::payload ( ) const
inline

◆ size()

unsigned int Packet::size ( void  ) const

Definition at line 186 of file AMC13Spec.cc.

References blocks(), SiStripPI::max, and payload_.

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), parse(), and write().

186  {
187  unsigned int words = 0;
188  unsigned int blocks = 0;
189  unsigned int maxblocks = 0;
190 
191  for (const auto& amc : payload_) {
192  words += amc.header().getSize();
193  blocks += amc.blocks();
194  maxblocks = std::max(maxblocks, amc.blocks());
195  }
196 
197  // Size is total amount of words + # of blocks for AMC headers + # of
198  // maxblocks for AMC13 block header, trailer
199  return words + blocks + maxblocks * 2;
200  }
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:96
unsigned int blocks() const
Definition: AMC13Spec.cc:177
Definition: AMCSpec.h:8

◆ write()

bool Packet::write ( const edm::Event ev,
unsigned char *  ptr,
unsigned int  skip,
unsigned int  size 
) const

Definition at line 202 of file AMC13Spec.cc.

References b, blocks(), data, makeMEIFBenchmarkPlots::ev, h, payload_, size(), optionsL1T::skip, and amc13::Trailer::writeCRC().

Referenced by pkg.AbstractPkg::generate().

202  {
203  if (size < this->size() * 8)
204  return false;
205 
206  if (size % 8 != 0)
207  return false;
208 
209  uint64_t* data = reinterpret_cast<uint64_t*>(ptr + skip);
210 
211  for (unsigned int b = 0; b < blocks(); ++b) {
212  // uint64_t * block_start = data;
213 
214  std::vector<uint64_t> block_headers;
215  std::vector<uint64_t> block_load;
216  for (const auto& amc : payload_) {
217  edm::LogInfo("AMC") << "Considering block " << b << " for payload " << amc.blockHeader().getBoardID()
218  << " with size " << amc.size() << " and " << amc.blocks() << " blocks";
219  if (amc.blocks() < b + 1)
220  continue;
221 
222  block_headers.push_back(amc.blockHeader(b));
223  auto words = amc.block(b);
224  block_load.insert(block_load.end(), words.begin(), words.end());
225  }
226 
227  if (b == 0) {
228  amc13::Header h(block_headers.size(), ev.orbitNumber());
229  edm::LogInfo("AMC") << "Writing header for AMC13 packet: "
230  << "format version " << h.getFormatVersion() << ", " << h.getNumberOfAMCs()
231  << " AMC packets, orbit " << h.getOrbitNumber();
232  }
233 
234  *(data++) = amc13::Header(block_headers.size(), ev.orbitNumber()).raw();
235 
236  block_headers.insert(block_headers.end(), block_load.begin(), block_load.end());
237  for (const auto& word : block_headers)
238  *(data++) = word;
239 
240  *data = Trailer(b, ev.id().event(), ev.bunchCrossing()).raw();
241  Trailer::writeCRC(reinterpret_cast<uint64_t*>(ptr), data);
242  }
243 
244  return true;
245  }
static void writeCRC(const uint64_t *start, uint64_t *end)
Definition: AMC13Spec.cc:40
unsigned int size() const
Definition: AMC13Spec.cc:186
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:96
uint64_t word
Log< level::Info, false > LogInfo
unsigned long long uint64_t
Definition: Time.h:13
double b
Definition: hdecay.h:118
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned int blocks() const
Definition: AMC13Spec.cc:177
Definition: AMCSpec.h:8
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

Member Data Documentation

◆ header_

Header amc13::Packet::header_
private

Definition at line 92 of file AMC13Spec.h.

Referenced by parse().

◆ payload_

std::vector<amc::Packet> amc13::Packet::payload_
private

Definition at line 96 of file AMC13Spec.h.

Referenced by add(), blocks(), parse(), payload(), size(), and write().