Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:54

0001 from __future__ import print_function
0002 # $Id: loadConditions.py,v 1.4 2008/12/19 11:02:21 argiro Exp $
0003 #
0004 # Author: Stefano Argiro'
0005 #
0006 # Script to load ECAL conditions to DB using PopCon
0007 # Intended to be used with the drop-box mechanism, where an XML file
0008 # containing Ecal conditions is sent to DB
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                   "", # default value
0039                   VarParsing.VarParsing.multiplicity.singleton, 
0040                   VarParsing.VarParsing.varType.string,     
0041                   "xml file to load")
0042 
0043 options.register ('record',
0044                   "", # default value
0045                   VarParsing.VarParsing.multiplicity.singleton, 
0046                   VarParsing.VarParsing.varType.string,     
0047                   "record type to load")
0048 
0049 options.register ('db',
0050                   "", # default value
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 #which analyzer to use for each record name
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_)) #python will make the int as
0116                                              #long as needed
0117     )                            
0118 )    
0119 
0120 
0121 process.p = cms.Path(process.popconAnalyzer)
0122 
0123