CMS 3D CMS Logo

AMCDumpToRaw.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventFilter/L1TRawToDigi
4 // Class: AMCDumpToRaw
5 //
13 //
14 // Original Author: James Brooke
15 // Created: Tue, 11 Mar 2014 14:55:45 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
30 
35 
37 
38 #include <fstream>
39 #include <iostream>
40 #include <sstream>
41 #include <string>
42 #include <iomanip>
43 #include <boost/algorithm/string.hpp>
44 
46 
47 namespace l1t {
48 
49  class AMCDumpToRaw : public edm::EDProducer {
50  public:
51  explicit AMCDumpToRaw(const edm::ParameterSet&);
52  ~AMCDumpToRaw() override;
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56  private:
57  void beginJob() override;
58  void produce(edm::Event&, const edm::EventSetup&) override;
59  void endJob() override;
60 
61  void readEvent(std::vector<uint32_t>& load32);
62 
63  void formatAMC(amc13::Packet& amc13, const std::vector<uint32_t>& load32);
64 
66 
67  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
68  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
69  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
70  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
71 
72  // ----------member data ---------------------------
73  std::ifstream file_;
75 
76  // DAQ params
77  int fedId_;
78  int iAmc_;
79  int boardId_;
80  int evType_;
81  int fwVer_;
82  int slinkHeaderSize_; // in 8-bit words
84  };
85 
86  //
87  // constants, enums and typedefs
88  //
89 
90  //
91  // static data member definitions
92  //
93 
94  //
95  // constructors and destructor
96  //
98  : filename_(iConfig.getUntrackedParameter<std::string>("filename", "data.txt")),
99  fedId_(iConfig.getUntrackedParameter<int>("fedId", 1)),
100  iAmc_(iConfig.getUntrackedParameter<int>("iAmc", 1)),
101  boardId_(iConfig.getUntrackedParameter<int>("boardId", 1)),
102  evType_(iConfig.getUntrackedParameter<int>("eventType", 1)),
103  fwVer_(iConfig.getUntrackedParameter<int>("fwVersion", 1)),
104  slinkHeaderSize_(iConfig.getUntrackedParameter<int>("lenSlinkHeader", 8)),
105  slinkTrailerSize_(iConfig.getUntrackedParameter<int>("lenSlinkTrailer", 8)) {
106  produces<FEDRawDataCollection>();
107  }
108 
110  // do anything here that needs to be done at desctruction time
111  // (e.g. close files, deallocate resources etc.)
112  }
113 
114  //
115  // member functions
116  //
117 
118  // ------------ method called for each event ------------
120  using namespace edm;
121 
122  // create AMC 13 packet
124 
125  std::vector<uint32_t> load32;
126 
127  readEvent(load32);
128 
129  formatAMC(amc13, load32);
130 
131  LogDebug("L1T") << "AMC13 size " << amc13.size();
132 
133  // prepare the raw data collection
134  std::unique_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
135  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
136 
137  formatRaw(iEvent, amc13, fed_data);
138 
139  LogDebug("L1T") << "Packing FED ID " << fedId_ << " size " << fed_data.size();
140 
141  // put the collection in the event
142  iEvent.put(std::move(raw_coll));
143  }
144 
145  void AMCDumpToRaw::readEvent(std::vector<uint32_t>& load32) {
146  // read file
148 
149  // while not encountering dumb errors
150  while (getline(file_, line) && !line.empty()) {
151  std::istringstream iss(line);
152  unsigned long d;
153  iss >> std::hex >> d;
154 
155  load32.push_back(d);
156  }
157  }
158 
159  void AMCDumpToRaw::formatAMC(amc13::Packet& amc13, const std::vector<uint32_t>& load32) {
160  // TODO this is an empty word to be replaced with a proper MP7
161  // header containing at least the firmware version
162 
163  std::vector<uint64_t> load64;
164  for (unsigned int i = 0; i < load32.size(); i += 2) {
165  uint64_t word = load32[i];
166  if (i + 1 < load32.size())
167  word |= static_cast<uint64_t>(load32[i + 1]) << 32;
168  load64.push_back(word);
169  }
170 
171  LogDebug("L1T") << "Creating AMC packet " << iAmc_;
172 
173  amc13.add(iAmc_, boardId_, 0, 0, 0, load64);
174  }
175 
177  unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
178  fed_data.resize(size);
179  unsigned char* payload = fed_data.data();
180  unsigned char* payload_start = payload;
181 
182  auto bxId = iEvent.bunchCrossing();
183  auto evtId = iEvent.id().event();
184 
185  LogDebug("L1T") << "Creating FEDRawData ID " << fedId_ << ", size " << size;
186 
188  header.set(payload, evType_, evtId, bxId, fedId_);
189 
191 
193  payload += amc13.size() * 8;
194 
195  FEDTrailer trailer(payload);
196  trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
197  }
198 
199  // ------------ method called once each job just before starting event loop ------------
201  // open VME file
202  file_.open(filename_.c_str(), std::ios::in);
203  if (!file_.good()) {
204  edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl;
205  }
206  }
207 
208  // ------------ method called once each job just after ending the event loop ------------
209  void AMCDumpToRaw::endJob() { file_.close(); }
210 
211  // ------------ method called when starting to processes a run ------------
212  /*
213 void
214 AMCDumpToRaw::beginRun(edm::Run const&, edm::EventSetup const&)
215 {
216 }
217 */
218 
219  // ------------ method called when ending the processing of a run ------------
220  /*
221 void
222 AMCDumpToRaw::endRun(edm::Run const&, edm::EventSetup const&)
223 {
224 }
225 */
226 
227  // ------------ method called when starting to processes a luminosity block ------------
228  /*
229 vvoid
230 AMCDumpToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
231 {
232 }
233 */
234 
235  // ------------ method called when ending the processing of a luminosity block ------------
236  /*
237 void
238 AMCDumpToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
239 {
240 }
241 */
242 
243  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
245  //The following says we do not know what parameters are allowed so do no validation
246  // Please change this to state exactly what you do use, even if it is no parameters
248  desc.setUnknown();
249  descriptions.addDefault(desc);
250  }
251 
252 } // namespace l1t
253 
254 using namespace l1t;
255 //define this as a plug-in
mps_fire.i
i
Definition: mps_fire.py:355
l1t::AMCDumpToRaw::iAmc_
int iAmc_
Definition: AMCDumpToRaw.cc:78
EDProducer.h
l1t::AMCDumpToRaw::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: AMCDumpToRaw.cc:119
l1t::AMCDumpToRaw::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: AMCDumpToRaw.cc:244
edm
HLT enums.
Definition: AlignableModifier.h:19
l1t::AMCDumpToRaw::~AMCDumpToRaw
~AMCDumpToRaw() override
Definition: AMCDumpToRaw.cc:109
edm::LogInfo
Definition: MessageLogger.h:254
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
amc13
Definition: AMC13Spec.h:14
FEDRawData.h
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
l1t::AMCDumpToRaw
Definition: AMCDumpToRaw.cc:49
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
l1t::AMCDumpToRaw::formatRaw
void formatRaw(edm::Event &iEvent, amc13::Packet &amc13, FEDRawData &fed_data)
Definition: AMCDumpToRaw.cc:176
Service.h
amc13::Packet
Definition: AMC13Spec.h:69
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition: EcalFEDMonitor_cfi.py:6
jets_cff.payload
payload
Definition: jets_cff.py:34
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
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
FEDTrailer
Definition: FEDTrailer.h:14
Event.h
l1t::AMCDumpToRaw::slinkHeaderSize_
int slinkHeaderSize_
Definition: AMCDumpToRaw.cc:82
l1t
delete x;
Definition: CaloConfig.h:22
l1t::AMCDumpToRaw::readEvent
void readEvent(std::vector< uint32_t > &load32)
Definition: AMCDumpToRaw.cc:145
recoMuon::in
Definition: RecoMuonEnumerators.h:6
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
l1t::AMCDumpToRaw::AMCDumpToRaw
AMCDumpToRaw(const edm::ParameterSet &)
Definition: AMCDumpToRaw.cc:97
FEDRawDataCollection.h
edm::ParameterSetDescription::setUnknown
void setUnknown()
Definition: ParameterSetDescription.cc:39
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
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
l1t::AMCDumpToRaw::file_
std::ifstream file_
Definition: AMCDumpToRaw.cc:73
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
l1t::AMCDumpToRaw::formatAMC
void formatAMC(amc13::Packet &amc13, const std::vector< uint32_t > &load32)
Definition: AMCDumpToRaw.cc:159
l1t::AMCDumpToRaw::endJob
void endJob() override
Definition: AMCDumpToRaw.cc:209
Frameworkfwd.h
l1t::AMCDumpToRaw::fwVer_
int fwVer_
Definition: AMCDumpToRaw.cc:81
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
l1t::AMCDumpToRaw::boardId_
int boardId_
Definition: AMCDumpToRaw.cc:79
l1t::AMCDumpToRaw::filename_
std::string filename_
Definition: AMCDumpToRaw.cc:74
edm::EDProducer
Definition: EDProducer.h:36
Exception.h
l1t::AMCDumpToRaw::fedId_
int fedId_
Definition: AMCDumpToRaw.cc:77
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
ztail.d
d
Definition: ztail.py:151
l1t::AMCDumpToRaw::evType_
int evType_
Definition: AMCDumpToRaw.cc:80
ParameterSet.h
l1t::AMCDumpToRaw::beginJob
void beginJob() override
Definition: AMCDumpToRaw.cc:200
FEDHeader
Definition: FEDHeader.h:14
edm::Event
Definition: Event.h:73
mps_splice.line
line
Definition: mps_splice.py:76
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
FEDHeader.h
CRC16.h
l1t::AMCDumpToRaw::slinkTrailerSize_
int slinkTrailerSize_
Definition: AMCDumpToRaw.cc:83
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
FEDTrailer.h