CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes

SiStripGainFromAsciiFile Class Reference

#include <SiStripGainFromAsciiFile.h>

Inheritance diagram for SiStripGainFromAsciiFile:
ConditionDBWriter< SiStripApvGain > edm::EDAnalyzer

List of all members.

Classes

struct  FibersGain

Public Member Functions

 SiStripGainFromAsciiFile (const edm::ParameterSet &)
 ~SiStripGainFromAsciiFile ()

Private Member Functions

SiStripApvGaingetNewObject ()

Private Attributes

std::string Asciifilename_
edm::FileInPath fp_
__gnu_cxx::hash_map< unsigned
int, FibersGain
GainsMap
float referenceValue_

Detailed Description

Definition at line 12 of file SiStripGainFromAsciiFile.h.


Constructor & Destructor Documentation

SiStripGainFromAsciiFile::SiStripGainFromAsciiFile ( const edm::ParameterSet iConfig) [explicit]

Definition at line 15 of file SiStripGainFromAsciiFile.cc.

References Asciifilename_, fp_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), referenceValue_, and AlCaHLTBitMon_QueryRunRegistry::string.

                                                                                 : ConditionDBWriter<SiStripApvGain>(iConfig){


  Asciifilename_=iConfig.getParameter<std::string>("InputFileName");
  referenceValue_ = iConfig.getParameter<double>("referenceValue");
  fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
}               
SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile ( )

Definition at line 24 of file SiStripGainFromAsciiFile.cc.

                                                   {
  edm::LogInfo("SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile");
}

Member Function Documentation

SiStripApvGain * SiStripGainFromAsciiFile::getNewObject ( ) [private, virtual]

Implements ConditionDBWriter< SiStripApvGain >.

Definition at line 28 of file SiStripGainFromAsciiFile.cc.

References Asciifilename_, DetId::det(), cond::rpcobgas::detid, SiStripGainFromAsciiFile::FibersGain::fiber, fp_, edm::FileInPath::fullPath(), GainsMap, SiStripGainFromAsciiFile::FibersGain::hard_reset(), EdgesToViz::infile, getGTfromDQMFile::obj, SiStripApvGain::put(), matplotRender::reader, referenceValue_, and align::Tracker.

                                                       {

  SiStripApvGain* obj = new SiStripApvGain();

  uint32_t detid;
  FibersGain FG;

  std::stringstream ss;
  ss.str("");
  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Reading Ascii File\n";
  std::ifstream infile;
  infile.open (Asciifilename_.c_str());
  if (infile.is_open()){
    while (infile.good()){
      infile >> detid >> FG.fiber[0] >> FG.fiber[1] >> FG.fiber[2];
      ss << detid << " " <<  FG.fiber[0] << " " <<  FG.fiber[1] << " " <<  FG.fiber[2] << std::endl;
      GainsMap.insert(std::pair<unsigned int,FibersGain>(detid,FG));
    }
    infile.close();
    edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
  } else  {
    edm::LogError("SiStripGainFromAsciiFile")<< " [SiStripGainFromAsciiFile::getNewObject] Error opening file " << Asciifilename_ << std::endl;
    assert(0);
  }
  
  

  SiStripDetInfoFileReader reader(fp_.fullPath());
  
  const std::vector<uint32_t> DetIds = reader.getAllDetIds();
  
  ss.str("");
  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Filling SiStripApvGain object";
  short nApvPair;
  for(std::vector<uint32_t>::const_iterator it=DetIds.begin(); it!=DetIds.end(); it++){

    if (DetId(*it).det()!=DetId::Tracker)
      continue;

    nApvPair=reader.getNumberOfApvsAndStripLength(*it).first/2;
    
    ss << "Looking at detid " << *it << " nApvPairs  " << nApvPair << std::endl;

    __gnu_cxx::hash_map< unsigned int,FibersGain>::const_iterator iter=GainsMap.find(*it);
    
    if (iter!=GainsMap.end()){
      FG = iter->second;
      ss << " " <<  FG.fiber[0] << " " <<  FG.fiber[1] << " " <<  FG.fiber[2] << std::endl;
    }
    else {
      ss << "Hard reset for detid " << *it << std::endl;
      FG.hard_reset(referenceValue_);
    }
    
    std::vector<float> DetGainsVector;
    
    if (nApvPair==2){
      DetGainsVector.push_back(FG.fiber[0]/referenceValue_);  
      DetGainsVector.push_back(FG.fiber[0]/referenceValue_);  
      DetGainsVector.push_back(FG.fiber[2]/referenceValue_);        
      DetGainsVector.push_back(FG.fiber[2]/referenceValue_);  
    } else if (nApvPair==3){                                              
      DetGainsVector.push_back(FG.fiber[0]/referenceValue_);  
      DetGainsVector.push_back(FG.fiber[0]/referenceValue_);  
      DetGainsVector.push_back(FG.fiber[1]/referenceValue_);  
      DetGainsVector.push_back(FG.fiber[1]/referenceValue_);  
      DetGainsVector.push_back(FG.fiber[2]/referenceValue_);  
      DetGainsVector.push_back(FG.fiber[2]/referenceValue_);  
    } else {
      edm::LogError("SiStripGainFromAsciiFile") << " SiStripGainFromAsciiFile::getNewObject] ERROR for detid " << *it << " not expected number of APV pairs " << nApvPair <<std::endl;
    }
    
    SiStripApvGain::Range range(DetGainsVector.begin(),DetGainsVector.end());
    if ( ! obj->put(*it,range) ){
      edm::LogError("SiStripGainFromAsciiFile")<<" [SiStripGainFromAsciiFile::getNewObject] detid already exists"<<std::endl;
      ss <<" [SiStripGainFromAsciiFile::getNewObject] detid already exists"<<std::endl;
    }
  }
  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();

  return obj;
}

Member Data Documentation

Definition at line 33 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().

Definition at line 35 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().

__gnu_cxx::hash_map< unsigned int,FibersGain> SiStripGainFromAsciiFile::GainsMap [private]

Definition at line 37 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject().

Definition at line 34 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().