Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:15:04

0001 /**
0002  *   
0003  * \author G. Franzoni
0004  *
0005  */
0006 
0007 #include "CaloOnlineTools/EcalTools/plugins/EcalHexDisplay.h"
0008 
0009 EcalHexDisplay::EcalHexDisplay(const edm::ParameterSet& ps)
0010     : verbosity_(ps.getUntrackedParameter<int>("verbosity", 1)),
0011       beg_fed_id_(ps.getUntrackedParameter<int>("beg_fed_id", 0)),
0012       end_fed_id_(ps.getUntrackedParameter<int>("end_fed_id", 654)),
0013       first_event_(ps.getUntrackedParameter<int>("first_event", 1)),
0014       last_event_(ps.getUntrackedParameter<int>("last_event", 9999999)),
0015       event_(0),
0016       writeDcc_(ps.getUntrackedParameter<bool>("writeDCC", false)),
0017       filename_(ps.getUntrackedParameter<std::string>("filename", "dump.bin")),
0018       fedRawDataCollectionTag_(ps.getParameter<edm::InputTag>("fedRawDataCollectionTag")) {}
0019 
0020 void EcalHexDisplay::analyze(const edm::Event& e, const edm::EventSetup& c) {
0021   event_++;
0022   if (event_ < first_event_ || last_event_ < event_)
0023     return;
0024 
0025   edm::Handle<FEDRawDataCollection> rawdata;
0026   e.getByLabel(fedRawDataCollectionTag_, rawdata);
0027 
0028   std::ofstream dumpFile(filename_.c_str(), std::ios::app);
0029 
0030   for (int id = 0; id <= FEDNumbering::MAXFEDID; ++id) {
0031     if (id < beg_fed_id_ || end_fed_id_ < id)
0032       continue;
0033 
0034     const FEDRawData& data = rawdata->FEDData(id);
0035 
0036     if (data.size() > 4) {
0037       std::cout << "\n\n\n[EcalHexDumperModule] Event: " << std::dec << event_ << " fed_id: " << id
0038                 << " size_fed: " << data.size() << "\n"
0039                 << std::endl;
0040 
0041       if ((data.size() % 16) != 0) {
0042         std::cout << "***********************************************" << std::endl;
0043         std::cout << "Fed size in bits not multiple of 64, strange." << std::endl;
0044         std::cout << "***********************************************" << std::endl;
0045       }
0046 
0047       int length = data.size();
0048       const unsigned long* pData = (reinterpret_cast<unsigned long*>(const_cast<unsigned char*>(data.data())));
0049       std::cout << std::setfill('0');
0050       for (int words = 0; words < length / 4; (words += 2)) {
0051         std::cout << std::setw(8) << std::hex << pData[words + 1] << " ";
0052         std::cout << std::setw(8) << std::hex << pData[words] << std::endl;
0053       }
0054 
0055       std::cout << "\n";
0056 
0057       if (beg_fed_id_ <= id && id <= end_fed_id_ && writeDcc_) {
0058         dumpFile.write(reinterpret_cast<const char*>(pData), length);
0059       }
0060     }
0061   }
0062   dumpFile.close();
0063   if (!writeDcc_)
0064     remove(filename_.c_str());
0065 }