Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:04

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author C. Battilana CIEMAT
0005  */
0006 
0007 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
0008 #include "L1TriggerConfig/DTTPGConfigProducers/plugins/DTTPGParamsWriter.h"
0009 
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 
0015 /* C++ Headers */
0016 #include <boost/algorithm/string/split.hpp>
0017 #include <boost/algorithm/string_regex.hpp>
0018 #include <iostream>
0019 #include <sstream>
0020 #include <string>
0021 #include <vector>
0022 
0023 using namespace std;
0024 using namespace edm;
0025 
0026 // Constructor
0027 DTTPGParamsWriter::DTTPGParamsWriter(const ParameterSet &pset) {
0028   debug_ = pset.getUntrackedParameter<bool>("debug", false);
0029   inputFileName_ = pset.getUntrackedParameter<string>("inputFile");
0030   // Create the object to be written to DB
0031   phaseMap_ = new DTTPGParameters();
0032 
0033   if (debug_)
0034     cout << "[DTTPGParamsWriter]Constructor called!" << endl;
0035 }
0036 
0037 // Destructor
0038 DTTPGParamsWriter::~DTTPGParamsWriter() {
0039   if (debug_)
0040     cout << "[DTTPGParamsWriter]Destructor called!" << endl;
0041 }
0042 
0043 // Do the job
0044 void DTTPGParamsWriter::analyze(const Event &event, const EventSetup &eventSetup) {
0045   if (debug_)
0046     cout << "[DTTPGParamsWriter]Reading data from file." << endl;
0047 
0048   std::ifstream inputFile_(inputFileName_.c_str());
0049   int nLines = 0;
0050   std::string line;
0051 
0052   while (std::getline(inputFile_, line)) {
0053     DTChamberId chId;
0054     float fine = 0.;
0055     int coarse = 0;
0056     pharseLine(line, chId, fine, coarse);
0057     phaseMap_->set(chId, coarse, fine, DTTimeUnits::ns);
0058     if (debug_) {
0059       float fineDB = 0.;
0060       int coarseDB = 0;
0061       phaseMap_->get(chId, coarseDB, fineDB, DTTimeUnits::ns);
0062       std::cout << "[DTTPGParamsWriter] Read data for chamber " << chId << ". File params -> fine: " << fine
0063                 << " coarse: " << coarse << ". DB params -> fine: " << fineDB << " coarse: " << coarseDB << std::endl;
0064     }
0065     nLines++;
0066   }
0067   if (debug_) {
0068     std::cout << "[DTTPGParamsWriter] # of entries written the the DB: " << nLines << std::endl;
0069   }
0070   if (nLines != 250) {
0071     std::cout << "[DTTPGParamsWriter] # of DB entries != 250. Check you input file!" << std::endl;
0072   }
0073 
0074   inputFile_.close();
0075 }
0076 
0077 void DTTPGParamsWriter::pharseLine(std::string &line, DTChamberId &chId, float &fine, int &coarse) {
0078   std::vector<std::string> elements;
0079   boost::algorithm::split(
0080       elements,
0081       line,
0082       boost::algorithm::is_any_of(string(" \t\n")));  // making string conversion explicit (needed to
0083                                                       // cope with -Warray-bounds in slc5_ia32_gcc434
0084   if (elements.size() != 5) {
0085     std::cout << "[DTTPGParamsWriter] wrong number of entries in line : " << line
0086               << " pleas check your input file syntax!" << std::endl;
0087   } else {
0088     chId = DTChamberId(atoi(elements[0].c_str()), atoi(elements[1].c_str()), atoi(elements[2].c_str()));
0089     fine = atof(elements[3].c_str());
0090     coarse = atoi(elements[4].c_str());
0091   }
0092 }
0093 
0094 // Write objects to DB
0095 void DTTPGParamsWriter::endJob() {
0096   if (debug_)
0097     cout << "[DTTPGParamsWriter] Writing ttrig object to DB!" << endl;
0098 
0099   string delayRecord = "DTTPGParametersRcd";
0100   DTCalibDBUtils::writeToDB(delayRecord, phaseMap_);
0101 }