Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:04

0001 // system includes
0002 #include <map>
0003 #include <sstream>
0004 #include <string>
0005 #include <utility>
0006 #include <vector>
0007 
0008 // user includes
0009 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
0010 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0013 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0014 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0015 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 
0023 /**
0024    @class SiStripFEDRawDataAnalyzer 
0025    @brief Analyzes contents of FEDRawData collection
0026 */
0027 
0028 class SiStripFEDRawDataAnalyzer : public edm::one::EDAnalyzer<> {
0029 public:
0030   typedef std::pair<uint16_t, uint16_t> Fed;
0031   typedef std::vector<Fed> Feds;
0032   typedef std::vector<uint16_t> Channels;
0033   typedef std::map<uint16_t, Channels> ChannelsMap;
0034 
0035   SiStripFEDRawDataAnalyzer(const edm::ParameterSet&);
0036   ~SiStripFEDRawDataAnalyzer();
0037 
0038   void beginJob();
0039   void analyze(const edm::Event&, const edm::EventSetup&);
0040   void endJob();
0041 
0042 private:
0043   const edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> esTokenCabling_;
0044   edm::InputTag label_;
0045 };
0046 
0047 using namespace sistrip;
0048 using namespace std;
0049 
0050 // -----------------------------------------------------------------------------
0051 //
0052 SiStripFEDRawDataAnalyzer::SiStripFEDRawDataAnalyzer(const edm::ParameterSet& pset)
0053     : esTokenCabling_(esConsumes()), label_(pset.getParameter<edm::InputTag>("InputLabel")) {
0054   LogDebug("SiStripFEDRawDataAnalyzer") << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]"
0055                                         << "Constructing object...";
0056   consumes<FEDRawDataCollection>(label_);
0057 }
0058 
0059 // -----------------------------------------------------------------------------
0060 //
0061 SiStripFEDRawDataAnalyzer::~SiStripFEDRawDataAnalyzer() {
0062   LogDebug("SiStripFEDRawDataAnalyzer") << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]"
0063                                         << " Destructing object...";
0064 }
0065 
0066 // -----------------------------------------------------------------------------
0067 //
0068 void SiStripFEDRawDataAnalyzer::beginJob() {
0069   LogDebug("SiStripFEDRawDataAnalyzer") << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]";
0070 }
0071 
0072 // -----------------------------------------------------------------------------
0073 //
0074 void SiStripFEDRawDataAnalyzer::endJob() {
0075   LogDebug("SiStripFEDRawDataAnalyzer") << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]";
0076 }
0077 
0078 // -----------------------------------------------------------------------------
0079 //
0080 void SiStripFEDRawDataAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& setup) {
0081   // Retrieve FED cabling object
0082   edm::ESHandle<SiStripFedCabling> cabling = setup.getHandle(esTokenCabling_);
0083 
0084   // Retrieve FEDRawData collection
0085   edm::Handle<FEDRawDataCollection> buffers;
0086   event.getByLabel(label_, buffers);
0087 
0088   // Local cache of fed ids from cabling
0089   auto fed_ids = cabling->fedIds();
0090 
0091   // Containers storing fed ids and buffer sizes
0092   Feds trg_feds;  // trigger feds
0093   Feds trk_feds;  // tracker feds
0094   Feds non_trk;   // feds from other sub-dets
0095   Feds in_data;   // feds in data but missing from cabling
0096   Feds in_cabl;   // feds in cabling but missing from data
0097 
0098   for (uint16_t ifed = 0; ifed <= sistrip::CMS_FED_ID_MAX; ++ifed) {
0099     const FEDRawData& fed = buffers->FEDData(static_cast<int>(ifed));
0100     const FEDTrailer* fed_trailer = reinterpret_cast<const FEDTrailer*>(fed.data() + fed.size() - sizeof(FEDTrailer));
0101     if (fed.size() && fed_trailer->check()) {
0102       trg_feds.push_back(Fed(ifed, fed.size()));
0103     } else {
0104       if (ifed < sistrip::FED_ID_MIN || ifed > sistrip::FED_ID_MAX) {
0105         if (fed.size()) {
0106           non_trk.push_back(Fed(ifed, fed.size()));
0107         }
0108       } else {
0109         bool found = find(fed_ids.begin(), fed_ids.end(), ifed) != fed_ids.end();
0110         if (fed.size()) {
0111           if (found) {
0112             trk_feds.push_back(Fed(ifed, fed.size()));
0113           } else {
0114             in_data.push_back(Fed(ifed, fed.size()));
0115           }
0116         }
0117         if (found && fed.size() == 0) {
0118           in_cabl.push_back(Fed(ifed, 0));
0119         }
0120       }
0121     }
0122   }
0123 
0124   // Trigger FEDs
0125   if (edm::isDebugEnabled()) {
0126     stringstream ss;
0127     ss << "[SiStripFEDRawDataCheck::" << __func__ << "]"
0128        << " Found " << trg_feds.size() << " trigger FEDs";
0129     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0130     ss << " with ids (and buffer sizes [bytes]): ";
0131     for (uint16_t ifed = 0; ifed < trg_feds.size(); ++ifed) {
0132       ss << trg_feds[ifed].first << "(" << trg_feds[ifed].second << ") ";
0133     }
0134     LogTrace(mlRawToDigi_) << ss.str();
0135   }
0136 
0137   // Not strip tracker FEDs
0138   if (edm::isDebugEnabled()) {
0139     stringstream ss;
0140     ss << "[SiStripFEDRawDataCheck::" << __func__ << "]"
0141        << " Found " << non_trk.size() << " non-tracker FEDs from other sub-dets";
0142     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0143     ss << " with ids (and buffer sizes [bytes]): ";
0144     for (uint16_t ifed = 0; ifed < non_trk.size(); ++ifed) {
0145       ss << non_trk[ifed].first << "(" << non_trk[ifed].second << ") ";
0146     }
0147     LogTrace(mlRawToDigi_) << ss.str();
0148   }
0149 
0150   // Strip tracker FEDs
0151   if (edm::isDebugEnabled()) {
0152     stringstream ss;
0153     ss << "[SiStripFEDRawDataCheck::" << __func__ << "]"
0154        << " Found " << trk_feds.size() << " strip tracker FEDs";
0155     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0156     ss << " with ids (and buffer sizes [bytes]): ";
0157     for (uint16_t ifed = 0; ifed < trk_feds.size(); ++ifed) {
0158       ss << trk_feds[ifed].first << "(" << trk_feds[ifed].second << ") ";
0159     }
0160     LogTrace(mlRawToDigi_) << ss.str();
0161   }
0162 
0163   // FEDs in data but missing from cabling
0164   if (edm::isDebugEnabled()) {
0165     stringstream ss;
0166     ss << "[SiStripFEDRawDataCheck::" << __func__ << "]"
0167        << " Found " << in_data.size() << " FEDs in data but missing from cabling";
0168     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0169     ss << " with ids (and buffer sizes [bytes]): ";
0170     for (uint16_t ifed = 0; ifed < in_data.size(); ++ifed) {
0171       ss << in_data[ifed].first << "(" << in_data[ifed].second << ") ";
0172     }
0173     LogTrace(mlRawToDigi_) << ss.str();
0174   }
0175 
0176   // FEDs in cabling but missing from data
0177   if (edm::isDebugEnabled()) {
0178     stringstream ss;
0179     ss << "[SiStripFEDRawDataCheck::" << __func__ << "]"
0180        << " Found " << in_cabl.size() << " FEDs in cabling but missing from data";
0181     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0182     ss << " with ids (and zero buffer size): ";
0183     for (uint16_t ifed = 0; ifed < in_cabl.size(); ++ifed) {
0184       ss << in_cabl[ifed].first << " ";
0185     }
0186     LogTrace(mlRawToDigi_) << ss.str();
0187   }
0188 
0189   // Strip tracker FEDs
0190   if (edm::isDebugEnabled()) {
0191     stringstream ss;
0192     ss << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]"
0193        << " Found " << trk_feds.size() << " strip tracker FEDs";
0194     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0195     ss << " with ids (and buffer sizes [bytes]): ";
0196     for (uint16_t ifed = 0; ifed < trk_feds.size(); ++ifed) {
0197       ss << trk_feds[ifed].first << "(" << trk_feds[ifed].second << ") ";
0198     }
0199     LogTrace(mlRawToDigi_) << ss.str();
0200   }
0201 
0202   // Containers storing fed ids and channels
0203   ChannelsMap construct;  // errors on contruction of object
0204   ChannelsMap channel_construct;
0205   ChannelsMap channels_with_data;
0206   ChannelsMap channels_missing_data;
0207   ChannelsMap cabling_missing_channels;
0208   ChannelsMap connected;
0209 
0210   // Analyze strip tracker FED buffers in data
0211   for (uint16_t ii = 0; ii < trk_feds.size(); ++ii) {
0212     uint16_t ifed = trk_feds[ii].first;
0213 
0214     // record connections
0215     auto channels = cabling->fedConnections(ifed);
0216     for (uint16_t chan = 0; chan < channels.size(); ++chan) {
0217       if (channels[chan].isConnected()) {
0218         connected[ifed].push_back(channels[chan].fedCh());
0219       }
0220     }
0221 
0222     const FEDRawData& fed = buffers->FEDData(static_cast<int>(ifed));
0223 
0224     // construct buffer
0225     std::unique_ptr<FEDBuffer> buffer;
0226     if (FEDBufferStatusCode::SUCCESS != preconstructCheckFEDBuffer(fed)) {
0227       construct[ifed].push_back(0);
0228     } else {
0229       buffer = std::make_unique<FEDBuffer>(fed);
0230       if (FEDBufferStatusCode::SUCCESS != buffer->findChannels()) {
0231         construct[ifed].push_back(0);
0232       }
0233     }
0234 
0235     // readout mode
0236     sistrip::FEDReadoutMode mode = buffer->readoutMode();
0237 
0238     // loop channels
0239     for (uint16_t ichan = 0; ichan < 96; ++ichan) {
0240       // check if channel is good
0241 
0242       if (!buffer->channelGood(ichan, true)) {
0243         channel_construct[ifed].push_back(ichan);
0244         continue;
0245       }
0246 
0247       // find channel data
0248 
0249       if (mode == sistrip::READOUT_MODE_ZERO_SUPPRESSED && buffer->channel(ichan).length() > 7)
0250         channels_with_data[ifed].push_back(ichan);
0251 
0252       else if (mode == sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE10 && buffer->channel(ichan).length() > 2)
0253         channels_with_data[ifed].push_back(ichan);
0254 
0255       else if (mode == sistrip::READOUT_MODE_VIRGIN_RAW && buffer->channel(ichan).length() > 3)
0256         channels_with_data[ifed].push_back(ichan);
0257 
0258       else if (mode == sistrip::READOUT_MODE_PROC_RAW && buffer->channel(ichan).length() > 3)
0259         channels_with_data[ifed].push_back(ichan);
0260 
0261       else if (mode == sistrip::READOUT_MODE_SCOPE && buffer->channel(ichan).length() > 3)
0262         channels_with_data[ifed].push_back(ichan);
0263 
0264       else
0265         channels_missing_data[ifed].push_back(ichan);
0266     }
0267 
0268     // check if channels with data are in cabling
0269     uint16_t chan = 0;
0270     bool found = true;
0271     while (chan < connected[ifed].size() && found) {
0272       Channels::iterator iter = channels_with_data[ifed].begin();
0273       while (iter < channels_with_data[ifed].end()) {
0274         if (*iter == connected[ifed][chan]) {
0275           break;
0276         }
0277         iter++;
0278       }
0279       found = iter != channels_with_data[ifed].end();
0280       if (!found) {
0281         cabling_missing_channels[ifed].push_back(connected[ifed][chan]);
0282       }
0283       chan++;
0284     }
0285   }  // fed loop
0286 
0287   // constructing SiStripFEDBuffers
0288   if (edm::isDebugEnabled()) {
0289     stringstream ss;
0290     ss << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]"
0291        << " Found " << construct.size() << " FED buffers that fail on construction of a FEDBuffer";
0292     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0293     ss << " with ids: ";
0294     for (ChannelsMap::iterator iter = construct.begin(); iter != construct.end(); ++iter) {
0295       ss << iter->first << " ";
0296     }
0297     LogTrace(mlRawToDigi_) << ss.str();
0298   }
0299 
0300   // channel check
0301   if (edm::isDebugEnabled()) {
0302     stringstream ss;
0303     ss << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]"
0304        << " Found " << channel_construct.size() << " FED channels that fail on FEDBuffer::channelGood()";
0305     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0306     ss << " with ids: ";
0307     for (ChannelsMap::iterator iter = channel_construct.begin(); iter != channel_construct.end(); ++iter) {
0308       ss << iter->first << " ";
0309     }
0310     LogTrace(mlRawToDigi_) << ss.str();
0311   }
0312 
0313   //  connected channels with data
0314   if (edm::isDebugEnabled()) {
0315     stringstream ss;
0316     ss << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]"
0317        << " Found " << channels_with_data.size() << " FED buffers with data in connected channels";
0318     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0319     ss << " with ids (and number of connected channels with data): ";
0320     for (ChannelsMap::iterator iter = channels_with_data.begin(); iter != channels_with_data.end(); ++iter) {
0321       ss << iter->first << "(" << iter->second.size() << ") ";
0322     }
0323     LogTrace(mlRawToDigi_) << ss.str();
0324   }
0325 
0326   //  connected channels with missing data
0327   if (edm::isDebugEnabled()) {
0328     stringstream ss;
0329     ss << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]"
0330        << " Found " << channels_missing_data.size() << " FED buffers with connected channels and missing data";
0331     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0332     ss << " with ids (and number of connected channels with missing data): ";
0333     for (ChannelsMap::iterator iter = channels_missing_data.begin(); iter != channels_missing_data.end(); ++iter) {
0334       ss << iter->first << "(" << iter->second.size() << ") ";
0335     }
0336     LogTrace(mlRawToDigi_) << ss.str();
0337   }
0338 
0339   //  channels with data but not in cabling
0340   if (edm::isDebugEnabled()) {
0341     stringstream ss;
0342     ss << "[SiStripFEDRawDataAnalyzer::" << __func__ << "]"
0343        << " Found " << cabling_missing_channels.size()
0344        << " FED buffers with data in channels that are missing from cabling";
0345     edm::LogVerbatim(mlRawToDigi_) << ss.str();
0346     ss << " with ids (number of channels containing data that are missing from cabling, channel number): ";
0347     for (ChannelsMap::iterator iter = cabling_missing_channels.begin(); iter != cabling_missing_channels.end();
0348          ++iter) {
0349       ss << iter->first << "(" << iter->second.size() << ":";
0350       for (Channels::iterator jter = iter->second.begin(); jter != iter->second.end(); ++jter) {
0351         ss << *jter << ",";
0352       }
0353       ss << ") ";
0354     }
0355     LogTrace(mlRawToDigi_) << ss.str();
0356   }
0357 }
0358 
0359 #include "FWCore/PluginManager/interface/ModuleDef.h"
0360 #include "FWCore/Framework/interface/MakerMacros.h"
0361 DEFINE_FWK_MODULE(SiStripFEDRawDataAnalyzer);