Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-11 03:13:07

0001 /**
0002  *   
0003  * \author G. Franzoni
0004  *
0005  */
0006 
0007 #include <FWCore/Framework/interface/one/EDAnalyzer.h>
0008 #include <DataFormats/Common/interface/Handle.h>
0009 #include <FWCore/Framework/interface/Event.h>
0010 #include <FWCore/Framework/interface/MakerMacros.h>
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 
0013 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
0014 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
0015 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
0016 
0017 #include <iostream>
0018 #include <vector>
0019 #include <string>
0020 
0021 #include <stdio.h>
0022 #include <fstream>
0023 
0024 #include <iomanip>
0025 
0026 class EcalHexDumperModule : public edm::one::EDAnalyzer<> {
0027 public:
0028   EcalHexDumperModule(const edm::ParameterSet& ps)
0029       : fedRawDataCollectionTag_(ps.getParameter<edm::InputTag>("fedRawDataCollectionTag")) {
0030     verbosity_ = ps.getUntrackedParameter<int>("verbosity", 1);
0031 
0032     beg_fed_id_ = ps.getUntrackedParameter<int>("beg_fed_id", 0);
0033     end_fed_id_ = ps.getUntrackedParameter<int>("end_fed_id", 654);
0034 
0035     first_event_ = ps.getUntrackedParameter<int>("first_event", 1);
0036     last_event_ = ps.getUntrackedParameter<int>("last_event", 9999999);
0037     event_ = 0;
0038 
0039     writeDcc_ = ps.getUntrackedParameter<bool>("writeDCC", false);
0040     filename_ = ps.getUntrackedParameter<std::string>("filename", "dump.bin");
0041   }
0042 
0043 protected:
0044   int verbosity_;
0045   bool writeDcc_;
0046   int beg_fed_id_;
0047   int end_fed_id_;
0048   int first_event_;
0049   int last_event_;
0050   std::string filename_;
0051   int event_;
0052 
0053   void analyze(const edm::Event& e, const edm::EventSetup& c);
0054 
0055 private:
0056   edm::InputTag fedRawDataCollectionTag_;
0057 };
0058 
0059 void EcalHexDumperModule::analyze(const edm::Event& e, const edm::EventSetup& c) {
0060   event_++;
0061   if (event_ < first_event_ || last_event_ < event_)
0062     return;
0063 
0064   edm::Handle<FEDRawDataCollection> rawdata;
0065   e.getByLabel(fedRawDataCollectionTag_, rawdata);
0066 
0067   std::ofstream dumpFile(filename_.c_str(), std::ios::app);
0068 
0069   for (int id = 0; id <= FEDNumbering::MAXFEDID; ++id) {
0070     if (id < beg_fed_id_ || end_fed_id_ < id)
0071       continue;
0072 
0073     const FEDRawData& data = rawdata->FEDData(id);
0074 
0075     if (data.size() > 4) {
0076       std::cout << "\n\n\n[EcalHexDumperModule] Event: " << std::dec << event_ << " fed_id: " << id
0077                 << " size_fed: " << data.size() << "\n"
0078                 << std::endl;
0079 
0080       if ((data.size() % 16) != 0) {
0081         std::cout << "***********************************************" << std::endl;
0082         std::cout << "Fed size in bits not multiple of 64, strange." << std::endl;
0083         std::cout << "***********************************************" << std::endl;
0084       }
0085 
0086       int length = data.size();
0087       const unsigned long* pData = (reinterpret_cast<unsigned long*>(const_cast<unsigned char*>(data.data())));
0088       std::cout << std::setfill('0');
0089       for (int words = 0; words < length / 4; (words += 2)) {
0090         std::cout << std::setw(8) << std::hex << pData[words + 1] << " ";
0091         std::cout << std::setw(8) << std::hex << pData[words] << std::endl;
0092       }
0093 
0094       std::cout << "\n";
0095 
0096       if (beg_fed_id_ <= id && id <= end_fed_id_ && writeDcc_) {
0097         dumpFile.write(reinterpret_cast<const char*>(pData), length);
0098       }
0099     }
0100   }
0101   dumpFile.close();
0102   if (!writeDcc_)
0103     remove(filename_.c_str());
0104 }
0105 
0106 DEFINE_FWK_MODULE(EcalHexDumperModule);