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 {
46  class L1TDigiToRaw : public edm::one::EDProducer<edm::one::SharedResources, edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
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 beginJob() override;
57  virtual void produce(edm::Event&, const edm::EventSetup&) override;
58  virtual void endJob() override;
59 
60  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override {};
61  virtual void endRun(edm::Run const&, edm::EventSetup const&) override {};
62  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
63  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {};
64 
65  // ----------member data ---------------------------
66  int evtType_;
67  int fedId_;
68  unsigned fwId_;
69 
70  // header and trailer sizes in chars
73 
74  std::auto_ptr<PackingSetup> setup_;
75  std::unique_ptr<PackerTokens> tokens_;
76  };
77 }
78 
79 namespace l1t {
81  fedId_(config.getParameter<int>("FedId"))
82  {
83  // Register products
84  produces<FEDRawDataCollection>();
85 
86  fwId_ = config.getParameter<unsigned int>("FWId");
87  evtType_ = config.getUntrackedParameter<int>("eventType", 1);
88 
90 
92  tokens_ = setup_->registerConsumes(config, cc);
93 
94  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader", 8);
95  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer", 8);
96  }
97 
98 
100  {
101  }
102 
103  // ------------ method called to produce the data ------------
104  void
106  {
107  using namespace edm;
108 
109  LogDebug("L1T") << "Packing data with FED ID " << fedId_;
110 
111  amc13::Packet amc13;
112 
113  // Create all the AMC payloads to pack into the AMC13
114  for (const auto& item: setup_->getPackers(fedId_, fwId_)) {
115  auto amc_no = item.first.first;
116  auto board = item.first.second;
117  auto packers = item.second;
118 
119  Blocks block_load;
120  for (const auto& packer: packers) {
121  LogDebug("L1T") << "Adding packed blocks";
122  auto blocks = packer->pack(event, tokens_.get());
123  block_load.insert(block_load.end(), blocks.begin(), blocks.end());
124  }
125 
126  std::sort(block_load.begin(), block_load.end());
127 
128  LogDebug("L1T") << "Concatenating blocks";
129 
130  std::vector<uint32_t> load32;
131  // TODO this is an empty word to be replaced with a proper MP7
132  // header containing at least the firmware version
133  load32.push_back(0);
134  for (const auto& block: block_load) {
135  LogDebug("L1T") << "Adding block " << block.header().getID() << " with size " << block.payload().size();
136  auto load = block.payload();
137 
138 #ifdef EDM_ML_DEBUG
139  std::stringstream s("");
140  s << "Block content:" << std::endl << std::hex << std::setfill('0');
141  for (const auto& word: load)
142  s << std::setw(8) << word << std::endl;
143  LogDebug("L1T") << s.str();
144 #endif
145 
146  load32.push_back(block.header().raw(MP7));
147  load32.insert(load32.end(), load.begin(), load.end());
148  }
149 
150  LogDebug("L1T") << "Converting payload";
151 
152  std::vector<uint64_t> load64;
153  for (unsigned int i = 0; i < load32.size(); i += 2) {
154  uint64_t word = load32[i];
155  if (i + 1 < load32.size())
156  word |= static_cast<uint64_t>(load32[i + 1]) << 32;
157  load64.push_back(word);
158  }
159 
160  LogDebug("L1T") << "Creating AMC packet";
161 
162  amc13.add(amc_no, board, load64);
163  }
164 
165  std::auto_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
166  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
167 
168  unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
169  fed_data.resize(size);
170  unsigned char * payload = fed_data.data();
171  unsigned char * payload_start = payload;
172 
173  auto bxId = event.bunchCrossing();
174  auto evtId = event.id().event();
175 
176  FEDHeader header(payload);
177  header.set(payload, evtType_, evtId, bxId, fedId_);
178 
179  payload += slinkHeaderSize_;
180 
181  amc13.write(event, payload, size - slinkHeaderSize_ - slinkTrailerSize_);
182 
183  payload += amc13.size() * 8;
184 
185  FEDTrailer trailer(payload);
186  trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
187 
188  event.put(raw_coll);
189  }
190 
191  // ------------ method called once each job just before starashtting event loop ------------
192  void
194  {
195  }
196 
197  // ------------ method called once each job just after ending the event loop ------------
198  void
200  }
201 
202  // ------------ method called when starting to processes a run ------------
203  /*
204  void
205  L1TDigiToRaw::beginRun(edm::Run const&, edm::EventSetup const&)
206  {
207  }
208  */
209 
210  // ------------ method called when ending the processing of a run ------------
211  /*
212  void
213  L1TDigiToRaw::endRun(edm::Run const&, edm::EventSetup const&)
214  {
215  }
216  */
217 
218  // ------------ method called when starting to processes a luminosity block ------------
219  /*
220  void
221  L1TDigiToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
222  {
223  }
224  */
225 
226  // ------------ method called when ending the processing of a luminosity block ------------
227  /*
228  void
229  L1TDigiToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
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)
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:75
std::auto_ptr< PackingSetup > setup_
Definition: L1TDigiToRaw.cc:74
#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:62
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:60
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void addDefault(ParameterSetDescription const &psetDescription)
virtual void beginJob() override
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:64
L1TDigiToRaw(const edm::ParameterSet &)
Definition: L1TDigiToRaw.cc:80
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
virtual void endJob() override
unsigned long long uint64_t
Definition: Time.h:15
list blocks
Definition: gather_cfg.py:90
static const PackingSetupFactory * get()
Definition: PackingSetup.h:46
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:61
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:63
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
Definition: Run.h:41