CMS 3D CMS Logo

Classes | Functions

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CondTools/Hcal/bin/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 harvestRelVal::args, Args::arguments(), Args::defineOption(), Args::defineParameter(), Args::getParameter(), align_cfg::inputdb, Args::optionIsSet(), Args::parse(), printHelp(), and publishObjects().

                                   {

  Args args;
  args.defineParameter ("-input", "DB connection string, POOL format, i.e. oracle://devdb10/CMS_COND_HCAL");
  args.defineParameter ("-inputtag", "tag for raw conditions");
  args.defineParameter ("-output", "DB connection string, POOL format, i.e. oracle://devdb10/CMS_COND_HCAL");
  args.defineParameter ("-outputtag", "tag for production conditions");
  args.defineOption ("-help", "this help");
  args.defineOption ("-verbose", "verbose");
  
  args.parse (argn, argv);
  
  std::vector<std::string> arguments = args.arguments ();

  if (arguments.size () < 1 || args.optionIsSet ("-help")) {
    printHelp (args);
    return -1;
  }

  std::string inputdb = args.getParameter ("-input");
  std::string inputtag = args.getParameter ("-inputtag");
  std::string outputdb = args.getParameter ("-output");
  std::string outputtag = args.getParameter ("-outputtag");
  bool verbose = args.optionIsSet ("-verbose");

  publishObjects (inputdb, inputtag, outputdb, outputtag, verbose);
}
void printHelp ( const Args args)

Definition at line 52 of file hcalPublishConditions.cc.

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

                                  {
  char buffer [1024];
  std::cout << "Tool to convert RAW HCAL conditions into standard offline accessible ones" << std::endl;
  std::cout << "    feedback -> ratnikov@fnal.gov" << std::endl;
  std::cout << "Use:" << std::endl;
  sprintf (buffer, " %s <what> <options> <parameters>\n", args.command ().c_str());
  std::cout << buffer;
  std::cout << "  where <what> is: \n    pedestals\n    gains\n    pwidths\n    gwidths\n    emap\n    qie\n    calibqie" << std::endl;
  args.printOptionsHelp ();
}
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 ExpressReco_HICollisions_FallBack::cerr, gather_cfg::cout, EcalCondDB::db, edm::Timestamp::endOfTime(), i, cond::IOV::iov, and CrabTask::run.

Referenced by main().

                                {
  HcalDbTool db (fInputDb, fVerbose);
  cond::IOV inputIov;
  cond::IOV outputIov;
  std::vector<std::string> allTags = db.metadataAllTags ();
  for (unsigned i = 0; i < allTags.size(); i++) {
    if (allTags[i] == fInputTag) {
      if (!db.getObject (&inputIov, fInputTag)) {
        std::cerr << "copyObject-> Can not get IOV for input tags " << fInputTag << std::endl;
        return false;
      }
    }
    if (allTags[i] == fOutputTag) {
      if (!db.getObject (&outputIov, fOutputTag)) {
        std::cerr << "copyObject-> Can not get IOV for output tags " << fOutputTag << std::endl;
        return false;
      }
    }
  }
  if (fVerbose) {
    std::vector <IntervalOV> allIOVs = allIOV (inputIov);
    std::cout << " all IOVs available for input tag " << fInputTag << " in CMS POOL DB instance: " << fInputDb << std::endl;
    for (unsigned i = 0; i < allIOVs.size(); i++) {
      std::cout << "[ " << allIOVs[i].first << " .. " << allIOVs[i].second << " )  " << inputIov.iov [allIOVs[i].second] << std::endl;
    }
    allIOVs = allIOV (outputIov);
    std::cout << "\n all IOVs available for output tag " << fOutputTag << " in CMS POOL DB instance: " << fInputDb << std::endl;
    for (unsigned i = 0; i < allIOVs.size(); i++) {
      std::cout << "[ " << allIOVs[i].first << " .. " << allIOVs[i].second << " )  " << outputIov.iov [allIOVs[i].second] << std::endl;
    }
  }
  
  // first check that all objects of output are contained in input
  IOVCollection::const_iterator iovIn = inputIov.iov.begin ();
  if (iovIn == inputIov.iov.end ()) {
    std::cerr << "Input IOV is empty - nothing to do" << std::endl;
    return true;
  }
  std::string inputToken = iovIn->second;
  iovIn++;
  IOVCollection::const_iterator iovOut = outputIov.iov.begin ();
  for (; ; iovOut++, iovIn++) {
    if (iovIn == inputIov.iov.end ()) {
      if (++iovOut == outputIov.iov.end ()) {
        std::cerr << "Nothing to update" << std::endl;
        return true;
      }
      else {
        std::cerr << "List of input IOV is too short" << std::endl;
        return false;
      }
    }
    if (iovOut == outputIov.iov.end ()) { // empty output
      outputIov.iov [iovIn->first] = inputToken;
      inputToken = iovIn->second;
      break;
    }
    if (inputToken != iovOut->second) {
      std::cerr << "Mismatched tokens: \n  in: " << iovIn->second << "\n out: " << iovOut->second << std::endl;
      return false;
    }
    
    // is it the open end?
    IOVCollection::const_iterator iovOut2 = iovOut;
    if (++iovOut2 == outputIov.iov.end ()) {
      outputIov.iov.erase (iovOut->first);
      outputIov.iov [iovIn->first] = inputToken;
      inputToken = iovIn->second;
      break;
    }
    if (iovIn->first != iovOut->first) {
      std::cerr << "Mismatched runs: in: " << iovIn->first << ", out: " << iovOut->first << std::endl;
      return false;
    }
    
    inputToken = iovIn->second;
  }
  std::cout << "Good! Input and output does match" << std::endl;
  
  for (iovIn++; iovIn != inputIov.iov.end (); iovIn++) {
    IOVRun run = iovIn->first;
    outputIov.iov [run] = inputToken;
    inputToken = iovIn->second;
  }
  // last open token
  outputIov.iov [edm::Timestamp::endOfTime().value()] = inputToken;
  
  if (fVerbose) {
    std::vector <IntervalOV> allIOVs = allIOV (outputIov);
    std::cout << "\n Done! All IOVs available for output tag " << fOutputTag << " in CMS POOL DB instance: " << fInputDb << std::endl;
    for (unsigned i = 0; i < allIOVs.size(); i++) {
      std::cout << "[ " << allIOVs[i].first << " ... " << allIOVs[i].second << " )  " << outputIov.iov [allIOVs[i].second] << std::endl;
    }
  }
  return db.putObject (&outputIov, fOutputTag);
}