CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 // system include files
21 #include <memory>
22 
23 // user include files
31 
36 
38 
39 #include <fstream>
40 #include <iostream>
41 #include <sstream>
42 #include <string>
43 #include <iomanip>
44 #include <boost/algorithm/string.hpp>
45 
47 
48 
49 namespace l1t {
50 
52 public:
53  explicit AMC13DumpToRaw(const edm::ParameterSet&);
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58 
59 private:
60  virtual void beginJob() override;
61  virtual void produce(edm::Event&, const edm::EventSetup&) override;
62  virtual void endJob() override;
63 
64  void readEvent(std::vector<uint32_t>& load32);
65 
66  // void formatAMC(amc13::Packet& amc13, const std::vector<uint32_t>& load32);
67 
68  // void formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data);
69 
70  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
71  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
72  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
73  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
74 
75  // ----------member data ---------------------------
76  std::ifstream file_;
78 
79  // DAQ params
80  int fedId_;
81  int iAmc_;
82  int boardId_;
83  int evType_;
84  int fwVer_;
85  int slinkHeaderSize_; // in 8-bit words
87 
88 };
89 
90 //
91 // constants, enums and typedefs
92 //
93 
94 //
95 // static data member definitions
96 //
97 
98 //
99 // constructors and destructor
100 //
102  filename_(iConfig.getUntrackedParameter<std::string>("filename", "data.txt")),
103  fedId_(iConfig.getUntrackedParameter<int>("fedId", 1)),
104  iAmc_(iConfig.getUntrackedParameter<int>("iAmc", 1)),
105  boardId_(iConfig.getUntrackedParameter<int>("boardId", 1)),
106  evType_(iConfig.getUntrackedParameter<int>("eventType", 1)),
107  fwVer_(iConfig.getUntrackedParameter<int>("fwVersion", 1)),
108  slinkHeaderSize_(iConfig.getUntrackedParameter<int>("lenSlinkHeader", 8)),
109  slinkTrailerSize_(iConfig.getUntrackedParameter<int>("lenSlinkTrailer", 8))
110 {
111 
112  produces<FEDRawDataCollection>();
113 
114 }
115 
116 
118 {
119 
120  // do anything here that needs to be done at desctruction time
121  // (e.g. close files, deallocate resources etc.)
122 
123 }
124 
125 
126 //
127 // member functions
128 //
129 
130 // ------------ method called for each event ------------
131 void
133 {
134  using namespace edm;
135 
136  // create AMC 13 packet
137  // amc13::Packet amc13;
138 
139  std::vector<uint32_t> load32;
140 
141  readEvent(load32);
142 
143  // formatAMC(amc13, load32);
144 
145  int size = load32.size() * 4;
146 
147  LogDebug("L1T") << "AMC13 size " << size << " bytes";
148 
149  // prepare the raw data collection
150  std::auto_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
151  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
152 
153  fed_data.resize(size);
154 
155  // fill FEDRawData object
156  for (unsigned i=0; i<load32.size(); ++i) {
157  for (unsigned j=0; j<4; ++j) {
158  fed_data.data()[i*4+j] = (load32.at(i)>>(8*j)) & 0xff;
159  }
160  }
161 
162  // formatRaw(iEvent, amc13, fed_data);
163 
164  LogDebug("L1T") << "Packing FED ID " << fedId_ << " size " << fed_data.size();
165 
166  // put the collection in the event
167  iEvent.put(raw_coll);
168 
169 }
170 
171 
172 void
173 AMC13DumpToRaw::readEvent(std::vector<uint32_t>& load32) {
174 
175  // read file
177 
178  // while not encountering dumb errors
179  while (getline(file_, line) && !line.empty() ) {
180 
181  std::istringstream iss(line);
182  unsigned long d;
183  iss >> std::hex >> d;
184 
185  load32.push_back( d ) ;
186 
187  }
188 
189 }
190 
191 
192 // void
193 // AMC13DumpToRaw::formatAMC(amc13::Packet& amc13, const std::vector<uint32_t>& load32) {
194 
195 // // TODO this is an empty word to be replaced with a proper MP7
196 // // header containing at least the firmware version
197 
198 // std::vector<uint64_t> load64;
199 // for (unsigned int i = 0; i < load32.size(); i += 2) {
200 // uint64_t word = load32[i];
201 // if (i + 1 < load32.size())
202 // word |= static_cast<uint64_t>(load32[i + 1]) << 32;
203 // load64.push_back(word);
204 // }
205 
206 // LogDebug("L1T") << "Creating AMC packet " << iAmc_;
207 
208 // amc13.add(iAmc_, boardId_, load64);
209 
210 // }
211 
212 
213 
214 // void
215 // AMC13DumpToRaw::formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data)
216 // {
217 
218 // unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
219 // fed_data.resize(size);
220 // unsigned char * payload = fed_data.data();
221 // unsigned char * payload_start = payload;
222 
223 // auto bxId = iEvent.bunchCrossing();
224 // auto evtId = iEvent.id().event();
225 
226 // LogDebug("L1T") << "Creating FEDRawData ID " << fedId_ << ", size " << size;
227 
228 // FEDHeader header(payload);
229 // header.set(payload, evType_, evtId, bxId, fedId_);
230 
231 // payload += slinkHeaderSize_;
232 
233 // amc13.write(iEvent, payload, size - slinkHeaderSize_ - slinkTrailerSize_);
234 
235 // payload += amc13.size() * 8;
236 
237 // FEDTrailer trailer(payload);
238 // trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
239 
240 // }
241 
242 
243 // ------------ method called once each job just before starting event loop ------------
244 void
246 {
247 
248  // open VME file
249  file_.open(filename_.c_str(), std::ios::in);
250  if(!file_.good()) { edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl; }
251 
252 
253 }
254 
255 
256 // ------------ method called once each job just after ending the event loop ------------
257 void
259 {
260 
261  file_.close();
262 
263 }
264 
265 // ------------ method called when starting to processes a run ------------
266 /*
267 void
268 AMC13DumpToRaw::beginRun(edm::Run const&, edm::EventSetup const&)
269 {
270 }
271 */
272 
273 // ------------ method called when ending the processing of a run ------------
274 /*
275 void
276 AMC13DumpToRaw::endRun(edm::Run const&, edm::EventSetup const&)
277 {
278 }
279 */
280 
281 // ------------ method called when starting to processes a luminosity block ------------
282 /*
283 vvoid
284 AMC13DumpToRaw::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
285 {
286 }
287 */
288 
289 // ------------ method called when ending the processing of a luminosity block ------------
290 /*
291 void
292 AMC13DumpToRaw::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
293 {
294 }
295 */
296 
297 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
298 void
300  //The following says we do not know what parameters are allowed so do no validation
301  // Please change this to state exactly what you do use, even if it is no parameters
303  desc.setUnknown();
304  descriptions.addDefault(desc);
305 }
306 
307 }
308 
309 using namespace l1t;
310 //define this as a plug-in
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void beginJob() override
tuple d
Definition: ztail.py:151
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
void resize(size_t newsize)
Definition: FEDRawData.cc:32
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
int j
Definition: DBlmapReader.cc:9
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void readEvent(std::vector< uint32_t > &load32)
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::ifstream file_
virtual void endJob() override
tuple size
Write out results.
AMC13DumpToRaw(const edm::ParameterSet &)