Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-27 23:38:23

0001 // system includes
0002 #include <utility>
0003 #include <vector>
0004 
0005 // user includes
0006 #include "DataFormats/Common/interface/DetSetVector.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0009 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0010 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0011 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDBuffer.h"
0012 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDChannel.h"
0013 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDHeader.h"
0014 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDRawChannelUnpacker.h"
0015 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDZSChannelUnpacker.h"
0016 #include "EventFilter/Phase2TrackerRawToDigi/interface/utils.h"
0017 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 
0023 #define LOGPRINT edm::LogPrint("Phase2TrackerFEDTestAnalyzer")
0024 
0025 /**
0026    @class Phase2TrackerFEDTestAnalyzer 
0027    @brief Analyzes contents of FED_test_ collection
0028 */
0029 
0030 class Phase2TrackerFEDTestAnalyzer : public edm::one::EDAnalyzer<> {
0031 public:
0032   typedef std::pair<uint16_t, uint16_t> Fed;
0033   typedef std::vector<Fed> Feds;
0034   typedef std::vector<uint16_t> Channels;
0035   typedef std::map<uint16_t, Channels> ChannelsMap;
0036 
0037   Phase2TrackerFEDTestAnalyzer(const edm::ParameterSet&);
0038   ~Phase2TrackerFEDTestAnalyzer();
0039 
0040   void beginJob();
0041   void analyze(const edm::Event&, const edm::EventSetup&);
0042   void endJob();
0043 
0044 private:
0045   const edm::EDGetTokenT<FEDRawDataCollection> token_;
0046 };
0047 
0048 using namespace Phase2Tracker;
0049 using namespace std;
0050 
0051 // -----------------------------------------------------------------------------
0052 //
0053 Phase2TrackerFEDTestAnalyzer::Phase2TrackerFEDTestAnalyzer(const edm::ParameterSet& pset)
0054     : token_(consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"))) {
0055   LogDebug("Phase2TrackerFEDTestAnalyzer") << "[Phase2TrackerFEDTestAnalyzer::" << __func__ << "]"
0056                                            << "Constructing object...";
0057 }
0058 
0059 // -----------------------------------------------------------------------------
0060 //
0061 Phase2TrackerFEDTestAnalyzer::~Phase2TrackerFEDTestAnalyzer() {
0062   LogDebug("Phase2TrackerFEDTestAnalyzer") << "[Phase2TrackerFEDTestAnalyzer::" << __func__ << "]"
0063                                            << " Destructing object...";
0064 }
0065 
0066 // -----------------------------------------------------------------------------
0067 //
0068 void Phase2TrackerFEDTestAnalyzer::beginJob() {
0069   LogDebug("Phase2TrackerFEDTestAnalyzer") << "[Phase2TrackerFEDTestAnalyzer::" << __func__ << "]";
0070 }
0071 
0072 // -----------------------------------------------------------------------------
0073 //
0074 void Phase2TrackerFEDTestAnalyzer::endJob() {
0075   LogDebug("Phase2TrackerFEDTestAnalyzer") << "[Phase2TrackerFEDTestAnalyzer::" << __func__ << "]";
0076 }
0077 
0078 // -----------------------------------------------------------------------------
0079 //
0080 void Phase2TrackerFEDTestAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& setup) {
0081   // Retrieve FEDRawData collection
0082   edm::Handle<FEDRawDataCollection> buffers;
0083   event.getByToken(token_, buffers);
0084 
0085   // Analyze strip tracker FED buffers in data
0086   size_t fedIndex;
0087   for (fedIndex = 0; fedIndex < Phase2Tracker::CMS_FED_ID_MAX; ++fedIndex) {
0088     const FEDRawData& fed = buffers->FEDData(fedIndex);
0089     if (fed.size() != 0 && fedIndex >= Phase2Tracker::FED_ID_MIN && fedIndex <= Phase2Tracker::FED_ID_MAX) {
0090       // construct buffer
0091       Phase2Tracker::Phase2TrackerFEDBuffer* buffer = 0;
0092       buffer = new Phase2Tracker::Phase2TrackerFEDBuffer(fed.data(), fed.size());
0093 
0094       LOGPRINT << " -------------------------------------------- ";
0095       LOGPRINT << " buffer debug ------------------------------- ";
0096       LOGPRINT << " -------------------------------------------- ";
0097       LOGPRINT << " buffer size : " << buffer->bufferSize();
0098       LOGPRINT << " fed id      : " << fedIndex;
0099       LOGPRINT << " -------------------------------------------- ";
0100       LOGPRINT << " tracker header debug ------------------------";
0101       LOGPRINT << " -------------------------------------------- ";
0102 
0103       Phase2TrackerFEDHeader tr_header = buffer->trackerHeader();
0104       LOGPRINT << " Version  : " << hex << setw(2) << (int)tr_header.getDataFormatVersion();
0105       LOGPRINT << " Mode     : " << hex << setw(2) << (int)tr_header.getDebugMode();
0106       LOGPRINT << " Type     : " << hex << setw(2) << (int)tr_header.getEventType();
0107       LOGPRINT << " Readout  : " << hex << setw(2) << (int)tr_header.getReadoutMode();
0108       LOGPRINT << " Status   : " << hex << setw(16) << (int)tr_header.getGlibStatusCode();
0109       LOGPRINT << " FE stat  : ";
0110       for (int i = 15; i >= 0; i--) {
0111         if ((tr_header.frontendStatus())[i]) {
0112           LOGPRINT << "1";
0113         } else {
0114           LOGPRINT << "0";
0115         }
0116       }
0117       LOGPRINT << "\n";
0118       LOGPRINT << " Nr CBC   : " << hex << setw(16) << (int)tr_header.getNumberOfCBC();
0119       LOGPRINT << " CBC stat : ";
0120       for (int i = 0; i < tr_header.getNumberOfCBC(); i++) {
0121         LOGPRINT << hex << setw(2) << (int)tr_header.CBCStatus()[i] << " ";
0122       }
0123       LOGPRINT << "\n";
0124       LOGPRINT << " -------------------------------------------- ";
0125       LOGPRINT << " Payload  ----------------------------------- ";
0126       LOGPRINT << " -------------------------------------------- ";
0127 
0128       // loop channels
0129       int ichan = 0;
0130       for (int ife = 0; ife < 16; ife++) {
0131         for (int icbc = 0; icbc < 16; icbc++) {
0132           const Phase2TrackerFEDChannel& channel = buffer->channel(ichan);
0133           if (channel.length() > 0) {
0134             LOGPRINT << dec << " reading channel : " << icbc << " on FE " << ife;
0135             LOGPRINT << dec << " with length  : " << (int)channel.length();
0136             Phase2TrackerFEDRawChannelUnpacker unpacker = Phase2TrackerFEDRawChannelUnpacker(channel);
0137             while (unpacker.hasData()) {
0138               LOGPRINT << (unpacker.stripOn() ? "1" : "_");
0139               unpacker++;
0140             }
0141             LOGPRINT << "\n";
0142           }
0143           ichan++;
0144         }
0145       }  // end loop on channels
0146     }
0147   }
0148 }
0149 
0150 #include "FWCore/PluginManager/interface/ModuleDef.h"
0151 #include "FWCore/Framework/interface/MakerMacros.h"
0152 DEFINE_FWK_MODULE(Phase2TrackerFEDTestAnalyzer);