CMS 3D CMS Logo

hcalCalibrationsDbTool.cc File Reference

#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
#include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"
#include "PluginManager/PluginManager.h"
#include "POOLCore/POOLContext.h"
#include "POOLCore/Token.h"
#include "FileCatalog/URIParser.h"
#include "FileCatalog/IFileCatalog.h"
#include "StorageSvc/DbType.h"
#include "PersistencySvc/DatabaseConnectionPolicy.h"
#include "PersistencySvc/ISession.h"
#include "PersistencySvc/ITransaction.h"
#include "PersistencySvc/IDatabase.h"
#include "PersistencySvc/Placement.h"
#include "DataSvc/DataSvcFactory.h"
#include "DataSvc/IDataSvc.h"
#include "DataSvc/ICacheSvc.h"
#include "DataSvc/Ref.h"
#include "RelationalAccess/SchemaException.h"
#include "Collection/Collection.h"
#include "CoralBase/AttributeList.h"
#include "FileCatalog/FCSystemTools.h"
#include "FileCatalog/FCException.h"
#include "FileCatalog/IFCAction.h"
#include "CondCore/IOVService/interface/IOV.h"
#include "CondCore/MetaDataService/interface/MetaData.h"
#include "CalibCalorimetry/HcalAlgos/interface/HcalDbHardcode.h"
#include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
#include "CalibCalorimetry/HcalAlgos/interface/HcalDbXml.h"
#include "CondFormats/HcalObjects/interface/HcalPedestals.h"
#include "CondFormats/HcalObjects/interface/HcalPedestalWidths.h"
#include "CondFormats/HcalObjects/interface/HcalGains.h"
#include "CondFormats/HcalObjects/interface/HcalGainWidths.h"
#include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
#include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "CondFormats/HcalObjects/interface/HcalQIEData.h"

Go to the source code of this file.

Classes

class  Args
class  PoolData

Functions

void fillDefaults (HcalElectronicsMap *fMap)
void fillDefaults (HcalGains *fGains)
void fillDefaults (HcalPedestals *fPedestals)
int main (int argn, char *argv[])
void printHelp (const Args &args)
template<class T>
std::vector< HcalDetIdundefinedCells (const T &fData)


Function Documentation

void fillDefaults ( HcalElectronicsMap fMap  ) 

Definition at line 148 of file hcalCalibrationsDbTool.cc.

References TestMuL1L2Filter_cff::cerr, and lat::endl().

00148                                              {
00149   std::cerr << "ERROR: fillDefaults (HcalElectronicsMap* fMap) is not implemented. Ignore." << std::endl;
00150 }

void fillDefaults ( HcalGains fGains  ) 

Definition at line 140 of file hcalCalibrationsDbTool.cc.

References HcalGain::getValues(), HcalDbHardcode::makeGain(), and undefinedCells().

00140                                       {
00141   std::vector<HcalDetId> cells = undefinedCells (*fGains);
00142   for (std::vector <HcalDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
00143     HcalGain item = HcalDbHardcode::makeGain (*cell);
00144     fGains->addValue (*cell, item.getValues ());
00145   }
00146 }

void fillDefaults ( HcalPedestals fPedestals  ) 

Definition at line 131 of file hcalCalibrationsDbTool.cc.

References HcalPedestal::getValues(), HcalDbHardcode::makePedestal(), and undefinedCells().

00131                                               {
00132   std::vector<HcalDetId> cells = undefinedCells (*fPedestals);
00133   for (std::vector <HcalDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
00134     HcalPedestal item = HcalDbHardcode::makePedestal (*cell);
00135     fPedestals->addValue (*cell, item.getValues ());
00136   }
00137   fPedestals->sort ();
00138 }

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

Definition at line 169 of file hcalCalibrationsDbTool.cc.

References cond::MetaData::addMapping(), Args::arguments(), TestMuL1L2Filter_cff::cerr, HLT_VtxMuL3::connect, archive::db, Args::defineOption(), Args::defineParameter(), dump(), HcalDbXml::dumpObject(), HcalDbASCIIIO::dumpObject(), lat::endl(), edm::pset::fill(), fillDefaults(), HcalDbASCIIIO::getObject(), PoolData::getObject(), Args::getParameter(), cond::MetaData::getToken(), iggi_31X_cfg::input, VarParsing::obj, Args::optionIsSet(), output(), Args::parse(), printHelp(), mergeAndRegister_online::run, PoolData::storeIOV(), PoolData::storeObject(), and ecalRecalibSequence_cff::tag.

