CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CalibMuon/DTCalibration/plugins/DTT0FillChamberFromDB.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2012/03/21 13:48:46 $
00005  *  $Revision: 1.2 $
00006  *  \author A. Vilela Pereira
00007  */
00008 
00009 #include "DTT0FillChamberFromDB.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00016 #include "CondFormats/DTObjects/interface/DTT0.h"
00017 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
00018 
00019 #include <string>
00020 #include <sstream>
00021 
00022 using namespace std;
00023 using namespace edm;
00024 
00025 namespace dtCalibration {
00026 
00027 DTT0FillChamberFromDB::DTT0FillChamberFromDB(const ParameterSet& pset):
00028   dbLabelRef_( pset.getParameter<string>("dbLabelRef") ),
00029   chamberRef_( pset.getParameter<string>("chamberId") ) {
00030 
00031   //DTChamberId chosenChamberId;
00032   if( chamberRef_ != "" && chamberRef_ != "None" ){
00033     stringstream linestr;
00034     int selWheel, selStation, selSector;
00035     linestr << chamberRef_;
00036     linestr >> selWheel >> selStation >> selSector;
00037     chosenChamberId_ = DTChamberId(selWheel, selStation, selSector);
00038     LogVerbatim("Calibration") << "[DTT0FillChamberFromDB] Chosen chamber: " << chosenChamberId_ << endl;
00039   }
00040   //FIXME: Check if chosen chamber is valid.
00041 
00042 }
00043 
00044 DTT0FillChamberFromDB::~DTT0FillChamberFromDB() {
00045 }
00046 
00047 void DTT0FillChamberFromDB::setES(const EventSetup& setup) {
00048   // Get t0 record from DB
00049   ESHandle<DTT0> t0H;
00050   setup.get<DTT0Rcd>().get(t0H);
00051   t0Map_ = &*t0H;
00052   LogVerbatim("Calibration") << "[DTT0FillChamberFromDB] T0 version: " << t0H->version();
00053 
00054   // Get reference t0 DB 
00055   ESHandle<DTT0> t0RefH;
00056   setup.get<DTT0Rcd>().get(dbLabelRef_,t0RefH);
00057   t0MapRef_ = &*t0RefH;
00058   LogVerbatim("Calibration") << "[DTT0FillChamberFromDB] Reference T0 version: " << t0RefH->version();
00059 
00060 }
00061 
00062 DTT0Data DTT0FillChamberFromDB::correction(const DTWireId& wireId) {
00063   // If wire belongs to chosen chamber, use t0 value from reference DB
00064   // Otherwise use value from default DB
00065  
00066   DTChamberId chamberId = wireId.layerId().superlayerId().chamberId();
00067 
00068   if( chamberRef_ != "" && chamberRef_ != "None" && chamberId == chosenChamberId_ ){
00069      // Access reference DB
00070      float t0MeanRef,t0RMSRef;
00071      int statusRef = t0MapRef_->get(wireId,t0MeanRef,t0RMSRef,DTTimeUnits::counts);
00072      if(!statusRef){
00073         return DTT0Data(t0MeanRef,t0RMSRef);
00074      } else{
00075         //... 
00076         throw cms::Exception("[DTT0FillChamberFromDB]") << "Could not find t0 entry in reference DB for"
00077                                                         << wireId << endl;
00078      }
00079   } else{
00080      // Access default DB
00081      float t0Mean,t0RMS;
00082      int status = t0Map_->get(wireId,t0Mean,t0RMS,DTTimeUnits::counts);
00083      if(!status){
00084         return DTT0Data(t0Mean,t0RMS);
00085      } else{
00086         //... 
00087         throw cms::Exception("[DTT0FillChamberFromDB]") << "Could not find t0 entry in DB for"
00088                                                         << wireId << endl;
00089      }
00090   }
00091 }
00092 
00093 } // namespace