File indexing completed on 2023-03-17 10:48:00
0001 from __future__ import print_function
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 import FWCore.ParameterSet.Config as cms
0012 import FWCore.ParameterSet.VarParsing as VarParsing
0013 from xml.etree.ElementTree import parse
0014 import sys,os
0015
0016
0017
0018
0019 def usage():
0020
0021 print("Usage: cmsRun loadConditions.py file=FILENAME record=RECORD db=CONNECTSTRING")
0022 print(" file=FILE")
0023 print(" specify xml file to load to DB")
0024 print()
0025 print(" record=RECORD")
0026 print(" specify record to be loaded (EcalChannelStatus, etc)")
0027 print()
0028 print(" db=CONNECTSTRING")
0029 print(" specify connection string, e.g. sqlite_file=file.db")
0030 print()
0031
0032
0033 usage()
0034
0035
0036 options = VarParsing.VarParsing ()
0037 options.register ('file',
0038 "",
0039 VarParsing.VarParsing.multiplicity.singleton,
0040 VarParsing.VarParsing.varType.string,
0041 "xml file to load")
0042
0043 options.register ('record',
0044 "",
0045 VarParsing.VarParsing.multiplicity.singleton,
0046 VarParsing.VarParsing.varType.string,
0047 "record type to load")
0048
0049 options.register ('db',
0050 "",
0051 VarParsing.VarParsing.multiplicity.singleton,
0052 VarParsing.VarParsing.varType.string,
0053 "db connection string")
0054
0055 options.parseArguments()
0056
0057
0058 def readTagAndSince(filename, headertag='EcalCondHeader'):
0059 '''Read tag and since from EcalCondHeader in XML file '''
0060 root = parse(filename).getroot()
0061 header = root.find(headertag)
0062 since = header.findtext('since')
0063 tag = header.findtext('tag')
0064
0065 return tag,since
0066
0067
0068 tag_ , since_ = readTagAndSince(options.file)
0069
0070
0071 analyzer_ = {'EcalGainRatios':'EcalGainRatiosAnalyzer', \
0072 'EcalADCToGeVConstant':'EcalADCToGeVConstantAnalyzer', \
0073 'EcalWeightXtalGroups':'EcalWeightGroupAnalyzer', \
0074 'EcalChannelStatus':'EcalChannelStatusHandler', \
0075 'EcalChannelStatus':'EcalChannelStatusAnalyzer', \
0076 'EcalTBWeights':'EcalTBWeightsAnalyzer', \
0077 'EcalIntercalibConstants':'EcalIntercalibConstantsAnalyzer', \
0078 'EcalIntercalibConstantsMC':'EcalIntercalibConstantsMCAnalyzer', \
0079 'EcalIntercalibErrors':'EcalIntercalibErrorsAnalyzer'
0080 }
0081
0082
0083
0084 process = cms.Process("LoadEcalConditions")
0085
0086 process.source = cms.Source("EmptyIOVSource",
0087 timetype = cms.string('runnumber'),
0088 firstValue = cms.uint64(1),
0089 lastValue = cms.uint64(1),
0090 interval = cms.uint64(1)
0091 )
0092
0093
0094 process.load("CondCore.DBCommon.CondDBCommon_cfi")
0095 process.CondDBCommon.connect = cms.string(options.db)
0096 process.CondDBCommon.DBParameters.authenticationPath = cms.untracked.string('/afs/cern.ch/cms/DB/conddb')
0097
0098 process.PoolDBOutputService = cms.Service("PoolDBOutputService",
0099 process.CondDBCommon,
0100 timetype = cms.untracked.string('runnumber'),
0101 toPut = cms.VPSet(cms.PSet(
0102 record = cms.string(options.record+'Rcd'),
0103 tag = cms.string(tag_)
0104 )),
0105 logconnect= cms.untracked.string('sqlite_file:log.db')
0106 )
0107
0108
0109 process.popconAnalyzer = cms.EDAnalyzer(analyzer_[options.record],
0110 record = cms.string(options.record+'Rcd'),
0111 loggingOn= cms.untracked.bool(True),
0112 SinceAppendMode=cms.bool(True),
0113 Source=cms.PSet(
0114 xmlFile = cms.untracked.string(options.file),
0115 since = cms.untracked.int64(int(since_))
0116
0117 )
0118 )
0119
0120
0121 process.p = cms.Path(process.popconAnalyzer)
0122
0123