Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-19 10:28:04

0001 /*
0002  *  See header file for a description of this class.
0003  */
0004 
0005 #include "DTT0FillDefaultFromDB.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0012 #include "CondFormats/DTObjects/interface/DTT0.h"
0013 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
0014 
0015 #include <string>
0016 
0017 using namespace std;
0018 using namespace edm;
0019 
0020 namespace dtCalibration {
0021 
0022   DTT0FillDefaultFromDB::DTT0FillDefaultFromDB(const ParameterSet& pset, edm::ConsumesCollector cc)
0023       : t0Token_(cc.esConsumes<edm::Transition::BeginRun>()),
0024         t0RefToken_(
0025             cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", pset.getParameter<string>("dbLabelRef")))) {}
0026 
0027   DTT0FillDefaultFromDB::~DTT0FillDefaultFromDB() {}
0028 
0029   void DTT0FillDefaultFromDB::setES(const EventSetup& setup) {
0030     // Get t0 record from DB
0031     ESHandle<DTT0> t0H = setup.getHandle(t0Token_);
0032     t0Map_ = &*t0H;
0033     LogVerbatim("Calibration") << "[DTT0FillDefaultFromDB] T0 version: " << t0H->version();
0034 
0035     // Get reference t0 DB
0036     ESHandle<DTT0> t0RefH = setup.getHandle(t0RefToken_);
0037     t0MapRef_ = &*t0RefH;
0038     LogVerbatim("Calibration") << "[DTT0FillDefaultFromDB] Reference T0 version: " << t0RefH->version();
0039   }
0040 
0041   DTT0Data DTT0FillDefaultFromDB::correction(const DTWireId& wireId) {
0042     // Try to access value in default DB
0043     // If it does not exist return value from reference DB
0044     // If it does not exist in reference DB, throw exception
0045     // Could also set to default zero value
0046     float t0Mean, t0RMS;
0047     int status = t0Map_->get(wireId, t0Mean, t0RMS, DTTimeUnits::counts);
0048     if (!status) {
0049       return DTT0Data(t0Mean, t0RMS);
0050     } else {
0051       // Now access reference DB
0052       float t0MeanRef, t0RMSRef;
0053       int statusRef = t0MapRef_->get(wireId, t0MeanRef, t0RMSRef, DTTimeUnits::counts);
0054       if (!statusRef) {
0055         return DTT0Data(t0MeanRef, t0RMSRef);
0056       } else {
0057         //...
0058         throw cms::Exception("[DTT0FillDefaultFromDB]")
0059             << "Could not find t0 entry in reference DB for" << wireId << endl;
0060       }
0061     }
0062   }
0063 
0064 }  // namespace dtCalibration