00001 00002 #include "L1Trigger/TextToDigi/plugins/RawToText.h" 00003 00004 // system 00005 #include <string> 00006 #include <fstream> 00007 #include <iostream> 00008 #include <iomanip> 00009 // framework 00010 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00011 #include "FWCore/Utilities/interface/Exception.h" 00012 // raw data collection 00013 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" 00014 00015 00016 RawToText::RawToText(const edm::ParameterSet& iConfig) : 00017 inputLabel_(iConfig.getParameter<edm::InputTag>("inputLabel")), 00018 fedId_(iConfig.getUntrackedParameter<int>("fedId", 745)), 00019 filename_(iConfig.getUntrackedParameter<std::string>("filename", "slinkOutput.txt")), 00020 nevt_(0) { 00021 edm::LogInfo("TextToDigi") << "Creating ASCII dump " << filename_ << std::endl; 00022 } 00023 00024 00025 RawToText::~RawToText() {} 00026 00027 00028 void RawToText::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { 00029 00030 nevt_++; 00031 00032 // get raw data collection 00033 edm::Handle<FEDRawDataCollection> feds; 00034 iEvent.getByLabel(inputLabel_, feds); 00035 const FEDRawData& gctRcd = feds->FEDData(fedId_); 00036 00037 edm::LogInfo("GCT") << "Upacking FEDRawData of size " 00038 << std::dec << gctRcd.size() 00039 << std::endl; 00040 00041 // do a simple check of the raw data 00042 if (gctRcd.size()<16) { 00043 edm::LogWarning("Invalid Data") 00044 << "Empty/invalid GCT raw data, size = " << gctRcd.size() 00045 << std::endl; 00046 return; 00047 } 00048 00049 const unsigned char * data = gctRcd.data(); 00050 00051 int eventSize = gctRcd.size() / 4; 00052 00053 unsigned long d = 0; 00054 for(int i=0; i<eventSize; i++) { 00055 d = 0; 00056 //d = data[i*4+0] + (data[i*4+1]<<8) + (data[i*4+2]<<16) + (data[i*4+3]<<24); 00057 for(int j=0; j<4; j++) { 00058 d += ((data[i*4+j]&0xff)<<(8*j)); 00059 } 00060 file_ << std::setw(8) << std::setfill('0') << std::hex << d << std::endl; 00061 } 00062 file_ << std::flush << std::endl; 00063 00064 } 00065 00066 00067 void RawToText::beginJob(const edm::EventSetup&) { 00068 00069 // open VME file 00070 file_.open(filename_.c_str(), std::ios::out); 00071 00072 if(!file_.good()) { 00073 edm::LogInfo("RawToText") << "Failed to open ASCII file " << filename_ 00074 << std::endl; 00075 } 00076 } 00077 00078 00079 void RawToText::endJob() { 00080 file_.close(); 00081 }