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  int fedId_;
60  int fwId_;
61 
62  std::auto_ptr<PackingSetup> prov_;
63 
64  // header and trailer sizes in chars
71  };
72 }
73 
74 std::ostream & operator<<(std::ostream& o, const l1t::BlockHeader& h) {
75  o << "L1T Block Header " << h.getID() << " with size " << h.getSize();
76  return o;
77 };
78 
79 namespace l1t {
81  fedId_(config.getParameter<int>("FedId")),
82  fwId_(config.getUntrackedParameter<int>("FWId", -1))
83  {
84  fedData_ = consumes<FEDRawDataCollection>(config.getParameter<edm::InputTag>("InputLabel"));
85 
87  prov_->registerProducts(*this);
88 
89  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader", 16);
90  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer", 16);
91  amcHeaderSize_ = config.getUntrackedParameter<int>("lenAMCHeader", 8);
92  amcTrailerSize_ = config.getUntrackedParameter<int>("lenAMCTrailer", 0);
93  amc13HeaderSize_ = config.getUntrackedParameter<int>("lenAMC13Header", 8);
94  amc13TrailerSize_ = config.getUntrackedParameter<int>("lenAMC13Trailer", 8);
95  }
96 
97 
99  {
100  }
101 
102 
103  //
104  // member functions
105  //
106 
107  // ------------ method called to produce the data ------------
108  void
110  {
111  using namespace edm;
112 
113  std::unique_ptr<UnpackerCollections> coll = prov_->getCollections(event);
114 
116  event.getByToken(fedData_, feds);
117 
118  if (!feds.isValid()) {
119  LogError("L1T") << "Cannot unpack: no collection found";
120  return;
121  }
122 
123  const FEDRawData& l1tRcd = feds->FEDData(fedId_);
124 
125  LogDebug("L1T") << "Found FEDRawDataCollection with ID " << fedId_ << " and size " << l1tRcd.size();
126 
128  //LogError("L1T") << "Cannot unpack: empty/invalid L1T raw data (size = "
129  // << l1tRcd.size() << ") for ID " << fedId_ << ". Returning empty collections!";
130  return;
131  }
132 
133  const unsigned char *data = l1tRcd.data();
134  FEDHeader header(data);
135 
136  if (header.check()) {
137  LogDebug("L1T") << "Found SLink header:"
138  << " Trigger type " << header.triggerType()
139  << " L1 event ID " << header.lvl1ID()
140  << " BX Number " << header.bxID()
141  << " FED source " << header.sourceID()
142  << " FED version " << header.version();
143  } else {
144  LogWarning("L1T") << "Did not find a SLink header!";
145  }
146 
147  FEDTrailer trailer(data + (l1tRcd.size() - slinkTrailerSize_));
148 
149  if (trailer.check()) {
150  LogDebug("L1T") << "Found SLink trailer:"
151  << " Length " << trailer.lenght()
152  << " CRC " << trailer.crc()
153  << " Status " << trailer.evtStatus()
154  << " Throttling bits " << trailer.ttsBits();
155  } else {
156  LogWarning("L1T") << "Did not find a SLink trailer!";
157  }
158 
159  amc13::Packet packet;
160  if (!packet.parse(
161  (const uint64_t*) (data + slinkHeaderSize_),
162  (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8)) {
163  LogError("L1T")
164  << "Could not extract AMC13 Packet.";
165  return;
166  }
167 
168  for (auto& amc: packet.payload()) {
169  auto payload64 = amc.data();
170  const uint32_t * payload = (const uint32_t*) payload64.get();
171  const uint32_t * end = payload + (amc.size() * 2);
172 
173  // TODO this skips the still to be added MP7 header containing the
174  // firmware version
175  unsigned fw = 0;
176  payload++;
177 
178  // Let parameterset value override FW version
179  if (fwId_ > 0)
180  fw = fwId_;
181 
182  unsigned board = amc.header().getBoardID();
183 
184  auto unpackers = prov_->getUnpackers(fedId_, board, fw);
185 
186  while (payload != end) {
187  BlockHeader block_hdr(payload++);
188 
189  /* LogDebug("L1T") << "Found " << block_hdr; */
190  //LogDebug("L1T") << "Found block " << block_hdr.getID() << " with size " << block_hdr.getSize();
191 
192  if (end - payload < block_hdr.getSize()) {
193  LogError("L1T")
194  << "Expecting a block size of " << block_hdr.getSize()
195  << " but only " << (end - payload) << " words remaining";
196  return;
197  }
198 
199  Block block(block_hdr, payload, payload + block_hdr.getSize());
200 
201  auto unpacker = unpackers.find(block_hdr.getID());
202  if (unpacker == unpackers.end()) {
203  //LogWarning("L1T") << "Cannot find an unpacker for block ID "
204  // << block_hdr.getID() << ", FED ID " << fedId_ << ", and FW ID "
205  // << fw << "!";
206  // TODO Handle error
207  } else if (!unpacker->second->unpack(block, coll.get())) {
208  LogWarning("L1T") << "Error unpacking data for block ID "
209  << block_hdr.getID() << ", FED ID " << fedId_ << ", and FW ID "
210  << fw << "!";
211  // TODO Handle error
212  }
213 
214  payload += block_hdr.getSize();
215  }
216  }
217  }
218 
219  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
220  void
222  //The following says we do not know what parameters are allowed so do no validation
223  // Please change this to state exactly what you do use, even if it is no parameters
225  desc.setUnknown();
226  descriptions.addDefault(desc);
227  }
228 }
229 
230 using namespace l1t;
231 //define this as a plug-in
#define LogDebug(id)
virtual void produce(edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
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:14
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
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
L1TRawToDigi(const edm::ParameterSet &)
Definition: L1TRawToDigi.cc:80
int sourceID()
Identifier of the FED.
Definition: FEDHeader.cc:28
void addDefault(ParameterSetDescription const &psetDescription)
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
#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
unsigned int getSize() const
Definition: Block.h:15
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
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