CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CalibTracker/SiStripChannelGain/plugins/SiStripGainFromAsciiFile.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripChannelGain/plugins/SiStripGainFromAsciiFile.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 
00005 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00006 
00007 #include "DataFormats/DetId/interface/DetId.h"
00008 
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 #include <sstream>
00013 
00014 
00015 SiStripGainFromAsciiFile::SiStripGainFromAsciiFile(const edm::ParameterSet& iConfig) : ConditionDBWriter<SiStripApvGain>(iConfig){
00016 
00017 
00018   Asciifilename_=iConfig.getParameter<std::string>("InputFileName");
00019   referenceValue_ = iConfig.getParameter<double>("referenceValue");
00020   fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
00021 }               
00022 
00023 
00024 SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile(){
00025   edm::LogInfo("SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile");
00026 }
00027 
00028 SiStripApvGain * SiStripGainFromAsciiFile::getNewObject(){
00029 
00030   SiStripApvGain* obj = new SiStripApvGain();
00031 
00032   uint32_t detid;
00033   FibersGain FG;
00034 
00035   std::stringstream ss;
00036   ss.str("");
00037   ss << "[SiStripGainFromAsciiFile::getNewObject]\n Reading Ascii File\n";
00038   std::ifstream infile;
00039   infile.open (Asciifilename_.c_str());
00040   if (infile.is_open()){
00041     while (infile.good()){
00042       infile >> detid >> FG.fiber[0] >> FG.fiber[1] >> FG.fiber[2];
00043       ss << detid << " " <<  FG.fiber[0] << " " <<  FG.fiber[1] << " " <<  FG.fiber[2] << std::endl;
00044       GainsMap.insert(std::pair<unsigned int,FibersGain>(detid,FG));
00045     }
00046     infile.close();
00047     edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
00048   } else  {
00049     edm::LogError("SiStripGainFromAsciiFile")<< " [SiStripGainFromAsciiFile::getNewObject] Error opening file " << Asciifilename_ << std::endl;
00050     assert(0);
00051   }
00052   
00053   
00054 
00055   SiStripDetInfoFileReader reader(fp_.fullPath());
00056   
00057   const std::vector<uint32_t> DetIds = reader.getAllDetIds();
00058   
00059   ss.str("");
00060   ss << "[SiStripGainFromAsciiFile::getNewObject]\n Filling SiStripApvGain object";
00061   short nApvPair;
00062   for(std::vector<uint32_t>::const_iterator it=DetIds.begin(); it!=DetIds.end(); it++){
00063 
00064     if (DetId(*it).det()!=DetId::Tracker)
00065       continue;
00066 
00067     nApvPair=reader.getNumberOfApvsAndStripLength(*it).first/2;
00068     
00069     ss << "Looking at detid " << *it << " nApvPairs  " << nApvPair << std::endl;
00070 
00071     __gnu_cxx::hash_map< unsigned int,FibersGain>::const_iterator iter=GainsMap.find(*it);
00072     
00073     if (iter!=GainsMap.end()){
00074       FG = iter->second;
00075       ss << " " <<  FG.fiber[0] << " " <<  FG.fiber[1] << " " <<  FG.fiber[2] << std::endl;
00076     }
00077     else {
00078       ss << "Hard reset for detid " << *it << std::endl;
00079       FG.hard_reset(referenceValue_);
00080     }
00081     
00082     std::vector<float> DetGainsVector;
00083     
00084     if (nApvPair==2){
00085       DetGainsVector.push_back(FG.fiber[0]/referenceValue_);  
00086       DetGainsVector.push_back(FG.fiber[0]/referenceValue_);  
00087       DetGainsVector.push_back(FG.fiber[2]/referenceValue_);        
00088       DetGainsVector.push_back(FG.fiber[2]/referenceValue_);  
00089     } else if (nApvPair==3){                                              
00090       DetGainsVector.push_back(FG.fiber[0]/referenceValue_);  
00091       DetGainsVector.push_back(FG.fiber[0]/referenceValue_);  
00092       DetGainsVector.push_back(FG.fiber[1]/referenceValue_);  
00093       DetGainsVector.push_back(FG.fiber[1]/referenceValue_);  
00094       DetGainsVector.push_back(FG.fiber[2]/referenceValue_);  
00095       DetGainsVector.push_back(FG.fiber[2]/referenceValue_);  
00096     } else {
00097       edm::LogError("SiStripGainFromAsciiFile") << " SiStripGainFromAsciiFile::getNewObject] ERROR for detid " << *it << " not expected number of APV pairs " << nApvPair <<std::endl;
00098     }
00099     
00100     SiStripApvGain::Range range(DetGainsVector.begin(),DetGainsVector.end());
00101     if ( ! obj->put(*it,range) ){
00102       edm::LogError("SiStripGainFromAsciiFile")<<" [SiStripGainFromAsciiFile::getNewObject] detid already exists"<<std::endl;
00103       ss <<" [SiStripGainFromAsciiFile::getNewObject] detid already exists"<<std::endl;
00104     }
00105   }
00106   edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
00107 
00108   return obj;
00109 }
00110 
00111 
00112 
00113