CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
hcalPublishConditions.cc File Reference
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include "DataFormats/Common/interface/Timestamp.h"
#include "CondCore/IOVService/interface/IOV.h"
#include "CondTools/Hcal/interface/HcalDbTool.h"

Go to the source code of this file.

Classes

class  Args
 

Functions

int main (int argn, char *argv[])
 
void printHelp (const Args &args)
 
bool publishObjects (const std::string &fInputDb, const std::string &fInputTag, const std::string &fOutputDb, const std::string &fOutputTag, bool fVerbose)
 

Function Documentation

int main ( int  argn,
char *  argv[] 
)

Definition at line 164 of file hcalPublishConditions.cc.

References dqmdata_cleaner::args, Args::arguments(), Args::defineOption(), Args::defineParameter(), Args::getParameter(), align_cfg::inputdb, Args::optionIsSet(), Args::parse(), printHelp(), publishObjects(), and AlCaHLTBitMon_QueryRunRegistry::string.

164  {
165 
166  Args args;
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");
173 
174  args.parse (argn, argv);
175 
176  std::vector<std::string> arguments = args.arguments ();
177 
178  if (arguments.size () < 1 || args.optionIsSet ("-help")) {
179  printHelp (args);
180  return -1;
181  }
182 
183  std::string inputdb = args.getParameter ("-input");
184  std::string inputtag = args.getParameter ("-inputtag");
185  std::string outputdb = args.getParameter ("-output");
186  std::string outputtag = args.getParameter ("-outputtag");
187  bool verbose = args.optionIsSet ("-verbose");
188 
189  publishObjects (inputdb, inputtag, outputdb, outputtag, verbose);
190 }
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::vector< std::string > arguments() const
void parse(int nArgs, char *fArgs[])
void printHelp(const Args &args)
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)
void printHelp ( const Args args)

Definition at line 52 of file hcalPublishConditions.cc.

References Args::command(), gather_cfg::cout, and Args::printOptionsHelp().

52  {
53  char buffer [1024];
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;
56  std::cout << "Use:" << std::endl;
57  sprintf (buffer, " %s <what> <options> <parameters>\n", args.command ().c_str());
58  std::cout << buffer;
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 ();
61 }
void printOptionsHelp() const
std::string command() const
tuple cout
Definition: gather_cfg.py:121
bool publishObjects ( const std::string &  fInputDb,
const std::string &  fInputTag,
const std::string &  fOutputDb,
const std::string &  fOutputTag,
bool  fVerbose 
)

Definition at line 64 of file hcalPublishConditions.cc.

References dtNoiseDBValidation_cfg::cerr, gather_cfg::cout, EcalCondDB::db, edm::Timestamp::endOfTime(), i, DTTTrigCorrFirst::run, AlCaHLTBitMon_QueryRunRegistry::string, and edm::Timestamp::value().

Referenced by main().

66  {
67  HcalDbTool db (fInputDb, fVerbose);
68  cond::IOV inputIov;
69  cond::IOV outputIov;
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;
75  return false;
76  }
77  }
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;
81  return false;
82  }
83  }
84  }
85  if (fVerbose) {
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;
90  }
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;
95  }
96  }
97 
98  // first check that all objects of output are contained in input
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;
102  return true;
103  }
104  std::string inputToken = iovIn->second;
105  iovIn++;
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;
111  return true;
112  }
113  else {
114  std::cerr << "List of input IOV is too short" << std::endl;
115  return false;
116  }
117  }
118  if (iovOut == outputIov.iov.end ()) { // empty output
119  outputIov.iov [iovIn->first] = inputToken;
120  inputToken = iovIn->second;
121  break;
122  }
123  if (inputToken != iovOut->second) {
124  std::cerr << "Mismatched tokens: \n in: " << iovIn->second << "\n out: " << iovOut->second << std::endl;
125  return false;
126  }
127 
128  // is it the open end?
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;
134  break;
135  }
136  if (iovIn->first != iovOut->first) {
137  std::cerr << "Mismatched runs: in: " << iovIn->first << ", out: " << iovOut->first << std::endl;
138  return false;
139  }
140 
141  inputToken = iovIn->second;
142  }
143  std::cout << "Good! Input and output does match" << std::endl;
144 
145  for (iovIn++; iovIn != inputIov.iov.end (); iovIn++) {
146  IOVRun run = iovIn->first;
147  outputIov.iov [run] = inputToken;
148  inputToken = iovIn->second;
149  }
150  // last open token
151  outputIov.iov [edm::Timestamp::endOfTime().value()] = inputToken;
152 
153  if (fVerbose) {
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;
158  }
159  }
160  return db.putObject (&outputIov, fOutputTag);
161 }
int i
Definition: DBlmapReader.cc:9
static Timestamp endOfTime()
Definition: Timestamp.h:102
tuple db
Definition: EcalCondDB.py:151
HcalDbTool::IOVRun IOVRun
tuple cout
Definition: gather_cfg.py:121
TimeValue_t value() const
Definition: Timestamp.h:56