18 #include "CondCore/IOVService/interface/IOV.h"
24 #include "CondTools/Hcal/interface/HcalDbTool.h"
52 void parse (
int nArgs,
char* fArgs []);
55 std::vector<std::string>
arguments ()
const;
62 std::vector <std::string>
mArgs;
63 std::map <std::string, std::string>
mParsed;
64 std::map <std::string, std::string>
mComments;
69 static std::vector<HcalDetId>
result;
70 if (result.size () <= 0) {
75 for (
int det = 1; det < 5; det++) {
78 fData.getValues (cell);
81 if (topology.
valid(cell)) result.push_back (cell);
97 for (std::vector <HcalDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
99 fPedestals->addValue (*cell, item.
getValues ());
110 for (std::vector <HcalDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
112 fPedestals->setWidth (item);
123 for (std::vector <HcalDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
125 fGains->addValue (*cell, item.
getValues ());
136 for (std::vector <HcalDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
138 fGains->addValue (*cell, item.
getValues ());
148 std::cerr <<
"Warning: fillDefaults (HcalElectronicsMap* fMap) is not implemented. Ignore." << std::endl;
160 for (
int det = 1; det < 5; det++) {
162 if (topology.
valid(cell)) {
182 for (
int det = 1; det < 5; det++) {
184 if (topology.
valid(cell)) {
197 std::cout <<
"Tool to manipulate by Hcal Calibrations" << std::endl;
198 std::cout <<
" feedback -> ratnikov@fnal.gov" << std::endl;
200 sprintf (buffer,
" %s <what> <options> <parameters>\n", args.
command ().c_str());
202 std::cout <<
" where <what> is: \n pedestals\n gains\n pwidths\n gwidths\n emap\n qie\n calibqie" << std::endl;
207 return fParam ==
"defaults";
211 return fParam.find (
':') == std::string::npos &&
std::string (fParam, fParam.length () - 4) ==
".txt";
215 return fParam.find (
':') == std::string::npos &&
std::string (fParam, fParam.length () - 4) ==
".xml";
219 return fParam.find (
':') != std::string::npos;
223 return fParam.find (
"cms_val_lb.cern.ch") != std::string::npos &&
224 fParam.find (
':') == std::string::npos;
228 return fParam.find (
'@') != std::string::npos &&
229 fParam.find (
"cms_val_lb") == std::string::npos;
236 unsigned long long fIovgmtbegin,
unsigned long long fIovgmtend,
237 unsigned fNread,
unsigned fNwrite,
unsigned fNtrace,
239 const char* fInputCatalog,
const char* fOutputCatalog,
bool fXmlAuth
241 typedef std::vector <std::pair<HcalDbTool::IOVRun, T*> > Objects;
244 time_t t0 =
time (0);
246 unsigned traceCounter = 0;
247 HcalDbTool* poolDb = 0;
250 Objects allInstances;
251 while (traceCounter < fNread) {
255 if (!traceCounter)
std::cout <<
"USE INPUT: defaults" << std::endl;
260 if (!traceCounter)
std::cout <<
"USE INPUT: ASCII: " << fInput << std::endl;
261 std::ifstream inStream (fInput.c_str ());
266 else if (
dbFile (fInput)) {
267 if (!traceCounter)
std::cout <<
"USE INPUT: Pool: " << fInput <<
"/" << fInputRun << std::endl;
268 if (!poolDb) poolDb =
new HcalDbTool (fInput, fVerbose, fXmlAuth, fInputCatalog);
271 result = poolDb->getObject (fObject, fInputTag, fInputRun);
274 std::cout <<
"Copy all instances... " << std::endl;
276 if (poolDb->getObject (&iov, fInputTag)) {
277 IOVCollection::const_iterator iovi = iov.iov.begin ();
278 for (; iovi != iov.iov.end (); iovi++) {
279 IOVRun iovMax = iovi->first;
281 std::cout <<
"fetching object for run " << iovMax << std::endl;
284 if (!poolDb->getObject (
object, fInputTag, iovMax)) {
285 std::cerr <<
"Failed to fetch object..." << std::endl;
290 allInstances.push_back (std::make_pair (iovMax,
object));
293 if (iovi == iov.iov.end ()) result =
true;
296 std::cerr <<
"can not find IOV for tag " << fInputTag << std::endl;
302 if (!traceCounter)
std::cout <<
"USE INPUT: Online: " << fInput << std::endl;
303 if (!onlineDb) onlineDb =
new HcalDbOnline (fInput, fVerbose);
306 result = onlineDb->
getObject (fObject, fInputTag, fInputRun);
309 std::cout <<
"Copy all instances... " << std::endl;
310 std::vector<HcalDbOnline::IntervalOV> iovs = onlineDb->
getIOVs (fInputTag);
311 for (
unsigned i = 0;
i < iovs.size ();
i++) {
314 std::cout <<
"fetching object for run " << iovMin << std::endl;
317 if (!onlineDb->
getObject (
object, fInputTag, iovMin)) {
318 std::cerr <<
"Failed to fetch object..." << std::endl;
323 allInstances.push_back (std::make_pair (iovMin,
object));
337 if (fNtrace && !(traceCounter % fNtrace)) {
339 std::cout <<
"read transaction: " << traceCounter <<
" time: " << t - t0 <<
" dtime: " << t - t1 << std::endl;
352 while (traceCounter < fNwrite) {
354 object = fObject ?
new T (*fObject) : 0;
356 if (!traceCounter)
std::cout <<
"USE OUTPUT: ASCII: " << fOutput << std::endl;
357 if (fObject && allInstances.empty ()) {
358 std::ofstream outStream (fOutput.c_str ());
362 for (
unsigned i = 0;
i < allInstances.size ();
i++) {
364 std::cout <<
"Storing object for run " << allInstances[
i].first << std::endl;
366 std::ostringstream outName;
367 unsigned ipos = fOutput.find (
".txt");
368 if (ipos == std::string::npos) {
369 outName << fOutput <<
"_" << allInstances[
i].first;
372 outName <<
std::string (fOutput, 0, ipos) <<
"_" << allInstances[
i].first <<
".txt";
374 std::ofstream outStream (outName.str().c_str ());
375 object = allInstances[
i].second;
378 allInstances[
i].second = 0;
384 if (!traceCounter)
std::cout <<
"USE OUTPUT: XML: " << fOutput << std::endl;
385 std::ofstream outStream (fOutput.c_str ());
390 else if (
dbFile (fOutput)) {
391 if (!traceCounter)
std::cout <<
"USE OUTPUT: Pool: " << fOutput <<
'/' << fOutputRun << std::endl;
392 if (!poolDb) poolDb =
new HcalDbTool (fOutput, fVerbose, fXmlAuth, fOutputCatalog);
393 if (fOutputRun > 0) {
394 poolDb->putObject (
object, fOutputTag, fOutputRun, fAppend);
398 for (
unsigned i = 0;
i < allInstances.size ();
i++) {
400 std::cout <<
"Storing object for run " << allInstances[
i].first << std::endl;
402 poolDb->putObject (allInstances[
i].
second, fOutputTag, allInstances[
i].
first, fAppend);
403 allInstances[
i].second = 0;
410 if (fNtrace && !(traceCounter % fNtrace)) {
412 std::cout <<
"write transaction: " << traceCounter <<
" time: " << t - t0 <<
" dtime: " << t - t1 << std::endl;
427 args.
defineParameter (
"-input",
"DB connection string, POOL format, or .txt file, or defaults");
428 args.
defineParameter (
"-output",
"DB connection string, POOL format, or .txt, or .xml file");
429 args.
defineParameter (
"-inputrun",
"run # for which constands should be made");
431 args.
defineParameter (
"-inputcatalog",
"catalog for POOL DB <$POOL_CATALOG>");
432 args.
defineParameter (
"-outputrun",
"run # for which constands should be dumped");
433 args.
defineParameter (
"-outputtag",
"tag for the output constants set");
434 args.
defineParameter (
"-outputcatalog",
"catalog for POOL DB <$POOL_CATALOG>");
435 args.
defineParameter (
"-iovgmtbegin",
"start time for online IOV <outputrun>");
437 args.
defineParameter (
"-nread",
"repeat input that many times with increasing run# <1>");
438 args.
defineParameter (
"-nwrite",
"repeat output that many times with increasing run# <1>");
439 args.
defineParameter (
"-trace",
"trace time every that many operations <false>");
441 args.
defineOption (
"-online",
"interpret input DB as an online DB");
442 args.
defineOption (
"-xmlauth",
"use XML authorization <false>");
443 args.
defineOption (
"-append",
"Strip previous IOV, make this IOV open (POOL DB) <false>");
444 args.
defineOption (
"-verbose",
"makes program verbose <false>");
446 args.
parse (argn, argv);
448 std::vector<std::string> arguments = args.
arguments ();
450 if (arguments.size () < 1 || args.
optionIsSet (
"-help")) {
463 unsigned long long iovgmtbegin = args.
getParameter (
"-iovgmtbegin").empty () ? outputRun : strtoull (args.
getParameter (
"-iovgmtbegin").c_str (), 0, 0);
464 unsigned long long iovgmtend = args.
getParameter (
"-iovgmtend").empty () ? 0 : strtoull (args.
getParameter (
"-iovgmtend").c_str (), 0, 0);
470 const char* inputCatalog = args.
getParameter (
"-inputcatalog").empty () ? 0 : args.
getParameter (
"-inputcatalog").c_str();
471 const char* outputCatalog = args.
getParameter (
"-outputcatalog").empty () ? 0 : args.
getParameter (
"-outputcatalog").c_str();
481 if (what ==
"pedestals") {
483 copyObject (
object, input, inputTag, inputRun, output, outputTag, outputRun, append, iovgmtbegin, iovgmtend, nread, nwrite, trace, verbose, inputCatalog, outputCatalog, xmlAuth);
485 else if (what ==
"gains") {
487 copyObject (
object, input, inputTag, inputRun, output, outputTag, outputRun, append, iovgmtbegin, iovgmtend, nread, nwrite, trace, verbose, inputCatalog, outputCatalog, xmlAuth);
489 else if (what ==
"pwidths") {
491 copyObject (
object, input, inputTag, inputRun, output, outputTag, outputRun, append, iovgmtbegin, iovgmtend, nread, nwrite, trace, verbose, inputCatalog, outputCatalog, xmlAuth);
493 else if (what ==
"gwidths") {
495 copyObject (
object, input, inputTag, inputRun, output, outputTag, outputRun, append, iovgmtbegin, iovgmtend, nread, nwrite, trace, verbose, inputCatalog, outputCatalog, xmlAuth);
497 else if (what ==
"emap") {
499 copyObject (
object, input, inputTag, inputRun, output, outputTag, outputRun, append, iovgmtbegin, iovgmtend, nread, nwrite, trace, verbose, inputCatalog, outputCatalog, xmlAuth);
501 else if (what ==
"qie") {
503 copyObject (
object, input, inputTag, inputRun, output, outputTag, outputRun, append, iovgmtbegin, iovgmtend, nread, nwrite, trace, verbose, inputCatalog, outputCatalog, xmlAuth);
505 else if (what ==
"calibqie") {
507 copyObject (
object, input, inputTag, inputRun, output, outputTag, outputRun, append, iovgmtbegin, iovgmtend, nread, nwrite, trace, verbose, inputCatalog, outputCatalog, xmlAuth);
524 if (nArgs <= 0)
return;
527 while (++iarg < nArgs) {
536 std::cerr <<
"ERROR: Parameter " <<
arg <<
" has no value specified. Ignore parameter." << std::endl;
552 sprintf (buffer,
" %-8s <value> : %s", (
mParameters [i]).c_str(), comment.c_str());
556 for (
unsigned i = 0; i <
mOptions.size (); i++) {
557 std::map<std::string, std::string>::const_iterator it =
mComments.find (
mOptions [i]);
559 sprintf (buffer,
" %-8s : %s", (
mOptions [i]).c_str(), comment.c_str());
void fillDefaults(HcalPedestals *&fPedestals)
void defineOption(const std::string &fOption, const std::string &fComment="")
CaloTopology const * topology(0)
std::map< std::string, std::string > mComments
bool defaultsFile(const std::string fParam)
std::vector< std::string > arguments() const
std::vector< std::string > mOptions
bool dumpObject(std::ostream &fOutput, unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string &fTag, unsigned fVersion, const HcalPedestals &fObject, const HcalPedestalWidths &fError)
std::map< IOVRun, std::string > IOVCollection
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
bool copyObject(T *fObject, const std::string &fInput, const std::string &fInputTag, HcalDbTool::IOVRun fInputRun, const std::string &fOutput, const std::string &fOutputTag, HcalDbTool::IOVRun fOutputRun, bool fAppend, unsigned long long fIovgmtbegin, unsigned long long fIovgmtend, unsigned fNread, unsigned fNwrite, unsigned fNtrace, bool fVerbose, const char *fInputCatalog, const char *fOutputCatalog, bool fXmlAuth)
HcalCalibrationQIECoder makeCalibrationQIECoder(HcalGenericDetId fId)
bool addCoder(const HcalQIECoder &fCoder)
const float * getValues() const
get value for all capId = 0..3
static std::string const input
int main(int argc, char **argv)
std::vector< std::string > mParameters
U second(std::pair< T, U > const &p)
HcalQIECoder makeQIECoder(HcalGenericDetId fId)
HcalPedestalWidth makePedestalWidth(HcalGenericDetId fId)
HcalGain makeGain(HcalGenericDetId fId, bool fSmear=false)
bool occiFile(const std::string fParam)
std::vector< IntervalOV > getIOVs(const std::string &fTag)
std::vector< std::string > mArgs
void printOptionsHelp() const
void parse(int nArgs, char *fArgs[])
Gather conditions data from online DB.
const float * getValues() const
get value for all capId = 0..3
bool dbFile(const std::string fParam)
bool getObject(HcalPedestals *fObject, HcalPedestalWidths *fWidths, const std::string &fTag, IOVTime fTime)
void printHelp(const Args &args)
std::string command() const
virtual bool valid(const DetId &id) const
bool xmlFile(const std::string fParam)
Geom::Phi< T > phi() const
HcalGainWidth makeGainWidth(HcalGenericDetId fId)
bool getObject(std::istream &fInput, HcalPedestals *fObject)
HcalDbTool::IOVRun IOVRun
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
bool asciiFile(const std::string fParam)
std::vector< HcalDetId > undefinedCells(const T &fData)
const float * getValues() const
get value for all capId = 0..3
std::map< std::string, std::string > mParsed
bool addCoder(const HcalCalibrationQIECoder &fCoder)
void defineParameter(const std::string &fParameter, const std::string &fComment="")
bool onlineFile(const std::string fParam)
bool optionIsSet(const std::string &fOption) const
std::string getParameter(const std::string &fKey)
HcalPedestal makePedestal(HcalGenericDetId fId, bool fSmear=false)