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", 16);
95  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer", 16);
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 board = item.first;
116  auto packers = item.second;
117 
118  Blocks block_load;
119  for (const auto& packer: packers) {
120  LogDebug("L1T") << "Adding packed blocks";
121  auto blocks = packer->pack(event, tokens_.get());
122  block_load.insert(block_load.end(), blocks.begin(), blocks.end());
123  }
124 
125  std::sort(block_load.begin(), block_load.end());
126 
127  LogDebug("L1T") << "Concatenating blocks";
128 
129  std::vector<uint32_t> load32;
130  // TODO this is an empty word to be replaced with a proper MP7
131  // header containing at least the firmware version
132  load32.push_back(0);
133  for (const auto& block: block_load) {
134  LogDebug("L1T") << "Adding block " << block.header().getID() << " with size " << block.payload().size();
135  auto load = block.payload();
136 
137 #ifdef EDM_ML_DEBUG
138  std::stringstream s("");
139  s << "Block content:" << std::endl << std::hex << std::setfill('0');
140  for (const auto& word: load)
141  s << std::setw(8) << word << std::endl;
142  LogDebug("L1T") << s.str();
143 #endif
144 
145  load32.push_back(block.header().raw());
146  load32.insert(load32.end(), load.begin(), load.end());
147  }
148 
149  LogDebug("L1T") << "Converting payload";
150 
151  std::vector<uint64_t> load64;
152  for (unsigned int i = 0; i < load32.size(); i += 2) {
153  uint64_t word = load32[i];
154  if (i + 1 < load32.size())
155  word |= static_cast<uint64_t>(load32[i + 1]) << 32;
156  load64.push_back(word);
157  }
158 
159  LogDebug("L1T") << "Creating AMC packet";
160 
161  amc13.add(board, load64);
162  }
163 
164  std::auto_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
165  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
166 
167  unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
168  fed_data.resize(size);
169  unsigned char * payload = fed_data.data();
170  unsigned char * payload_start = payload;
171 
172  auto bxId = event.bunchCrossing();
173  auto evtId = event.id().event();
174 
175  FEDHeader header(payload);
176  header.set(payload, evtType_, evtId, bxId, fedId_);
177 
178  payload += slinkHeaderSize_;
179 
180  amc13.write(event, payload, size - slinkHeaderSize_ - slinkTrailerSize_);
181 
182  payload += amc13.size() * 8;
183 
184  FEDTrailer trailer(payload);
185  trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
186 
187  event.put(raw_coll);
188  }
189 
190  // ------------ method called once each job just before starashtting event loop ------------
191  void
193  {
194  }
195 
196  // ------------ method called once each job just after ending the event loop ------------
197  void
199  }
200 
201  // ------------ method called when starting to processes a run ------------
202  /*
203  void
204  L1TDigiToRaw::beginRun(edm::Run const&, edm::EventSetup const&)
205  {
206  }
207  */
208 
209  // ------------ method called when ending the processing of a run ------------
210  /*
211  void
212  L1TDigiToRaw::endRun(edm::Run const&, edm::EventSetup const&)
213  {
214  }
215  */
216 
217  // ------------ method called when starting to processes a luminosity block ------------
218  /*
219  void
220  L1TDigiToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
221  {
222  }
223  */
224 
225  // ------------ method called when ending the processing of a luminosity block ------------
226  /*
227  void
228  L1TDigiToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
229  {
230  }
231  */
232 
233  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
234  void
236  //The following says we do not know what parameters are allowed so do no validation
237  // Please change this to state exactly what you do use, even if it is no parameters
239  desc.setUnknown();
240  descriptions.addDefault(desc);
241  }
242 }
243 
244 using namespace l1t;
245 //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
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:45
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