Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:07

0001 /** \file
0002  * 
0003  * 
0004  * \author N. Amapane - S. Argiro'
0005  *
0006 */
0007 
0008 #include <iostream>
0009 #include <iomanip>
0010 
0011 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0012 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0013 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0014 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 
0020 using namespace edm;
0021 
0022 namespace {
0023   template <typename T>
0024   std::set<T> make_set(std::vector<T> const& v) {
0025     std::set<T> s;
0026     for (auto const& e : v)
0027       s.insert(e);
0028     return s;
0029   }
0030 
0031   template <typename T>
0032   std::set<T> make_set(std::vector<T>&& v) {
0033     std::set<T> s;
0034     for (auto& e : v)
0035       s.insert(std::move(e));
0036     return s;
0037   }
0038 }  // anonymous namespace
0039 
0040 namespace test {
0041 
0042   class DumpFEDRawDataProduct : public edm::global::EDAnalyzer<> {
0043   private:
0044     const std::set<int> feds_;
0045     const edm::EDGetTokenT<FEDRawDataCollection> token_;
0046     const bool dumpPayload_;
0047 
0048   public:
0049     DumpFEDRawDataProduct(const ParameterSet& pset)
0050         : feds_(make_set(pset.getUntrackedParameter<std::vector<int>>("feds"))),
0051           token_(consumes<FEDRawDataCollection>(pset.getUntrackedParameter<edm::InputTag>("label"))),
0052           dumpPayload_(pset.getUntrackedParameter<bool>("dumpPayload")) {}
0053 
0054     void analyze(edm::StreamID sid, const Event& e, const EventSetup& c) const override {
0055       edm::LogSystem out("DumpFEDRawDataProduct");
0056       Handle<FEDRawDataCollection> rawdata;
0057       e.getByToken(token_, rawdata);
0058       for (int i = 0; i <= FEDNumbering::lastFEDId(); i++) {
0059         const FEDRawData& data = rawdata->FEDData(i);
0060         size_t size = data.size();
0061 
0062         if (size > 0 && (feds_.empty() || feds_.find(i) != feds_.end())) {
0063           out << "FED# " << std::setw(4) << i << " " << std::setw(8) << size << " bytes ";
0064 
0065           FEDHeader header(data.data());
0066           FEDTrailer trailer(data.data() + size - FEDTrailer::length);
0067 
0068           out << " L1Id: " << std::setw(8) << header.lvl1ID();
0069           out << " BXId: " << std::setw(4) << header.bxID();
0070           out << '\n';
0071 
0072           if (dumpPayload_) {
0073             const uint64_t* payload = (uint64_t*)(data.data());
0074             out << std::hex << std::setfill('0');
0075             for (unsigned int i = 0; i < data.size() / sizeof(uint64_t); i++) {
0076               out << std::setw(4) << i << "  " << std::setw(16) << payload[i] << '\n';
0077             }
0078             out << std::dec << std::setfill(' ');
0079           }
0080 
0081           if (not trailer.check()) {
0082             out << "    FED trailer check failed\n";
0083           }
0084           if (trailer.fragmentLength() * 8 != data.size()) {
0085             out << "    FED fragment size mismatch: " << trailer.fragmentLength() << " (fragment length) vs "
0086                 << (float)data.size() / 8 << " (data size) words\n";
0087           }
0088         } else if (size == 0 && feds_.find(i) != feds_.end()) {
0089           out << "FED# " << std::setw(4) << i << " " << std::setw(8) << size << " bytes\n";
0090         }
0091       }
0092     }
0093   };
0094 
0095   DEFINE_FWK_MODULE(DumpFEDRawDataProduct);
0096 }  // namespace test