00169                                    {
00170 
00171   Args args;
00172   args.defineParameter ("-connect", "DB connection string, POOL format");
00173   args.defineParameter ("-input", "input file where to get constants from");
00174   args.defineParameter ("-output", "output file where to dump constants to");
00175   args.defineParameter ("-run", "run # for which constands should be dumped");
00176   args.defineParameter ("-tag", "tag for the constants set");
00177   args.defineOption ("-help", "this help");
00178   args.defineOption ("-defaults", "fill default values for not specifyed cells");
00179   args.defineOption ("-xml", "dump constants in XML format suitable for feeling online DB");
00180   
00181   args.parse (argn, argv);
00182   
00183   std::vector<std::string> arguments = args.arguments ();
00184 
00185   if (arguments.size () < 2 || args.optionIsSet ("-help")) {
00186     printHelp (args);
00187     return -1;
00188   }
00189 
00190   bool dump = arguments [0] == "dump";
00191   bool fill = arguments [0] == "fill";
00192   bool add = arguments [0] == "add";
00193   bool getPedestals = arguments [1] == "pedestals";
00194   bool getGains = arguments [1] == "gains";
00195   bool emap = arguments [1] == "emap";
00196   bool defaults = args.optionIsSet ("-defaults");
00197   bool xml = args.optionIsSet ("-xml");
00198 
00199   std::string what = arguments [1];
00200 
00201   std::string connect = args.getParameter ("-connect");
00202   if (connect.empty ()) {
00203     std::cerr << "ERROR: -connect is mandatory parameter" << std::endl;
00204     return -1;
00205   }
00206   std::string tag = args.getParameter ("-tag");
00207   if (tag.empty ()) {
00208     std::cerr << "ERROR: -tag is mandatory parameter" << std::endl;
00209     return -1;
00210   }
00211   std::string runStr = args.getParameter ("-run");
00212   if (runStr.empty ()) runStr = "0";
00213   unsigned run = atoi (runStr.c_str());
00214   
00215   std::string metadataToken; // need to separate RAL and ORA operations
00216 
00217   if (dump || add) { // get metadata
00218     cond::MetaData md (connect);
00219     metadataToken = md.getToken (tag);
00220     if (metadataToken.empty ()) {
00221       std::cerr << "ERROR: can not find metadata for tag " << tag << std::cerr;
00222       return 2;
00223     }
00224   }
00225   {
00226     PoolData db (connect);
00227     
00228     // get IOV object
00229     pool::Ref<cond::IOV> iov;
00230     if (!metadataToken.empty ()) {
00231       db.getObject (metadataToken, &iov);
00232       if (iov.isNull ()) {
00233         std::cerr << "ERROR: can not find IOV for token " << metadataToken << std::endl;;
00234         return 2;
00235       }
00236     }
00237     
00238     if (dump) { // dump DB
00239       std::string output = args.getParameter ("-output");
00240       if (output.empty ()) output = "/dev/null";
00241       std::ofstream outStream (output.c_str ());
00242       if (getPedestals) {
00243         pool::Ref<HcalPedestals> ref;
00244         if (db.getObject (iov, run, &ref)) {
00245           if (xml) {
00246             HcalPedestalWidths widths; widths.sort ();
00247             HcalDbXml::dumpObject (outStream, run, tag, *ref, widths);
00248           }
00249           else {
00250             HcalDbASCIIIO::dumpObject (outStream, *ref);
00251           }
00252         }
00253       }
00254       else if (getGains) {
00255         pool::Ref<HcalGains> ref;
00256         if (db.getObject (iov, run, &ref)) {
00257           if (xml) {
00258             HcalGainWidths widths; widths.sort ();
00259             HcalDbXml::dumpObject (outStream, run, tag, *ref, widths);
00260           }
00261           else {
00262             HcalDbASCIIIO::dumpObject (outStream, *ref);
00263           }
00264         }
00265       }
00266       else if (emap) {
00267         pool::Ref<HcalElectronicsMap> ref;
00268         if (db.getObject (iov, run, &ref)) {
00269           HcalDbASCIIIO::dumpObject (outStream, *ref);
00270         }
00271       }
00272       else {
00273         std::cerr << "ERROR object " << what << " is not supported" << std::endl;
00274       }
00275     }
00276     else if (fill || add) { // fill DB
00277       std::string input = args.getParameter ("-input");
00278       if (input.empty ()) input = "/dev/null";
00279       std::ifstream inStream (input.c_str ());
00280       
00281       if (getPedestals) {
00282         HcalPedestals* obj = new HcalPedestals ();
00283         HcalDbASCIIIO::getObject (inStream, obj); 
00284         if (defaults) fillDefaults (obj); 
00285         pool::Ref<HcalPedestals> ref;
00286         if (!db.storeObject (obj, "HcalPedestals", &ref) ||
00287             !db.storeIOV (ref, run, &iov)) {
00288           std::cerr << "ERROR: failed to store object or its IOV" << std::endl;
00289           return 1;
00290         }
00291       }
00292       else if (getGains) {
00293         HcalGains* obj = new HcalGains ();
00294         HcalDbASCIIIO::getObject (inStream, obj); 
00295         if (defaults) fillDefaults (obj); 
00296         pool::Ref<HcalGains> ref;
00297         if (!db.storeObject (obj, "HcalGains", &ref) ||
00298             !db.storeIOV (ref, run, &iov)) {
00299           std::cerr << "ERROR: failed to store object or its IOV" << std::endl;
00300           return 1;
00301         }
00302       }
00303       else if (emap) {
00304         HcalElectronicsMap* obj = new HcalElectronicsMap ();
00305         HcalDbASCIIIO::getObject (inStream, obj); 
00306         pool::Ref<HcalElectronicsMap> ref;
00307         if (defaults) fillDefaults (obj); 
00308         if (!db.storeObject (obj, "HcalElectronicsMap", &ref) ||
00309             !db.storeIOV (ref, run, &iov)) {
00310           std::cerr << "ERROR: failed to store object or its IOV" << std::endl;
00311           return 1;
00312         }
00313       }
00314       metadataToken = iov.toString ();
00315     }
00316     else {
00317       std::cerr << "Unknown option. Try -help option for more details" << std::endl;
00318     }
00319   }
00320   
00321   if (fill) { // update metadata
00322     cond::MetaData md (connect);
00323     md.addMapping (tag, metadataToken);
00324   }
00325   return 0;
00326 }

