Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:21

0001 // -*- C++ -*-
0002 //
0003 // Package:    PixelPopConCalibChecker
0004 // Class:      PixelPopConCalibChecker
0005 //
0006 /**\class PixelPopConCalibChecker PixelPopConCalibChecker.h SiPixel/test/PixelPopConCalibChecker.h
0007 
0008  Description: Test analyzer for checking calib configuration objects written to db
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  M. Eads
0015 //         Created:  August 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <string>
0022 #include <iostream>
0023 
0024 // user include files
0025 #include "CalibFormats/SiPixelObjects/interface/PixelCalibConfiguration.h"
0026 #include "CondFormats/DataRecord/interface/SiPixelCalibConfigurationRcd.h"
0027 #include "CondFormats/SiPixelObjects/interface/SiPixelCalibConfiguration.h"
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/EventSetup.h"
0030 #include "FWCore/Framework/interface/Frameworkfwd.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 
0035 //
0036 // class decleration
0037 //
0038 class PixelPopConCalibChecker : public edm::one::EDAnalyzer<> {
0039 public:
0040   explicit PixelPopConCalibChecker(const edm::ParameterSet&);
0041   ~PixelPopConCalibChecker() override;
0042   void analyze(const edm::Event&, const edm::EventSetup&) override;
0043 
0044 private:
0045   // ----------member data ---------------------------
0046   const edm::ESGetToken<SiPixelCalibConfiguration, SiPixelCalibConfigurationRcd> gainCalibToken_;
0047   const std::string _filename;
0048   const int _messageLevel;
0049 };
0050 
0051 using namespace std;
0052 
0053 //
0054 // constructors and destructor
0055 //
0056 PixelPopConCalibChecker::PixelPopConCalibChecker(const edm::ParameterSet& iConfig)
0057     : gainCalibToken_(esConsumes()),
0058       _filename(iConfig.getParameter<string>("filename")),
0059       _messageLevel(iConfig.getUntrackedParameter("messageLevel", 0)) {
0060   if (_messageLevel > 0)
0061     edm::LogPrint("PixelPopConCalibChecker") << "********* PixelPopConCalibChecker ************" << endl;
0062 }
0063 
0064 PixelPopConCalibChecker::~PixelPopConCalibChecker() = default;
0065 
0066 //
0067 // member functions
0068 //
0069 
0070 // ------------ method called to for each event  ------------
0071 void PixelPopConCalibChecker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0072   using namespace edm;
0073 
0074   bool isSame = true;
0075 
0076   // get the run and event number from the EmptyIOVSource
0077   if (_messageLevel > 0) {
0078     EventID eventID = iEvent.id();
0079     edm::LogPrint("PixelPopConCalibChecker") << "Comparing SiPixelCalibConfiguration object from database for run "
0080                                              << eventID.run() << " to calib.dat file at " << _filename << endl;
0081   }  // if (_messageLevel > 0)
0082 
0083   // get the calib config object in the database from the event setup
0084   const SiPixelCalibConfiguration* calibES = &iSetup.getData(gainCalibToken_);
0085 
0086   // get the calib config object from the calib.dat file
0087   pos::PixelCalibConfiguration fancyCalib(_filename);
0088   SiPixelCalibConfiguration* calibFile = new SiPixelCalibConfiguration(fancyCalib);
0089 
0090   // check if mode matches
0091   string modeES = calibES->getCalibrationMode();
0092   string modeFile = calibFile->getCalibrationMode();
0093   if (_messageLevel > 1) {
0094     edm::LogPrint("PixelPopConCalibChecker") << "*** Checking calibration mode ***" << endl;
0095     edm::LogPrint("PixelPopConCalibChecker") << "  mode from DB:   " << modeES << endl;
0096     edm::LogPrint("PixelPopConCalibChecker") << "  mode from file: " << modeFile << endl;
0097   }
0098   if (modeES != modeFile) {
0099     isSame = false;
0100     if (_messageLevel > 0) {
0101       edm::LogPrint("PixelPopConCalibChecker") << "Mismatch in calibration mode!" << endl;
0102       edm::LogPrint("PixelPopConCalibChecker") << "  " << modeES << " in database, " << modeFile << " in file" << endl;
0103     }
0104   }
0105 
0106   // check if the number of triggers matches
0107   short ntriggerES = calibES->getNTriggers();
0108   short ntriggerFile = calibFile->getNTriggers();
0109   if (_messageLevel > 1) {
0110     edm::LogPrint("PixelPopConCalibChecker") << "*** Checking number of triggers ***" << endl;
0111     edm::LogPrint("PixelPopConCalibChecker") << "  NTriggers from DB:   " << ntriggerES << endl;
0112     edm::LogPrint("PixelPopConCalibChecker") << "  NTriggers from file: " << ntriggerFile << endl;
0113   }
0114   if (ntriggerES != ntriggerFile) {
0115     isSame = false;
0116     if (_messageLevel > 0) {
0117       edm::LogPrint("PixelPopConCalibChecker") << "Mismatch in number of triggers!" << endl;
0118       edm::LogPrint("PixelPopConCalibChecker")
0119           << "  " << ntriggerES << " in database, " << ntriggerFile << " in file" << endl;
0120     }
0121   }
0122 
0123   // check if vcal values match
0124   vector<short> vcalES = calibES->getVCalValues();
0125   vector<short> vcalFile = calibFile->getVCalValues();
0126   if (_messageLevel > 1) {
0127     edm::LogPrint("PixelPopConCalibChecker") << "*** Checking vcal values ***" << endl;
0128     edm::LogPrint("PixelPopConCalibChecker") << "  vcal values from DB:   ";
0129     for (vector<short>::const_iterator it = vcalES.begin(); it != vcalES.end(); ++it)
0130       edm::LogPrint("PixelPopConCalibChecker") << *it << ", ";
0131     edm::LogPrint("PixelPopConCalibChecker") << endl;
0132     edm::LogPrint("PixelPopConCalibChecker") << "  vcal values from file: ";
0133     for (vector<short>::const_iterator it = vcalFile.begin(); it != vcalFile.end(); ++it)
0134       edm::LogPrint("PixelPopConCalibChecker") << *it << ", ";
0135     edm::LogPrint("PixelPopConCalibChecker") << endl;
0136   }
0137   if (vcalES != vcalFile) {
0138     isSame = false;
0139     if (_messageLevel > 0) {
0140       edm::LogPrint("PixelPopConCalibChecker") << "Mismatch in vcal values!" << endl;
0141     }
0142   }
0143 
0144   // check if column values match
0145   vector<short> colES = calibES->getColumnPattern();
0146   vector<short> colFile = calibFile->getColumnPattern();
0147   if (_messageLevel > 1) {
0148     edm::LogPrint("PixelPopConCalibChecker") << "*** Checking column pattern values ***" << endl;
0149     edm::LogPrint("PixelPopConCalibChecker") << "  column pattern from DB:   ";
0150     for (vector<short>::const_iterator it = colES.begin(); it != colES.end(); ++it)
0151       edm::LogPrint("PixelPopConCalibChecker") << *it << ", ";
0152     edm::LogPrint("PixelPopConCalibChecker") << endl;
0153     edm::LogPrint("PixelPopConCalibChecker") << "  column pattern from file: ";
0154     for (vector<short>::const_iterator it = colFile.begin(); it != colFile.end(); ++it)
0155       edm::LogPrint("PixelPopConCalibChecker") << *it << ", ";
0156     edm::LogPrint("PixelPopConCalibChecker") << endl;
0157   }
0158   if (colES != colFile) {
0159     isSame = false;
0160     if (_messageLevel > 0) {
0161       edm::LogPrint("PixelPopConCalibChecker") << "Mismatch in column pattern!" << endl;
0162     }
0163   }
0164 
0165   // check if row values match
0166   vector<short> rowES = calibES->getRowPattern();
0167   vector<short> rowFile = calibFile->getRowPattern();
0168   if (_messageLevel > 1) {
0169     edm::LogPrint("PixelPopConCalibChecker") << "*** Checking row pattern values ***" << endl;
0170     edm::LogPrint("PixelPopConCalibChecker") << "  row pattern from DB:   ";
0171     for (vector<short>::const_iterator it = rowES.begin(); it != rowES.end(); ++it)
0172       edm::LogPrint("PixelPopConCalibChecker") << *it << ", ";
0173     edm::LogPrint("PixelPopConCalibChecker") << endl;
0174     edm::LogPrint("PixelPopConCalibChecker") << "  row pattern from file: ";
0175     for (vector<short>::const_iterator it = rowFile.begin(); it != rowFile.end(); ++it)
0176       edm::LogPrint("PixelPopConCalibChecker") << *it << ", ";
0177     edm::LogPrint("PixelPopConCalibChecker") << endl;
0178   }
0179   if (rowES != rowFile) {
0180     isSame = false;
0181     if (_messageLevel > 0) {
0182       edm::LogPrint("PixelPopConCalibChecker") << "Mismatch in row pattern!" << endl;
0183     }
0184   }
0185 
0186   edm::LogPrint("PixelPopConCalibChecker") << endl;
0187   if (isSame) {
0188     edm::LogPrint("PixelPopConCalibChecker")
0189         << "*** Calibration configuration in database and file match. Go forth and calibrate." << endl;
0190   } else {
0191     edm::LogPrint("PixelPopConCalibChecker")
0192         << "*** WARNING! Calibration configuration is database and file DO NOT match!" << endl;
0193   }
0194 
0195 }  // PixelPopConCalibChecker::analyze()
0196 
0197 //define this as a plug-in
0198 DEFINE_FWK_MODULE(PixelPopConCalibChecker);