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() override;
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
55 
56  private:
57  void produce(edm::Event&, const edm::EventSetup&) override;
58 
59  void beginRun(edm::Run const&, edm::EventSetup const&) override{};
60  void endRun(edm::Run const&, edm::EventSetup const&) override{};
62  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  bool ctp7_mode_;
77  };
78 } // namespace l1t
79 
80 namespace l1t {
82  : fedId_(config.getParameter<int>("FedId")), ctp7_mode_(config.getUntrackedParameter<bool>("CTP7")) {
83  // Register products
84  produces<FEDRawDataCollection>();
85 
86  fwId_ = config.getParameter<unsigned int>("FWId");
87  evtType_ = config.getUntrackedParameter<int>("eventType", 1);
88 
89  auto cc = edm::ConsumesCollector(consumesCollector());
90 
91  setup_ = PackingSetupFactory::get()->make(config.getParameter<std::string>("Setup"));
92  tokens_ = setup_->registerConsumes(config, cc);
93 
94  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader", 8);
95  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer", 8);
96  }
97 
99 
100  // ------------ method called to produce the data ------------
102  using namespace edm;
103 
104  LogDebug("L1T") << "Packing data with FED ID " << fedId_;
105 
107 
108  auto bxId = event.bunchCrossing();
109  // Note: L1ID != event ID
110  // See e.g. triggerCount vs. eventNumber
111  // in EventFilter/FEDInterface/interface/FED1024.h
112  // But the trigger count is not stored in cmssw event class
113  auto evtId = event.id().event();
114  auto orbit = event.eventAuxiliary().orbitNumber();
115  LogDebug("L1T") << "Forming FED with metadata bxId=" << bxId << ", l1ID=" << evtId << ", orbit=" << orbit;
116 
117  // Create all the AMC payloads to pack into the AMC13
118  for (const auto& item : setup_->getPackers(fedId_, fwId_)) {
119  auto amc_no = item.first.first;
120  auto board = item.first.second;
121  auto packers = item.second;
122 
123  Blocks block_load;
124  for (const auto& packer : packers) {
125  LogDebug("L1T") << "Adding packed blocks";
126  packer->setBoard(board);
127  auto blocks = packer->pack(event, tokens_.get());
128  block_load.insert(block_load.end(), blocks.begin(), blocks.end());
129  }
130 
131  std::sort(block_load.begin(), block_load.end());
132 
133  LogDebug("L1T") << "Concatenating blocks";
134 
135  std::vector<uint32_t> load32;
136  // CTP7 stores this info in AMC user header
137  if (not ctp7_mode_) {
138  // TODO Infrastructure firmware version. Currently not used.
139  // Would change the way the payload has to be unpacked.
140  load32.push_back(0);
141  load32.push_back(fwId_);
142  }
143  for (const auto& block : block_load) {
144  LogDebug("L1T") << "Adding block " << block.header().getID() << " with size " << block.payload().size();
145  auto load = block.payload();
146 
147 #ifdef EDM_ML_DEBUG
148  std::stringstream s("");
149  s << "Block content:" << std::endl << std::hex << std::setfill('0');
150  for (const auto& word : load)
151  s << std::setw(8) << word << std::endl;
152  LogDebug("L1T") << s.str();
153 #endif
154 
155  if (block.header().getType() == CTP7) {
156  // Header is two words for CTP7, first word is just a magic
157  load32.push_back(0xA110CA7E);
158  }
159  load32.push_back(block.header().raw());
160  load32.insert(load32.end(), load.begin(), load.end());
161  }
162 
163  LogDebug("L1T") << "Converting payload";
164 
165  std::vector<uint64_t> load64;
166  for (unsigned int i = 0; i < load32.size(); i += 2) {
167  uint64_t word = load32[i];
168  if (i + 1 < load32.size()) {
169  word |= static_cast<uint64_t>(load32[i + 1]) << 32;
170  } else {
171  word |= static_cast<uint64_t>(0xffffffff) << 32;
172  }
173  load64.push_back(word);
174  }
175 
176  LogDebug("L1T") << "Creating AMC packet";
177 
178  unsigned amc_user_header = 0;
179  if (ctp7_mode_)
180  amc_user_header = fwId_;
181  amc13.add(amc_no, board, evtId, orbit, bxId, load64, amc_user_header);
182  }
183 
184  std::unique_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
185  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
186 
187  unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
188  fed_data.resize(size);
189  unsigned char* payload = fed_data.data();
190  unsigned char* payload_start = payload;
191 
193  header.set(payload, evtType_, evtId, bxId, fedId_);
194 
196 
198  payload += amc13.size() * 8;
199 
200  FEDTrailer trailer(payload);
201  trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
202 
203  event.put(std::move(raw_coll));
204  }
205 
206  // ------------ method called when starting to processes a run ------------
207  /*
208  void
209  L1TDigiToRaw::beginRun(edm::Run const&, edm::EventSetup const&)
210  {
211  }
212  */
213 
214  // ------------ method called when ending the processing of a run ------------
215  /*
216  void
217  L1TDigiToRaw::endRun(edm::Run const&, edm::EventSetup const&)
218  {
219  }
220  */
221 
222  // ------------ method called when starting to processes a luminosity block ------------
223  /*
224  void
225  L1TDigiToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
226  {
227  }
228  */
229 
230  // ------------ method called when ending the processing of a luminosity block ------------
231  /*
232  void
233  L1TDigiToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
234  {
235  }
236  */
237 
238  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
241  desc.add<unsigned int>("FWId", -1);
242  desc.add<int>("FedId");
243  desc.addUntracked<int>("eventType", 1);
244  desc.add<std::string>("Setup");
245  desc.addOptional<edm::InputTag>("InputLabel", edm::InputTag(""));
246  desc.addOptional<edm::InputTag>("InputLabel2", edm::InputTag(""));
247  desc.addUntracked<int>("lenSlinkHeader", 8);
248  desc.addUntracked<int>("lenSlinkTrailer", 8);
249  desc.addUntracked<bool>("CTP7", false);
250 
252 
253  descriptions.add("l1tDigiToRaw", desc);
254  }
255 } // namespace l1t
256 
257 using namespace l1t;
258 //define this as a plug-in
l1t::Blocks
std::vector< Block > Blocks
Definition: Block.h:99
FEDNumbering.h
l1t::L1TDigiToRaw::fedId_
int fedId_
Definition: L1TDigiToRaw.cc:66
l1t::L1TDigiToRaw::L1TDigiToRaw
L1TDigiToRaw(const edm::ParameterSet &)
Definition: L1TDigiToRaw.cc:81
electrons_cff.bool
bool
Definition: electrons_cff.py:393
l1t::L1TDigiToRaw::evtType_
int evtType_
Definition: L1TDigiToRaw.cc:62
mps_fire.i
i
Definition: mps_fire.py:428
l1t::L1TDigiToRaw
Definition: L1TDigiToRaw.cc:47
l1t::L1TDigiToRaw::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TDigiToRaw.cc:239
l1t::L1TDigiToRaw::slinkHeaderSize_
int slinkHeaderSize_
Definition: L1TDigiToRaw.cc:70
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
PackingSetupFactory.h
l1t::CTP7
Definition: Block.h:11
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
amc13
Definition: AMC13Spec.h:14
l1t::L1TDigiToRaw::~L1TDigiToRaw
~L1TDigiToRaw() override
Definition: L1TDigiToRaw.cc:98
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
AMC13Spec.h
cc
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
config
Definition: config.py:1
l1t::L1TDigiToRaw::fwId_
unsigned fwId_
Definition: L1TDigiToRaw.cc:67
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
l1t::L1TDigiToRaw::setup_
std::unique_ptr< PackingSetup > setup_
Definition: L1TDigiToRaw.cc:73
l1t::L1TDigiToRaw::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:61
amc13::Packet
Definition: AMC13Spec.h:69
svgfig.load
def load(fileName)
Definition: svgfig.py:547
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition: EcalFEDMonitor_cfi.py:6
jets_cff.payload
payload
Definition: jets_cff.py:32
evf::compute_crc
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1t::L1TDigiToRaw::tokens_
std::unique_ptr< PackerTokens > tokens_
Definition: L1TDigiToRaw.cc:74
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
FEDTrailer
Definition: FEDTrailer.h:14
Event.h
l1t::L1TDigiToRaw::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:59
l1t::L1TDigiToRaw::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TDigiToRaw.cc:101
l1t
delete x;
Definition: CaloConfig.h:22
l1t::L1TDigiToRaw::slinkTrailerSize_
int slinkTrailerSize_
Definition: L1TDigiToRaw.cc:71
l1t::PackingSetupFactory::fillDescription
void fillDescription(edm::ParameterSetDescription &) const
Definition: PackingSetupFactory.cc:12
createfilelist.int
int
Definition: createfilelist.py:10
FEDRawDataCollection.h
edm::stream::EDProducer
Definition: EDProducer.h:38
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::EventSetup
Definition: EventSetup.h:57
FEDTrailer::set
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:31
InputTag.h
l1t::L1TDigiToRaw::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:60
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
l1t::L1TDigiToRaw::ctp7_mode_
bool ctp7_mode_
Definition: L1TDigiToRaw.cc:76
l1t::PackingSetupFactory::make
std::unique_ptr< PackingSetup > make(const std::string &) const
Definition: PackingSetupFactory.cc:8
l1t::L1TDigiToRaw::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TDigiToRaw.cc:62
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
l1t::PackingSetupFactory::get
static const PackingSetupFactory * get()
Definition: PackingSetupFactory.h:14
ConsumesCollector.h
ParameterSet.h
event
Definition: event.py:1
FEDHeader
Definition: FEDHeader.h:14
edm::Event
Definition: Event.h:73
FEDHeader.h
gather_cfg.blocks
blocks
Definition: gather_cfg.py:90
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
CRC16.h
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
FEDTrailer.h