void printHelp ( const Args args  ) 

Definition at line 152 of file hcalCalibrationsDbTool.cc.

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

00152                                   {
00153   char buffer [1024];
00154   std::cout << "Tool to manipulate by Hcal Calibrations" << std::endl;
00155   std::cout << "    feedback -> ratnikov@fnal.gov" << std::endl;
00156   std::cout << "Use:" << std::endl;
00157   sprintf (buffer, " %s dump <what> <options> <parameters>\n", args.command ().c_str());
00158   std::cout << buffer;
00159   sprintf (buffer, " %s fill <what> <options> <parameters>\n", args.command ().c_str());
00160   std::cout << buffer;
00161   sprintf (buffer, " %s add <what> <options> <parameters>\n", args.command ().c_str());
00162   std::cout << buffer;
00163   std::cout << "  where <what> is: \n    pedestals\n    gains\n    emap\n" << std::endl;
00164   args.printOptionsHelp ();
00165 }

template<class T>
std::vector<HcalDetId> undefinedCells ( const T &  fData  )  [inline]

Definition at line 113 of file hcalCalibrationsDbTool.cc.

References eta, phi, DetId::rawId(), HLT_VtxMuL3::result, and HcalTopology::valid().

00113                                                      {
00114   static std::vector<HcalDetId> result;
00115   if (result.size () <= 0) {
00116     HcalTopology topology;
00117     for (int eta = -50; eta < 50; eta++) {
00118       for (int phi = 0; phi < 100; phi++) {
00119         for (int depth = 1; depth < 5; depth++) {
00120           for (int det = 1; det < 5; det++) {
00121             HcalDetId cell ((HcalSubdetector) det, eta, phi, depth);
00122             if (topology.valid(cell) && !fData.getValues (cell.rawId())) result.push_back (cell);
00123           }
00124         }
00125       }
00126     }
00127   }
00128   return result;
00129 }


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