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 #include "FWCore/MessageLogger/interface/MessageLogger.h" // Logger
0020 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
0021 #include "SourceCardTextToRctDigi.h"
0022
0023 using namespace edm;
0024 using namespace std;
0025
0026
0027 const static unsigned NUM_LINES_PER_EVENT = 63;
0028 const static int NUM_RCT_CRATES = 18;
0029
0030 SourceCardTextToRctDigi::SourceCardTextToRctDigi(const edm::ParameterSet &iConfig)
0031 : m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
0032 m_fileEventOffset(iConfig.getParameter<int>("fileEventOffset")),
0033 m_nevt(0) {
0034
0035 produces<L1CaloEmCollection>();
0036 produces<L1CaloRegionCollection>();
0037
0038
0039 m_file.open(m_textFileName.c_str(), std::ios::in);
0040
0041 if (!m_file.good()) {
0042 throw cms::Exception("SourceCardTextToRctDigiTextFileOpenError")
0043 << "SourceCardTextToRctDigi::SourceCardTextToRctDigi : "
0044 << " couldn't open the file " << m_textFileName << " for reading" << std::endl;
0045 }
0046
0047
0048 SourceCardRouting m_scRouting;
0049 }
0050
0051 SourceCardTextToRctDigi::~SourceCardTextToRctDigi() {
0052
0053 m_file.close();
0054 }
0055
0056
0057 void SourceCardTextToRctDigi::putEmptyDigi(edm::Event &iEvent) {
0058 std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
0059 std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
0060 for (int i = 0; i < NUM_RCT_CRATES; i++) {
0061 for (int j = 0; j < 4; j++) {
0062 em->push_back(L1CaloEmCand(0, i, true));
0063 em->push_back(L1CaloEmCand(0, i, false));
0064 }
0065 for (int j = 0; j < 14; j++)
0066 rgn->push_back(L1CaloRegion(0, false, false, false, false, i, j / 2, j % 2));
0067 for (unsigned j = 0; j < 8; j++)
0068 rgn->push_back(L1CaloRegion(0, true, i, j));
0069 }
0070 iEvent.put(std::move(em));
0071 iEvent.put(std::move(rgn));
0072 }
0073
0074
0075 void SourceCardTextToRctDigi::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0076
0077 if (m_nevt < m_fileEventOffset) {
0078
0079
0080
0081
0082 putEmptyDigi(iEvent);
0083 m_nevt++;
0084 return;
0085 } else if (m_nevt == 0 && m_fileEventOffset < 0) {
0086
0087 std::string tmp;
0088 for (int i = 0; i < abs(m_fileEventOffset); i++)
0089 for (unsigned line = 0; line < NUM_LINES_PER_EVENT; line++)
0090 if (!getline(m_file, tmp)) {
0091 throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
0092 << "SourceCardTextToRctDigi::produce() : "
0093 << " couldn't read from the file " << m_textFileName << std::endl;
0094 }
0095 }
0096
0097
0098 std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
0099 std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
0100
0101
0102 unsigned long VHDCI[2][2];
0103 int routingMode;
0104 int crate;
0105 std::string dataString;
0106 unsigned short eventNumber;
0107 unsigned short logicalCardID;
0108
0109
0110 unsigned short eIsoRank[18][4];
0111 unsigned short eIsoCardId[18][4];
0112 unsigned short eIsoRegionId[18][4];
0113 unsigned short eNonIsoRank[18][4];
0114 unsigned short eNonIsoCardId[18][4];
0115 unsigned short eNonIsoRegionId[18][4];
0116
0117
0118 unsigned short RC[18][7][2];
0119 unsigned short RCof[18][7][2];
0120 unsigned short RCtau[18][7][2];
0121 unsigned short MIPbits[18][7][2];
0122 unsigned short Qbits[18][7][2];
0123 unsigned short HF[18][4][2];
0124 unsigned short HFQ[18][4][2];
0125
0126
0127 if (m_file.eof()) {
0128 throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
0129 << "SourceCardTextToRctDigi::produce : "
0130 << " unexpected end of file " << m_textFileName << std::endl;
0131 }
0132
0133 int thisEventNumber = -1;
0134
0135 for (unsigned line = 0; line < NUM_LINES_PER_EVENT; line++) {
0136 if (!getline(m_file, dataString)) {
0137 throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
0138 << "SourceCardTextToRctDigi::SourceCardTextToRctDigi : "
0139 << " couldn't read from the file " << m_textFileName << std::endl;
0140 }
0141
0142
0143 m_scRouting.STRINGtoVHDCI(logicalCardID, eventNumber, dataString, VHDCI);
0144
0145
0146 if (line != 0)
0147 assert(eventNumber == thisEventNumber);
0148 thisEventNumber = eventNumber;
0149
0150
0151 m_scRouting.LogicalCardIDtoRoutingMode(logicalCardID, routingMode, crate);
0152
0153 if (routingMode == 0) {
0154
0155 m_scRouting.VHDCItoEMU(eIsoRank[crate],
0156 eIsoCardId[crate],
0157 eIsoRegionId[crate],
0158 eNonIsoRank[crate],
0159 eNonIsoCardId[crate],
0160 eNonIsoRegionId[crate],
0161 MIPbits[crate],
0162 Qbits[crate],
0163 VHDCI);
0164
0165 } else if (routingMode == 1) {
0166
0167 m_scRouting.VHDCItoRC56HF(RC[crate], RCof[crate], RCtau[crate], HF[crate], HFQ[crate], VHDCI);
0168
0169 } else if (routingMode == 2) {
0170
0171 m_scRouting.VHDCItoRC012(RC[crate], RCof[crate], RCtau[crate], VHDCI);
0172
0173 } else if (routingMode == 3) {
0174
0175 m_scRouting.VHDCItoRC234(
0176 RC[crate], RCof[crate], RCtau[crate], RC[crate + 9], RCof[crate + 9], RCtau[crate + 9], VHDCI);
0177
0178 } else {
0179
0180 throw cms::Exception("SourceCardtextToRctDigiError") << "SourceCardTextToRctDigi::produce : "
0181 << " unknown routing mode=" << routingMode << std::endl;
0182 }
0183 }
0184
0185
0186 for (crate = 0; crate < NUM_RCT_CRATES; crate++) {
0187
0188 for (int i = 0; i < 4; i++) {
0189 em->push_back(L1CaloEmCand(eIsoRank[crate][i], eIsoRegionId[crate][i], eIsoCardId[crate][i], crate, true, i, 0));
0190 em->push_back(
0191 L1CaloEmCand(eNonIsoRank[crate][i], eNonIsoRegionId[crate][i], eNonIsoCardId[crate][i], crate, false, i, 0));
0192 }
0193
0194
0195 for (int i = 0; i < 7; i++) {
0196 for (int j = 0; j < 2; j++) {
0197 rgn->push_back(L1CaloRegion::makeHBHERegion(RC[crate][i][j],
0198 RCof[crate][i][j],
0199 RCtau[crate][i][j],
0200 MIPbits[crate][i][j],
0201 Qbits[crate][i][j],
0202 crate,
0203 i,
0204 j));
0205 }
0206 }
0207
0208
0209 for (int i = 0; i < 4; i++) {
0210 for (int j = 0; j < 2; j++) {
0211 rgn->push_back(L1CaloRegion::makeHFRegion(HF[crate][i][j],
0212 HFQ[crate][i][j],
0213 crate,
0214 i + (4 * j)));
0215 }
0216 }
0217 }
0218
0219
0220 for (L1CaloEmCollection::const_iterator iem = em->begin(); iem != em->end(); iem++) {
0221 LogDebug("Electrons") << (*iem);
0222 }
0223
0224 for (L1CaloRegionCollection::const_iterator irgn = rgn->begin(); irgn != rgn->end(); irgn++) {
0225 LogDebug("HFRegions") << (*irgn);
0226 }
0227
0228 iEvent.put(std::move(em));
0229 iEvent.put(std::move(rgn));
0230
0231 m_nevt++;
0232 }