10 #include "DataFormats/Common/interface/Timestamp.h" 11 #include "CondCore/IOVService/interface/IOV.h" 12 #include "CondTools/Hcal/interface/HcalDbTool.h" 15 typedef HcalDbTool::IOVRun IOVRun;
16 typedef std::map<IOVRun,std::string> IOVCollection;
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));
37 void parse (
int nArgs,
char* fArgs []);
38 void printOptionsHelp ()
const;
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;
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;
60 args.printOptionsHelp ();
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;
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");
168 args.defineParameter (
"-inputtag",
"tag for raw conditions");
169 args.defineParameter (
"-output",
"DB connection string, POOL format, i.e. oracle://devdb10/CMS_COND_HCAL");
170 args.defineParameter (
"-outputtag",
"tag for production conditions");
171 args.defineOption (
"-help",
"this help");
172 args.defineOption (
"-verbose",
"verbose");
195 mOptions.push_back (fOption);
196 mComments [fOption] = fComment;
200 mParameters.push_back (fParameter);
201 mComments [fParameter] = fComment;
205 if (nArgs <= 0)
return;
208 while (++iarg < nArgs) {
210 if (
arg [0] !=
'-') mArgs.push_back (
arg);
212 if (
std::find (mOptions.begin(), mOptions.end (),
arg) != mOptions.end ()) {
215 if (
std::find (mParameters.begin(), mParameters.end (),
arg) != mParameters.end ()) {
217 std::cerr <<
"ERROR: Parameter " <<
arg <<
" has no value specified. Ignore parameter." << std::endl;
230 for (
unsigned i = 0;
i < mParameters.size ();
i++) {
231 std::map<std::string, std::string>::const_iterator it = mComments.find (mParameters [
i]);
232 std::string comment = it != mComments.end () ? it->second :
"uncommented";
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());
246 int ipos = mProgramName.rfind (
'/');
253 return mParsed.find (fOption) != mParsed.end ();
257 if (optionIsSet (fKey))
return mParsed [fKey];
vector< string > parse(string line, const string &delimiter)
static Timestamp endOfTime()
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 > mParsed
std::vector< std::string > mParameters
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< std::string > mArgs
std::vector< std::string > mOptions
void printOptionsHelp() const
void printHelp(const Args &args)
TimeValue_t value() const
bool optionIsSet(const std::string &fOption) const
void defineParameter(const std::string &fParameter, const std::string &fComment="")
int main(int argn, char *argv [])
std::map< std::string, std::string > mComments
std::string getParameter(const std::string &fKey)