File indexing completed on 2024-04-06 12:05:18
0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "DataFormats/TCDS/interface/BSTRecord.h"
0003 #include "DataFormats/TCDS/interface/L1aInfo.h"
0004 #include "DataFormats/TCDS/interface/TCDSRaw.h"
0005 #include "DataFormats/TCDS/interface/TCDSRecord.h"
0006
0007 #include <cstdint>
0008 #include <cstdlib>
0009 #include <fstream>
0010 #include <sstream>
0011 #include <string>
0012 #include <vector>
0013
0014 class TestTCDSRecord : public CppUnit::TestFixture {
0015 CPPUNIT_TEST_SUITE(TestTCDSRecord);
0016 CPPUNIT_TEST(testHeader);
0017 CPPUNIT_TEST(testBstRecord);
0018 CPPUNIT_TEST(testL1aHistory);
0019 CPPUNIT_TEST(testBgoHistory);
0020 CPPUNIT_TEST_SUITE_END();
0021
0022 public:
0023 void setUp() override;
0024 void tearDown() override {}
0025
0026 void testHeader();
0027 void testBstRecord();
0028 void testL1aHistory();
0029 void testBgoHistory();
0030
0031 private:
0032 const std::string dumpFileName = "dump_run302403_event00112245_fed1024.txt";
0033 std::vector<uint32_t> data;
0034 TCDSRecord tcdsRecord;
0035 };
0036
0037
0038 CPPUNIT_TEST_SUITE_REGISTRATION(TestTCDSRecord);
0039
0040 void TestTCDSRecord::setUp() {
0041 if (data.empty()) {
0042 char* cmsswBase;
0043 cmsswBase = getenv("CMSSW_BASE");
0044 std::ostringstream dumpFileStr;
0045 dumpFileStr << cmsswBase << "/src/DataFormats/TCDS/test/" << dumpFileName;
0046
0047 std::ifstream dumpFile(dumpFileStr.str().c_str());
0048 uint32_t address;
0049
0050 std::string line, column;
0051 while (dumpFile.good()) {
0052 getline(dumpFile, line);
0053
0054 std::istringstream iss(line);
0055 if (!(iss >> std::hex >> address >> column))
0056 continue;
0057 for (int i = 0; i < 4; ++i) {
0058 uint32_t value;
0059 if (iss >> std::hex >> value) {
0060 data.push_back(value);
0061 }
0062 }
0063 }
0064 dumpFile.close();
0065
0066 CPPUNIT_ASSERT(data.size() == 238);
0067
0068 tcdsRecord = TCDSRecord((unsigned char*)data.data());
0069
0070 }
0071 }
0072
0073 void TestTCDSRecord::testHeader() {
0074 CPPUNIT_ASSERT(tcdsRecord.getMacAddress() == 0x80030f30044);
0075 CPPUNIT_ASSERT(tcdsRecord.getSwVersion() == 0x3005002);
0076 CPPUNIT_ASSERT(tcdsRecord.getFwVersion() == 0x5601222a);
0077 CPPUNIT_ASSERT(tcdsRecord.getRecordVersion() == 1);
0078 CPPUNIT_ASSERT(tcdsRecord.getRunNumber() == 302403);
0079 CPPUNIT_ASSERT(tcdsRecord.getNibble() == 23);
0080 CPPUNIT_ASSERT(tcdsRecord.getLumiSection() == 6);
0081 CPPUNIT_ASSERT(tcdsRecord.getEventType() == 2);
0082 CPPUNIT_ASSERT(tcdsRecord.getInputs() == 0);
0083 CPPUNIT_ASSERT(tcdsRecord.getOrbitNr() == 1403708);
0084 CPPUNIT_ASSERT(tcdsRecord.getBXID() == 3490);
0085 CPPUNIT_ASSERT(tcdsRecord.getTriggerCount() == 112245);
0086 CPPUNIT_ASSERT(tcdsRecord.getEventNumber() == 112245);
0087 CPPUNIT_ASSERT(tcdsRecord.getBstReceptionStatus() == TCDSRecord::BSTstatus::Okay);
0088 CPPUNIT_ASSERT(tcdsRecord.getActivePartitions().none());
0089 }
0090
0091 void TestTCDSRecord::testBstRecord() {
0092 CPPUNIT_ASSERT(tcdsRecord.getBST().getGpsTime() == 6462610227703219200);
0093 CPPUNIT_ASSERT(tcdsRecord.getBST().getBstMaster() == 1);
0094 CPPUNIT_ASSERT(tcdsRecord.getBST().getTurnCount() == 49907439);
0095 CPPUNIT_ASSERT(tcdsRecord.getBST().getLhcFill() == 6172);
0096 CPPUNIT_ASSERT(tcdsRecord.getBST().getBeamMode() == BSTRecord::BeamMode::RAMPDOWN);
0097 CPPUNIT_ASSERT(tcdsRecord.getBST().getParticleBeam1() == BSTRecord::Particle::PROTON);
0098 CPPUNIT_ASSERT(tcdsRecord.getBST().getParticleBeam2() == BSTRecord::Particle::PROTON);
0099 CPPUNIT_ASSERT(tcdsRecord.getBST().getBeamMomentum() == 1302);
0100 CPPUNIT_ASSERT(tcdsRecord.getBST().getIntensityBeam1() == 0);
0101 CPPUNIT_ASSERT(tcdsRecord.getBST().getIntensityBeam2() == 0);
0102 }
0103
0104 void TestTCDSRecord::testL1aHistory() {
0105 TCDSRecord::L1aHistory l1aHistory = tcdsRecord.getFullL1aHistory();
0106 CPPUNIT_ASSERT(l1aHistory.size() == tcds::l1aHistoryDepth_v1);
0107
0108 uint8_t index = 0;
0109 const uint64_t expectedOrbits[tcds::l1aHistoryDepth_v1] = {1403697,
0110 1403691,
0111 1403686,
0112 1403685,
0113 1403678,
0114 1403675,
0115 1403671,
0116 1403664,
0117 1403660,
0118 1403651,
0119 1403650,
0120 1403643,
0121 1403632,
0122 1403630,
0123 1403620,
0124 1403616};
0125 const uint64_t expectedBXIDs[tcds::l1aHistoryDepth_v1] = {
0126 297, 2090, 3136, 60, 249, 580, 3375, 2049, 524, 2518, 1083, 2571, 612, 2130, 2089, 3049};
0127 const uint64_t expectedEventTypes[tcds::l1aHistoryDepth_v1] = {3, 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 1, 3, 1, 3, 3};
0128
0129 for (auto l1a : l1aHistory) {
0130 CPPUNIT_ASSERT(l1a.getIndex() == -1 - index);
0131 CPPUNIT_ASSERT(l1a.getOrbitNr() == expectedOrbits[index]);
0132 CPPUNIT_ASSERT(l1a.getBXID() == expectedBXIDs[index]);
0133 CPPUNIT_ASSERT(l1a.getEventType() == expectedEventTypes[index]);
0134 ++index;
0135 }
0136 }
0137
0138 void TestTCDSRecord::testBgoHistory() {
0139 const uint64_t expectedOrbits[tcds::bgoCount_v1] = {
0140 1400831, 1403708, 1403708, 0, 0, 4518870, 0, 8, 4518878, 7, 0, 1403708, 0, 1403707, 1403606};
0141
0142 CPPUNIT_ASSERT(tcdsRecord.getLastOrbitCounter0() == 4518878);
0143 CPPUNIT_ASSERT(tcdsRecord.getLastTestEnable() == 1403708);
0144 CPPUNIT_ASSERT(tcdsRecord.getLastResync() == 4518870);
0145 CPPUNIT_ASSERT(tcdsRecord.getLastStart() == 7);
0146 CPPUNIT_ASSERT(tcdsRecord.getLastEventCounter0() == 8);
0147 CPPUNIT_ASSERT(tcdsRecord.getLastHardReset() == 0);
0148
0149 for (uint8_t bgo = 0; bgo < tcds::bgoCount_v1; ++bgo) {
0150 CPPUNIT_ASSERT(tcdsRecord.getOrbitOfLastBgo(bgo) == expectedOrbits[bgo]);
0151 }
0152 }