CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/L1TriggerConfig/DTTPGConfigProducers/plugins/DTTPGParamsWriter.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2011/02/17 14:42:44 $
00005  *  $Revision: 1.2 $
00006  *  \author C. Battilana CIEMAT
00007  */
00008 
00009 #include "L1TriggerConfig/DTTPGConfigProducers/plugins/DTTPGParamsWriter.h"
00010 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
00011 
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 
00017 /* C++ Headers */
00018 #include <vector> 
00019 #include <iostream>
00020 #include <string>
00021 #include <sstream>
00022 #include <boost/algorithm/string/split.hpp>
00023 #include <boost/algorithm/string_regex.hpp>
00024 
00025 using namespace std;
00026 using namespace edm;
00027 
00028 
00029 // Constructor
00030 DTTPGParamsWriter::DTTPGParamsWriter(const ParameterSet& pset) {
00031 
00032   debug_ = pset.getUntrackedParameter<bool>("debug", "false");
00033   inputFileName_ = pset.getUntrackedParameter<string>("inputFile");
00034   // Create the object to be written to DB
00035   phaseMap_ = new DTTPGParameters();
00036   
00037   if(debug_)
00038     cout << "[DTTPGParamsWriter]Constructor called!" << endl;
00039 
00040 }
00041 
00042 
00043 
00044 // Destructor
00045 DTTPGParamsWriter::~DTTPGParamsWriter(){
00046 
00047   if(debug_)
00048     cout << "[DTTPGParamsWriter]Destructor called!" << endl;
00049 
00050 }
00051 
00052 // Do the job
00053 void DTTPGParamsWriter::analyze(const Event & event, const EventSetup& eventSetup) {
00054 
00055   if(debug_)
00056     cout << "[DTTPGParamsWriter]Reading data from file." << endl;
00057 
00058   std::ifstream inputFile_(inputFileName_.c_str());  
00059   int nLines=0;
00060   std::string line;
00061 
00062   while(std::getline(inputFile_, line)) {
00063     DTChamberId chId;
00064     float fine;
00065     int coarse;
00066     pharseLine(line,chId,fine,coarse);
00067     phaseMap_->set(chId,coarse,fine,DTTimeUnits::ns);
00068     if (debug_) {
00069       float fineDB;
00070       int coarseDB;
00071       phaseMap_->get(chId,coarseDB,fineDB,DTTimeUnits::ns);
00072       std::cout << "[DTTPGParamsWriter] Read data for chamber " << chId 
00073                 << ". File params -> fine: " << fine << " coarse: " << coarse 
00074                 << ". DB params -> fine: " << fineDB << " coarse: " << coarseDB << std::endl;
00075     }
00076     nLines++;
00077   }
00078   if (debug_) {
00079     std::cout << "[DTTPGParamsWriter] # of entries written the the DB: " << nLines << std::endl;
00080   }
00081   if (nLines!=250) {
00082     std::cout << "[DTTPGParamsWriter] # of DB entries != 250. Check you input file!" << std::endl;
00083   }
00084   
00085 
00086   inputFile_.close();
00087 
00088 
00089 }
00090 
00091 void DTTPGParamsWriter::pharseLine(std::string &line, DTChamberId& chId, float &fine, int  &coarse) {
00092 
00093   std::vector<std::string> elements;
00094   boost::algorithm::split(elements,line,boost::algorithm::is_any_of(string(" \t\n")));  // making string conversion explicit (needed to cope with -Warray-bounds in slc5_ia32_gcc434  
00095   if (elements.size() != 5) {
00096     std::cout << "[DTTPGParamsWriter] wrong number of entries in line : " << line << " pleas check your input file syntax!" << std::endl;
00097   } else {
00098     chId   = DTChamberId(atoi(elements[0].c_str()),atoi(elements[1].c_str()),atoi(elements[2].c_str()));
00099     fine   = atof(elements[3].c_str());
00100     coarse = atoi(elements[4].c_str());
00101   }
00102 
00103 }
00104 
00105 // Write objects to DB
00106 void DTTPGParamsWriter::endJob() {
00107   if(debug_) 
00108         cout << "[DTTPGParamsWriter] Writing ttrig object to DB!" << endl;
00109 
00110   string delayRecord = "DTTPGParametersRcd";
00111   DTCalibDBUtils::writeToDB(delayRecord, phaseMap_);
00112 
00113 }