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 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55  private:
56  void beginJob() override;
57  void produce(edm::Event&, const edm::EventSetup&) override;
58  void endJob() override;
59 
60  void readEvent(std::vector<uint32_t>& load32);
61 
62  // void formatAMC(amc13::Packet& amc13, const std::vector<uint32_t>& load32);
63 
64  // void formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data);
65 
66  // ----------member data ---------------------------
67  std::ifstream file_;
69 
70  // DAQ params
71  int fedId_;
72  int iAmc_;
73  int boardId_;
74  int evType_;
75  int fwVer_;
76  int slinkHeaderSize_; // in 8-bit words
78  };
79 
80  //
81  // constants, enums and typedefs
82  //
83 
84  //
85  // static data member definitions
86  //
87 
88  //
89  // constructors and destructor
90  //
92  : filename_(iConfig.getUntrackedParameter<std::string>("filename", "data.txt")),
93  fedId_(iConfig.getUntrackedParameter<int>("fedId", 1)),
94  iAmc_(iConfig.getUntrackedParameter<int>("iAmc", 1)),
95  boardId_(iConfig.getUntrackedParameter<int>("boardId", 1)),
96  evType_(iConfig.getUntrackedParameter<int>("eventType", 1)),
97  fwVer_(iConfig.getUntrackedParameter<int>("fwVersion", 1)),
98  slinkHeaderSize_(iConfig.getUntrackedParameter<int>("lenSlinkHeader", 8)),
99  slinkTrailerSize_(iConfig.getUntrackedParameter<int>("lenSlinkTrailer", 8)) {
100  produces<FEDRawDataCollection>();
101  }
102 
103  //
104  // member functions
105  //
106 
107  // ------------ method called for each event ------------
109  using namespace edm;
110 
111  // create AMC 13 packet
112  // amc13::Packet amc13;
113 
114  std::vector<uint32_t> load32;
115 
116  readEvent(load32);
117 
118  // formatAMC(amc13, load32);
119 
120  int size = load32.size() * 4;
121 
122  LogDebug("L1T") << "AMC13 size " << size << " bytes";
123 
124  // prepare the raw data collection
125  std::unique_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
126  FEDRawData& fed_data = raw_coll->FEDData(fedId_);
127 
128  fed_data.resize(size);
129 
130  // fill FEDRawData object
131  for (unsigned i = 0; i < load32.size(); ++i) {
132  for (unsigned j = 0; j < 4; ++j) {
133  fed_data.data()[i * 4 + j] = (load32.at(i) >> (8 * j)) & 0xff;
134  }
135  }
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 AMC13DumpToRaw::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
160  // AMC13DumpToRaw::formatAMC(amc13::Packet& amc13, const std::vector<uint32_t>& load32) {
161 
162  // // TODO this is an empty word to be replaced with a proper MP7
163  // // header containing at least the firmware version
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  // load64.push_back(word);
171  // }
172 
173  // LogDebug("L1T") << "Creating AMC packet " << iAmc_;
174 
175  // amc13.add(iAmc_, boardId_, load64);
176 
177  // }
178 
179  // void
180  // AMC13DumpToRaw::formatRaw(edm::Event& iEvent, amc13::Packet& amc13, FEDRawData& fed_data)
181  // {
182 
183  // unsigned int size = slinkHeaderSize_ + slinkTrailerSize_ + amc13.size() * 8;
184  // fed_data.resize(size);
185  // unsigned char * payload = fed_data.data();
186  // unsigned char * payload_start = payload;
187 
188  // auto bxId = iEvent.bunchCrossing();
189  // auto evtId = iEvent.id().event();
190 
191  // LogDebug("L1T") << "Creating FEDRawData ID " << fedId_ << ", size " << size;
192 
193  // FEDHeader header(payload);
194  // header.set(payload, evType_, evtId, bxId, fedId_);
195 
196  // payload += slinkHeaderSize_;
197 
198  // amc13.write(iEvent, payload, size - slinkHeaderSize_ - slinkTrailerSize_);
199 
200  // payload += amc13.size() * 8;
201 
202  // FEDTrailer trailer(payload);
203  // trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
204 
205  // }
206 
207  // ------------ method called once each job just before starting event loop ------------
209  // open VME file
210  file_.open(filename_.c_str(), std::ios::in);
211  if (!file_.good()) {
212  edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl;
213  }
214  }
215 
216  // ------------ method called once each job just after ending the event loop ------------
217  void AMC13DumpToRaw::endJob() { file_.close(); }
218 
219  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
221  //The following says we do not know what parameters are allowed so do no validation
222  // Please change this to state exactly what you do use, even if it is no parameters
224  desc.setUnknown();
225  descriptions.addDefault(desc);
226  }
227 
228 } // namespace l1t
229 
230 using namespace l1t;
231 //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
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)