CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoHI/HiCentralityAlgos/src/HiTrivialConditionRetriever.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HiTrivialConditionRetriever
00004 // Class:      HiTrivialConditionRetriever
00005 // 
00013 //
00014 // Original Author:  Yetkin Yilmaz
00015 //         Created:  Wed May  2 21:41:30 EDT 2007
00016 // $Id: HiTrivialConditionRetriever.cc,v 1.1 2010/03/23 21:56:39 yilmaz Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <iostream>
00023 #include <fstream>
00024 #include <sstream>
00025 #include <vector>
00026 #include <string>
00027 
00028 // user include files
00029 #include "FWCore/Framework/interface/ESProducer.h"
00030 #include "FWCore/Framework/interface/EventSetup.h"
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 #include "FWCore/Framework/interface/SourceFactory.h"
00033 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035 #include "CondFormats/DataRecord/interface/HeavyIonRcd.h"
00036 #include "CondFormats/HIObjects/interface/CentralityTable.h"
00037 
00038 using namespace std;
00039 
00040 //
00041 // class decleration
00042 //
00043 
00044 class HiTrivialConditionRetriever : public edm::ESProducer, 
00045                                 public edm::EventSetupRecordIntervalFinder
00046 {
00047 public:
00048   HiTrivialConditionRetriever(const edm::ParameterSet&);
00049 
00050 protected:
00051   //overriding from ContextRecordIntervalFinder
00052   virtual void setIntervalFor( const edm::eventsetup::EventSetupRecordKey&,
00053                                const edm::IOVSyncValue& ,
00054                                edm::ValidityInterval& ) ;
00055   
00056    private:
00057   virtual std::auto_ptr<CentralityTable> produceTable( const HeavyIonRcd& );
00058   void printBin(const CentralityTable::CBin*);
00059 
00060   // ----------member data ---------------------------
00061 
00062  int verbose_;
00063    string inputFileName_;   
00064 };
00065 
00066 //
00067 // constants, enums and typedefs
00068 //
00069 
00070 //
00071 // static data member definitions
00072 //
00073 
00074 //
00075 // constructors and destructor
00076 //
00077 HiTrivialConditionRetriever::HiTrivialConditionRetriever(const edm::ParameterSet& iConfig){
00078   
00079   setWhatProduced(this, &HiTrivialConditionRetriever::produceTable);
00080   findingRecord<HeavyIonRcd>();
00081   
00082   //now do what ever initialization is needed
00083   verbose_ = iConfig.getUntrackedParameter<int>("verbosity",1);
00084   inputFileName_ = iConfig.getParameter<string>("inputFile");
00085 }
00086 
00087 std::auto_ptr<CentralityTable> 
00088 HiTrivialConditionRetriever::produceTable( const HeavyIonRcd& ){
00089 
00090   std::auto_ptr<CentralityTable> CT(new CentralityTable()) ;
00091 
00092   // Get values from text file
00093   ifstream in( edm::FileInPath(inputFileName_).fullPath().c_str() );
00094   string line;
00095 
00096   int i = 0;
00097   while ( getline( in, line ) ) {
00098     if ( !line.size() || line[0]=='#' ) { continue; }
00099     CentralityTable::CBin thisBin;
00100     CT->m_table.push_back(thisBin);
00101     istringstream ss(line);
00102     ss>>CT->m_table[i].bin_edge
00103       >>CT->m_table[i].n_part.mean
00104       >>CT->m_table[i].n_part.var
00105       >>CT->m_table[i].n_coll.mean
00106       >>CT->m_table[i].n_coll.var
00107       >>CT->m_table[i].n_hard.mean
00108       >>CT->m_table[i].n_hard.var
00109       >>CT->m_table[i].b.mean
00110       >>CT->m_table[i].b.var;
00111     i++;
00112   }
00113 
00114   return CT; 
00115 }
00116 
00117 void HiTrivialConditionRetriever::printBin(const CentralityTable::CBin* thisBin){
00118    cout<<"HF Cut = "<<thisBin->bin_edge<<endl;
00119    cout<<"Npart = "<<thisBin->n_part.mean<<endl;
00120    cout<<"sigma = "<<thisBin->n_part.var<<endl;
00121    cout<<"Ncoll = "<<thisBin->n_coll.mean<<endl;
00122    cout<<"sigma = "<<thisBin->n_coll.var<<endl;
00123    cout<<"B     = "<<thisBin->b.mean<<endl;
00124    cout<<"sigma = "<<thisBin->b.var<<endl;
00125    cout<<"__________________________________________________"<<endl;
00126 }
00127 
00128 void
00129 HiTrivialConditionRetriever::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& rk,
00130                                              const edm::IOVSyncValue& iTime,
00131                                              edm::ValidityInterval& oValidity)
00132 {
00133   if(verbose_>=1) std::cout << "HiTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name() << "\ttime: " << iTime.time().value() << std::endl;
00134   //For right now, we will just use an infinite interval of validity
00135   oValidity = edm::ValidityInterval( edm::IOVSyncValue::beginOfTime(),edm::IOVSyncValue::endOfTime() );
00136 }
00137 
00138 //define this as a plug-in
00139 DEFINE_FWK_EVENTSETUP_SOURCE(HiTrivialConditionRetriever);