CMS 3D CMS Logo

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

Typedefs

typedef std::pair< IOVRun, IOVRunIntervalOV
typedef std::map< IOVRun,
std::string > 
IOVCollection
typedef HcalDbTool::IOVRun IOVRun

Functions

std::vector< IntervalOVallIOV (const cond::IOV &fIOV)
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)


Typedef Documentation

typedef std::pair<IOVRun,IOVRun> IntervalOV [static]

Definition at line 17 of file hcalPublishConditions.cc.

typedef std::map<IOVRun,std::string> IOVCollection [static]

Definition at line 16 of file hcalPublishConditions.cc.

typedef HcalDbTool::IOVRun IOVRun [static]

Definition at line 15 of file hcalPublishConditions.cc.


Function Documentation

std::vector<IntervalOV> @3073::allIOV ( const cond::IOV fIOV  )  [static]

Definition at line 19 of file hcalPublishConditions.cc.

References cond::IOV::iov, and HLT_VtxMuL3::result.

00019                                                       {
00020     std::vector <IntervalOV> result;
00021     IOVRun iovMin = 0;
00022     for (IOVCollection::const_iterator iovi = fIOV.iov.begin (); iovi != fIOV.iov.end (); iovi++) {
00023       IOVRun iovMax = iovi->first;
00024       result.push_back (std::make_pair (iovMin, iovMax));
00025       iovMin = iovMax;
00026     }
00027     return result;
00028   }

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

Definition at line 164 of file hcalPublishConditions.cc.

References Args::arguments(), Args::defineOption(), Args::defineParameter(), Args::getParameter(), Args::optionIsSet(), Args::parse(), printHelp(), and publishObjects().

00164                                    {
00165 
00166   Args args;
00167   args.defineParameter ("-input", "DB connection string, POOL format, i.e. oracle://devdb10/CMS_COND_HCAL");
00168   args.defineParameter ("-inputtag", "tag for raw conditions");
00169   args.defineParameter ("-output", "DB connection string, POOL format, i.e. oracle://devdb10/CMS_COND_HCAL");
00170   args.defineParameter ("-outputtag", "tag for production conditions");
00171   args.defineOption ("-help", "this help");
00172   args.defineOption ("-verbose", "verbose");
00173   
00174   args.parse (argn, argv);
00175   
00176   std::vector<std::string> arguments = args.arguments ();
00177 
00178   if (arguments.size () < 1 || args.optionIsSet ("-help")) {
00179     printHelp (args);
00180     return -1;
00181   }
00182 
00183   std::string inputdb = args.getParameter ("-input");
00184   std::string inputtag = args.getParameter ("-inputtag");
00185   std::string outputdb = args.getParameter ("-output");
00186   std::string outputtag = args.getParameter ("-outputtag");
00187   bool verbose = args.optionIsSet ("-verbose");
00188 
00189   publishObjects (inputdb, inputtag, outputdb, outputtag, verbose);
00190 }

void printHelp ( const Args args  ) 

Definition at line 52 of file hcalPublishConditions.cc.

References Args::command(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), and Args::printOptionsHelp().

00052                                   {
00053   char buffer [1024];
00054   std::cout << "Tool to convert RAW HCAL conditions into standard offline accessible ones" << std::endl;
00055   std::cout << "    feedback -> ratnikov@fnal.gov" << std::endl;
00056   std::cout << "Use:" << std::endl;
00057   sprintf (buffer, " %s <what> <options> <parameters>\n", args.command ().c_str());
00058   std::cout << buffer;
00059   std::cout << "  where <what> is: \n    pedestals\n    gains\n    pwidths\n    gwidths\n    emap\n    qie\n    calibqie" << std::endl;
00060   args.printOptionsHelp ();
00061 }

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 allIOV(), TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, archive::db, lat::endl(), edm::Timestamp::endOfTime(), i, cond::IOV::iov, and mergeAndRegister_online::run.

Referenced by main().

