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

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 
)

Definition at line 61 of file AMC13Spec.cc.

Referenced by l1t::AMCDumpToRaw::formatAMC(), l1t::MP7BufferDumpToRaw::formatAMC(), l1t::L1TDigiToRaw::produce(), counter.Counter::register(), SequenceTypes.Task::remove(), and SequenceTypes.Task::replace().

62  {
63  edm::LogInfo("AMC") << "Adding board " << board << " with payload size " << load.size()
64  << " as payload #" << amc_no;
65  // Start by indexing with 1
66  payload_.push_back(amc::Packet(amc_no, board, lv1id, orbit, bx, load));
67  }
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:84
def load(fileName)
Definition: svgfig.py:546
unsigned int Packet::blocks ( ) const

Definition at line 189 of file AMC13Spec.cc.

References hpstanc_transforms::max.

190  {
191  unsigned int maxblocks = 0;
192 
193  for (const auto& amc: payload_)
194  maxblocks = std::max(maxblocks, amc.blocks());
195 
196  return maxblocks;
197  }
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:84
Definition: AMCSpec.h:8
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 70 of file AMC13Spec.cc.

References b, amc13::Header::check(), amc13::Trailer::check(), cms::CRC32Calculator::checksum(), TauDecayModes::dec, amc13::Header::getNumberOfAMCs(), amc13::Header::Header(), mps_fire::i, LogDebug, hpstanc_transforms::max, AlCaHLTBitMon_QueryRunRegistry::string, and lumiQTWidget::t.

Referenced by L1TMP7ZeroSupp::analyze(), and l1t::L1TRawToDigi::produce().

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

Definition at line 80 of file AMC13Spec.h.

Referenced by L1TMP7ZeroSupp::analyze(), and l1t::L1TRawToDigi::produce().

80 { return payload_; };
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:84
unsigned int Packet::size ( void  ) const

Definition at line 200 of file AMC13Spec.cc.

References gather_cfg::blocks, and hpstanc_transforms::max.

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), l1t::AMCDumpToRaw::formatRaw(), l1t::MP7BufferDumpToRaw::formatRaw(), l1t::L1TDigiToRaw::produce(), l1t::AMCDumpToRaw::produce(), and l1t::MP7BufferDumpToRaw::produce().

201  {
202  unsigned int words = 0;
203  unsigned int blocks = 0;
204  unsigned int maxblocks = 0;
205 
206  for (const auto& amc: payload_) {
207  words += amc.header().getSize();
208  blocks += amc.blocks();
209  maxblocks = std::max(maxblocks, amc.blocks());
210  }
211 
212  // Size is total amount of words + # of blocks for AMC headers + # of
213  // maxblocks for AMC13 block header, trailer
214  return words + blocks + maxblocks * 2;
215  }
unsigned int blocks() const
Definition: AMC13Spec.cc:189
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:84
Definition: AMCSpec.h:8
bool Packet::write ( const edm::Event ev,
unsigned char *  ptr,
unsigned int  skip,
unsigned int  size 
) const

Definition at line 218 of file AMC13Spec.cc.

References b, gather_cfg::blocks, edm::EventBase::bunchCrossing(), data, edm::EventID::event(), h, edm::EventBase::id(), edm::EventBase::orbitNumber(), amc13::Header::raw(), findQualityFiles::size, createPayload::skip, and amc13::Trailer::writeCRC().

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

219  {
220  if (size < this->size() * 8)
221  return false;
222 
223  if (size % 8 != 0)
224  return false;
225 
226  uint64_t * data = reinterpret_cast<uint64_t*>(ptr + skip);
227 
228  for (unsigned int b = 0; b < blocks(); ++b) {
229  // uint64_t * block_start = data;
230 
231  std::vector<uint64_t> block_headers;
232  std::vector<uint64_t> block_load;
233  for (const auto& amc: payload_) {
234  edm::LogInfo("AMC")
235  << "Considering block " << b
236  << " for payload " << amc.blockHeader().getBoardID()
237  << " with size " << amc.size()
238  << " and " << amc.blocks() << " blocks";
239  if (amc.blocks() < b + 1)
240  continue;
241 
242  block_headers.push_back(amc.blockHeader(b));
243  auto words = amc.block(b);
244  block_load.insert(block_load.end(), words.begin(), words.end());
245  }
246 
247  if (b == 0) {
248  amc13::Header h(block_headers.size(), ev.orbitNumber());
249  edm::LogInfo("AMC")
250  << "Writing header for AMC13 packet: "
251  << "format version " << h.getFormatVersion()
252  << ", " << h.getNumberOfAMCs()
253  << " AMC packets, orbit " << h.getOrbitNumber();
254  }
255 
256  *(data++) = amc13::Header(block_headers.size(), ev.orbitNumber()).raw();
257 
258  block_headers.insert(block_headers.end(), block_load.begin(), block_load.end());
259  for (const auto& word: block_headers)
260  *(data++) = word;
261 
262  *data = Trailer(b, ev.id().event(), ev.bunchCrossing()).raw();
263  Trailer::writeCRC(reinterpret_cast<uint64_t*>(ptr), data);
264  }
265 
266  return true;
267  }
EventNumber_t event() const
Definition: EventID.h:41
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static void writeCRC(const uint64_t *start, uint64_t *end)
Definition: AMC13Spec.cc:52
unsigned int size() const
Definition: AMC13Spec.cc:200
unsigned int blocks() const
Definition: AMC13Spec.cc:189
int bunchCrossing() const
Definition: EventBase.h:66
std::vector< amc::Packet > payload_
Definition: AMC13Spec.h:84
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
Definition: AMCSpec.h:8

Member Data Documentation

Header amc13::Packet::header_
private

Definition at line 80 of file AMC13Spec.h.

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

Definition at line 84 of file AMC13Spec.h.