CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
hcalDeleteObject.cc
Go to the documentation of this file.
1 #include <stdlib.h>
2 
3 #include <iostream>
4 #include <fstream>
5 #include <vector>
6 #include <map>
7 #include <algorithm>
8 #include <string>
9 
10 // other
15 
16 
17 #include "CondCore/IOVService/interface/IOV.h"
18 
19 // Hcal calibrations
24 #include "CondTools/Hcal/interface/HcalDbTool.h"
33 
34 //using namespace cms;
35 
36 
38 typedef std::map<IOVRun,std::string> IOVCollection;
39 
40 
41 class Args {
42  public:
43  Args () {};
44  ~Args () {};
45  void defineOption (const std::string& fOption, const std::string& fComment = "");
46  void defineParameter (const std::string& fParameter, const std::string& fComment = "");
47  void parse (int nArgs, char* fArgs []);
48  void printOptionsHelp () const;
49  std::string command () const;
50  std::vector<std::string> arguments () const;
51  bool optionIsSet (const std::string& fOption) const;
52  std::string getParameter (const std::string& fKey);
53  private:
54  std::string mProgramName;
55  std::vector <std::string> mOptions;
56  std::vector <std::string> mParameters;
57  std::vector <std::string> mArgs;
58  std::map <std::string, std::string> mParsed;
59  std::map <std::string, std::string> mComments;
60 };
61 
62 void printHelp (const Args& args) {
63  char buffer [1024];
64  std::cout << "Tool to delete object from Hcal Calibrations" << std::endl;
65  std::cout << "CAUTION: Could cause inconsistency for running jobs using DB" << std::endl;
66  std::cout << " feedback -> ratnikov@fnal.gov" << std::endl;
67  std::cout << "Use:" << std::endl;
68  sprintf (buffer, " %s <what> <options> <parameters>\n", args.command ().c_str());
69  std::cout << buffer;
70  std::cout << " where <what> is: \n pedestals\n gains\n pwidths\n gwidths\n emap\n qie\n calibqie" << std::endl;
71  args.printOptionsHelp ();
72 }
73 
74 template <class T> bool deleteObject (T* fObject,
75  const std::string& fInput, const std::string& fInputTag, HcalDbTool::IOVRun fInputRun, bool fVerbose) {
76  HcalDbTool poolDb (fInput, fVerbose);
77  return poolDb.deleteObject (fObject, fInputTag, fInputRun);
78 }
79 
80 int main (int argn, char* argv []) {
81 
82  Args args;
83  args.defineParameter ("-db", "DB connection string, POOL format");
84  args.defineParameter ("-run", "run # for which constands should be deleted");
85  args.defineParameter ("-tag", "tag for the input constants set");
86  args.defineOption ("-verbose", "makes program verbose");
87 
88  args.parse (argn, argv);
89 
90  std::vector<std::string> arguments = args.arguments ();
91 
92  if (arguments.size () < 1 || args.optionIsSet ("-help")) {
93  printHelp (args);
94  return -1;
95  }
96 
97  std::string input = args.getParameter ("-db");
98 
99  unsigned inputRun = args.getParameter ("-run").empty () ? 0 : strtoull (args.getParameter ("-run").c_str (), 0, 0);
100  std::string inputTag = args.getParameter ("-tag");
101 
102  bool verbose = args.optionIsSet ("-verbose");
103 
104 
105  std::string what = arguments [0];
106 
107  if (what == "pedestals") {
108  HcalPedestals* object = 0;
109  deleteObject (object, input, inputTag, inputRun, verbose);
110  }
111  else if (what == "gains") {
112  HcalGains* object = 0;
113  }
114  else if (what == "pwidths") {
115  HcalPedestalWidths* object = 0;
116  }
117  else if (what == "gwidths") {
118  HcalGainWidths* object = 0;
119  }
120  else if (what == "emap") {
121  HcalElectronicsMap* object = 0;
122  }
123  else if (what == "qie") {
124  HcalQIEData* object = 0;
125  }
126  else if (what == "calibqie") {
127  HcalCalibrationQIEData* object = 0;
128  }
129 }
130 
131 
132 //==================== Args ===== BEGIN ==============================
133 void Args::defineOption (const std::string& fOption, const std::string& fComment) {
134  mOptions.push_back (fOption);
135  mComments [fOption] = fComment;
136 }
137 
138 void Args::defineParameter (const std::string& fParameter, const std::string& fComment) {
139  mParameters.push_back (fParameter);
140  mComments [fParameter] = fComment;
141 }
142 
143 void Args::parse (int nArgs, char* fArgs []) {
144  if (nArgs <= 0) return;
145  mProgramName = std::string (fArgs [0]);
146  int iarg = 0;
147  while (++iarg < nArgs) {
148  std::string arg (fArgs [iarg]);
149  if (arg [0] != '-') mArgs.push_back (arg);
150  else {
151  if (std::find (mOptions.begin(), mOptions.end (), arg) != mOptions.end ()) {
152  mParsed [arg] = "";
153  }
154  if (std::find (mParameters.begin(), mParameters.end (), arg) != mParameters.end ()) {
155  if (iarg >= nArgs) {
156  std::cerr << "ERROR: Parameter " << arg << " has no value specified. Ignore parameter." << std::endl;
157  }
158  else {
159  mParsed [arg] = std::string (fArgs [++iarg]);
160  }
161  }
162  }
163  }
164 }
165 
166 void Args::printOptionsHelp () const {
167  char buffer [1024];
168  std::cout << "Parameters:" << std::endl;
169  for (unsigned i = 0; i < mParameters.size (); i++) {
170  std::map<std::string, std::string>::const_iterator it = mComments.find (mParameters [i]);
171  std::string comment = it != mComments.end () ? it->second : "uncommented";
172  sprintf (buffer, " %-8s <value> : %s", (mParameters [i]).c_str(), comment.c_str());
173  std::cout << buffer << std::endl;
174  }
175  std::cout << "Options:" << std::endl;
176  for (unsigned i = 0; i < mOptions.size (); i++) {
177  std::map<std::string, std::string>::const_iterator it = mComments.find (mOptions [i]);
178  std::string comment = it != mComments.end () ? it->second : "uncommented";
179  sprintf (buffer, " %-8s : %s", (mOptions [i]).c_str(), comment.c_str());
180  std::cout << buffer << std::endl;
181  }
182 }
183 
184 std::string Args::command () const {
185  int ipos = mProgramName.rfind ('/');
186  return std::string (mProgramName, ipos+1);
187 }
188 
189 std::vector<std::string> Args::arguments () const {return mArgs;}
190 
191 bool Args::optionIsSet (const std::string& fOption) const {
192  return mParsed.find (fOption) != mParsed.end ();
193 }
194 
195 std::string Args::getParameter (const std::string& fKey) {
196  if (optionIsSet (fKey)) return mParsed [fKey];
197  return "";
198 }
199 //==================== Args ===== END ==============================
int i
Definition: DBlmapReader.cc:9
std::string mProgramName
void defineOption(const std::string &fOption, const std::string &fComment="")
std::map< std::string, std::string > mComments
std::vector< std::string > arguments() const
std::vector< std::string > mOptions
std::map< IOVRun, std::string > IOVCollection
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
A arg
Definition: Factorize.h:36
int main(int argc, char **argv)
std::vector< std::string > mParameters
std::vector< std::string > mArgs
void printOptionsHelp() const
void parse(int nArgs, char *fArgs[])
HcalDbTool::IOVRun IOVRun
std::string command() const
dictionary args
void printHelp(const Args &args)
tuple cout
Definition: gather_cfg.py:121
std::map< std::string, std::string > mParsed
bool deleteObject(T *fObject, const std::string &fInput, const std::string &fInputTag, HcalDbTool::IOVRun fInputRun, bool fVerbose)
void defineParameter(const std::string &fParameter, const std::string &fComment="")
long double T
bool optionIsSet(const std::string &fOption) const
std::string getParameter(const std::string &fKey)
#define comment(par)
Definition: vmac.h:162