Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-05 22:48:05

0001 #include "EventFilter/SiStripRawToDigi/plugins/ExcludedFEDListProducer.h"
0002 #include "DataFormats/Common/interface/DetSet.h"
0003 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0005 #include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
0006 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0007 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0008 #include "EventFilter/SiStripRawToDigi/interface/TFHeaderDescription.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0013 #include <iostream>
0014 #include <sstream>
0015 #include <iomanip>
0016 #include <ext/algorithm>
0017 
0018 namespace sistrip {
0019 
0020   ExcludedFEDListProducer::ExcludedFEDListProducer(const edm::ParameterSet& pset)
0021       : runNumber_(0),
0022         cacheId_(0),
0023         cabling_(nullptr),
0024         token_(consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"))),
0025         cablingToken_(esConsumes<SiStripFedCabling, SiStripFedCablingRcd, edm::Transition::BeginRun>()) {
0026     produces<DetIdCollection>();
0027   }
0028 
0029   ExcludedFEDListProducer::~ExcludedFEDListProducer() {}
0030 
0031   void ExcludedFEDListProducer::beginRun(const edm::Run& run, const edm::EventSetup& es) {
0032     uint32_t cacheId = es.get<SiStripFedCablingRcd>().cacheIdentifier();
0033 
0034     if (cacheId_ != cacheId) {
0035       cacheId_ = cacheId;
0036 
0037       edm::ESHandle<SiStripFedCabling> c = es.getHandle(cablingToken_);
0038       cabling_ = c.product();
0039     }
0040   }
0041 
0042   void ExcludedFEDListProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0043     edm::ParameterSetDescription desc;
0044     desc.add<edm::InputTag>("ProductLabel", edm::InputTag("rawDataCollector"));
0045     descriptions.add("siStripExcludedFEDListProducer", desc);
0046   }
0047 
0048   void ExcludedFEDListProducer::produce(edm::Event& event, const edm::EventSetup& es) {
0049     if (runNumber_ != event.run()) {
0050       runNumber_ = event.run();
0051 
0052       DetIdCollection emptyDetIdCollection;
0053       detids_.swap(emptyDetIdCollection);
0054       // Reserve space in bad module list
0055       detids_.reserve(100);
0056 
0057       edm::Handle<FEDRawDataCollection> buffers;
0058       event.getByToken(token_, buffers);
0059 
0060       // Retrieve FED ids from cabling map and iterate through
0061       for (auto ifed = cabling_->fedIds().begin(); ifed != cabling_->fedIds().end(); ifed++) {
0062         // ignore trigger FED
0063         // if ( *ifed == triggerFedId_ ) { continue; }
0064 
0065         // Retrieve FED raw data for given FED
0066         const FEDRawData& input = buffers->FEDData(static_cast<int>(*ifed));
0067         // The FEDData contains a vector<unsigned char>. Check the size of this vector:
0068 
0069         if (input.size() == 0) {
0070           // std::cout << "Input size == 0 for FED number " << static_cast<int>(*ifed) << std::endl;
0071           // get the cabling connections for this FED
0072           auto conns = cabling_->fedConnections(*ifed);
0073           // Mark FED modules as bad
0074           detids_.reserve(detids_.size() + conns.size());
0075           for (auto iconn = conns.begin(); iconn != conns.end(); ++iconn) {
0076             if (!iconn->detId() || iconn->detId() == sistrip::invalid32_)
0077               continue;
0078             detids_.push_back(iconn->detId());  //@@ Possible multiple entries
0079           }
0080         }
0081       }
0082     }
0083 
0084     // for( unsigned int it = 0; it < detids->size(); ++it ) {
0085     //   std::cout << "detId = " << (*detids)[it]() << std::endl;
0086     // }
0087 
0088     event.put(std::make_unique<DetIdCollection>(detids_));
0089   }
0090 }  // namespace sistrip