File indexing completed on 2024-04-06 12:10:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GtTextToRaw.h"
0017
0018
0019 #include <vector>
0020 #include <iostream>
0021 #include <iomanip>
0022
0023
0024 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0025 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0026
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0029
0030 #include "FWCore/Utilities/interface/typedefs.h"
0031
0032
0033 L1GtTextToRaw::L1GtTextToRaw(const edm::ParameterSet& pSet) {
0034 m_textFileType = pSet.getUntrackedParameter<std::string>("TextFileType", "VmeSpyDump");
0035
0036 LogDebug("L1GtTextToRaw") << "\nText file type: " << m_textFileType << "\n" << std::endl;
0037
0038 m_textFileName = pSet.getUntrackedParameter<std::string>("TextFileName", "gtfe.dmp");
0039
0040 LogDebug("L1GtTextToRaw") << "\nText file name: " << m_textFileName << "\n" << std::endl;
0041
0042
0043 m_rawDataSize = pSet.getUntrackedParameter<int>("RawDataSize");
0044
0045 LogDebug("L1GtTextToRaw") << "\nRaw data size (units of 8 bits): " << m_rawDataSize
0046 << "\n If negative value, the size is retrieved from the trailer."
0047 << "\n"
0048 << std::endl;
0049
0050
0051
0052
0053 m_daqGtFedId = pSet.getUntrackedParameter<int>("DaqGtFedId", FEDNumbering::MAXTriggerGTPFEDID);
0054
0055 LogDebug("L1GtTextToRaw") << "\nFED Id for DAQ GT record: " << m_daqGtFedId << " \n" << std::endl;
0056
0057
0058 m_textFile.open(m_textFileName.c_str(), std::ios::in);
0059 if (!m_textFile.good()) {
0060 throw cms::Exception("NotFound") << "\nError: failed to open text file = " << m_textFileName << "\n" << std::endl;
0061 }
0062
0063
0064 produces<FEDRawDataCollection>();
0065 }
0066
0067
0068 L1GtTextToRaw::~L1GtTextToRaw() {
0069
0070 }
0071
0072
0073
0074
0075 void L1GtTextToRaw::beginJob() { cleanTextFile(); }
0076
0077
0078 void L1GtTextToRaw::cleanTextFile() { LogDebug("L1GtTextToRaw") << "\nCleaning the text file\n" << std::endl; }
0079
0080
0081 int L1GtTextToRaw::getDataSize() {
0082 LogDebug("L1GtTextToRaw") << "\nComputing raw data size with getRecordSize() method." << std::endl;
0083
0084 int rawDataSize = 0;
0085
0086 LogDebug("L1GtTextToRaw") << "\nComputed raw data size: " << rawDataSize << std::endl;
0087
0088 return rawDataSize;
0089 }
0090
0091
0092 void L1GtTextToRaw::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {
0093
0094
0095 int rawDataSize = 0;
0096
0097 if (m_rawDataSize < 0) {
0098 rawDataSize = getDataSize();
0099 } else {
0100 rawDataSize = m_rawDataSize;
0101 }
0102
0103
0104
0105 std::unique_ptr<FEDRawDataCollection> fedRawColl(new FEDRawDataCollection);
0106
0107 FEDRawData& rawData = fedRawColl->FEDData(m_daqGtFedId);
0108
0109
0110 rawData.resize(rawDataSize);
0111
0112 LogDebug("L1GtTextToRaw") << "\n Size of raw data: " << rawData.size() << "\n" << std::endl;
0113
0114
0115
0116
0117
0118 std::string lineString;
0119
0120 cms_uint64_t lineInt = 0ULL;
0121 int sizeL = sizeof(lineInt);
0122
0123 int fedBlockSize = 8;
0124 int maskBlock = 0xff;
0125
0126 int iLine = 0;
0127
0128 while (std::getline(m_textFile, lineString)) {
0129 if (lineString.empty()) {
0130 break;
0131 }
0132
0133
0134 std::istringstream iss(lineString);
0135
0136 iss >> std::hex >> lineInt;
0137
0138 LogTrace("L1GtTextToRaw") << std::dec << std::setw(4) << std::setfill('0') << iLine << ": " << std::hex
0139 << std::setw(sizeL * 2) << lineInt << std::dec << std::setfill(' ') << std::endl;
0140
0141
0142 for (int j = 0; j < sizeL; j++) {
0143 char blockContent = (lineInt >> (fedBlockSize * j)) & maskBlock;
0144 rawData.data()[iLine * sizeL + j] = blockContent;
0145 }
0146
0147 ++iLine;
0148 }
0149
0150
0151 iEvent.put(std::move(fedRawColl));
0152 }
0153
0154
0155 void L1GtTextToRaw::endJob() {
0156
0157 }
0158
0159