CMS 3D CMS Logo

L1TDigiToRaw.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventFilter/L1TRawToDigi
4 // Class: L1TDigiToRaw
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 <iomanip>
21 #include <memory>
22 
23 #define EDM_ML_DEBUG 1
24 
25 // user include files
30 
37 
39 
41 
43 
44 #include "PackingSetupFactory.h"
45 
46 namespace l1t {
48  public:
49  explicit L1TDigiToRaw(const edm::ParameterSet&);
50  ~L1TDigiToRaw();
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
55 
56  private:
57  virtual void produce(edm::Event&, const edm::EventSetup&) override;
58 
59  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override {};
60  virtual void endRun(edm::Run const&, edm::EventSetup const&) override {};
61  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
62  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
63 
64  // ----------member data ---------------------------
65  int evtType_;
66  int fedId_;
67  unsigned fwId_;
68 
69  // header and trailer sizes in chars
72 
73  std::unique_ptr<PackingSetup> setup_;
74  std::unique_ptr<PackerTokens> tokens_;
75  };
76 }
77 
78 namespace l1t {
80  fedId_(config.getParameter<int>("FedId"))
81  {
82  // Register products
83  produces<FEDRawDataCollection>();
84 
85  fwId_ = config.getParameter<unsigned int>("FWId");
86  evtType_ = config.getUntrackedParameter<int>("eventType", 1);
87 
89 
91  tokens_ = setup_->registerConsumes(config, cc);
92 
93  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader", 8);
94  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer", 8);
95  }
96 
97 
99  {
100  }
101 
102  // ------------ method called to produce the data ------------
103  void
105  {
106  using namespace edm;
107 
108  LogDebug("L1T") << "Packing data with FED ID " << fedId_;
109 
111 
112  auto bxId = event.bunchCrossing();
113  auto evtId = event.id().event();
114  auto orbit = event.eventAuxiliary().orbitNumber();
115 
116  // Create all the AMC payloads to pack into the AMC13
117  for (const auto& item: setup_->getPackers(fedId_, fwId_)) {
118  auto amc_no = item.first.first;
119  auto board = item.first.second;
120  auto packers = item.second;
121 
122  Blocks block_load;
123  for (const auto& packer: packers) {
124  LogDebug("L1T") << "Adding packed blocks";
125  auto blocks = packer->pack(event, tokens_.get());
126  block_load.insert(block_load.end(), blocks.begin(), blocks.end());
127  }
128 
129  std::sort(block_load.begin(), block_load.end());
130 
131  LogDebug("L1T") << "Concatenating blocks";
132 
133  std::vector<uint32_t> load32;
134  // TODO Infrastructure firmware version. Currently not used.
135  // Would change the way the payload has to be unpacked.
136  load32.push_back(0);
137  load32.push_back(fwId_);
138  for (const auto& block: block_load) {
139  LogDebug("L1T") << "Adding block " << block.header().getID() << " with size " << block.payload().size();
140  auto load = block.payload();
141 
142 #ifdef EDM_ML_DEBUG
143  std::stringstream s("");
144  s << "Block content:" << std::endl << std::hex << std::setfill('0');
145  for (const auto& word: load)
146  s << std::setw(8) << word << std::endl;
147  LogDebug("L1T") << s.str();
148 #endif
149 
150  load32.push_back(block.header().raw(MP7));
151  load32.insert(load32.end(), load.begin(), load.end());
152  }
153 
154  LogDebug("L1T") << "Converting payload";
155 
156  std::vector<uint64_t> load64;
157  for (unsigned int i = 0; i < load32.size(); i += 2) {
158  uint64_t word = load32[i];
159  if (i + 1 < load32.size()) {
160  word |= static_cast<uint64_t>(load32[i + 1]) << 32;
161  } else {
162  word |= static_cast<uint64_t>(0xffffffff) << 32;
163  }
164  load64.push_back(word);
165  }
166 
167  LogDebug("L1T") << "Creating AMC packet";
168 
169  amc13.add(amc_no, board, evtId, orbit, bxId, load64);
170  }
171 
172  std::unique_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
173  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
174 
175  unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
176  fed_data.resize(size);
177  unsigned char * payload = fed_data.data();
178  unsigned char * payload_start = payload;
179 
180  FEDHeader header(payload);
181  header.set(payload, evtType_, evtId, bxId, fedId_);
182 
183  amc13.write(event, payload, slinkHeaderSize_, size - slinkHeaderSize_ - slinkTrailerSize_);
184 
185  payload += slinkHeaderSize_;
186  payload += amc13.size() * 8;
187 
188  FEDTrailer trailer(payload);
189  trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
190 
191  event.put(std::move(raw_coll));
192  }
193 
194  // ------------ method called when starting to processes a run ------------
195  /*
196  void
197  L1TDigiToRaw::beginRun(edm::Run const&, edm::EventSetup const&)
198  {
199  }
200  */
201 
202  // ------------ method called when ending the processing of a run ------------
203  /*
204  void
205  L1TDigiToRaw::endRun(edm::Run const&, edm::EventSetup const&)
206  {
207  }
208  */
209 
210  // ------------ method called when starting to processes a luminosity block ------------
211  /*
212  void
213  L1TDigiToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
214  {
215  }
216  */
217 
218  // ------------ method called when ending the processing of a luminosity block ------------
219  /*
220  void
221  L1TDigiToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
222  {
223  }
224  */
225 
226  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
227  void
230  desc.add<unsigned int>("FWId", -1);
231  desc.add<int>("FedId");
232  desc.addUntracked<int>("eventType", 1);
233  desc.add<std::string>("Setup");
234  desc.addOptional<edm::InputTag>("InputLabel",edm::InputTag(""));
235  desc.addUntracked<int>("lenSlinkHeader", 8);
236  desc.addUntracked<int>("lenSlinkTrailer", 8);
237 
239 
240  descriptions.add("l1tDigiToRaw", desc);
241  }
242 }
243 
244 using namespace l1t;
245 //define this as a plug-in
#define LogDebug(id)
size
Write out results.
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< PackerTokens > tokens_
Definition: L1TDigiToRaw.cc:74
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
std::unique_ptr< PackingSetup > setup_
Definition: L1TDigiToRaw.cc:73
Definition: Block.h:10
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
unsigned int size() const
Definition: AMC13Spec.cc:200
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:61
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
bool write(const edm::Event &ev, unsigned char *ptr, unsigned int skip, unsigned int size) const
Definition: AMC13Spec.cc:218
static void set(unsigned char *trailer, int evt_lgth, int crc, int evt_stat, int tts, bool T=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:42
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:59
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
payload
payload postfix for testing
void fillDescription(edm::ParameterSetDescription &) const
virtual void produce(edm::Event &, const edm::EventSetup &) override
void resize(size_t newsize)
Definition: FEDRawData.cc:32
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
static void set(unsigned char *header, int evt_ty, int lvl1_ID, int bx_ID, int source_ID, int version=0, bool H=false)
Set all fields in the header.
Definition: FEDHeader.cc:40
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:67
std::vector< Block > Blocks
Definition: Block.h:72
L1TDigiToRaw(const edm::ParameterSet &)
Definition: L1TDigiToRaw.cc:79
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< PackingSetup > make(const std::string &) const
unsigned long long uint64_t
Definition: Time.h:15
void add(unsigned int amc_no, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector< uint64_t > &load)
Definition: AMC13Spec.cc:61
def load(fileName)
Definition: svgfig.py:546
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static const PackingSetupFactory * get()
HLT enums.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:60
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:62
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1
Definition: Run.h:42