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 <memory>
21 
22 #define EDM_ML_DEBUG 1
23 
24 // user include files
31 
36 
40 
41 namespace l1t {
42  class L1TRawToDigi : public edm::one::EDProducer<edm::one::SharedResources, edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
43  public:
44  explicit L1TRawToDigi(const edm::ParameterSet&);
45  ~L1TRawToDigi();
46 
47  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48 
49  private:
50  virtual void produce(edm::Event&, const edm::EventSetup&) override;
51 
52  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override {};
53  virtual void endRun(edm::Run const&, edm::EventSetup const&) override {};
54  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
55  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
56 
57  // ----------member data ---------------------------
59  std::vector<int> fedIds_;
60  int fwId_;
61 
62  std::auto_ptr<PackingSetup> prov_;
63 
64  // header and trailer sizes in chars
71 
72  bool ctp7_mode_;
73  };
74 }
75 
76 std::ostream & operator<<(std::ostream& o, const l1t::BlockHeader& h) {
77  o << "L1T Block Header " << h.getID() << " with size " << h.getSize();
78  return o;
79 };
80 
81 namespace l1t {
83  fwId_(config.getUntrackedParameter<int>("FWId", -1)),
84  ctp7_mode_(config.getUntrackedParameter<bool>("CTP7", false))
85  {
86  fedData_ = consumes<FEDRawDataCollection>(config.getParameter<edm::InputTag>("InputLabel"));
87 
88  if (config.exists("FedId") and config.exists("FedIds")) {
90  << "Cannot have FedId and FedIds as parameter at the same time";
91  } else if (config.exists("FedId")) {
92  fedIds_ = {config.getParameter<int>("FedId")};
93  } else {
94  fedIds_ = config.getParameter<std::vector<int>>("FedIds");
95  }
96 
98  prov_->registerProducts(*this);
99 
100  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader", 8);
101  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer", 8);
102  amcHeaderSize_ = config.getUntrackedParameter<int>("lenAMCHeader", 8);
103  amcTrailerSize_ = config.getUntrackedParameter<int>("lenAMCTrailer", 0);
104  amc13HeaderSize_ = config.getUntrackedParameter<int>("lenAMC13Header", 8);
105  amc13TrailerSize_ = config.getUntrackedParameter<int>("lenAMC13Trailer", 8);
106  }
107 
108 
110  {
111  }
112 
113 
114  //
115  // member functions
116  //
117 
118  // ------------ method called to produce the data ------------
119  void
121  {
122  using namespace edm;
123 
124  std::unique_ptr<UnpackerCollections> coll = prov_->getCollections(event);
125 
127  event.getByToken(fedData_, feds);
128 
129  if (!feds.isValid()) {
130  LogError("L1T") << "Cannot unpack: no collection found";
131  return;
132  }
133 
134  for (const auto& fedId: fedIds_) {
135  const FEDRawData& l1tRcd = feds->FEDData(fedId);
136 
137  LogDebug("L1T") << "Found FEDRawDataCollection with ID " << fedId << " and size " << l1tRcd.size();
138 
140  LogError("L1T") << "Cannot unpack: empty/invalid L1T raw data (size = "
141  << l1tRcd.size() << ") for ID " << fedId << ". Returning empty collections!";
142  continue;
143  //return;
144  }
145 
146  const unsigned char *data = l1tRcd.data();
147  FEDHeader header(data);
148 
149  if (header.check()) {
150  LogDebug("L1T") << "Found SLink header:"
151  << " Trigger type " << header.triggerType()
152  << " L1 event ID " << header.lvl1ID()
153  << " BX Number " << header.bxID()
154  << " FED source " << header.sourceID()
155  << " FED version " << header.version();
156  } else {
157  LogWarning("L1T") << "Did not find a SLink header!";
158  }
159 
160  FEDTrailer trailer(data + (l1tRcd.size() - slinkTrailerSize_));
161 
162  if (trailer.check()) {
163  LogDebug("L1T") << "Found SLink trailer:"
164  << " Length " << trailer.lenght()
165  << " CRC " << trailer.crc()
166  << " Status " << trailer.evtStatus()
167  << " Throttling bits " << trailer.ttsBits();
168  } else {
169  LogWarning("L1T") << "Did not find a SLink trailer!";
170  }
171 
172  amc13::Packet packet;
173  if (!packet.parse(
174  (const uint64_t*) (data + slinkHeaderSize_),
175  (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8)) {
176  LogError("L1T")
177  << "Could not extract AMC13 Packet.";
178  return;
179  }
180 
181  for (auto& amc: packet.payload()) {
182  auto payload64 = amc.data();
183  const uint32_t * start = (const uint32_t*) payload64.get();
184  const uint32_t * end = start + (amc.size() * 2);
185 
186  std::auto_ptr<Payload> payload;
187  if (ctp7_mode_) {
188  LogDebug("L1T") << "Using CTP7 mode";
189  payload.reset(new CTP7Payload(start, end));
190  } else {
191  LogDebug("L1T") << "Using MP7 mode";
192  payload.reset(new MP7Payload(start, end));
193  }
194  unsigned fw = payload->getFirmwareId();
195 
196  // Let parameterset value override FW version
197  if (fwId_ > 0)
198  fw = fwId_;
199 
200  unsigned board = amc.header().getBoardID();
201  unsigned amc_no = amc.header().getAMCNumber();
202 
203  auto unpackers = prov_->getUnpackers(fedId, board, amc_no, fw);
204 
205  // getBlock() returns a non-null auto_ptr on success
206  std::auto_ptr<Block> block;
207  while ((block = payload->getBlock()).get()) {
208  // skip empty filler blocks
209  if (block->header().getID() == 0 and block->header().getSize() == 0)
210  continue;
211 
212  auto unpacker = unpackers.find(block->header().getID());
213 
214  block->amc(amc.header());
215 
216  if (unpacker == unpackers.end()) {
217  LogDebug("L1T") << "Cannot find an unpacker for block ID "
218  << block->header().getID() << ", AMC # " << amc_no
219  << ", board ID " << board << ", FED ID " << fedId
220  << ", and FW ID " << fw << "!";
221  // TODO Handle error
222  } else if (!unpacker->second->unpack(*block, coll.get())) {
223  LogDebug("L1T") << "Error unpacking data for block ID "
224  << block->header().getID() << ", AMC # " << amc_no
225  << ", board ID " << board << ", FED ID " << fedId
226  << ", and FW ID " << fw << "!";
227  // TODO Handle error
228  }
229  }
230  }
231  }
232  }
233 
234  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
235  void
237  //The following says we do not know what parameters are allowed so do no validation
238  // Please change this to state exactly what you do use, even if it is no parameters
240  desc.setUnknown();
241  descriptions.addDefault(desc);
242  }
243 }
244 
245 using namespace l1t;
246 //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: AMCSpec.h:142
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
unsigned int getID() const
Definition: Block.h:22
std::auto_ptr< PackingSetup > prov_
Definition: L1TRawToDigi.cc:62
#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
bool exists(std::string const &parameterName) const
checks if a parameter exists
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:82
int sourceID()
Identifier of the FED.
Definition: FEDHeader.cc:28
void addDefault(ParameterSetDescription const &psetDescription)
double amc
Definition: hdecay.h:20
std::vector< int > fedIds_
Definition: L1TRawToDigi.cc:59
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define end
Definition: vmac.h:37
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:54
static const PackingSetupFactory * get()
Definition: PackingSetup.h:46
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
edm::EDGetTokenT< FEDRawDataCollection > fedData_
Definition: L1TRawToDigi.cc:55
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 *, unsigned int)
Definition: AMCSpec.cc:142
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:53
volatile std::atomic< bool > shutdown_flag false
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:55
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:41
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:52