CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
amc13::Packet Class Reference

#include <AMCSpec.h>

Public Member Functions

void add (unsigned int amc_no, unsigned int board, const std::vector< uint64_t > &load)
 
unsigned int blocks () const
 
 Packet ()
 
bool parse (const uint64_t *, unsigned int)
 
std::vector< amc::Packetpayload () const
 
unsigned int size () const
 
bool write (const edm::Event &ev, unsigned char *ptr, unsigned int size) const
 

Private Attributes

Header header_
 
std::vector< amc::Packetpayload_
 

Detailed Description

Definition at line 131 of file AMCSpec.h.

Constructor & Destructor Documentation

amc13::Packet::Packet ( )
inline

Definition at line 133 of file AMCSpec.h.

133 {};

Member Function Documentation

void Packet::add ( unsigned int  amc_no,
unsigned int  board,
const std::vector< uint64_t > &  load 
)

Definition at line 133 of file AMCSpec.cc.

References payload_.

Referenced by l1t::MP7BufferDumpToRaw::formatAMC(), and counter.Counter::register().

134  {
135  edm::LogInfo("AMC") << "Adding board " << board << " with payload size " << load.size()
136  << " as payload #" << amc_no;
137  // Start by indexing with 1
138  payload_.push_back(amc::Packet(amc_no, board, load));
139  }
std::vector< amc::Packet > payload_
Definition: AMCSpec.h:146
def load
Definition: svgfig.py:546
unsigned int Packet::blocks ( ) const

Definition at line 259 of file AMCSpec.cc.

References amc, bookConverter::max, and payload_.

Referenced by size(), and write().

260  {
261  unsigned int maxblocks = 0;
262 
263  for (const auto& amc: payload_)
264  maxblocks = std::max(maxblocks, amc.blocks());
265 
266  return maxblocks;
267  }
std::vector< amc::Packet > payload_
Definition: AMCSpec.h:146
double amc
Definition: hdecay.h:20
bool Packet::parse ( const uint64_t *  data,
unsigned int  size 
)

Definition at line 142 of file AMCSpec.cc.

References amc, b, DDVectorGetter::check(), cms::CRC32Calculator::checksum(), data, amc13::Trailer::getBlock(), amc13::Trailer::getCRC(), amc13::Header::getFormatVersion(), amc13::Header::getNumberOfAMCs(), amc13::Header::getOrbitNumber(), header_, getRunAppsInfo::headers, i, bookConverter::max, payload_, AlCaHLTBitMon_QueryRunRegistry::string, edmStreamStallGrapher::t, and amc13::Header::valid().

Referenced by l1t::L1TRawToDigi::produce().

143  {
144  // Need at least a header and trailer
145  // TODO check if this can be removed
146  if (size < 2) {
147  edm::LogError("AMC") << "AMC13 packet size too small";
148  return false;
149  }
150 
151  auto block_start = data;
152  header_ = Header(data++);
153 
154  if (!header_.valid()) {
155  edm::LogError("AMC")
156  << "Invalid header for AMC13 packet: "
157  << "format version " << header_.getFormatVersion()
158  << ", " << header_.getNumberOfAMCs()
159  << " AMC packets, orbit " << header_.getOrbitNumber();
160  return false;
161  }
162 
163  if (size < 2 + header_.getNumberOfAMCs())
164  return false;
165 
166  // Initial filling of AMC payloads. First, get the headers. The
167  // first payload follows afterwards.
168  for (unsigned int i = 0; i < header_.getNumberOfAMCs(); ++i) {
169  payload_.push_back(amc::Packet(data++));
170  }
171 
172  unsigned int tot_size = 0; // total payload size
173  unsigned int tot_nblocks = 0; // total blocks of payload
174  unsigned int maxblocks = 0; // counting the # of amc13 header/trailers (1 ea per block)
175 
176  for (const auto& amc: payload_) {
177  tot_size += amc.header().getSize();
178  tot_nblocks += amc.header().getBlocks();
179  maxblocks = std::max(maxblocks, amc.header().getBlocks());
180  }
181 
182  unsigned int words = tot_size + // payload size
183  tot_nblocks + // AMC headers
184  2 * maxblocks; // AMC13 headers
185 
186  if (size < words) {
187  edm::LogError("L1T")
188  << "Encountered AMC 13 packet with "
189  << size << " words, "
190  << "but expected "
191  << words << " words: "
192  << tot_size << " payload words, "
193  << tot_nblocks << " AMC header words, and 2 AMC 13 header words.";
194  return false;
195  }
196 
197  // Read in the first AMC block and append the payload to the
198  // corresponding AMC packet.
199  for (auto& amc: payload_) {
200  amc.addPayload(data, amc.header().getBlockSize());
201  data += amc.header().getBlockSize();
202  }
203  auto block_end = data;
204 
205  Trailer t(data++);
206 
207  std::string check(reinterpret_cast<const char*>(block_start), reinterpret_cast<const char*>(block_end));
209 
210  if (crc.checksum() != t.getCRC()) {
211  edm::LogWarning("L1T") << "Mismatch in checksums for block 0";
212  }
213 
214  if (t.getBlock() != 0 ) {
215  edm::LogWarning("L1T")
216  << "Block trailer mismatch: "
217  << "expected block 0, but trailer is for block "
218  << t.getBlock();
219  }
220 
221  // Read in remaining AMC blocks
222  for (unsigned int b = 1; b < maxblocks; ++b) {
223  block_start = data;
224 
225  Header block_h(data++);
226  std::vector<amc::Header> headers;
227 
228  for (unsigned int i = 0; i < block_h.getNumberOfAMCs(); ++i)
229  headers.push_back(amc::Header(data++));
230 
231  for (const auto& amc: headers) {
232  payload_[amc.getAMCNumber() - 1].addPayload(data, amc.getBlockSize());
233  data += amc.getBlockSize();
234  }
235 
236  block_end = data;
237 
238  t = Trailer(data++);
239 
240  check = std::string(reinterpret_cast<const char*>(block_start), reinterpret_cast<const char*>(block_end));
242 
243  if (crc.checksum() != t.getCRC()) {
244  edm::LogWarning("L1T") << "Mismatch in checksums for block " << b;
245  }
246 
247  if (t.getBlock() != 0 ) {
248  edm::LogWarning("L1T")
249  << "Block trailer mismatch: "
250  << "expected block " << b
251  << ", but trailer is for block " << t.getBlock();
252  }
253  }
254 
255  return true;
256  }
int i
Definition: DBlmapReader.cc:9
Header header_
Definition: AMCSpec.h:142
unsigned int size() const
Definition: AMCSpec.cc:270
bool valid()
Definition: AMCSpec.cc:118
std::vector< amc::Packet > payload_
Definition: AMCSpec.h:146
bool check(const std::string &)
double amc
Definition: hdecay.h:20
unsigned int getOrbitNumber() const
Definition: AMCSpec.h:90
double b
Definition: hdecay.h:120
unsigned int getNumberOfAMCs() const
Definition: AMCSpec.h:89
unsigned int getFormatVersion() const
Definition: AMCSpec.h:88
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::vector<amc::Packet> amc13::Packet::payload ( ) const
inline

