CMS 3D CMS Logo

AMC13DumpToRaw.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventFilter/L1TRawToDigi
4 // Class: AMC13DumpToRaw
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 
50  public:
51  explicit AMC13DumpToRaw(const edm::ParameterSet&);
52  ~AMC13DumpToRaw() 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 
65  // void formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data);
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
123  // amc13::Packet amc13;
124 
125  std::vector<uint32_t> load32;
126 
127  readEvent(load32);
128 
129  // formatAMC(amc13, load32);
130 
131  int size = load32.size() * 4;
132 
133  LogDebug("L1T") << "AMC13 size " << size << " bytes";
134 
135  // prepare the raw data collection
136  std::unique_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
137  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
138 
139  fed_data.resize(size);
140 
141  // fill FEDRawData object
142  for (unsigned i = 0; i < load32.size(); ++i) {
143  for (unsigned j = 0; j < 4; ++j) {
144  fed_data.data()[i * 4 + j] = (load32.at(i) >> (8 * j)) & 0xff;
145  }
146  }
147 
148  // formatRaw(iEvent, amc13, fed_data);
149 
150  LogDebug("L1T") << "Packing FED ID " << fedId_ << " size " << fed_data.size();
151 
152  // put the collection in the event
153  iEvent.put(std::move(raw_coll));
154  }
155 
156  void AMC13DumpToRaw::readEvent(std::vector<uint32_t>& load32) {
157  // read file
159 
160  // while not encountering dumb errors
161  while (getline(file_, line) && !line.empty()) {
162  std::istringstream iss(line);
163  unsigned long d;
164  iss >> std::hex >> d;
165 
166  load32.push_back(d);
167  }
168  }
169 
170  // void
171  // AMC13DumpToRaw::formatAMC(amc13::Packet& amc13, const std::vector<uint32_t>& load32) {
172 
173  // // TODO this is an empty word to be replaced with a proper MP7
174  // // header containing at least the firmware version
175 
176  // std::vector<uint64_t> load64;
177  // for (unsigned int i = 0; i < load32.size(); i += 2) {
178  // uint64_t word = load32[i];
179  // if (i + 1 < load32.size())
180  // word |= static_cast<uint64_t>(load32[i + 1]) << 32;
181  // load64.push_back(word);
182  // }
183 
184  // LogDebug("L1T") << "Creating AMC packet " << iAmc_;
185 
186  // amc13.add(iAmc_, boardId_, load64);
187 
188  // }
189 
190  // void
191  // AMC13DumpToRaw::formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data)
192  // {
193 
194  // unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
195  // fed_data.resize(size);
196  // unsigned char * payload = fed_data.data();
197  // unsigned char * payload_start = payload;
198 
199  // auto bxId = iEvent.bunchCrossing();
200  // auto evtId = iEvent.id().event();
201 
202  // LogDebug("L1T") << "Creating FEDRawData ID " << fedId_ << ", size " << size;
203 
204  // FEDHeader header(payload);
205  // header.set(payload, evType_, evtId, bxId, fedId_);
206 
207  // payload += slinkHeaderSize_;
208 
209  // amc13.write(iEvent, payload, size - slinkHeaderSize_ - slinkTrailerSize_);
210 
211  // payload += amc13.size() * 8;
212 
213  // FEDTrailer trailer(payload);
214  // trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
215 
216  // }
217 
218  // ------------ method called once each job just before starting event loop ------------
220  // open VME file
221  file_.open(filename_.c_str(), std::ios::in);
222  if (!file_.good()) {
223  edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl;
224  }
225  }
226 
227  // ------------ method called once each job just after ending the event loop ------------
228  void AMC13DumpToRaw::endJob() { file_.close(); }
229 
230  // ------------ method called when starting to processes a run ------------
231  /*
232 void
233 AMC13DumpToRaw::beginRun(edm::Run const&, edm::EventSetup const&)
234 {
235 }
236 */
237 
238  // ------------ method called when ending the processing of a run ------------
239  /*
240 void
241 AMC13DumpToRaw::endRun(edm::Run const&, edm::EventSetup const&)
242 {
243 }
244 */
245 
246  // ------------ method called when starting to processes a luminosity block ------------
247  /*
248 vvoid
249 AMC13DumpToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
250 {
251 }
252 */
253 
254  // ------------ method called when ending the processing of a luminosity block ------------
255  /*
256 void
257 AMC13DumpToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
258 {
259 }
260 */
261 
262  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
264  //The following says we do not know what parameters are allowed so do no validation
265  // Please change this to state exactly what you do use, even if it is no parameters
267  desc.setUnknown();
268  descriptions.addDefault(desc);
269  }
270 
271 } // namespace l1t
272 
273 using namespace l1t;
274 //define this as a plug-in
void beginJob() override
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
delete x;
Definition: CaloConfig.h:22
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
d
Definition: ztail.py:151
Log< level::Info, false > LogInfo
~AMC13DumpToRaw() override
void resize(size_t newsize, size_t wordsize=8)
Definition: FEDRawData.cc:28
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
void readEvent(std::vector< uint32_t > &load32)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
void produce(edm::Event &, const edm::EventSetup &) override
std::ifstream file_
void endJob() override
AMC13DumpToRaw(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)