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 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 130 of file AMCSpec.h.

Constructor & Destructor Documentation

amc13::Packet::Packet ( )
inline

Definition at line 132 of file AMCSpec.h.

132 {};

Member Function Documentation

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

Definition at line 133 of file AMCSpec.cc.

References svgfig::load(), and payload_.

Referenced by counter.Counter::register().

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

Definition at line 258 of file AMCSpec.cc.

References amc, bookConverter::max, and payload_.

Referenced by size(), and write().

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

Definition at line 141 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().

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

Definition at line 141 of file AMCSpec.h.

References payload_.

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

Definition at line 269 of file AMCSpec.cc.

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

Referenced by write().

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

Definition at line 287 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 pkg.AbstractPkg::generate().

288  {
289  if (size < this->size() * 8)
290  return false;
291 
292  if (size % 8 != 0)
293  return false;
294 
295  uint64_t * data = reinterpret_cast<uint64_t*>(ptr);
296 
297  for (unsigned int b = 0; b < blocks(); ++b) {
298  uint64_t * block_start = data;
299 
300  std::vector<uint64_t> block_headers;
301  std::vector<uint64_t> block_load;
302  for (const auto& amc: payload_) {
303  edm::LogInfo("AMC")
304  << "Considering block " << b
305  << " for payload " << amc.header().getBoardID()
306  << " with size " << amc.size()
307  << " and " << amc.blocks() << " blocks";
308  if (amc.blocks() < b + 1)
309  continue;
310 
311  block_headers.push_back(amc.header(b));
312  auto words = amc.block(b);
313  block_load.insert(block_load.end(), words.begin(), words.end());
314  }
315 
316  if (b == 0) {
317  amc13::Header h(block_headers.size(), ev.orbitNumber());
318  edm::LogInfo("AMC")
319  << "Writing header for AMC13 packet: "
320  << "format version " << h.getFormatVersion()
321  << ", " << h.getNumberOfAMCs()
322  << " AMC packets, orbit " << h.getOrbitNumber();
323  }
324 
325  *(data++) = amc13::Header(block_headers.size(), ev.orbitNumber()).raw();
326 
327  block_headers.insert(block_headers.end(), block_load.begin(), block_load.end());
328  for (const auto& word: block_headers)
329  *(data++) = word;
330 
331  std::string dstring(reinterpret_cast<char*>(block_start), reinterpret_cast<char*>(data));
332  cms::CRC32Calculator crc(dstring);
333  *(data++) = Trailer(crc.checksum(), b, ev.id().event(), ev.bunchCrossing()).raw();
334  }
335 
336  return true;
337  }
EventNumber_t event() const
Definition: EventID.h:41
unsigned int size() const
Definition: AMCSpec.cc:269
unsigned int blocks() const
Definition: AMCSpec.cc:258
int bunchCrossing() const
Definition: EventBase.h:62
std::vector< amc::Packet > payload_
Definition: AMCSpec.h:145
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:63
unsigned long long uint64_t
Definition: Time.h:15
double b
Definition: hdecay.h:120
edm::EventID id() const
Definition: EventBase.h:56
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82

Member Data Documentation

Header amc13::Packet::header_
private

Definition at line 141 of file AMCSpec.h.

Referenced by parse().

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

Definition at line 145 of file AMCSpec.h.

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