CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
HcalPedestalValidator.cc File Reference
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include "CondFormats/HcalObjects/interface/HcalPedestals.h"
#include "CondFormats/HcalObjects/interface/HcalPedestalWidths.h"
#include "CondTools/Hcal/interface/HcalDbOnline.h"
#include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
#include "CalibCalorimetry/HcalAlgos/interface/HcalPedestalAnalysis.h"

Go to the source code of this file.

Classes

class  Args
 

Functions

int main (int argn, char *argv[])
 

Function Documentation

int main ( int  argn,
char *  argv[] 
)

Definition at line 92 of file HcalPedestalValidator.cc.

References harvestRelVal::args, Args::arguments(), dtNoiseDBValidation_cfg::cerr, Args::defineOption(), Args::defineParameter(), getObject(), Args::getParameter(), HcalPedestalAnalysis::HcalPedVal(), Args::optionIsSet(), Args::parse(), and Args::printOptionsHelp().

92  {
93 
94 // CORAL required variables to be set, even if not needed
95  const char* foo1 = "CORAL_AUTH_USER=blaaah";
96  const char* foo2 = "CORAL_AUTH_PASSWORD=blaaah";
97  if (!::getenv("CORAL_AUTH_USER")) ::putenv(const_cast<char*>(foo1));
98  if (!::getenv("CORAL_AUTH_PASSWORD")) ::putenv(const_cast<char*>(foo2));
99 
100  Args args;
101  args.defineParameter ("-p", "raw pedestals");
102  args.defineParameter ("-w", "raw widths");
103  args.defineParameter ("-run", "current run number <0>");
104  args.defineParameter ("-ptag", "raw pedestal tag <NULL>");
105  args.defineParameter ("-wtag", "raw width tag <ptag>");
106  args.defineParameter ("-pref", "reference pedestals");
107  args.defineParameter ("-wref", "reference widths");
108  args.defineParameter ("-ptagref", "reference pedestal tag <NULL>");
109  args.defineParameter ("-wtagref", "reference width tag <ptagref>");
110  args.defineParameter ("-pval", "validated pedestals");
111  args.defineParameter ("-wval", "validated widths");
112  args.defineOption ("-help", "this help");
113 
114  args.parse (argn, argv);
115  std::vector<std::string> arguments = args.arguments ();
116  if (args.optionIsSet ("-help")) {
117  args.printOptionsHelp ();
118  return -1;
119  }
120 
121 // read parameters from command line
122  std::string RawPedSource = args.getParameter("-p");
123  std::string RawPedWidSource = args.getParameter("-w");
124  std::string RawPedTag = args.getParameter("-ptag").empty() ? "" : args.getParameter("-ptag");
125  std::string RawPedWidTag = args.getParameter("-wtag").empty() ? RawPedTag : args.getParameter("-wtag");
126  int RawPedRun = args.getParameter("-run").empty() ? 0 : (int)strtoll (args.getParameter("-run").c_str(),0,0);
127  int RawPedWidRun = RawPedRun;
128  std::string RefPedSource = args.getParameter("-pref");
129  std::string RefPedWidSource = args.getParameter("-wref");
130  std::string RefPedTag = args.getParameter("-ptagref").empty() ? "" : args.getParameter("-ptagref");
131  std::string RefPedWidTag = args.getParameter("-wtagref").empty() ? RefPedTag : args.getParameter("-wtagref");
132  int RefPedRun = RawPedRun;
133  int RefPedWidRun = RefPedRun;
134  std::string outputPedDest = args.getParameter("-pval");
135  std::string outputPedWidDest = args.getParameter("-wval");
136  std::string outputPedTag = "";
137  std::string outputPedWidTag = "";
138  int outputPedRun = RawPedRun;
139  int outputPedWidRun = outputPedRun;
140 
141 // get reference objects
142  HcalPedestals* RefPeds = 0;
143  RefPeds = new HcalPedestals ();
144  if (!getObject (RefPeds, RefPedSource, RefPedTag, RefPedRun)) {
145  std::cerr << "HcalPedestalValidator-> Failed to get reference Pedestals" << std::endl;
146  return 1;
147  }
148  HcalPedestalWidths* RefPedWids = 0;
149  RefPedWids = new HcalPedestalWidths ();
150  if (!getObject (RefPedWids, RefPedWidSource, RefPedWidTag, RefPedWidRun)) {
151  std::cerr << "HcalPedestalValidator-> Failed to get reference PedestalWidths" << std::endl;
152  return 2;
153  }
154 
155 // get input raw objects
156  HcalPedestals* RawPeds = 0;
157  RawPeds = new HcalPedestals ();
158  if (!getObject (RawPeds, RawPedSource, RawPedTag, RawPedRun)) {
159  std::cerr << "HcalPedestalValidator-> Failed to get raw Pedestals" << std::endl;
160  return 3;
161  }
162  HcalPedestalWidths* RawPedWids = 0;
163  RawPedWids = new HcalPedestalWidths ();
164  if (!getObject (RawPedWids, RawPedWidSource, RawPedWidTag, RawPedWidRun)) {
165  std::cerr << "HcalPedestalValidator-> Failed to get raw PedestalWidths" << std::endl;
166  return 4;
167  }
168 
169 // make output objects
170  HcalPedestals* outputPeds = 0;
171  outputPeds = new HcalPedestals ();
172  HcalPedestalWidths* outputPedWids = 0;
173  outputPedWids = new HcalPedestalWidths ();
174 
175 // run algorithm
176  int nstat[4]={2500,2500,2500,2500};
177  int Flag=HcalPedestalAnalysis::HcalPedVal(nstat,RefPeds,RefPedWids,RawPeds,RawPedWids,outputPeds,outputPedWids);
178 
179  delete RefPeds;
180  delete RefPedWids;
181  delete RawPeds;
182  delete RawPedWids;
183 
184 
185 // store new objects if necessary
186  if (Flag%100000>0) {
187  if (outputPeds) {
188  if (!putObject (&outputPeds, outputPedDest, outputPedTag, outputPedRun)) {
189  std::cerr << "HcalPedestalAnalyzer-> Failed to put output Pedestals" << std::endl;
190  return 5;
191  }
192  }
193  if (outputPedWids) {
194  if (!putObject (&outputPedWids, outputPedWidDest, outputPedWidTag, outputPedWidRun)) {
195  std::cerr << "HcalPedestalAnalyzer-> Failed to put output PedestalWidths" << std::endl;
196  return 6;
197  }
198  }
199  }
200  delete outputPeds;
201  delete outputPedWids;
202 
203 return 0;
204 }
void defineOption(const std::string &fOption, const std::string &fComment="")
TObject * getObject(TDirectory *fDir, const std::vector< std::string > &fObjectName)
Definition: compareHists.cc:44
std::vector< std::string > arguments() const
void printOptionsHelp() const
void parse(int nArgs, char *fArgs[])
dictionary args
static int HcalPedVal(int nstat[4], const HcalPedestals *fRefPedestals, const HcalPedestalWidths *fRefPedestalWidths, HcalPedestals *fRawPedestals, HcalPedestalWidths *fRawPedestalWidths, HcalPedestals *fValPedestals, HcalPedestalWidths *fValPedestalWidths)
void defineParameter(const std::string &fParameter, const std::string &fComment="")
bool optionIsSet(const std::string &fOption) const
std::string getParameter(const std::string &fKey)