File indexing completed on 2024-04-06 12:10:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Utilities/interface/Exception.h"
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDProducer.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/ServiceRegistry/interface/Service.h"
0030
0031 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0032 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0033 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0034 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0035
0036 #include "FWCore/Utilities/interface/CRC16.h"
0037
0038 #include <fstream>
0039 #include <iostream>
0040 #include <sstream>
0041 #include <string>
0042 #include <iomanip>
0043 #include <boost/algorithm/string.hpp>
0044
0045 #include "EventFilter/L1TRawToDigi/interface/AMCSpec.h"
0046
0047 namespace l1t {
0048
0049 class AMC13DumpToRaw : public edm::one::EDProducer<> {
0050 public:
0051 explicit AMC13DumpToRaw(const edm::ParameterSet&);
0052
0053 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0054
0055 private:
0056 void beginJob() override;
0057 void produce(edm::Event&, const edm::EventSetup&) override;
0058 void endJob() override;
0059
0060 void readEvent(std::vector<uint32_t>& load32);
0061
0062
0063
0064
0065
0066
0067 std::ifstream file_;
0068 std::string filename_;
0069
0070
0071 int fedId_;
0072 int iAmc_;
0073 int boardId_;
0074 int evType_;
0075 int fwVer_;
0076 int slinkHeaderSize_;
0077 int slinkTrailerSize_;
0078 };
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 AMC13DumpToRaw::AMC13DumpToRaw(const edm::ParameterSet& iConfig)
0092 : filename_(iConfig.getUntrackedParameter<std::string>("filename", "data.txt")),
0093 fedId_(iConfig.getUntrackedParameter<int>("fedId", 1)),
0094 iAmc_(iConfig.getUntrackedParameter<int>("iAmc", 1)),
0095 boardId_(iConfig.getUntrackedParameter<int>("boardId", 1)),
0096 evType_(iConfig.getUntrackedParameter<int>("eventType", 1)),
0097 fwVer_(iConfig.getUntrackedParameter<int>("fwVersion", 1)),
0098 slinkHeaderSize_(iConfig.getUntrackedParameter<int>("lenSlinkHeader", 8)),
0099 slinkTrailerSize_(iConfig.getUntrackedParameter<int>("lenSlinkTrailer", 8)) {
0100 produces<FEDRawDataCollection>();
0101 }
0102
0103
0104
0105
0106
0107
0108 void AMC13DumpToRaw::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0109 using namespace edm;
0110
0111
0112
0113
0114 std::vector<uint32_t> load32;
0115
0116 readEvent(load32);
0117
0118
0119
0120 int size = load32.size() * 4;
0121
0122 LogDebug("L1T") << "AMC13 size " << size << " bytes";
0123
0124
0125 std::unique_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
0126 FEDRawData& fed_data = raw_coll->FEDData(fedId_);
0127
0128 fed_data.resize(size);
0129
0130
0131 for (unsigned i = 0; i < load32.size(); ++i) {
0132 for (unsigned j = 0; j < 4; ++j) {
0133 fed_data.data()[i * 4 + j] = (load32.at(i) >> (8 * j)) & 0xff;
0134 }
0135 }
0136
0137
0138
0139 LogDebug("L1T") << "Packing FED ID " << fedId_ << " size " << fed_data.size();
0140
0141
0142 iEvent.put(std::move(raw_coll));
0143 }
0144
0145 void AMC13DumpToRaw::readEvent(std::vector<uint32_t>& load32) {
0146
0147 std::string line;
0148
0149
0150 while (getline(file_, line) && !line.empty()) {
0151 std::istringstream iss(line);
0152 unsigned long d;
0153 iss >> std::hex >> d;
0154
0155 load32.push_back(d);
0156 }
0157 }
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208 void AMC13DumpToRaw::beginJob() {
0209
0210 file_.open(filename_.c_str(), std::ios::in);
0211 if (!file_.good()) {
0212 edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl;
0213 }
0214 }
0215
0216
0217 void AMC13DumpToRaw::endJob() { file_.close(); }
0218
0219
0220 void AMC13DumpToRaw::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0221
0222
0223 edm::ParameterSetDescription desc;
0224 desc.setUnknown();
0225 descriptions.addDefault(desc);
0226 }
0227
0228 }
0229
0230 using namespace l1t;
0231
0232 DEFINE_FWK_MODULE(AMC13DumpToRaw);