Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:32

0001 /** \file
0002  *
0003  *
0004  * \author N. Amapane - S. Argiro'
0005  *
0006 */
0007 
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0015 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0016 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0017 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0018 #include "DataFormats/TCDS/interface/TCDSRaw.h"
0019 #include "DataFormats/TCDS/interface/TCDSRecord.h"
0020 
0021 #include "EventFilter/Utilities/interface/GlobalEventNumber.h"
0022 
0023 #include "boost/date_time/posix_time/posix_time.hpp"
0024 
0025 #include <ctime>
0026 #include <iomanip>
0027 #include <sstream>
0028 #include <string>
0029 
0030 namespace test {
0031 
0032   static const unsigned int GTEVMId = 812;
0033   static const unsigned int GTPEId = 814;
0034   class GlobalNumbersAnalysis : public edm::one::EDAnalyzer<> {
0035   private:
0036     edm::EDGetTokenT<FEDRawDataCollection> m_fedRawDataCollectionToken;
0037 
0038   public:
0039     GlobalNumbersAnalysis(const edm::ParameterSet& pset)
0040         : m_fedRawDataCollectionToken(consumes<FEDRawDataCollection>(
0041               pset.getUntrackedParameter<edm::InputTag>("inputTag", edm::InputTag("source")))) {}
0042 
0043     void analyze(const edm::Event& e, const edm::EventSetup& c) override {
0044       boost::posix_time::ptime event_timestamp;
0045       event_timestamp = boost::posix_time::from_time_t((time_t)e.time().unixTime());
0046       event_timestamp += boost::posix_time::microseconds(e.time().microsecondOffset());
0047       edm::LogInfo("GlobalNumbersAnalysis")
0048           << "--- Run: " << e.id().run() << " LS: " << e.luminosityBlock() << " Event: " << e.id().event()
0049           << " Timestamp: " << e.time().unixTime() << "." << e.time().microsecondOffset() << " ("
0050           << boost::posix_time::to_iso_extended_string(event_timestamp) << " UTC)"
0051           << " Type: " << e.experimentType() << std::endl;
0052       edm::Handle<FEDRawDataCollection> rawdata;
0053       e.getByToken(m_fedRawDataCollectionToken, rawdata);
0054       const FEDRawData& data = rawdata->FEDData(GTEVMId);
0055       size_t size = data.size();
0056 
0057       if (size > 0) {
0058         edm::LogInfo("GlobalNumberAnalysis")
0059             << "FED# " << std::setw(4) << GTEVMId << " " << std::setw(8) << size << " bytes " << std::endl;
0060         if (evf::evtn::evm_board_sense(data.data(), size)) {
0061           edm::LogInfo("GlobalNumberAnalysis")
0062               << "FED# " << std::setw(4) << GTEVMId << " is the real GT EVM block"
0063               << "\nEvent # " << evf::evtn::get(data.data(), true) << "\nLS # " << evf::evtn::getlbn(data.data())
0064               << "\nORBIT # " << evf::evtn::getorbit(data.data()) << "\nGPS LOW # " << evf::evtn::getgpslow(data.data())
0065               << "\nGPS HI # " << evf::evtn::getgpshigh(data.data()) << "\nBX FROM FDL 0-xing # "
0066               << evf::evtn::getfdlbx(data.data()) << "\nPRESCALE INDEX FROM FDL 0-xing # "
0067               << evf::evtn::getfdlpsc(data.data()) << std::endl;
0068         }
0069       } else {
0070         edm::LogWarning("GlobalNumberAnalysis") << "FED# " << std::setw(4) << GTEVMId << " not read out." << std::endl;
0071       }
0072 
0073       const FEDRawData& data2 = rawdata->FEDData(GTPEId);
0074       size = data2.size();
0075 
0076       if (size > 0) {
0077         edm::LogInfo("GlobalNumberAnalysis")
0078             << "FED# " << std::setw(4) << GTPEId << " " << std::setw(8) << size << " bytes " << std::endl;
0079         if (evf::evtn::gtpe_board_sense(data2.data())) {
0080           edm::LogInfo("GlobalNumberAnalysis")
0081               << "FED# " << std::setw(4) << GTPEId << " is the real GTPE block"
0082               << "\nEvent # " << evf::evtn::gtpe_get(data2.data()) << "\nLS # " << evf::evtn::gtpe_getlbn(data2.data())
0083               << "\nORBIT # " << evf::evtn::gtpe_getorbit(data2.data()) << "\nBX # "
0084               << evf::evtn::gtpe_getbx(data2.data()) << std::endl;
0085         }
0086       } else {
0087         edm::LogWarning("GlobalNumberAnalysis") << "FED# " << std::setw(4) << GTPEId << " not read out." << std::endl;
0088       }
0089 
0090       const FEDRawData& data3 = rawdata->FEDData(FEDNumbering::MINTCDSuTCAFEDID);
0091       size = data3.size();
0092 
0093       if (size > 0) {
0094         tcds::Raw_v1 const* record = reinterpret_cast<tcds::Raw_v1 const*>(data3.data());
0095         edm::LogInfo("GlobalNumberAnalysis") << "FED# " << std::setw(4) << FEDNumbering::MINTCDSuTCAFEDID << " "
0096                                              << std::setw(8) << size << " bytes " << std::endl;
0097         edm::LogInfo("GlobalNumberAnalysis")
0098             << "sizes: "
0099             << " BGOSize " << std::hex << (unsigned int)record->sizes.BGOSize << "  reserved2;" << std::hex
0100             << (unsigned int)record->sizes.reserved2 << "  reserved1;" << std::hex
0101             << (unsigned int)record->sizes.reserved1 << "  reserved0;" << std::hex
0102             << (unsigned int)record->sizes.reserved0 << "  BSTSize;" << std::hex << (unsigned int)record->sizes.BSTSize
0103             << "  L1AhistSize;" << std::hex << (unsigned int)record->sizes.L1AhistSize << "  summarySize;" << std::hex
0104             << (unsigned int)record->sizes.summarySize << "  headerSize;" << std::hex
0105             << (unsigned int)record->sizes.headerSize << std::endl;
0106         edm::LogInfo("GlobalNumberAnalysis")
0107             << "macAddress;             " << std::hex << (uint64_t)record->header.macAddress
0108             << "\nswVersion;            " << std::hex << (unsigned int)record->header.swVersion
0109             << "\nfwVersion;            " << std::hex << (unsigned int)record->header.fwVersion
0110             << "\nreserved0;            " << std::hex << (unsigned int)record->header.reserved0
0111             << "\nrecordVersion;        " << std::hex << (unsigned int)record->header.recordVersion
0112             << "\nrunNumber;            " << std::dec << (unsigned int)record->header.runNumber
0113             << "\nreserved1;            " << std::hex << (unsigned int)record->header.reserved1
0114             << "\nactivePartitions2;    " << std::hex << (unsigned int)record->header.activePartitions2
0115             << "\nbstReceptionStatus;   " << std::hex << (unsigned int)record->header.bstReceptionStatus
0116             << "\nactivePartitions0;    " << std::hex << (unsigned int)record->header.activePartitions0
0117             << "\nactivePartitions1;    " << std::hex << (unsigned int)record->header.activePartitions1
0118             << "\nnibble;               " << std::dec << (unsigned int)record->header.nibble
0119             << "\nlumiSection;          " << std::dec << (unsigned int)record->header.lumiSection
0120             << "\nnibblesPerLumiSection;" << std::hex << (unsigned int)record->header.nibblesPerLumiSection
0121             << "\ntriggerTypeFlags;     " << std::hex << (unsigned int)record->header.triggerTypeFlags
0122             << "\nreserved5;            " << std::hex << (unsigned int)record->header.reserved5
0123             << "\ninputs;               " << std::hex << (unsigned int)record->header.inputs
0124             << "\nbxid;                 " << std::dec << (unsigned int)record->header.bxid << "\norbitLow;             "
0125             << std::dec << (unsigned int)record->header.orbitLow << "\norbitHigh;            " << std::dec
0126             << (unsigned int)record->header.orbitHigh << "\ntriggerCount;         " << std::dec
0127             << (uint64_t)record->header.triggerCount << "\neventNumber;          " << std::dec
0128             << (uint64_t)record->header.eventNumber << std::endl;
0129 
0130         std::ostringstream osl1ah;
0131         osl1ah << "====================l1a history===================";
0132         const tcds::L1aInfo_v1* history = record->l1aHistory.l1aInfo;
0133         for (unsigned int i = 0; i < tcds::l1aHistoryDepth_v1; i++) {
0134           osl1ah << "\n"
0135                  << i << " " << std::hex << history[i].bxid << "\n"
0136                  << i << " " << std::hex << history[i].orbitlow << "\n"
0137                  << i << " " << std::hex << history[i].orbithigh << "\n"
0138                  << i << " " << std::hex << (unsigned int)history[i].eventtype;
0139         }
0140         edm::LogInfo("GlobalNumberAnalysis") << osl1ah.str();
0141 
0142         edm::LogInfo("GlobalNumberAnalysis")
0143             << "====================BST record==================="
0144             << "\ngpstimehigh;" << std::setw(19) << std::hex << record->bst.gpstimehigh << "\ngpstimelow;"
0145             << std::setw(20) << std::hex << record->bst.gpstimelow << "\nbireserved8_11;" << std::setw(16)
0146             << record->bst.bireserved8_11 << "\nbireserved12_15;" << std::setw(15) << record->bst.bireserved12_15
0147             << "\nbstMaster;" << std::setw(21) << record->bst.bstMaster << "\nturnCountLow;" << std::setw(18)
0148             << record->bst.turnCountLow << "\nturnCountHigh;" << std::setw(17) << record->bst.turnCountHigh
0149             << "\nlhcFillLow;" << std::setw(20) << record->bst.lhcFillLow << "\nlhcFillHigh;" << std::setw(19)
0150             << record->bst.lhcFillHigh << "\nbeamMode;" << std::setw(22) << record->bst.beamMode << "\nparticleTypes;"
0151             << std::setw(17) << record->bst.particleTypes << "\nbeamMomentum;" << std::setw(18)
0152             << record->bst.beamMomentum << "\nintensityBeam1;" << std::setw(16) << record->bst.intensityBeam1
0153             << "\nintensityBeam2;" << std::setw(16) << record->bst.intensityBeam2 << "\nbireserved40_43;"
0154             << std::setw(15) << record->bst.bireserved40_43 << "\nbireserved44_47;" << std::setw(15)
0155             << record->bst.bireserved44_47 << "\nbireserved48_51;" << std::setw(15) << record->bst.bireserved48_51
0156             << "\nbireserved52_55;" << std::setw(15) << record->bst.bireserved52_55 << "\nbireserved56_59;"
0157             << std::setw(15) << record->bst.bireserved56_59 << "\nbireserved60_63;" << std::setw(15)
0158             << record->bst.bireserved60_63 << std::endl;
0159 
0160         time_t nowtime = (time_t)record->bst.gpstimehigh;
0161         uint32_t turnCountHigh = record->bst.turnCountHigh;
0162         uint16_t turnCountLow = record->bst.turnCountLow;
0163         uint32_t lhcFillHigh = record->bst.lhcFillHigh;
0164         uint16_t lhcFillLow = record->bst.lhcFillLow;
0165         edm::LogInfo("GlobalNumberAnalysis")
0166             << "value of nowtime: hex " << std::hex << nowtime << std::dec << ", dec " << nowtime << "\nGPS time "
0167             << ctime(&nowtime) << "plus microseconds: " << std::dec << record->bst.gpstimelow << "\nBeam "
0168             << (record->bst.bstMaster >> 8) << " master sent turn count "
0169             << (uint32_t)((turnCountHigh << 16) + turnCountLow)
0170             << "\nFill: " << (uint32_t)((lhcFillHigh << 16) + lhcFillLow) << "\nBeam Mode: " << record->bst.beamMode
0171             << "\nparticleType1: " << (record->bst.particleTypes & 0xFF)
0172             << ", particleType2: " << (record->bst.particleTypes >> 8)
0173             << "\nBeam Momentum: " << record->bst.beamMomentum << " GeV/c"
0174             << "\nB1 intensity: (10E10 charges) " << record->bst.intensityBeam1 << ", B2 intensity: (10E10 charges) "
0175             << record->bst.intensityBeam2 << std::endl;
0176 
0177         TCDSRecord tcds(data3.data());
0178         edm::LogInfo("GlobalNumberAnalysis") << "====================TCDS Record===================\n"
0179                                              << tcds << std::endl;
0180       } else {
0181         edm::LogInfo("GlobalNumberAnalysis")
0182             << "FED# " << std::setw(4) << FEDNumbering::MINTCDSuTCAFEDID << " not read out." << std::endl;
0183       }
0184 
0185       //      CPPUNIT_ASSERT(trailer.check()==true);
0186       //      CPPUNIT_ASSERT(trailer.lenght()==(int)data.size()/8);
0187     }
0188   };
0189   DEFINE_FWK_MODULE(GlobalNumbersAnalysis);
0190 }  // namespace test