File indexing completed on 2024-04-06 12:08:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <memory>
0016
0017 #include "FWCore/Utilities/interface/EDGetToken.h"
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/Framework/interface/ESWatcher.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 #include "FWCore/Utilities/interface/Exception.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/ServiceRegistry/interface/Service.h"
0029
0030 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0031 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0032 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0033 #include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h"
0034 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0035 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0036
0037 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
0038 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0039
0040 #include "DQMServices/Core/interface/DQMStore.h"
0041
0042 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
0043
0044 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
0045
0046 #include <DQMServices/Core/interface/DQMOneEDAnalyzer.h>
0047
0048
0049
0050
0051
0052 class SiStripFEDCheckPlugin : public DQMOneEDAnalyzer<> {
0053 public:
0054 explicit SiStripFEDCheckPlugin(const edm::ParameterSet&);
0055 ~SiStripFEDCheckPlugin() override;
0056 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0057
0058 private:
0059 void analyze(const edm::Event&, const edm::EventSetup&) override;
0060 void dqmEndRun(edm::Run const&, edm::EventSetup const&) override;
0061
0062 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0063
0064 bool hasFatalError(const FEDRawData& fedData, unsigned int fedId) const;
0065 bool hasNonFatalError(const FEDRawData& fedData, unsigned int fedId) const;
0066 void updateCabling(const SiStripFedCablingRcd& cablingRcd);
0067
0068 inline void fillPresent(unsigned int fedId, bool present);
0069 inline void fillFatalError(unsigned int fedId, bool fatalError);
0070 inline void fillNonFatalError(unsigned int fedId, float nonFatalError);
0071
0072 void doUpdateIfNeeded();
0073 void updateHistograms();
0074
0075 edm::InputTag rawDataTag_;
0076 edm::EDGetTokenT<FEDRawDataCollection> rawDataToken_;
0077 std::string dirName_;
0078 bool printDebug_;
0079
0080
0081 bool doPLOTfedsPresent_, doPLOTfedFatalErrors_, doPLOTfedNonFatalErrors_;
0082 bool doPLOTnFEDinVsLS_, doPLOTnFEDinWdataVsLS_;
0083 MonitorElement* fedsPresent_;
0084 MonitorElement* fedFatalErrors_;
0085 MonitorElement* fedNonFatalErrors_;
0086
0087 MonitorElement* nFEDinVsLS_;
0088 MonitorElement* nFEDinWdataVsLS_;
0089
0090
0091 unsigned int
0092 updateFrequency_;
0093
0094 std::vector<unsigned int> fedsPresentBinContents_;
0095 std::vector<unsigned int> fedFatalErrorBinContents_;
0096 std::vector<unsigned int> fedNonFatalErrorBinContents_;
0097 unsigned int eventCount_;
0098
0099
0100 bool doPayloadChecks_, checkChannelLengths_, checkPacketCodes_, checkFELengths_, checkChannelStatusBits_, verbose_;
0101
0102
0103 const SiStripFedCabling* cabling_;
0104
0105 edm::ESWatcher<SiStripFedCablingRcd> fedCablingWatcher_;
0106 edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> fedCablingToken_;
0107 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0108
0109 unsigned int siStripFedIdMin_;
0110 unsigned int siStripFedIdMax_;
0111
0112 edm::ParameterSet conf_;
0113 };
0114
0115
0116
0117
0118
0119 SiStripFEDCheckPlugin::SiStripFEDCheckPlugin(const edm::ParameterSet& iConfig)
0120 : rawDataTag_(iConfig.getParameter<edm::InputTag>("RawDataTag")),
0121 dirName_(iConfig.getUntrackedParameter<std::string>("DirName", "SiStrip/FEDIntegrity/")),
0122 printDebug_(iConfig.getUntrackedParameter<bool>("PrintDebugMessages", false)),
0123 doPLOTfedsPresent_(iConfig.getParameter<bool>("doPLOTfedsPresent")),
0124 doPLOTfedFatalErrors_(iConfig.getParameter<bool>("doPLOTfedFatalErrors")),
0125 doPLOTfedNonFatalErrors_(iConfig.getParameter<bool>("doPLOTfedNonFatalErrors")),
0126 doPLOTnFEDinVsLS_(iConfig.getParameter<bool>("doPLOTnFEDinVsLS")),
0127 doPLOTnFEDinWdataVsLS_(iConfig.getParameter<bool>("doPLOTnFEDinWdataVsLS")),
0128 fedsPresent_(nullptr),
0129 fedFatalErrors_(nullptr),
0130 fedNonFatalErrors_(nullptr),
0131 nFEDinVsLS_(nullptr),
0132 nFEDinWdataVsLS_(nullptr),
0133 updateFrequency_(iConfig.getUntrackedParameter<unsigned int>("HistogramUpdateFrequency", 0)),
0134 fedsPresentBinContents_(FEDNumbering::MAXSiStripFEDID + 1, 0),
0135 fedFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID + 1, 0),
0136 fedNonFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID + 1, 0),
0137 eventCount_(0),
0138 doPayloadChecks_(iConfig.getUntrackedParameter<bool>("DoPayloadChecks", true)),
0139 checkChannelLengths_(iConfig.getUntrackedParameter<bool>("CheckChannelLengths", true)),
0140 checkPacketCodes_(iConfig.getUntrackedParameter<bool>("CheckChannelPacketCodes", true)),
0141 checkFELengths_(iConfig.getUntrackedParameter<bool>("CheckFELengths", true)),
0142 checkChannelStatusBits_(iConfig.getUntrackedParameter<bool>("CheckChannelStatus", true)),
0143 verbose_(iConfig.getUntrackedParameter<bool>("verbose", false)),
0144 fedCablingWatcher_(this, &SiStripFEDCheckPlugin::updateCabling),
0145 fedCablingToken_(esConsumes<>()),
0146 tTopoToken_(esConsumes<>()) {
0147 rawDataToken_ = consumes<FEDRawDataCollection>(rawDataTag_);
0148 if (printDebug_ && !doPayloadChecks_ && (checkChannelLengths_ || checkPacketCodes_ || checkFELengths_)) {
0149 std::stringstream ss;
0150 ss << "Payload checks are disabled but individual payload checks have been enabled. The following payload checks "
0151 "will be skipped: ";
0152 if (checkChannelLengths_)
0153 ss << "Channel length check, ";
0154 if (checkPacketCodes_)
0155 ss << "Channel packet code check, ";
0156 if (checkChannelStatusBits_)
0157 ss << "Cabled channel status bits checks, ";
0158 if (checkFELengths_)
0159 ss << "FE Unit legnth check";
0160 edm::LogWarning("SiStripFEDCheck") << ss.str();
0161 }
0162
0163 siStripFedIdMin_ = FEDNumbering::MINSiStripFEDID;
0164 siStripFedIdMax_ = FEDNumbering::MAXSiStripFEDID;
0165
0166 conf_ = iConfig;
0167 }
0168
0169 SiStripFEDCheckPlugin::~SiStripFEDCheckPlugin() {}
0170
0171
0172
0173
0174
0175
0176 void SiStripFEDCheckPlugin::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0177 const auto tTopo = &iSetup.getData(tTopoToken_);
0178 fedCablingWatcher_.check(iSetup);
0179
0180
0181 edm::Handle<FEDRawDataCollection> rawDataCollectionHandle;
0182 const bool gotData = iEvent.getByToken(rawDataToken_, rawDataCollectionHandle);
0183 if (verbose_)
0184 std::cout << "[SiStripFEDCheckPlugin::analyze] gotData ? " << (gotData ? "YES" : "NOPE") << std::endl;
0185 if (!gotData) {
0186
0187 return;
0188 }
0189 const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
0190
0191
0192 FEDErrors lFedErrors;
0193
0194
0195 size_t nFEDin = 0;
0196 size_t nFEDinWdata = 0;
0197 for (unsigned int fedId = siStripFedIdMin_; fedId <= siStripFedIdMax_; fedId++) {
0198 const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
0199
0200
0201
0202 lFedErrors.initialiseFED(fedId, cabling_, tTopo, false);
0203
0204
0205 if (!fedData.size() || !fedData.data()) {
0206 fillPresent(fedId, false);
0207 continue;
0208 }
0209 if (verbose_)
0210 std::cout << "FED " << fedId;
0211 if (verbose_)
0212 std::cout << " fedData.size(): " << fedData.size();
0213 if (verbose_)
0214 std::cout << " fedData.data(): " << fedData.data() << std::endl;
0215 if (fedData.size())
0216 nFEDin++;
0217 if (fedData.size() && fedData.data())
0218 nFEDinWdata++;
0219
0220
0221 fillPresent(fedId, true);
0222
0223
0224
0225 bool hasFatalErrors = false;
0226 float rateNonFatal = 0;
0227
0228 std::unique_ptr<const sistrip::FEDBuffer> buffer;
0229
0230 if (!lFedErrors.fillFatalFEDErrors(fedData, 0)) {
0231 hasFatalErrors = true;
0232 } else {
0233
0234 if (doPayloadChecks_ || checkChannelStatusBits_) {
0235 const auto st_buffer = sistrip::preconstructCheckFEDBuffer(fedData, true);
0236 if (sistrip::FEDBufferStatusCode::SUCCESS != st_buffer) {
0237 throw cms::Exception("FEDBuffer") << st_buffer << " (check debug output for more details)";
0238 }
0239 auto tmp_buffer = std::make_unique<sistrip::FEDBuffer>(fedData, true);
0240 tmp_buffer->findChannels();
0241 buffer = std::move(tmp_buffer);
0242 if (doPayloadChecks_) {
0243 bool channelLengthsOK = checkChannelLengths_ ? buffer->checkChannelLengthsMatchBufferLength() : true;
0244 bool channelPacketCodesOK = checkPacketCodes_ ? buffer->checkChannelPacketCodes() : true;
0245 bool feLengthsOK = checkFELengths_ ? buffer->checkFEUnitLengths() : true;
0246 if (!channelLengthsOK || !channelPacketCodesOK || !feLengthsOK) {
0247 hasFatalErrors = true;
0248 }
0249 }
0250 if (checkChannelStatusBits_)
0251 rateNonFatal = lFedErrors.fillNonFatalFEDErrors(buffer.get(), cabling_);
0252 }
0253 }
0254
0255 if (hasFatalErrors) {
0256 fillFatalError(fedId, true);
0257 if (printDebug_) {
0258 if (!buffer.get()) {
0259 const auto st_buffer = sistrip::preconstructCheckFEDBuffer(fedData, true);
0260 if (sistrip::FEDBufferStatusCode::SUCCESS != st_buffer) {
0261 throw cms::Exception("FEDBuffer") << st_buffer << " (check debug output for more details)";
0262 }
0263 auto tmp_buffer = std::make_unique<sistrip::FEDBuffer>(fedData, true);
0264 tmp_buffer->findChannels();
0265 buffer = std::move(tmp_buffer);
0266 }
0267 edm::LogInfo("SiStripFEDCheck") << "Fatal error with FED ID " << fedId << ". Check summary: " << std::endl
0268 << buffer->checkSummary() << std::endl;
0269 std::stringstream ss;
0270 buffer->dump(ss);
0271 edm::LogInfo("SiStripFEDCheck") << ss.str();
0272 }
0273 } else {
0274 fillFatalError(fedId, false);
0275
0276 fillNonFatalError(fedId, rateNonFatal);
0277 if (printDebug_ && rateNonFatal > 0) {
0278 if (!buffer.get()) {
0279 const auto st_buffer = sistrip::preconstructCheckFEDBuffer(fedData, true);
0280 if (sistrip::FEDBufferStatusCode::SUCCESS != st_buffer) {
0281 throw cms::Exception("FEDBuffer") << st_buffer << " (check debug output for more details)";
0282 }
0283 auto tmp_buffer = std::make_unique<sistrip::FEDBuffer>(fedData, true);
0284 tmp_buffer->findChannels();
0285 buffer = std::move(tmp_buffer);
0286 }
0287 edm::LogInfo("SiStripFEDCheck") << "Non-fatal error with FED ID " << fedId << " for " << rateNonFatal
0288 << " of the channels. Check summary: " << std::endl
0289 << buffer->checkSummary() << std::endl;
0290 std::stringstream ss;
0291 buffer->dump(ss);
0292 edm::LogInfo("SiStripFEDCheck") << ss.str();
0293 }
0294 }
0295 }
0296 if (verbose_)
0297 std::cout << "nFEDin: " << nFEDin << " nFEDinWdata: " << nFEDinWdata << std::endl;
0298 if (doPLOTnFEDinVsLS_)
0299 nFEDinVsLS_->Fill(static_cast<double>(iEvent.id().luminosityBlock()), nFEDin);
0300 if (doPLOTnFEDinWdataVsLS_)
0301 nFEDinWdataVsLS_->Fill(static_cast<double>(iEvent.id().luminosityBlock()), nFEDinWdata);
0302
0303
0304 doUpdateIfNeeded();
0305 }
0306
0307
0308 void SiStripFEDCheckPlugin::bookHistograms(DQMStore::IBooker& ibooker,
0309 const edm::Run& run,
0310 const edm::EventSetup& eSetup) {
0311 size_t nFED = siStripFedIdMax_ - siStripFedIdMin_ + 1;
0312 double xFEDmin = siStripFedIdMin_ - 0.5;
0313 double xFEDmax = siStripFedIdMax_ + 0.5;
0314
0315
0316 ibooker.setCurrentFolder(dirName_);
0317
0318 if (doPLOTfedsPresent_) {
0319 fedsPresent_ =
0320 ibooker.book1D("FEDEntries", "Number of times FED buffer is present in data", nFED, xFEDmin, xFEDmax);
0321 fedsPresent_->setAxisTitle("FED-ID", 1);
0322 }
0323
0324 if (doPLOTfedFatalErrors_) {
0325 fedFatalErrors_ = ibooker.book1D("FEDFatal", "Number of fatal errors in FED buffer", nFED, xFEDmin, xFEDmax);
0326 fedFatalErrors_->setAxisTitle("FED-ID", 1);
0327 }
0328
0329 if (doPLOTfedNonFatalErrors_) {
0330 fedNonFatalErrors_ =
0331 ibooker.book1D("FEDNonFatal", "Number of non fatal errors in FED buffer", nFED, xFEDmin, xFEDmax);
0332 fedNonFatalErrors_->setAxisTitle("FED-ID", 1);
0333 }
0334
0335 int LSBin = conf_.getParameter<int>("LSBin");
0336 double LSMin = conf_.getParameter<double>("LSMin");
0337 double LSMax = conf_.getParameter<double>("LSMax");
0338
0339 if (doPLOTnFEDinVsLS_) {
0340 nFEDinVsLS_ =
0341 ibooker.bookProfile("nFEDinVsLS", "number of FED in Vs LS", LSBin, LSMin, LSMax, nFED, xFEDmin, xFEDmax);
0342 nFEDinVsLS_->setAxisTitle("LS", 1);
0343 nFEDinVsLS_->setAxisTitle("FED-ID", 2);
0344 }
0345
0346 if (doPLOTnFEDinWdataVsLS_) {
0347 nFEDinWdataVsLS_ = ibooker.bookProfile(
0348 "nFEDinWdataVsLS", "number of FED in (with data) Vs LS", LSBin, LSMin, LSMax, nFED, xFEDmin, xFEDmax);
0349 nFEDinWdataVsLS_->setAxisTitle("LS", 1);
0350 nFEDinWdataVsLS_->setAxisTitle("FED-ID", 2);
0351 }
0352 }
0353
0354
0355 void SiStripFEDCheckPlugin::dqmEndRun(edm::Run const&, edm::EventSetup const&) { updateHistograms(); }
0356
0357 void SiStripFEDCheckPlugin::updateCabling(const SiStripFedCablingRcd& cablingRcd) {
0358 cabling_ = &cablingRcd.get(fedCablingToken_);
0359 }
0360
0361 void SiStripFEDCheckPlugin::fillPresent(unsigned int fedId, bool present) {
0362 if (present) {
0363 if (updateFrequency_)
0364 fedsPresentBinContents_[fedId]++;
0365 else if (doPLOTfedsPresent_)
0366 fedsPresent_->Fill(fedId);
0367 }
0368 }
0369
0370 void SiStripFEDCheckPlugin::fillFatalError(unsigned int fedId, bool fatalError) {
0371 if (updateFrequency_) {
0372 if (fatalError)
0373 fedFatalErrorBinContents_[fedId]++;
0374 } else {
0375
0376 if (fatalError)
0377 if (doPLOTfedFatalErrors_)
0378 fedFatalErrors_->Fill(fedId);
0379 }
0380 }
0381
0382 void SiStripFEDCheckPlugin::fillNonFatalError(unsigned int fedId, float nonFatalError) {
0383 if (updateFrequency_) {
0384 if (nonFatalError > 0)
0385 fedNonFatalErrorBinContents_[fedId]++;
0386 } else {
0387 if (nonFatalError > 0)
0388 if (doPLOTfedNonFatalErrors_)
0389 fedNonFatalErrors_->Fill(fedId);
0390 }
0391 }
0392
0393 void SiStripFEDCheckPlugin::doUpdateIfNeeded() {
0394 eventCount_++;
0395 if (updateFrequency_ && (eventCount_ % updateFrequency_ == 0)) {
0396 updateHistograms();
0397 }
0398 }
0399
0400 void SiStripFEDCheckPlugin::updateHistograms() {
0401
0402 if (!updateFrequency_)
0403 return;
0404 unsigned int entriesFedsPresent = 0;
0405 unsigned int entriesFatalErrors = 0;
0406 unsigned int entriesNonFatalErrors = 0;
0407 for (unsigned int fedId = siStripFedIdMin_, bin = 1; fedId < siStripFedIdMax_ + 1; fedId++, bin++) {
0408 unsigned int fedsPresentBin = fedsPresentBinContents_[fedId];
0409 if (doPLOTfedsPresent_)
0410 fedsPresent_->getTH1()->SetBinContent(bin, fedsPresentBin);
0411 entriesFedsPresent += fedsPresentBin;
0412 unsigned int fedFatalErrorsBin = fedFatalErrorBinContents_[fedId];
0413 if (doPLOTfedFatalErrors_)
0414 fedFatalErrors_->getTH1()->SetBinContent(bin, fedFatalErrorsBin);
0415 entriesFatalErrors += fedFatalErrorsBin;
0416 unsigned int fedNonFatalErrorsBin = fedNonFatalErrorBinContents_[fedId];
0417 if (doPLOTfedNonFatalErrors_)
0418 fedNonFatalErrors_->getTH1()->SetBinContent(bin, fedNonFatalErrorsBin);
0419 entriesNonFatalErrors += fedNonFatalErrorsBin;
0420 }
0421 if (doPLOTfedsPresent_)
0422 fedsPresent_->getTH1()->SetEntries(entriesFedsPresent);
0423 if (doPLOTfedFatalErrors_)
0424 fedFatalErrors_->getTH1()->SetEntries(entriesFatalErrors);
0425 if (doPLOTfedNonFatalErrors_)
0426 fedNonFatalErrors_->getTH1()->SetEntries(entriesNonFatalErrors);
0427 }
0428 void SiStripFEDCheckPlugin::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0429 edm::ParameterSetDescription desc;
0430
0431
0432 desc.addUntracked<std::string>("DirName", "SiStrip/FEDIntegrity/");
0433
0434 desc.add<edm::InputTag>("RawDataTag", edm::InputTag("source"));
0435
0436
0437
0438 desc.addUntracked<unsigned int>("HistogramUpdateFrequency", 1000);
0439
0440 desc.addUntracked<bool>("PrintDebugMessages", false);
0441 desc.add<bool>("doPLOTfedsPresent", true);
0442 desc.add<bool>("doPLOTfedFatalErrors", true);
0443 desc.add<bool>("doPLOTfedNonFatalErrors", true);
0444 desc.add<bool>("doPLOTnFEDinVsLS", false);
0445 desc.add<bool>("doPLOTnFEDinWdataVsLS", false);
0446
0447 desc.addUntracked<bool>("WriteDQMStore", false);
0448
0449 desc.addUntracked<bool>("DoPayloadChecks", true);
0450
0451 desc.addUntracked<bool>("CheckChannelLengths", true);
0452
0453 desc.addUntracked<bool>("CheckChannelPacketCodes", true);
0454
0455 desc.addUntracked<bool>("CheckFELengths", true);
0456
0457 desc.addUntracked<bool>("CheckChannelStatus", true);
0458 desc.add<int>("LSBin", 5000);
0459 desc.add<double>("LSMin", 0.5);
0460 desc.add<double>("LSMax", 5000.5);
0461
0462 descriptions.addDefault(desc);
0463 }
0464
0465
0466
0467
0468
0469 #include "FWCore/Framework/interface/MakerMacros.h"
0470 DEFINE_FWK_MODULE(SiStripFEDCheckPlugin);