Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-06 04:00:44

0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0003 #include "DataFormats/OnlineMetaData/interface/CTPPSRecord.h"
0004 #include "DataFormats/OnlineMetaData/interface/DCSRecord.h"
0005 #include "DataFormats/OnlineMetaData/interface/OnlineLuminosityRecord.h"
0006 #include "DataFormats/OnlineMetaData/interface/OnlineMetaDataRaw.h"
0007 
0008 #include <cstdint>
0009 #include <cstdlib>
0010 #include <filesystem>
0011 #include <fstream>
0012 #include <sstream>
0013 #include <string.h>
0014 #include <vector>
0015 
0016 class TestOnlineMetaDataRecord : public CppUnit::TestFixture {
0017   CPPUNIT_TEST_SUITE(TestOnlineMetaDataRecord);
0018   CPPUNIT_TEST(testDCSRecord_v1);
0019   CPPUNIT_TEST(testDCSRecord_v2);
0020   CPPUNIT_TEST(testDCSRecord_v3);
0021   CPPUNIT_TEST(testOnlineLuminosityRecord_v1);
0022   CPPUNIT_TEST(testOnlineLuminosityRecord_v2);
0023   CPPUNIT_TEST(testCTPPSRecord_v2);
0024   CPPUNIT_TEST_SUITE_END();
0025 
0026 public:
0027   void setUp() override{};
0028   void tearDown() override;
0029 
0030   void testDCSRecord_v1();
0031   void testDCSRecord_v2();
0032   void testDCSRecord_v3();
0033   void testOnlineLuminosityRecord_v1();
0034   void testOnlineLuminosityRecord_v2();
0035   void testCTPPSRecord_v2();
0036 
0037 private:
0038   const unsigned char* readPayload(const std::string& dumpFileName);
0039 
0040   std::vector<uint32_t> data;
0041 };
0042 
0043 ///registration of the test so that the runner can find it
0044 CPPUNIT_TEST_SUITE_REGISTRATION(TestOnlineMetaDataRecord);
0045 
0046 const unsigned char* TestOnlineMetaDataRecord::readPayload(const std::string& dumpFileName) {
0047   const std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0048   const std::string CMSSW_RELEASE_BASE(std::getenv("CMSSW_RELEASE_BASE"));
0049   const std::string dumpFilePath = "/src/DataFormats/OnlineMetaData/test/" + dumpFileName;
0050   const std::string fullPath = std::filesystem::exists((CMSSW_BASE + dumpFilePath).c_str())
0051                                    ? CMSSW_BASE + dumpFilePath
0052                                    : CMSSW_RELEASE_BASE + dumpFilePath;
0053 
0054   std::ifstream dumpFile(fullPath.c_str());
0055   uint32_t address;
0056 
0057   std::string line, column;
0058   while (dumpFile.good()) {
0059     getline(dumpFile, line);
0060     //std::cout << line << std::endl;
0061     std::istringstream iss(line);
0062     if (!(iss >> std::hex >> address >> column))
0063       continue;
0064     for (int i = 0; i < 4; ++i) {
0065       uint32_t value;
0066       if (iss >> std::hex >> value) {
0067         data.push_back(value);
0068       }
0069     }
0070   }
0071   dumpFile.close();
0072 
0073   return reinterpret_cast<unsigned char*>(data.data());
0074 }
0075 
0076 void TestOnlineMetaDataRecord::tearDown() { data.clear(); }
0077 
0078 float castToFloat(uint32_t value) {
0079   float f;
0080   memcpy(&f, &value, sizeof(uint32_t));
0081   return f;
0082 }
0083 
0084 void TestOnlineMetaDataRecord::testDCSRecord_v1() {
0085   const unsigned char* payload = readPayload("dump_run000001_event00057185_fed1022.txt");
0086   const online::Data_v1* data_v1 = reinterpret_cast<online::Data_v1 const*>(payload + FEDHeader::length);
0087   DCSRecord dcs(data_v1->dcs);
0088   std::cout << dcs << std::endl;
0089 
0090   // DIP timestamp is in milliseconds
0091   const uint64_t ts = dcs.timestamp().unixTime() * 1000UL + dcs.timestamp().microsecondOffset() / 1000;
0092   CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(0x160036025f6), ts);
0093   CPPUNIT_ASSERT(dcs.highVoltageReady(DCSRecord::Partition::HF));
0094   CPPUNIT_ASSERT(!dcs.highVoltageReady(DCSRecord::Partition::CASTOR));
0095   CPPUNIT_ASSERT(dcs.highVoltageReady(DCSRecord::Partition::ESm));
0096   CPPUNIT_ASSERT_EQUAL(castToFloat(0x468de7eb), dcs.magnetCurrent());
0097 }
0098 
0099 void TestOnlineMetaDataRecord::testDCSRecord_v2() {
0100   const unsigned char* payload = readPayload("dump_run000001_event00013761_fed1022.txt");
0101   const online::Data_v2* data_v2 = reinterpret_cast<online::Data_v2 const*>(payload + FEDHeader::length);
0102   DCSRecord dcs(data_v2->dcs);
0103   std::cout << dcs << std::endl;
0104 
0105   // DIP timestamp is in milliseconds
0106   const uint64_t ts = dcs.timestamp().unixTime() * 1000UL + dcs.timestamp().microsecondOffset() / 1000;
0107   CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(0x1616b52f433), ts);
0108   CPPUNIT_ASSERT(dcs.highVoltageReady(DCSRecord::Partition::CSCp));
0109   CPPUNIT_ASSERT(!dcs.highVoltageReady(DCSRecord::Partition::BPIX));
0110   CPPUNIT_ASSERT(dcs.highVoltageReady(DCSRecord::Partition::TOB));
0111   CPPUNIT_ASSERT_EQUAL(castToFloat(0x3ccd2785), dcs.magnetCurrent());
0112 }
0113 
0114 void TestOnlineMetaDataRecord::testDCSRecord_v3() {
0115   const unsigned char* payload = readPayload("dump_run000001_event1350583585_fed1022.txt");
0116   const online::Data_v3* data_v3 = reinterpret_cast<online::Data_v3 const*>(payload + FEDHeader::length);
0117   DCSRecord dcs(data_v3->dcs);
0118 
0119   // DIP timestamp is in milliseconds
0120   const uint64_t ts = dcs.timestamp().unixTime() * 1000UL + dcs.timestamp().microsecondOffset() / 1000;
0121   CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(0x17d6fae1ad6), ts);
0122   CPPUNIT_ASSERT(dcs.highVoltageValid(DCSRecord::Partition::CSCp));
0123   CPPUNIT_ASSERT(!dcs.highVoltageReady(DCSRecord::Partition::CSCp));
0124   CPPUNIT_ASSERT(dcs.highVoltageValid(DCSRecord::Partition::BPIX));
0125   CPPUNIT_ASSERT(!dcs.highVoltageReady(DCSRecord::Partition::BPIX));
0126   CPPUNIT_ASSERT(dcs.highVoltageValid(DCSRecord::Partition::TOB));
0127   CPPUNIT_ASSERT(!dcs.highVoltageReady(DCSRecord::Partition::TOB));
0128   CPPUNIT_ASSERT(!dcs.highVoltageValid(DCSRecord::Partition::ZDC));
0129   CPPUNIT_ASSERT(!dcs.highVoltageValid(DCSRecord::Partition::CASTOR));
0130   CPPUNIT_ASSERT_EQUAL(castToFloat(0x3D69F92E), dcs.magnetCurrent());
0131 }
0132 
0133 void TestOnlineMetaDataRecord::testOnlineLuminosityRecord_v1() {
0134   const unsigned char* payload = readPayload("dump_run000001_event00057185_fed1022.txt");
0135   const online::Data_v1* data_v1 = reinterpret_cast<online::Data_v1 const*>(payload + FEDHeader::length);
0136   OnlineLuminosityRecord lumi(data_v1->luminosity);
0137   std::cout << lumi << std::endl;
0138 
0139   // DIP timestamp is in milliseconds
0140   const uint64_t ts = lumi.timestamp().unixTime() * 1000UL + lumi.timestamp().microsecondOffset() / 1000;
0141   CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(0x160070979e4), ts);
0142   CPPUNIT_ASSERT_EQUAL(static_cast<uint16_t>(0x59), lumi.lumiSection());
0143   CPPUNIT_ASSERT_EQUAL(static_cast<uint16_t>(0x30), lumi.lumiNibble());
0144   CPPUNIT_ASSERT_EQUAL(static_cast<float>(0), lumi.instLumi());
0145   CPPUNIT_ASSERT_EQUAL(static_cast<float>(0), lumi.avgPileUp());
0146 }
0147 
0148 void TestOnlineMetaDataRecord::testOnlineLuminosityRecord_v2() {
0149   const unsigned char* payload = readPayload("dump_run000001_event00013761_fed1022.txt");
0150   const online::Data_v2* data_v2 = reinterpret_cast<online::Data_v2 const*>(payload + FEDHeader::length);
0151   OnlineLuminosityRecord lumi(data_v2->luminosity);
0152   std::cout << lumi << std::endl;
0153 
0154   // DIP timestamp is in milliseconds
0155   const uint64_t ts = lumi.timestamp().unixTime() * 1000UL + lumi.timestamp().microsecondOffset() / 1000;
0156   CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(0x161070979e4), ts);
0157   CPPUNIT_ASSERT_EQUAL(static_cast<uint16_t>(0x45), lumi.lumiSection());
0158   CPPUNIT_ASSERT_EQUAL(static_cast<uint16_t>(0x33), lumi.lumiNibble());
0159   CPPUNIT_ASSERT_EQUAL(static_cast<float>(0), lumi.instLumi());
0160   CPPUNIT_ASSERT_EQUAL(static_cast<float>(0), lumi.avgPileUp());
0161 }
0162 
0163 void TestOnlineMetaDataRecord::testCTPPSRecord_v2() {
0164   const unsigned char* payload = readPayload("dump_run000001_event00013761_fed1022.txt");
0165   const online::Data_v2* data_v2 = reinterpret_cast<online::Data_v2 const*>(payload + FEDHeader::length);
0166   CTPPSRecord ctpps(data_v2->ctpps);
0167   std::cout << ctpps << std::endl;
0168 
0169   // DIP timestamp is in milliseconds
0170   const uint64_t ts = ctpps.timestamp().unixTime() * 1000UL + ctpps.timestamp().microsecondOffset() / 1000;
0171   CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(0x1616b5a0e5f), ts);
0172   CPPUNIT_ASSERT_EQUAL(CTPPSRecord::Status::bad, ctpps.status(CTPPSRecord::RomanPot::RP_45_210_FR_BT));
0173   CPPUNIT_ASSERT_EQUAL(CTPPSRecord::Status::ok, ctpps.status(CTPPSRecord::RomanPot::RP_45_220_FR_TP));
0174   CPPUNIT_ASSERT_EQUAL(CTPPSRecord::Status::warning, ctpps.status(CTPPSRecord::RomanPot::RP_45_220_NR_TP));
0175   CPPUNIT_ASSERT_EQUAL(CTPPSRecord::Status::unused, ctpps.status(CTPPSRecord::RomanPot::RP_56_220_NR_TP));
0176 }