Definition at line 142 of file AMCSpec.h.

References payload_.

Referenced by l1t::L1TRawToDigi::produce().

142 { return payload_; };
std::vector< amc::Packet > payload_
Definition: AMCSpec.h:146
unsigned int Packet::size ( void  ) const

Definition at line 270 of file AMCSpec.cc.

References amc, blocks(), bookConverter::max, and payload_.

Referenced by l1t::MP7BufferDumpToRaw::formatRaw(), and write().

271  {
272  unsigned int words = 0;
273  unsigned int blocks = 0;
274  unsigned int maxblocks = 0;
275 
276  for (const auto& amc: payload_) {
277  words += amc.size();
278  blocks += amc.blocks();
279  maxblocks = std::max(maxblocks, amc.blocks());
280  }
281 
282  // Size is total amount of words + # of blocks for AMC headers + # of
283  // maxblocks for AMC13 block header, trailer
284  return words + blocks + maxblocks * 2;
285  }
unsigned int blocks() const
Definition: AMCSpec.cc:259
std::vector< amc::Packet > payload_
Definition: AMCSpec.h:146
double amc
Definition: hdecay.h:20
bool Packet::write ( const edm::Event ev,
unsigned char *  ptr,
unsigned int  size 
) const

Definition at line 288 of file AMCSpec.cc.

References amc, b, blocks(), edm::EventBase::bunchCrossing(), cms::CRC32Calculator::checksum(), data, edm::EventID::event(), h, edm::EventBase::id(), edm::EventBase::orbitNumber(), payload_, size(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by l1t::MP7BufferDumpToRaw::formatRaw(), and pkg.AbstractPkg::generate().

289  {
290  if (size < this->size() * 8)
291  return false;
292 
293  if (size % 8 != 0)
294  return false;
295 
296  uint64_t * data = reinterpret_cast<uint64_t*>(ptr);
297 
298  for (unsigned int b = 0; b < blocks(); ++b) {
299  uint64_t * block_start = data;
300 
301  std::vector<uint64_t> block_headers;
302  std::vector<uint64_t> block_load;
303  for (const auto& amc: payload_) {
304  edm::LogInfo("AMC")
305  << "Considering block " << b
306  << " for payload " << amc.header().getBoardID()
307  << " with size " << amc.size()
308  << " and " << amc.blocks() << " blocks";
309  if (amc.blocks() < b + 1)
310  continue;
311 
312  block_headers.push_back(amc.header(b));
313  auto words = amc.block(b);
314  block_load.insert(block_load.end(), words.begin(), words.end());
315  }
316 
317  if (b == 0) {
318  amc13::Header h(block_headers.size(), ev.orbitNumber());
319  edm::LogInfo("AMC")
320  << "Writing header for AMC13 packet: "
321  << "format version " << h.getFormatVersion()
322  << ", " << h.getNumberOfAMCs()
323  << " AMC packets, orbit " << h.getOrbitNumber();
324  }
325 
326  *(data++) = amc13::Header(block_headers.size(), ev.orbitNumber()).raw();
327 
328  block_headers.insert(block_headers.end(), block_load.begin(), block_load.end());
329  for (const auto& word: block_headers)
330  *(data++) = word;
331 
332  std::string dstring(reinterpret_cast<char*>(block_start), reinterpret_cast<char*>(data));
333  cms::CRC32Calculator crc(dstring);
334  *(data++) = Trailer(crc.checksum(), b, ev.id().event(), ev.bunchCrossing()).raw();
335  }
336 
337  return true;
338  }
EventNumber_t event() const
Definition: EventID.h:41
unsigned int size() const
Definition: AMCSpec.cc:270
unsigned int blocks() const
Definition: AMCSpec.cc:259
int bunchCrossing() const
Definition: EventBase.h:66
std::vector< amc::Packet > payload_
Definition: AMCSpec.h:146
double amc
Definition: hdecay.h:20
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
int orbitNumber() const
Definition: EventBase.h:67
unsigned long long uint64_t
Definition: Time.h:15
double b
Definition: hdecay.h:120
edm::EventID id() const
Definition: EventBase.h:60
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82

Member Data Documentation

Header amc13::Packet::header_
private

Definition at line 142 of file AMCSpec.h.

Referenced by parse().

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

Definition at line 146 of file AMCSpec.h.

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