00066                                 {
00067   HcalDbTool db (fInputDb, fVerbose);
00068   cond::IOV inputIov;
00069   cond::IOV outputIov;
00070   std::vector<std::string> allTags = db.metadataAllTags ();
00071   for (unsigned i = 0; i < allTags.size(); i++) {
00072     if (allTags[i] == fInputTag) {
00073       if (!db.getObject (&inputIov, fInputTag)) {
00074         std::cerr << "copyObject-> Can not get IOV for input tags " << fInputTag << std::endl;
00075         return false;
00076       }
00077     }
00078     if (allTags[i] == fOutputTag) {
00079       if (!db.getObject (&outputIov, fOutputTag)) {
00080         std::cerr << "copyObject-> Can not get IOV for output tags " << fOutputTag << std::endl;
00081         return false;
00082       }
00083     }
00084   }
00085   if (fVerbose) {
00086     std::vector <IntervalOV> allIOVs = allIOV (inputIov);
00087     std::cout << " all IOVs available for input tag " << fInputTag << " in CMS POOL DB instance: " << fInputDb << std::endl;
00088     for (unsigned i = 0; i < allIOVs.size(); i++) {
00089       std::cout << "[ " << allIOVs[i].first << " .. " << allIOVs[i].second << " )  " << inputIov.iov [allIOVs[i].second] << std::endl;
00090     }
00091     allIOVs = allIOV (outputIov);
00092     std::cout << "\n all IOVs available for output tag " << fOutputTag << " in CMS POOL DB instance: " << fInputDb << std::endl;
00093     for (unsigned i = 0; i < allIOVs.size(); i++) {
00094       std::cout << "[ " << allIOVs[i].first << " .. " << allIOVs[i].second << " )  " << outputIov.iov [allIOVs[i].second] << std::endl;
00095     }
00096   }
00097   
00098   // first check that all objects of output are contained in input
00099   IOVCollection::const_iterator iovIn = inputIov.iov.begin ();
00100   if (iovIn == inputIov.iov.end ()) {
00101     std::cerr << "Input IOV is empty - nothing to do" << std::endl;
00102     return true;
00103   }
00104   std::string inputToken = iovIn->second;
00105   iovIn++;
00106   IOVCollection::const_iterator iovOut = outputIov.iov.begin ();
00107   for (; ; iovOut++, iovIn++) {
00108     if (iovIn == inputIov.iov.end ()) {
00109       if (++iovOut == outputIov.iov.end ()) {
00110         std::cerr << "Nothing to update" << std::endl;
00111         return true;
00112       }
00113       else {
00114         std::cerr << "List of input IOV is too short" << std::endl;
00115         return false;
00116       }
00117     }
00118     if (iovOut == outputIov.iov.end ()) { // empty output
00119       outputIov.iov [iovIn->first] = inputToken;
00120       inputToken = iovIn->second;
00121       break;
00122     }
00123     if (inputToken != iovOut->second) {
00124       std::cerr << "Mismatched tokens: \n  in: " << iovIn->second << "\n out: " << iovOut->second << std::endl;
00125       return false;
00126     }
00127     
00128     // is it the open end?
00129     IOVCollection::const_iterator iovOut2 = iovOut;
00130     if (++iovOut2 == outputIov.iov.end ()) {
00131       outputIov.iov.erase (iovOut->first);
00132       outputIov.iov [iovIn->first] = inputToken;
00133       inputToken = iovIn->second;
00134       break;
00135     }
00136     if (iovIn->first != iovOut->first) {
00137       std::cerr << "Mismatched runs: in: " << iovIn->first << ", out: " << iovOut->first << std::endl;
00138       return false;
00139     }
00140     
00141     inputToken = iovIn->second;
00142   }
00143   std::cout << "Good! Input and output does match" << std::endl;
00144   
00145   for (iovIn++; iovIn != inputIov.iov.end (); iovIn++) {
00146     IOVRun run = iovIn->first;
00147     outputIov.iov [run] = inputToken;
00148     inputToken = iovIn->second;
00149   }
00150   // last open token
00151   outputIov.iov [edm::Timestamp::endOfTime().value()] = inputToken;
00152   
00153   if (fVerbose) {
00154     std::vector <IntervalOV> allIOVs = allIOV (outputIov);
00155     std::cout << "\n Done! All IOVs available for output tag " << fOutputTag << " in CMS POOL DB instance: " << fInputDb << std::endl;
00156     for (unsigned i = 0; i < allIOVs.size(); i++) {
00157       std::cout << "[ " << allIOVs[i].first << " ... " << allIOVs[i].second << " )  " << outputIov.iov [allIOVs[i].second] << std::endl;
00158     }
00159   }
00160   return db.putObject (&outputIov, fOutputTag);
00161 }


Generated on Tue Jun 9 17:51:44 2009 for CMSSW by  doxygen 1.5.4