Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:10

0001 #include <stdlib.h>
0002 #include <iostream>
0003 #include <fstream>
0004 #include <vector>
0005 #include <map>
0006 
0007 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
0008 #include "CondTools/Hcal/interface/HcalDbXml.h"
0009 #include "CondTools/Hcal/interface/HcalDbTool.h"
0010 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
0011 #include "CondFormats/HcalObjects/interface/HcalPedestalWidths.h"
0012 #include "CondFormats/HcalObjects/interface/HcalGains.h"
0013 #include "CondFormats/HcalObjects/interface/HcalGainWidths.h"
0014 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
0015 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
0016 #include "CondFormats/HcalObjects/interface/HcalQIEData.h"
0017 #include "CondFormats/HcalObjects/interface/HcalCalibrationQIEData.h"
0018 
0019 
0020 class Args {
0021  public:
0022   Args () {};
0023   ~Args () {};
0024   void defineOption (const std::string& fOption, const std::string& fComment = "");
0025   void defineParameter (const std::string& fParameter, const std::string& fComment = "");
0026   void parse (int nArgs, char* fArgs []);
0027   void printOptionsHelp () const;
0028   std::string command () const;
0029   std::vector<std::string> arguments () const;
0030   bool optionIsSet (const std::string& fOption) const;
0031   std::string getParameter (const std::string& fKey);
0032  private:
0033   std::string mProgramName;
0034   std::vector <std::string> mOptions;
0035   std::vector <std::string> mParameters;
0036   std::vector <std::string> mArgs;
0037   std::map <std::string, std::string> mParsed;
0038   std::map <std::string, std::string> mComments;
0039 };
0040 
0041 void printHelp (const Args& args) {
0042   char buffer [1024];
0043   std::cout << "Tool to combine pedestals and widths into single xml file" << std::endl;
0044   std::cout << "    feedback -> ratnikov@fnal.gov" << std::endl;
0045   std::cout << "Use:" << std::endl;
0046   sprintf (buffer, " %s <options> <parameters>\n", args.command ().c_str());
0047   std::cout << buffer;
0048   args.printOptionsHelp ();
0049 }
0050 
0051 int main (int argn, char* argv []) {
0052 
0053   Args args;
0054   args.defineParameter ("-values", "ascii pedestals input");
0055   args.defineParameter ("-widths", "ascii widths input");
0056   args.defineParameter ("-output", "xml output");
0057   args.defineOption ("-help", "this help");
0058   args.defineParameter ("-outputrun", "run # for which constands should be dumped");
0059   args.defineParameter ("-outputtag", "tag for the output constants set");
0060   args.defineParameter ("-iovgmtbegin", "start time for online IOV <outputrun>");
0061   args.defineParameter ("-iovgmtend", "end time for online IOV <0>");
0062 
0063   
0064   args.parse (argn, argv);
0065   
0066   std::vector<std::string> arguments = args.arguments ();
0067 
0068   if (args.optionIsSet ("-help")) {
0069     printHelp (args);
0070     return -1;
0071   }
0072 
0073   std::string peds = args.getParameter ("-values");
0074   std::string widths = args.getParameter ("-widths");
0075   std::string output = args.getParameter ("-output");
0076   HcalDbTool::IOVRun outputRun = args.getParameter ("-outputrun").empty () ? 0 : strtoll (args.getParameter ("-outputrun").c_str (), 0, 0);
0077   std::string outputTag = args.getParameter ("-outputtag");
0078   unsigned long long iovgmtbegin = args.getParameter ("-iovgmtbegin").empty () ? outputRun : strtoull (args.getParameter ("-iovgmtbegin").c_str (), 0, 0);
0079   unsigned long long iovgmtend = args.getParameter ("-iovgmtend").empty () ? 0 : strtoull (args.getParameter ("-iovgmtend").c_str (), 0, 0);
0080 
0081 
0082   std::ifstream inStream (peds.c_str ());
0083   HcalPedestals object;
0084   HcalDbASCIIIO::getObject (inStream, &object);
0085   object.sort ();
0086   std::ifstream inStream2 (widths.c_str ());
0087   HcalPedestalWidths objectW;
0088   HcalDbASCIIIO::getObject (inStream2, &objectW);
0089   objectW.sort ();
0090   std::ofstream outStream (output.c_str ());
0091   HcalDbXml::dumpObject (outStream, outputRun, iovgmtbegin, iovgmtend, outputTag, object, objectW);
0092 
0093   return 0;
0094 }
0095 
0096 
0097 //==================== Args ===== BEGIN ==============================
0098 void Args::defineOption (const std::string& fOption, const std::string& fComment) {
0099   mOptions.push_back (fOption);
0100   mComments [fOption] = fComment;
0101 }
0102 
0103 void Args::defineParameter (const std::string& fParameter, const std::string& fComment) {
0104   mParameters.push_back (fParameter);
0105   mComments [fParameter] = fComment;
0106 }
0107 
0108 void Args::parse (int nArgs, char* fArgs []) {
0109   if (nArgs <= 0) return;
0110   mProgramName = std::string (fArgs [0]);
0111   int iarg = 0;
0112   while (++iarg < nArgs) {
0113     std::string arg (fArgs [iarg]);
0114     if (arg [0] != '-') mArgs.push_back (arg);
0115     else {
0116       if (std::find (mOptions.begin(), mOptions.end (), arg) !=  mOptions.end ()) {
0117     mParsed [arg] = "";
0118       }
0119       if (std::find (mParameters.begin(), mParameters.end (), arg) !=  mParameters.end ()) {
0120     if (iarg >= nArgs) {
0121       std::cerr << "ERROR: Parameter " << arg << " has no value specified. Ignore parameter." << std::endl;
0122     }
0123     else {
0124       mParsed [arg] = std::string (fArgs [++iarg]);
0125     }
0126       }
0127     }
0128   }
0129 }
0130 
0131 void Args::printOptionsHelp () const {
0132   char buffer [1024];
0133   std::cout << "Parameters:" << std::endl;
0134   for (unsigned i = 0; i < mParameters.size (); i++) {
0135     std::map<std::string, std::string>::const_iterator it = mComments.find (mParameters [i]);
0136     std::string comment = it != mComments.end () ? it->second : "uncommented";
0137     sprintf (buffer, "  %-8s <value> : %s", (mParameters [i]).c_str(),  comment.c_str());
0138     std::cout << buffer << std::endl;
0139   }
0140   std::cout << "Options:" << std::endl;
0141   for (unsigned i = 0; i < mOptions.size (); i++) {
0142     std::map<std::string, std::string>::const_iterator it = mComments.find (mOptions [i]);
0143     std::string comment = it != mComments.end () ? it->second : "uncommented";
0144     sprintf (buffer, "  %-8s  : %s", (mOptions [i]).c_str(),  comment.c_str());
0145     std::cout << buffer << std::endl;
0146   }
0147 }
0148 
0149 std::string Args::command () const {
0150   int ipos = mProgramName.rfind ('/');
0151   return std::string (mProgramName, ipos+1);
0152 }
0153 
0154 std::vector<std::string> Args::arguments () const {return mArgs;}
0155 
0156 bool Args::optionIsSet (const std::string& fOption) const {
0157   return mParsed.find (fOption) != mParsed.end ();
0158 }
0159 
0160 std::string Args::getParameter (const std::string& fKey) {
0161   if (optionIsSet (fKey)) return mParsed [fKey];
0162   return "";
0163 }
0164 //==================== Args ===== END ==============================
0165 
0166