CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TRawToDigi.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventFilter/L1TRawToDigi
4 // Class: L1TRawToDigi
5 //
13 //
14 // Original Author: Matthias Wolf
15 // Created: Mon, 10 Feb 2014 14:29:40 GMT
16 //
17 //
18 
19 // system include files
20 #include <iostream>
21 #include <iomanip>
22 #include <memory>
23 
24 #define EDM_ML_DEBUG 1
25 
26 // user include files
33 
38 
42 
43 namespace l1t {
45  public:
46  explicit L1TRawToDigi(const edm::ParameterSet&);
47  ~L1TRawToDigi();
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51  private:
52  virtual void produce(edm::Event&, const edm::EventSetup&) override;
53 
54  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override {};
55  virtual void endRun(edm::Run const&, edm::EventSetup const&) override {};
56  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
57  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
58 
59  // ----------member data ---------------------------
61  std::vector<int> fedIds_;
62  unsigned int fwId_;
64 
65  std::auto_ptr<PackingSetup> prov_;
66 
67  // header and trailer sizes in chars
74 
75  bool ctp7_mode_;
76  bool mtf7_mode_;
77  bool debug_;
78  int warns_;
79  };
80 }
81 
82 std::ostream & operator<<(std::ostream& o, const l1t::BlockHeader& h) {
83  o << "L1T Block Header " << h.getID() << " with size " << h.getSize();
84  return o;
85 };
86 
87 namespace l1t {
89  fedIds_(config.getParameter<std::vector<int>>("FedIds")),
90  fwId_(config.getParameter<unsigned int>("FWId")),
91  fwOverride_(config.getParameter<bool>("FWOverride")),
92  ctp7_mode_(config.getUntrackedParameter<bool>("CTP7")),
93  mtf7_mode_(config.getUntrackedParameter<bool>("MTF7"))
94  {
95  fedData_ = consumes<FEDRawDataCollection>(config.getParameter<edm::InputTag>("InputLabel"));
96 
97  if (ctp7_mode_ and mtf7_mode_) {
98  throw cms::Exception("L1TRawToDigi") << "Can only use one unpacking mode concurrently!";
99  }
100 
102  prov_->registerProducts(*this);
103 
104  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader");
105  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer");
106  amcHeaderSize_ = config.getUntrackedParameter<int>("lenAMCHeader");
107  amcTrailerSize_ = config.getUntrackedParameter<int>("lenAMCTrailer");
108  amc13HeaderSize_ = config.getUntrackedParameter<int>("lenAMC13Header");
109  amc13TrailerSize_ = config.getUntrackedParameter<int>("lenAMC13Trailer");
110 
111  debug_ = config.getUntrackedParameter<bool>("debug");
112  warns_ = 0;
113  }
114 
115 
117  {
118  }
119 
120 
121  //
122  // member functions
123  //
124 
125  // ------------ method called to produce the data ------------
126  void
128  {
129  using namespace edm;
130 
131  std::unique_ptr<UnpackerCollections> coll = prov_->getCollections(event);
132 
134  event.getByToken(fedData_, feds);
135 
136  if (!feds.isValid()) {
137  LogError("L1T") << "Cannot unpack: no FEDRawDataCollection found";
138  return;
139  }
140 
141  for (const auto& fedId: fedIds_) {
142  const FEDRawData& l1tRcd = feds->FEDData(fedId);
143 
144  LogDebug("L1T") << "Found FEDRawDataCollection with ID " << fedId << " and size " << l1tRcd.size();
145 
147  if (l1tRcd.size() > 0) {
148  LogError("L1T") << "Cannot unpack: invalid L1T raw data (size = "
149  << l1tRcd.size() << ") for ID " << fedId << ". Returning empty collections!";
150  } else if (warns_ < 5) {
151  warns_++;
152  LogWarning("L1T") << "Cannot unpack: empty L1T raw data (size = "
153  << l1tRcd.size() << ") for ID " << fedId << ". Returning empty collections!";
154  }
155  continue;
156  }
157 
158  const unsigned char *data = l1tRcd.data();
159  FEDHeader header(data);
160 
161  if (header.check()) {
162  LogDebug("L1T") << "Found SLink header:"
163  << " Trigger type " << header.triggerType()
164  << " L1 event ID " << header.lvl1ID()
165  << " BX Number " << header.bxID()
166  << " FED source " << header.sourceID()
167  << " FED version " << header.version();
168  } else {
169  LogWarning("L1T") << "Did not find a SLink header!";
170  }
171 
172  FEDTrailer trailer(data + (l1tRcd.size() - slinkTrailerSize_));
173 
174  if (trailer.check()) {
175  LogDebug("L1T") << "Found SLink trailer:"
176  << " Length " << trailer.lenght()
177  << " CRC " << trailer.crc()
178  << " Status " << trailer.evtStatus()
179  << " Throttling bits " << trailer.ttsBits();
180  } else {
181  LogWarning("L1T") << "Did not find a SLink trailer!";
182  }
183 
184  // FIXME Hard-coded firmware version for first 74x MC campaigns.
185  // Will account for differences in the AMC payload, MP7 payload,
186  // and unpacker setup.
187  bool legacy_mc = fwOverride_ && ((fwId_ >> 24) == 0xff);
188 
189  amc13::Packet packet;
190  if (!packet.parse(
191  (const uint64_t*) data,
192  (const uint64_t*) (data + slinkHeaderSize_),
193  (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8,
194  header.lvl1ID(),
195  header.bxID(),
196  legacy_mc)) {
197  LogError("L1T")
198  << "Could not extract AMC13 Packet.";
199  return;
200  }
201 
202  for (auto& amc: packet.payload()) {
203  if (amc.size() == 0)
204  continue;
205 
206  auto payload64 = amc.data();
207  const uint32_t * start = (const uint32_t*) payload64.get();
208  // Want to have payload size in 32 bit words, but AMC measures
209  // it in 64 bit words → factor 2.
210  const uint32_t * end = start + (amc.size() * 2);
211 
212  std::auto_ptr<Payload> payload;
213  if (ctp7_mode_) {
214  LogDebug("L1T") << "Using CTP7 mode";
215  payload.reset(new CTP7Payload(start, end));
216  } else if (mtf7_mode_) {
217  LogDebug("L1T") << "Using MTF7 mode";
218  payload.reset(new MTF7Payload(start, end));
219  } else {
220  LogDebug("L1T") << "Using MP7 mode";
221  payload.reset(new MP7Payload(start, end, legacy_mc));
222  }
223  unsigned fw = payload->getAlgorithmFWVersion();
224 
225  // Let parameterset value override FW version
226  if (fwOverride_)
227  fw = fwId_;
228 
229  unsigned board = amc.blockHeader().getBoardID();
230  unsigned amc_no = amc.blockHeader().getAMCNumber();
231 
232  auto unpackers = prov_->getUnpackers(fedId, board, amc_no, fw);
233 
234  // getBlock() returns a non-null auto_ptr on success
235  std::auto_ptr<Block> block;
236  while ((block = payload->getBlock()).get()) {
237  if (debug_) {
238  std::cout << ">>> block to unpack <<<" << std::endl
239  << "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw() << std::dec
240  << " (ID " << block->header().getID() << ", size " << block->header().getSize()
241  << ", CapID 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getCapID()
242  << ")" << std::dec << std::endl;
243  for (const auto& word: block->payload()) {
244  if (debug_)
245  std::cout << "data: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec << std::endl;
246  }
247  }
248 
249  auto unpacker = unpackers.find(block->header().getID());
250 
251  block->amc(amc.header());
252 
253  if (unpacker == unpackers.end()) {
254  LogDebug("L1T") << "Cannot find an unpacker for"
255  << "\n\tblock: ID " << block->header().getID() << ", size " << block->header().getSize()
256  << "\n\tAMC: # " << amc_no << ", board ID 0x" << std::hex << board << std::dec
257  << "\n\tFED ID " << fedId << ", and FW ID " << fw;
258  // TODO Handle error
259  } else if (!unpacker->second->unpack(*block, coll.get())) {
260  LogDebug("L1T") << "Error unpacking data for block ID "
261  << block->header().getID() << ", AMC # " << amc_no
262  << ", board ID " << board << ", FED ID " << fedId
263  << ", and FW ID " << fw << "!";
264  // TODO Handle error
265  }
266  }
267  }
268  }
269  }
270 
271  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
272  void
275  // These parameters are part of the L1T/HLT interface, avoid changing if possible:
276  desc.add<std::vector<int>>("FedIds", {})->setComment("required parameter: default value is invalid");
277  desc.add<std::string>("Setup", "")->setComment("required parameter: default value is invalid");
278  // These parameters have well defined default values and are not currently
279  // part of the L1T/HLT interface. They can be cleaned up or updated at will:
280  desc.add<unsigned int>("FWId",0)->setComment("Ignored unless FWOverride is true. Calo Stage1: 32 bits: if the first eight bits are 0xff, will read the 74x MC format.\n");
281  desc.add<bool>("FWOverride", false)->setComment("Firmware version should be taken as FWId parameters");
282  desc.addUntracked<bool>("CTP7", false);
283  desc.addUntracked<bool>("MTF7", false);
284  desc.add<edm::InputTag>("InputLabel",edm::InputTag("rawDataCollector"));
285  desc.addUntracked<int>("lenSlinkHeader", 8);
286  desc.addUntracked<int>("lenSlinkTrailer", 8);
287  desc.addUntracked<int>("lenAMCHeader", 8);
288  desc.addUntracked<int>("lenAMCTrailer", 0);
289  desc.addUntracked<int>("lenAMC13Header", 8);
290  desc.addUntracked<int>("lenAMC13Trailer", 8);
291  desc.addUntracked<bool>("debug", false)->setComment("turn on verbose output");
292  descriptions.add("l1tRawToDigi", desc);
293  }
294 }
295 
296 using namespace l1t;
297 //define this as a plug-in
#define LogDebug(id)
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< amc::Packet > payload() const
Definition: AMC13Spec.h:80
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
bool check()
Definition: FEDTrailer.cc:64
int version()
Version identifier of the FED data format.
Definition: FEDHeader.cc:32
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
unsigned int getID() const
Definition: Block.h:22
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::auto_ptr< PackingSetup > prov_
Definition: L1TRawToDigi.cc:65
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::auto_ptr< PackingSetup > make(const std::string &) const
Definition: PackingSetup.cc:12
int evtStatus()
Event fragment status information.
Definition: FEDTrailer.cc:27
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
L1TRawToDigi(const edm::ParameterSet &)
Definition: L1TRawToDigi.cc:88
int sourceID()
Identifier of the FED.
Definition: FEDHeader.cc:28
double amc
Definition: hdecay.h:20
std::vector< int > fedIds_
Definition: L1TRawToDigi.cc:61
#define end
Definition: vmac.h:37
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
int ttsBits()
Current value of the Trigger Throttling System bitsAQ).
Definition: FEDTrailer.cc:32
bool check()
Check that the header is OK.
Definition: FEDHeader.cc:64
JetCorrectorParametersCollection coll
Definition: classes.h:10
unsigned long long uint64_t
Definition: Time.h:15
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:17
int bxID()
The bunch crossing number.
Definition: FEDHeader.cc:24
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:56
unsigned int fwId_
Definition: L1TRawToDigi.cc:62
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static const PackingSetupFactory * get()
Definition: PackingSetup.h:52
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< FEDRawDataCollection > fedData_
Definition: L1TRawToDigi.cc:57
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
unsigned int getSize() const
Definition: Block.h:23
bool parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false)
Definition: AMC13Spec.cc:70
int crc()
Cyclic Redundancy Code of the event fragment including header and trailer.
Definition: FEDTrailer.cc:22
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:55
tuple cout
Definition: gather_cfg.py:145
int lvl1ID()
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:20
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:57
int triggerType()
Event Trigger type identifier.
Definition: FEDHeader.cc:16
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:43
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:54