00001 #include "IORawData/SiStripInputSources/plugins/FEDRawDataAnalyzer.h" 00002 #include "DataFormats/Common/interface/Handle.h" 00003 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" 00004 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h" 00005 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00006 #include "interface/shared/fed_trailer.h" 00007 #include <iostream> 00008 #include <sstream> 00009 #include <iomanip> 00010 #include <unistd.h> 00011 00012 using namespace std; 00013 using namespace sistrip; 00014 00015 // ----------------------------------------------------------------------------- 00016 // 00017 FEDRawDataAnalyzer::FEDRawDataAnalyzer( const edm::ParameterSet& pset ) 00018 : label_( pset.getUntrackedParameter<std::string>("ProductLabel","source") ), 00019 instance_( pset.getUntrackedParameter<std::string>("ProductInstance","") ), 00020 sleep_( pset.getUntrackedParameter<int>("pause_us",0) ) 00021 { 00022 LogTrace(mlRawToDigi_) 00023 << "[FEDRawDataAnalyzer::" << __func__ << "]" 00024 << " Constructing object..."; 00025 } 00026 00027 // ----------------------------------------------------------------------------- 00028 // 00029 void FEDRawDataAnalyzer::analyze( const edm::Event& event, 00030 const edm::EventSetup& setup ) { 00031 00032 // Introduce optional delay 00033 if ( sleep_ > 0 ) { for ( int ii = 0; ii < sleep_; ++ii ) { usleep(1); } } 00034 00035 // Retrieve FED raw data 00036 edm::Handle<FEDRawDataCollection> buffers; 00037 event.getByLabel( label_, instance_, buffers ); 00038 00039 // Some init 00040 std::stringstream ss; 00041 ss << std::endl; 00042 uint16_t cntr = 0; 00043 bool trigger_fed = false; 00044 00045 // Check FEDRawDataCollection 00046 for ( uint16_t ifed = 0; ifed < sistrip::CMS_FED_ID_MAX; ifed++ ) { 00047 const FEDRawData& fed = buffers->FEDData( static_cast<int>(ifed) ); 00048 if ( fed.size() ) { 00049 cntr++; 00050 if ( edm::isDebugEnabled() ) { 00051 ss << " #FEDs: " 00052 << std::setw(3) << std::setfill(' ') << cntr 00053 << " FED id: " 00054 << std::setw(4) << std::setfill(' ') << ifed 00055 << " Buffer size [chars]: " 00056 << std::setw(6) << std::setfill(' ') << fed.size(); 00057 } 00058 uint8_t* data = const_cast<uint8_t*>( fed.data() ); 00059 fedt_t* fed_trailer = reinterpret_cast<fedt_t*>( data + fed.size() - sizeof(fedt_t) ); 00060 if ( fed_trailer->conscheck == 0xDEADFACE ) { 00061 ss << " (Candidate for \"trigger FED\"!)"; 00062 trigger_fed = true; 00063 } 00064 ss << std::endl; 00065 } 00066 } 00067 00068 // Print out debug 00069 std::stringstream sss; 00070 sss << "[FEDRawDataAnalyzer::" << __func__ << "]" 00071 << " Number of FED buffers (with non-zero size) found in collection is " 00072 << cntr; 00073 if ( trigger_fed ) { sss << " (One buffer contains the \"trigger FED\" info!)"; } 00074 edm::LogVerbatim(mlRawToDigi_) << sss.str(); 00075 00076 LogTrace(mlRawToDigi_) 00077 << "[FEDRawDataAnalyzer::" << __func__ << "]" 00078 << " Buffer size for " << cntr << " FEDs: " 00079 << ss.str(); 00080 00081 } 00082 00083 // ----------------------------------------------------------------------------- 00084 // 00085 void FEDRawDataAnalyzer::beginJob( edm::EventSetup const& ) {;} 00086 00087 // ----------------------------------------------------------------------------- 00088 // 00089 void FEDRawDataAnalyzer::endJob() {;}