10 #include "DataFormats/Common/interface/Timestamp.h"
11 #include "CondCore/IOVService/interface/IOV.h"
12 #include "CondTools/Hcal/interface/HcalDbTool.h"
17 typedef std::pair<IOVRun,IOVRun> IntervalOV;
19 std::vector <IntervalOV> allIOV (
const cond::IOV& fIOV) {
20 std::vector <IntervalOV>
result;
22 for (IOVCollection::const_iterator iovi = fIOV.iov.begin (); iovi != fIOV.iov.end (); iovi++) {
23 IOVRun iovMax = iovi->first;
24 result.push_back (std::make_pair (iovMin, iovMax));
35 void defineOption (
const std::string& fOption,
const std::string& fComment =
"");
36 void defineParameter (
const std::string& fParameter,
const std::string& fComment =
"");
37 void parse (
int nArgs,
char* fArgs []);
40 std::vector<std::string>
arguments ()
const;
41 bool optionIsSet (
const std::string& fOption)
const;
47 std::vector <std::string>
mArgs;
48 std::map <std::string, std::string>
mParsed;
49 std::map <std::string, std::string>
mComments;
54 std::cout <<
"Tool to convert RAW HCAL conditions into standard offline accessible ones" << std::endl;
55 std::cout <<
" feedback -> ratnikov@fnal.gov" << std::endl;
57 sprintf (buffer,
" %s <what> <options> <parameters>\n", args.
command ().c_str());
59 std::cout <<
" where <what> is: \n pedestals\n gains\n pwidths\n gwidths\n emap\n qie\n calibqie" << std::endl;
64 bool publishObjects (
const std::string& fInputDb,
const std::string& fInputTag,
65 const std::string& fOutputDb,
const std::string& fOutputTag,
67 HcalDbTool
db (fInputDb, fVerbose);
70 std::vector<std::string> allTags = db.metadataAllTags ();
71 for (
unsigned i = 0;
i < allTags.size();
i++) {
72 if (allTags[
i] == fInputTag) {
73 if (!db.getObject (&inputIov, fInputTag)) {
74 std::cerr <<
"copyObject-> Can not get IOV for input tags " << fInputTag << std::endl;
78 if (allTags[
i] == fOutputTag) {
79 if (!db.getObject (&outputIov, fOutputTag)) {
80 std::cerr <<
"copyObject-> Can not get IOV for output tags " << fOutputTag << std::endl;
86 std::vector <IntervalOV> allIOVs = allIOV (inputIov);
87 std::cout <<
" all IOVs available for input tag " << fInputTag <<
" in CMS POOL DB instance: " << fInputDb << std::endl;
88 for (
unsigned i = 0;
i < allIOVs.size();
i++) {
89 std::cout <<
"[ " << allIOVs[
i].first <<
" .. " << allIOVs[
i].second <<
" ) " << inputIov.iov [allIOVs[
i].second] << std::endl;
91 allIOVs = allIOV (outputIov);
92 std::cout <<
"\n all IOVs available for output tag " << fOutputTag <<
" in CMS POOL DB instance: " << fInputDb << std::endl;
93 for (
unsigned i = 0;
i < allIOVs.size();
i++) {
94 std::cout <<
"[ " << allIOVs[
i].first <<
" .. " << allIOVs[
i].second <<
" ) " << outputIov.iov [allIOVs[
i].second] << std::endl;
99 IOVCollection::const_iterator iovIn = inputIov.iov.begin ();
100 if (iovIn == inputIov.iov.end ()) {
101 std::cerr <<
"Input IOV is empty - nothing to do" << std::endl;
104 std::string inputToken = iovIn->second;
106 IOVCollection::const_iterator iovOut = outputIov.iov.begin ();
107 for (; ; iovOut++, iovIn++) {
108 if (iovIn == inputIov.iov.end ()) {
109 if (++iovOut == outputIov.iov.end ()) {
110 std::cerr <<
"Nothing to update" << std::endl;
114 std::cerr <<
"List of input IOV is too short" << std::endl;
118 if (iovOut == outputIov.iov.end ()) {
119 outputIov.iov [iovIn->first] = inputToken;
120 inputToken = iovIn->second;
123 if (inputToken != iovOut->second) {
124 std::cerr <<
"Mismatched tokens: \n in: " << iovIn->second <<
"\n out: " << iovOut->second << std::endl;
129 IOVCollection::const_iterator iovOut2 = iovOut;
130 if (++iovOut2 == outputIov.iov.end ()) {
131 outputIov.iov.erase (iovOut->first);
132 outputIov.iov [iovIn->first] = inputToken;
133 inputToken = iovIn->second;
136 if (iovIn->first != iovOut->first) {
137 std::cerr <<
"Mismatched runs: in: " << iovIn->first <<
", out: " << iovOut->first << std::endl;
141 inputToken = iovIn->second;
143 std::cout <<
"Good! Input and output does match" << std::endl;
145 for (iovIn++; iovIn != inputIov.iov.end (); iovIn++) {
146 IOVRun
run = iovIn->first;
147 outputIov.iov [
run] = inputToken;
148 inputToken = iovIn->second;
154 std::vector <IntervalOV> allIOVs = allIOV (outputIov);
155 std::cout <<
"\n Done! All IOVs available for output tag " << fOutputTag <<
" in CMS POOL DB instance: " << fInputDb << std::endl;
156 for (
unsigned i = 0;
i < allIOVs.size();
i++) {
157 std::cout <<
"[ " << allIOVs[
i].first <<
" ... " << allIOVs[
i].second <<
" ) " << outputIov.iov [allIOVs[
i].second] << std::endl;
160 return db.putObject (&outputIov, fOutputTag);
167 args.
defineParameter (
"-input",
"DB connection string, POOL format, i.e. oracle://devdb10/CMS_COND_HCAL");
169 args.
defineParameter (
"-output",
"DB connection string, POOL format, i.e. oracle://devdb10/CMS_COND_HCAL");
174 args.
parse (argn, argv);
176 std::vector<std::string> arguments = args.
arguments ();
178 if (arguments.size () < 1 || args.
optionIsSet (
"-help")) {
186 std::string outputtag = args.
getParameter (
"-outputtag");
205 if (nArgs <= 0)
return;
208 while (++iarg < nArgs) {
209 std::string
arg (fArgs [iarg]);
217 std::cerr <<
"ERROR: Parameter " <<
arg <<
" has no value specified. Ignore parameter." << std::endl;
233 sprintf (buffer,
" %-8s <value> : %s", (
mParameters [i]).c_str(), comment.c_str());
237 for (
unsigned i = 0; i <
mOptions.size (); i++) {
238 std::map<std::string, std::string>::const_iterator it =
mComments.find (
mOptions [i]);
239 std::string comment = it !=
mComments.end () ? it->second :
"uncommented";
240 sprintf (buffer,
" %-8s : %s", (
mOptions [i]).c_str(), comment.c_str());
bool publishObjects(const std::string &fInputDb, const std::string &fInputTag, const std::string &fOutputDb, const std::string &fOutputTag, bool fVerbose)
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)
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
TimeValue_t value() const
std::string command() const
static Timestamp const & endOfTime()
void printHelp(const Args &args)
std::map< std::string, std::string > mParsed
void defineParameter(const std::string &fParameter, const std::string &fComment="")
bool optionIsSet(const std::string &fOption) const
std::string getParameter(const std::string &fKey)