CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

amc13::Packet::Packet ( )
inline

Definition at line 71 of file AMC13Spec.h.

71 {};

Member Function Documentation

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 payload_.

Referenced by l1t::AMCDumpToRaw::formatAMC(), l1t::MP7BufferDumpToRaw::formatAMC(), omtf::OmtfPacker::produce(), counter.Counter::register(), SequenceTypes.Task::remove(), and SequenceTypes.Task::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
def load
Definition: svgfig.py:547
Log< level::Info, false > LogInfo
unsigned int Packet::blocks ( ) const

Definition at line 177 of file AMC13Spec.cc.

References amc, 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
double amc
Definition: hdecay.h:20
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 amc, b, trackerTree::check(), amc13::Header::check(), amc13::Trailer::check(), cms::CRC32Calculator::checksum(), TauDecayModes::dec, amc13::Header::getFormatVersion(), amc13::Header::getNumberOfAMCs(), header_, getRunAppsInfo::headers, mps_fire::i, LogDebug, SiStripPI::max, payload_, 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  }
Header header_
Definition: AMC13Spec.h:92
unsigned int size() const
Definition: AMC13Spec.cc:186
Log< level::Error, false > LogError
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:96
double amc
Definition: hdecay.h:20
double b
Definition: hdecay.h:118
unsigned int getNumberOfAMCs() const
Definition: AMC13Spec.h:25
unsigned int getFormatVersion() const
Definition: AMC13Spec.h:24
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::uint32_t checksum()
bool check() const
Definition: AMC13Spec.cc:19
#define LogDebug(id)
std::vector<amc::Packet> amc13::Packet::payload ( ) const
inline
unsigned int Packet::size ( void  ) const

Definition at line 186 of file AMC13Spec.cc.

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

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), l1t::AMCDumpToRaw::formatRaw(), l1t::MP7BufferDumpToRaw::formatRaw(), omtf::OmtfPacker::produce(), 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  }
unsigned int blocks() const
Definition: AMC13Spec.cc:177
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:96
double amc
Definition: hdecay.h:20
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 amc, b, blocks(), edm::EventBase::bunchCrossing(), data, edm::EventID::event(), h, edm::EventBase::id(), edm::EventBase::orbitNumber(), payload_, size(), createPayload::skip, and amc13::Trailer::writeCRC().

Referenced by l1t::AMCDumpToRaw::formatRaw(), l1t::MP7BufferDumpToRaw::formatRaw(), pkg.AbstractPkg::generate(), and omtf::OmtfPacker::produce().

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  }
EventNumber_t event() const
Definition: EventID.h:40
static void writeCRC(const uint64_t *start, uint64_t *end)
Definition: AMC13Spec.cc:40
unsigned int size() const
Definition: AMC13Spec.cc:186
unsigned int blocks() const
Definition: AMC13Spec.cc:177
int bunchCrossing() const
Definition: EventBase.h:64
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:96
uint64_t word
double amc
Definition: hdecay.h:20
int orbitNumber() const
Definition: EventBase.h:65
Log< level::Info, false > LogInfo
unsigned long long uint64_t
Definition: Time.h:13
double b
Definition: hdecay.h:118
edm::EventID id() const
Definition: EventBase.h:59
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
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 amc13::Packet::header_
private

Definition at line 92 of file AMC13Spec.h.

Referenced by parse().

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().