CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CondTools/Ecal/scripts/loadConditions.py

Go to the documentation of this file.
00001 # $Id: loadConditions.py,v 1.5 2009/05/13 13:48:05 argiro Exp $
00002 #
00003 # Author: Stefano Argiro'
00004 #
00005 # Script to load ECAL conditions to DB using PopCon
00006 # Intended to be used with the drop-box mechanism, where an XML file
00007 # containing Ecal conditions is sent to DB
00008 #
00009 
00010 import FWCore.ParameterSet.Config as cms
00011 import FWCore.ParameterSet.VarParsing as VarParsing
00012 from   elementtree.ElementTree import parse
00013 import sys,os
00014 
00015 
00016 
00017 
00018 def usage():
00019 
00020    print "Usage: cmsRun loadConditions.py file=FILENAME record=RECORD db=CONNECTSTRING"
00021    print "   file=FILE"
00022    print "       specify xml file to load to DB"
00023    print
00024    print "   record=RECORD"
00025    print "       specify record to be loaded (EcalChannelStatus, etc)"
00026    print 
00027    print "   db=CONNECTSTRING"
00028    print "       specify connection string, e.g. sqlite_file=file.db"
00029    print 
00030 
00031 
00032 usage()
00033 
00034 
00035 options = VarParsing.VarParsing ()
00036 options.register ('file',
00037                   "", # default value
00038                   VarParsing.VarParsing.multiplicity.singleton, 
00039                   VarParsing.VarParsing.varType.string,     
00040                   "xml file to load")
00041 
00042 options.register ('record',
00043                   "", # default value
00044                   VarParsing.VarParsing.multiplicity.singleton, 
00045                   VarParsing.VarParsing.varType.string,     
00046                   "record type to load")
00047 
00048 options.register ('db',
00049                   "", # default value
00050                   VarParsing.VarParsing.multiplicity.singleton, 
00051                   VarParsing.VarParsing.varType.string,     
00052                   "db connection string")
00053 
00054 options.parseArguments()
00055 
00056 
00057 def readTagAndSince(filename, headertag='EcalCondHeader'):
00058     '''Read tag and since from EcalCondHeader in XML file '''
00059     root   = parse(filename).getroot()
00060     header = root.find(headertag)
00061     since  = header.findtext('since') 
00062     tag    = header.findtext('tag')     
00063 
00064     return tag,since
00065 
00066 
00067 tag_ , since_ = readTagAndSince(options.file)
00068 
00069 #which analyzer to use for each record name
00070 analyzer_ =   {'EcalGainRatios':'EcalGainRatiosAnalyzer',             \
00071                'EcalADCToGeVConstant':'EcalADCToGeVConstantAnalyzer', \
00072                'EcalWeightXtalGroups':'EcalWeightGroupAnalyzer',      \
00073                'EcalChannelStatus':'EcalChannelStatusHandler',        \
00074                'EcalChannelStatus':'EcalChannelStatusAnalyzer',       \
00075                'EcalTBWeights':'EcalTBWeightsAnalyzer',               \
00076                'EcalIntercalibConstants':'EcalIntercalibConstantsAnalyzer', \
00077                'EcalIntercalibConstantsMC':'EcalIntercalibConstantsMCAnalyzer', \ 
00078                'EcalIntercalibErrors':'EcalIntercalibErrorsAnalyzer'
00079                }
00080 
00081 
00082 
00083 process = cms.Process("LoadEcalConditions")
00084 
00085 process.source = cms.Source("EmptyIOVSource",
00086     timetype = cms.string('runnumber'),
00087     firstValue = cms.uint64(1),
00088     lastValue  = cms.uint64(1),
00089     interval = cms.uint64(1)
00090 )
00091 
00092 
00093 process.load("CondCore.DBCommon.CondDBCommon_cfi")
00094 process.CondDBCommon.connect = cms.string(options.db)
00095 process.CondDBCommon.DBParameters.authenticationPath = cms.untracked.string('/afs/cern.ch/cms/DB/conddb')
00096 
00097 process.PoolDBOutputService = cms.Service("PoolDBOutputService",
00098     process.CondDBCommon,
00099     timetype = cms.untracked.string('runnumber'),
00100     toPut = cms.VPSet(cms.PSet(
00101         record = cms.string(options.record+'Rcd'),
00102         tag = cms.string(tag_)
00103          )),
00104         logconnect= cms.untracked.string('sqlite_file:log.db')                                  
00105 )
00106 
00107 
00108 process.popconAnalyzer = cms.EDAnalyzer(analyzer_[options.record],
00109     record = cms.string(options.record+'Rcd'),
00110     loggingOn= cms.untracked.bool(True),
00111     SinceAppendMode=cms.bool(True),
00112     Source=cms.PSet(
00113     xmlFile = cms.untracked.string(options.file),
00114     since = cms.untracked.int64(int(since_)) #python will make the int as
00115                                              #long as needed
00116     )                            
00117 )    
00118 
00119 
00120 process.p = cms.Path(process.popconAnalyzer)
00121 
00122