File indexing completed on 2023-03-17 11:13:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include "FWCore/MessageLogger/interface/MessageLogger.h" // Logger
0036 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
0037 #include "RctTextToRctDigi.h"
0038 #include <iomanip>
0039
0040 using namespace edm;
0041 using namespace std;
0042
0043
0044 const static unsigned NUM_RCT_CRATES = 18;
0045
0046 RctTextToRctDigi::RctTextToRctDigi(const edm::ParameterSet &iConfig)
0047 : m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
0048 m_fileEventOffset(iConfig.getParameter<int>("FileEventOffset")),
0049 m_nevt(0) {
0050
0051 produces<L1CaloEmCollection>();
0052 produces<L1CaloRegionCollection>();
0053
0054
0055 for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
0056 std::stringstream fileStream;
0057 fileStream << m_textFileName << std::setw(2) << std::setfill('0') << i << ".txt";
0058 std::string fileName(fileStream.str());
0059 m_file[i].open(fileName.c_str(), std::ios::in);
0060
0061 if (!m_file[i].good()) {
0062
0063 LogDebug("RctTextToRctDigi") << "RctTextToRctDigi::RctTextToRctDigi : "
0064 << " couldn't open the file " << fileName << "...skipping!" << std::endl;
0065 }
0066 }
0067 }
0068
0069 RctTextToRctDigi::~RctTextToRctDigi() {
0070
0071 for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
0072 m_file[i].close();
0073 }
0074 }
0075
0076
0077 void RctTextToRctDigi::putEmptyDigi(edm::Event &iEvent) {
0078 std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
0079 std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
0080 for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
0081 for (unsigned j = 0; j < 4; j++) {
0082 em->push_back(L1CaloEmCand(0, i, true));
0083 em->push_back(L1CaloEmCand(0, i, false));
0084 }
0085 for (unsigned j = 0; j < 14; j++)
0086 rgn->push_back(L1CaloRegion(0, false, false, false, false, i, j / 2, j % 2));
0087 for (unsigned j = 0; j < 8; j++)
0088 rgn->push_back(L1CaloRegion(0, true, i, j));
0089 }
0090 iEvent.put(std::move(em));
0091 iEvent.put(std::move(rgn));
0092 }
0093
0094
0095 void RctTextToRctDigi::bxSynchro(int &bx, int crate) {
0096 std::string tmp;
0097
0098 while (bx < m_nevt + m_fileEventOffset) {
0099 for (int j = 0; j < 6; j++) {
0100 getline(m_file[crate], tmp);
0101 }
0102 m_file[crate] >> tmp >> bx;
0103 if (tmp != "Crossing")
0104 throw cms::Exception("RctTextToRctDigiTextFileReadError")
0105 << "RctTextToRctDigi::bxSynchro : "
0106 << " something screwy happened Crossing!=" << tmp << std::endl;
0107 }
0108 }
0109
0110
0111 void RctTextToRctDigi::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0112
0113 if (m_nevt < m_fileEventOffset) {
0114
0115
0116
0117
0118 putEmptyDigi(iEvent);
0119 m_nevt++;
0120 return;
0121 }
0122
0123
0124 std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
0125 std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
0126
0127
0128 for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
0129 if (!m_file[i].good()) {
0130 continue;
0131 }
0132
0133
0134 if (m_file[i].eof()) {
0135
0136 LogDebug("RctTextToRctDigi") << "RctTextToRctDigi::produce : "
0137 << " unexpected end of file " << m_textFileName << i
0138 << " adding empty collection for event !" << std::endl;
0139 putEmptyDigi(iEvent);
0140 continue;
0141 }
0142
0143
0144 std::string tmp;
0145 m_file[i] >> tmp;
0146 if (tmp != "Crossing") {
0147 throw cms::Exception("RctTextToRctDigiTextFileReadError")
0148 << "RctTextToRctDigi::produce : "
0149 << " something screwy happened Crossing!=" << tmp << std::endl;
0150 }
0151
0152
0153 dec(m_file[i]);
0154 int BXNum;
0155 m_file[i] >> BXNum;
0156
0157
0158 bxSynchro(BXNum, i);
0159
0160 if (BXNum != m_nevt + m_fileEventOffset)
0161 throw cms::Exception("RctTextToRctDigiTextSyncError")
0162 << "RctTextToRctDigi::produce : "
0163 << " something screwy happened "
0164 << "evt:" << m_nevt << " != bx:" << BXNum << " + " << m_fileEventOffset << std::endl;
0165
0166
0167 unsigned long int uLongBuffer;
0168 bool mipBitBuffer[14], qBitBuffer[14];
0169
0170
0171 hex(m_file[i]);
0172
0173
0174 for (unsigned j = 0; j < 4; j++) {
0175 m_file[i] >> uLongBuffer;
0176 em->push_back(L1CaloEmCand(uLongBuffer, i, true, j, BXNum, false));
0177 }
0178
0179
0180 for (unsigned j = 0; j < 4; j++) {
0181 m_file[i] >> uLongBuffer;
0182 em->push_back(L1CaloEmCand(uLongBuffer, i, false, j, BXNum, false));
0183 }
0184
0185
0186 for (unsigned j = 0; j < 14; j++) {
0187 m_file[i] >> mipBitBuffer[j];
0188 }
0189
0190
0191 for (unsigned j = 0; j < 14; j++) {
0192 m_file[i] >> qBitBuffer[j];
0193 }
0194
0195
0196 for (unsigned j = 0; j < 14; j++) {
0197 m_file[i] >> uLongBuffer;
0198
0199 unsigned et = uLongBuffer & 0x3ff;
0200 uLongBuffer >>= 10;
0201
0202 bool overFlow = ((uLongBuffer & 0x1) != 0);
0203 bool tauVeto = (((uLongBuffer & 0x2) >> 1) != 0);
0204
0205 rgn->push_back(L1CaloRegion(et, overFlow, tauVeto, mipBitBuffer[j], qBitBuffer[j], i, j / 2, j % 2));
0206 }
0207
0208
0209 for (unsigned j = 0; j < 8; j++) {
0210 m_file[i] >> uLongBuffer;
0211
0212 unsigned et = uLongBuffer & 0xff;
0213
0214 rgn->push_back(L1CaloRegion(et, true, i, j));
0215 }
0216
0217 dec(m_file[i]);
0218 }
0219
0220 iEvent.put(std::move(em));
0221 iEvent.put(std::move(rgn));
0222
0223 m_nevt++;
0224 }