CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
hcalInitDb.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 #include "DataFormats/Common/interface/Timestamp.h"
11 #include "CondCore/IOVService/interface/IOV.h"
12 #include "CondTools/Hcal/interface/HcalDbTool.h"
13 
22 
23 
24 namespace {
25  typedef HcalDbTool::IOVRun IOVRun;
26  typedef std::map<IOVRun,std::string> IOVCollection;
27  typedef std::pair<IOVRun,IOVRun> IntervalOV;
28 
29 class Args {
30  public:
31  Args () {};
32  ~Args () {};
33  void defineOption (const std::string& fOption, const std::string& fComment = "");
34  void defineParameter (const std::string& fParameter, const std::string& fComment = "");
35  void parse (int nArgs, char* fArgs []);
36  void printOptionsHelp () const;
37  std::string command () const;
38  std::vector<std::string> arguments () const;
39  bool optionIsSet (const std::string& fOption) const;
40  std::string getParameter (const std::string& fKey);
41  private:
43  std::vector <std::string> mOptions;
44  std::vector <std::string> mParameters;
45  std::vector <std::string> mArgs;
46  std::map <std::string, std::string> mParsed;
47  std::map <std::string, std::string> mComments;
48 };
49 
50 void printHelp (const Args& args) {
51  char buffer [1024];
52  std::cout << "Initialize POOL DB with dummy HCAL data" << std::endl;
53  std::cout << " feedback -> ratnikov@fnal.gov" << std::endl;
54  std::cout << "Use:" << std::endl;
55  sprintf (buffer, " %s <parameters>\n", args.command ().c_str());
56  std::cout << buffer;
57  args.printOptionsHelp ();
58 }
59 
60 void initDb (const std::string& inputdb, bool verbose) {
61  HcalDbTool db (inputdb, verbose);
62  if (inputdb.find ("sqlite") != std::string::npos) {
63  unsigned pos = inputdb.find (':');
64  if (pos != std::string::npos) {
65  std::string filename (inputdb, pos+1);
66  std::cout << "initDb-> creating file " << filename << std::endl;
67  std::ifstream file (filename.c_str()); // touch file
68  file.close ();
69  }
70  }
71  // make dummy metadata entry
72  std::cout << "initDb-> initializing metadata" << std::endl;
73  db.metadataSetTag ("dummy_tag", "dummy_token");
74  // make dummy objects
75  std::cout << "initDb-> initializing pedestals" << std::endl;
76  HcalPedestals* peds = new HcalPedestals;
77  db.putObject (peds, "dummy_pedestals", 1);
78  std::cout << "initDb-> initializing pedestal widths" << std::endl;
80  db.putObject (pedws, "dummy_pedestalwidths", 1);
81  std::cout << "initDb-> initializing gains" << std::endl;
82  HcalGains* gains = new HcalGains;
83  db.putObject (gains, "dummy_gains", 1);
84  std::cout << "initDb-> initializing gain widths" << std::endl;
85  HcalGainWidths* gainws = new HcalGainWidths;
86  db.putObject (gainws, "dummy_gainwidths", 1);
87  std::cout << "initDb-> initializing qie" << std::endl;
88  HcalQIEData* qie = new HcalQIEData;
89  db.putObject (qie, "dummy_qie", 1);
90  std::cout << "initDb-> initializing electronics map" << std::endl;
92  db.putObject (map, "dummy_map", 1);
93  std::cout << "initDb-> initializing channel quality" << std::endl;
95  db.putObject (quality, "dummy_quality", 1);
96 }
97 
98 } // namespace
99 
100 int main (int argn, char* argv []) {
101 
102  Args args;
103  args.defineParameter ("-db", "DB connection string, POOL format, i.e. oracle://devdb10/CMS_COND_HCAL");
104  args.defineOption ("-help", "this help");
105  args.defineOption ("-verbose", "verbose");
106 
107  args.parse (argn, argv);
108 
109  std::vector<std::string> arguments = args.arguments ();
110 
111  if (args.getParameter ("-db").empty() || args.optionIsSet ("-help")) {
112  printHelp (args);
113  return -1;
114  }
115 
116  std::string inputdb = args.getParameter ("-db");
117  bool verbose = args.optionIsSet ("-verbose");
118 
119  initDb (inputdb, verbose);
120  return 0;
121 }
122 
123 
124 //==================== Args ===== BEGIN ==============================
125 void Args::defineOption (const std::string& fOption, const std::string& fComment) {
126  mOptions.push_back (fOption);
127  mComments [fOption] = fComment;
128 }
129 
130 void Args::defineParameter (const std::string& fParameter, const std::string& fComment) {
131  mParameters.push_back (fParameter);
132  mComments [fParameter] = fComment;
133 }
134 
135 void Args::parse (int nArgs, char* fArgs []) {
136  if (nArgs <= 0) return;
137  mProgramName = std::string (fArgs [0]);
138  int iarg = 0;
139  while (++iarg < nArgs) {
140  std::string arg (fArgs [iarg]);
141  if (arg [0] != '-') mArgs.push_back (arg);
142  else {
143  if (std::find (mOptions.begin(), mOptions.end (), arg) != mOptions.end ()) {
144  mParsed [arg] = "";
145  }
146  if (std::find (mParameters.begin(), mParameters.end (), arg) != mParameters.end ()) {
147  if (iarg >= nArgs) {
148  std::cerr << "ERROR: Parameter " << arg << " has no value specified. Ignore parameter." << std::endl;
149  }
150  else {
151  mParsed [arg] = std::string (fArgs [++iarg]);
152  }
153  }
154  }
155  }
156 }
157 
158 void Args::printOptionsHelp () const {
159  char buffer [1024];
160  std::cout << "Parameters:" << std::endl;
161  for (unsigned i = 0; i < mParameters.size (); i++) {
162  std::map<std::string, std::string>::const_iterator it = mComments.find (mParameters [i]);
163  std::string comment = it != mComments.end () ? it->second : "uncommented";
164  sprintf (buffer, " %-8s <value> : %s", (mParameters [i]).c_str(), comment.c_str());
165  std::cout << buffer << std::endl;
166  }
167  std::cout << "Options:" << std::endl;
168  for (unsigned i = 0; i < mOptions.size (); i++) {
169  std::map<std::string, std::string>::const_iterator it = mComments.find (mOptions [i]);
170  std::string comment = it != mComments.end () ? it->second : "uncommented";
171  sprintf (buffer, " %-8s : %s", (mOptions [i]).c_str(), comment.c_str());
172  std::cout << buffer << std::endl;
173  }
174 }
175 
176 std::string Args::command () const {
177  int ipos = mProgramName.rfind ('/');
178  return std::string (mProgramName, ipos+1);
179 }
180 
181 std::vector<std::string> Args::arguments () const {return mArgs;}
182 
183 bool Args::optionIsSet (const std::string& fOption) const {
184  return mParsed.find (fOption) != mParsed.end ();
185 }
186 
188  if (optionIsSet (fKey)) return mParsed [fKey];
189  return "";
190 }
191 //==================== 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
tuple db
Definition: EcalCondDB.py:151
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
void printHelp(const Args &args)
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
std::map< std::string, std::string > mParsed
list inputdb
Definition: align_cfg.py:8
void defineParameter(const std::string &fParameter, const std::string &fComment="")
bool optionIsSet(const std::string &fOption) const
std::string getParameter(const std::string &fKey)
#define comment(par)
Definition: vmac.h:161