CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CondTools/Hcal/bin/hcalDeleteObject.cc

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 
00003 #include <iostream>
00004 #include <fstream>
00005 #include <vector>
00006 #include <map>
00007 #include <algorithm>
00008 #include <string>
00009 
00010 // other
00011 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00012 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
00013 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
00014 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00015 
00016 
00017 #include "CondCore/IOVService/interface/IOV.h"
00018 
00019 // Hcal calibrations
00020 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbHardcode.h"
00021 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00022 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbXml.h"
00023 #include "CondTools/Hcal/interface/HcalDbOnline.h"
00024 #include "CondTools/Hcal/interface/HcalDbTool.h"
00025 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
00026 #include "CondFormats/HcalObjects/interface/HcalPedestalWidths.h"
00027 #include "CondFormats/HcalObjects/interface/HcalGains.h"
00028 #include "CondFormats/HcalObjects/interface/HcalGainWidths.h"
00029 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
00030 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00031 #include "CondFormats/HcalObjects/interface/HcalQIEData.h"
00032 #include "CondFormats/HcalObjects/interface/HcalCalibrationQIEData.h"
00033 
00034 //using namespace cms;
00035 
00036 
00037 typedef HcalDbTool::IOVRun IOVRun;
00038 typedef std::map<IOVRun,std::string> IOVCollection;
00039 
00040 
00041 class Args {
00042  public:
00043   Args () {};
00044   ~Args () {};
00045   void defineOption (const std::string& fOption, const std::string& fComment = "");
00046   void defineParameter (const std::string& fParameter, const std::string& fComment = "");
00047   void parse (int nArgs, char* fArgs []);
00048   void printOptionsHelp () const;
00049   std::string command () const;
00050   std::vector<std::string> arguments () const;
00051   bool optionIsSet (const std::string& fOption) const;
00052   std::string getParameter (const std::string& fKey);
00053  private:
00054   std::string mProgramName;
00055   std::vector <std::string> mOptions;
00056   std::vector <std::string> mParameters;
00057   std::vector <std::string> mArgs;
00058   std::map <std::string, std::string> mParsed;
00059   std::map <std::string, std::string> mComments;
00060 };
00061 
00062 void printHelp (const Args& args) {
00063   char buffer [1024];
00064   std::cout << "Tool to delete object from Hcal Calibrations" << std::endl;
00065   std::cout << "CAUTION: Could cause inconsistency for running jobs using DB" << std::endl;
00066   std::cout << "    feedback -> ratnikov@fnal.gov" << std::endl;
00067   std::cout << "Use:" << std::endl;
00068   sprintf (buffer, " %s <what> <options> <parameters>\n", args.command ().c_str());
00069   std::cout << buffer;
00070   std::cout << "  where <what> is: \n    pedestals\n    gains\n    pwidths\n    gwidths\n    emap\n    qie\n    calibqie" << std::endl;
00071   args.printOptionsHelp ();
00072 }
00073 
00074 template <class T> bool deleteObject (T* fObject, 
00075                                       const std::string& fInput, const std::string& fInputTag, HcalDbTool::IOVRun fInputRun, bool fVerbose) {
00076   HcalDbTool poolDb (fInput, fVerbose);
00077   return poolDb.deleteObject (fObject, fInputTag, fInputRun);
00078 }
00079 
00080 int main (int argn, char* argv []) {
00081 
00082   Args args;
00083   args.defineParameter ("-db", "DB connection string, POOL format");
00084   args.defineParameter ("-run", "run # for which constands should be deleted");
00085   args.defineParameter ("-tag", "tag for the input constants set");
00086   args.defineOption ("-verbose", "makes program verbose");
00087   
00088   args.parse (argn, argv);
00089   
00090   std::vector<std::string> arguments = args.arguments ();
00091 
00092   if (arguments.size () < 1 || args.optionIsSet ("-help")) {
00093     printHelp (args);
00094     return -1;
00095   }
00096 
00097   std::string input = args.getParameter ("-db");
00098   
00099   unsigned inputRun = args.getParameter ("-run").empty () ? 0 : strtoull (args.getParameter ("-run").c_str (), 0, 0);
00100   std::string inputTag = args.getParameter ("-tag");
00101 
00102   bool verbose = args.optionIsSet ("-verbose");
00103 
00104 
00105   std::string what = arguments [0];
00106 
00107   if (what == "pedestals") {
00108     HcalPedestals* object = 0;
00109     deleteObject (object, input, inputTag, inputRun, verbose);
00110   }
00111   else if (what == "gains") {
00112     HcalGains* object = 0;
00113   }
00114   else if (what == "pwidths") {
00115     HcalPedestalWidths* object = 0;
00116   }
00117   else if (what == "gwidths") {
00118     HcalGainWidths* object = 0;
00119   }
00120   else if (what == "emap") {
00121     HcalElectronicsMap* object = 0;
00122   }
00123   else if (what == "qie") {
00124     HcalQIEData* object = 0;
00125   }
00126   else if (what == "calibqie") {
00127     HcalCalibrationQIEData* object = 0;
00128   }
00129 }
00130 
00131 
00132 //==================== Args ===== BEGIN ==============================
00133 void Args::defineOption (const std::string& fOption, const std::string& fComment) {
00134   mOptions.push_back (fOption);
00135   mComments [fOption] = fComment;
00136 }
00137 
00138 void Args::defineParameter (const std::string& fParameter, const std::string& fComment) {
00139   mParameters.push_back (fParameter);
00140   mComments [fParameter] = fComment;
00141 }
00142 
00143 void Args::parse (int nArgs, char* fArgs []) {
00144   if (nArgs <= 0) return;
00145   mProgramName = std::string (fArgs [0]);
00146   int iarg = 0;
00147   while (++iarg < nArgs) {
00148     std::string arg (fArgs [iarg]);
00149     if (arg [0] != '-') mArgs.push_back (arg);
00150     else {
00151       if (std::find (mOptions.begin(), mOptions.end (), arg) !=  mOptions.end ()) {
00152         mParsed [arg] = "";
00153       }
00154       if (std::find (mParameters.begin(), mParameters.end (), arg) !=  mParameters.end ()) {
00155         if (iarg >= nArgs) {
00156           std::cerr << "ERROR: Parameter " << arg << " has no value specified. Ignore parameter." << std::endl;
00157         }
00158         else {
00159           mParsed [arg] = std::string (fArgs [++iarg]);
00160         }
00161       }
00162     }
00163   }
00164 }
00165 
00166 void Args::printOptionsHelp () const {
00167   char buffer [1024];
00168   std::cout << "Parameters:" << std::endl;
00169   for (unsigned i = 0; i < mParameters.size (); i++) {
00170     std::map<std::string, std::string>::const_iterator it = mComments.find (mParameters [i]);
00171     std::string comment = it != mComments.end () ? it->second : "uncommented";
00172     sprintf (buffer, "  %-8s <value> : %s", (mParameters [i]).c_str(),  comment.c_str());
00173     std::cout << buffer << std::endl;
00174   }
00175   std::cout << "Options:" << std::endl;
00176   for (unsigned i = 0; i < mOptions.size (); i++) {
00177     std::map<std::string, std::string>::const_iterator it = mComments.find (mOptions [i]);
00178     std::string comment = it != mComments.end () ? it->second : "uncommented";
00179     sprintf (buffer, "  %-8s  : %s", (mOptions [i]).c_str(),  comment.c_str());
00180     std::cout << buffer << std::endl;
00181   }
00182 }
00183 
00184 std::string Args::command () const {
00185   int ipos = mProgramName.rfind ('/');
00186   return std::string (mProgramName, ipos+1);
00187 }
00188 
00189 std::vector<std::string> Args::arguments () const {return mArgs;}
00190 
00191 bool Args::optionIsSet (const std::string& fOption) const {
00192   return mParsed.find (fOption) != mParsed.end ();
00193 }
00194 
00195 std::string Args::getParameter (const std::string& fKey) {
00196   if (optionIsSet (fKey)) return mParsed [fKey];
00197   return "";
00198 }
00199 //==================== Args ===== END ==============================