CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
44 
45 namespace l1t {
47  public:
48  explicit L1TDigiToRaw(const edm::ParameterSet&);
49  ~L1TDigiToRaw();
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
54 
55  private:
56  virtual void produce(edm::Event&, const edm::EventSetup&) override;
57 
58  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override {};
59  virtual void endRun(edm::Run const&, edm::EventSetup const&) override {};
60  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
61  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
62 
63  // ----------member data ---------------------------
64  int evtType_;
65  int fedId_;
66  unsigned fwId_;
67 
68  // header and trailer sizes in chars
71 
72  std::auto_ptr<PackingSetup> setup_;
73  std::unique_ptr<PackerTokens> tokens_;
74  };
75 }
76 
77 namespace l1t {
79  fedId_(config.getParameter<int>("FedId"))
80  {
81  // Register products
82  produces<FEDRawDataCollection>();
83 
84  fwId_ = config.getParameter<unsigned int>("FWId");
85  evtType_ = config.getUntrackedParameter<int>("eventType", 1);
86 
88 
90  tokens_ = setup_->registerConsumes(config, cc);
91 
92  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader", 8);
93  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer", 8);
94  }
95 
96 
98  {
99  }
100 
101  // ------------ method called to produce the data ------------
102  void
104  {
105  using namespace edm;
106 
107  LogDebug("L1T") << "Packing data with FED ID " << fedId_;
108 
109  amc13::Packet amc13;
110 
111  auto bxId = event.bunchCrossing();
112  auto evtId = event.id().event();
113  auto orbit = event.eventAuxiliary().orbitNumber();
114 
115  // Create all the AMC payloads to pack into the AMC13
116  for (const auto& item: setup_->getPackers(fedId_, fwId_)) {
117  auto amc_no = item.first.first;
118  auto board = item.first.second;
119  auto packers = item.second;
120 
121  Blocks block_load;
122  for (const auto& packer: packers) {
123  LogDebug("L1T") << "Adding packed blocks";
124  auto blocks = packer->pack(event, tokens_.get());
125  block_load.insert(block_load.end(), blocks.begin(), blocks.end());
126  }
127 
128  std::sort(block_load.begin(), block_load.end());
129 
130  LogDebug("L1T") << "Concatenating blocks";
131 
132  std::vector<uint32_t> load32;
133  // TODO Infrastructure firmware version. Currently not used.
134  // Would change the way the payload has to be unpacked.
135  load32.push_back(0);
136  load32.push_back(fwId_);
137  for (const auto& block: block_load) {
138  LogDebug("L1T") << "Adding block " << block.header().getID() << " with size " << block.payload().size();
139  auto load = block.payload();
140 
141 #ifdef EDM_ML_DEBUG
142  std::stringstream s("");
143  s << "Block content:" << std::endl << std::hex << std::setfill('0');
144  for (const auto& word: load)
145  s << std::setw(8) << word << std::endl;
146  LogDebug("L1T") << s.str();
147 #endif
148 
149  load32.push_back(block.header().raw(MP7));
150  load32.insert(load32.end(), load.begin(), load.end());
151  }
152 
153  LogDebug("L1T") << "Converting payload";
154 
155  std::vector<uint64_t> load64;
156  for (unsigned int i = 0; i < load32.size(); i += 2) {
157  uint64_t word = load32[i];
158  if (i + 1 < load32.size()) {
159  word |= static_cast<uint64_t>(load32[i + 1]) << 32;
160  } else {
161  word |= static_cast<uint64_t>(0xffffffff) << 32;
162  }
163  load64.push_back(word);
164  }
165 
166  LogDebug("L1T") << "Creating AMC packet";
167 
168  amc13.add(amc_no, board, evtId, orbit, bxId, load64);
169  }
170 
171  std::auto_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
172  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
173 
174  unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
175  fed_data.resize(size);
176  unsigned char * payload = fed_data.data();
177  unsigned char * payload_start = payload;
178 
179  FEDHeader header(payload);
180  header.set(payload, evtType_, evtId, bxId, fedId_);
181 
182  amc13.write(event, payload, slinkHeaderSize_, size - slinkHeaderSize_ - slinkTrailerSize_);
183 
184  payload += slinkHeaderSize_;
185  payload += amc13.size() * 8;
186 
187  FEDTrailer trailer(payload);
188  trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
189 
190  event.put(raw_coll);
191  }
192 
193  // ------------ method called when starting to processes a run ------------
194  /*
195  void
196  L1TDigiToRaw::beginRun(edm::Run const&, edm::EventSetup const&)
197  {
198  }
199  */
200 
201  // ------------ method called when ending the processing of a run ------------
202  /*
203  void
204  L1TDigiToRaw::endRun(edm::Run const&, edm::EventSetup const&)
205  {
206  }
207  */
208 
209  // ------------ method called when starting to processes a luminosity block ------------
210  /*
211  void
212  L1TDigiToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
213  {
214  }
215  */
216 
217  // ------------ method called when ending the processing of a luminosity block ------------
218  /*
219  void
220  L1TDigiToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
221  {
222  }
223  */
224 
225  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
226  void
229  desc.add<unsigned int>("FWId", -1);
230  desc.add<int>("FedId");
231  desc.addUntracked<int>("eventType", 1);
232  desc.add<std::string>("Setup");
233  desc.addOptional<edm::InputTag>("InputLabel",edm::InputTag(""));
234  desc.addUntracked<int>("lenSlinkHeader", 8);
235  desc.addUntracked<int>("lenSlinkTrailer", 8);
236 
238 
239  descriptions.add("l1tDigiToRaw", desc);
240  }
241 }
242 
243 using namespace l1t;
244 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::unique_ptr< PackerTokens > tokens_
Definition: L1TDigiToRaw.cc:73
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
std::auto_ptr< PackingSetup > setup_
Definition: L1TDigiToRaw.cc:72
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Definition: Block.h:10
std::auto_ptr< PackingSetup > make(const std::string &) const
Definition: PackingSetup.cc:12
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:60
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:58
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void fillDescription(edm::ParameterSetDescription &) const
Definition: PackingSetup.cc:23
virtual void produce(edm::Event &, const edm::EventSetup &) override
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
def load
Definition: svgfig.py:546
std::vector< Block > Blocks
Definition: Block.h:68
L1TDigiToRaw(const edm::ParameterSet &)
Definition: L1TDigiToRaw.cc:78
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
unsigned long long uint64_t
Definition: Time.h:15
list blocks
Definition: gather_cfg.py:90
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static const PackingSetupFactory * get()
Definition: PackingSetup.h:52
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:59
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:61
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
Definition: Run.h:41