Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:41

0001 
0002 #include "L1Trigger/TextToDigi/plugins/RawToText.h"
0003 
0004 // system
0005 #include <fstream>
0006 #include <iomanip>
0007 #include <iostream>
0008 #include <string>
0009 // framework
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 // raw data collection
0013 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0014 
0015 RawToText::RawToText(const edm::ParameterSet &iConfig)
0016     : inputLabel_(iConfig.getParameter<edm::InputTag>("inputLabel")),
0017       fedId_(iConfig.getUntrackedParameter<int>("fedId", 745)),
0018       filename_(iConfig.getUntrackedParameter<std::string>("filename", "slinkOutput.txt")),
0019       nevt_(0) {
0020   edm::LogInfo("TextToDigi") << "Creating ASCII dump " << filename_ << std::endl;
0021 }
0022 
0023 RawToText::~RawToText() {}
0024 
0025 void RawToText::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0026   nevt_++;
0027 
0028   // get raw data collection
0029   edm::Handle<FEDRawDataCollection> feds;
0030   iEvent.getByLabel(inputLabel_, feds);
0031   const FEDRawData &gctRcd = feds->FEDData(fedId_);
0032 
0033   edm::LogInfo("GCT") << "Upacking FEDRawData of size " << std::dec << gctRcd.size() << std::endl;
0034 
0035   // do a simple check of the raw data
0036   if (gctRcd.size() < 16) {
0037     edm::LogWarning("Invalid Data") << "Empty/invalid GCT raw data, size = " << gctRcd.size() << std::endl;
0038     return;
0039   }
0040 
0041   const unsigned char *data = gctRcd.data();
0042 
0043   int eventSize = gctRcd.size() / 4;
0044 
0045   unsigned long d = 0;
0046   for (int i = 0; i < eventSize; i++) {
0047     d = 0;
0048     // d  = data[i*4+0] + (data[i*4+1]<<8) + (data[i*4+2]<<16) +
0049     // (data[i*4+3]<<24);
0050     for (int j = 0; j < 4; j++) {
0051       d += ((data[i * 4 + j] & 0xff) << (8 * j));
0052     }
0053     file_ << std::setw(8) << std::setfill('0') << std::hex << d << std::endl;
0054   }
0055   file_ << std::flush << std::endl;
0056 }
0057 
0058 void RawToText::beginJob() {
0059   // open VME file
0060   file_.open(filename_.c_str(), std::ios::out);
0061 
0062   if (!file_.good()) {
0063     edm::LogInfo("RawToText") << "Failed to open ASCII file " << filename_ << std::endl;
0064   }
0065 }
0066 
0067 void RawToText::endJob() { file_.close(); }