1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# $Id: loadConditions.py,v 1.4 2008/12/19 11:02:21 argiro Exp $
#
# Author: Stefano Argiro'
#
# Script to load ECAL conditions to DB using PopCon
# Intended to be used with the drop-box mechanism, where an XML file
# containing Ecal conditions is sent to DB
#
import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing
from xml.etree.ElementTree import parse
import sys,os
def usage():
print("Usage: cmsRun loadConditions.py file=FILENAME record=RECORD db=CONNECTSTRING")
print(" file=FILE")
print(" specify xml file to load to DB")
print()
print(" record=RECORD")
print(" specify record to be loaded (EcalChannelStatus, etc)")
print()
print(" db=CONNECTSTRING")
print(" specify connection string, e.g. sqlite_file=file.db")
print()
usage()
options = VarParsing.VarParsing ()
options.register ('file',
"", # default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"xml file to load")
options.register ('record',
"", # default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"record type to load")
options.register ('db',
"", # default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"db connection string")
options.parseArguments()
def readTagAndSince(filename, headertag='EcalCondHeader'):
'''Read tag and since from EcalCondHeader in XML file '''
root = parse(filename).getroot()
header = root.find(headertag)
since = header.findtext('since')
tag = header.findtext('tag')
return tag,since
tag_ , since_ = readTagAndSince(options.file)
#which analyzer to use for each record name
analyzer_ = {'EcalGainRatios':'EcalGainRatiosAnalyzer', \
'EcalADCToGeVConstant':'EcalADCToGeVConstantAnalyzer', \
'EcalWeightXtalGroups':'EcalWeightGroupAnalyzer', \
'EcalChannelStatus':'EcalChannelStatusHandler', \
'EcalChannelStatus':'EcalChannelStatusAnalyzer', \
'EcalTBWeights':'EcalTBWeightsAnalyzer', \
'EcalIntercalibConstants':'EcalIntercalibConstantsAnalyzer', \
'EcalIntercalibConstantsMC':'EcalIntercalibConstantsMCAnalyzer', \
'EcalIntercalibErrors':'EcalIntercalibErrorsAnalyzer'
}
process = cms.Process("LoadEcalConditions")
process.source = cms.Source("EmptyIOVSource",
timetype = cms.string('runnumber'),
firstValue = cms.uint64(1),
lastValue = cms.uint64(1),
interval = cms.uint64(1)
)
process.load("CondCore.DBCommon.CondDBCommon_cfi")
process.CondDBCommon.connect = cms.string(options.db)
process.CondDBCommon.DBParameters.authenticationPath = cms.untracked.string('/afs/cern.ch/cms/DB/conddb')
process.PoolDBOutputService = cms.Service("PoolDBOutputService",
process.CondDBCommon,
timetype = cms.untracked.string('runnumber'),
toPut = cms.VPSet(cms.PSet(
record = cms.string(options.record+'Rcd'),
tag = cms.string(tag_)
)),
logconnect= cms.untracked.string('sqlite_file:log.db')
)
process.popconAnalyzer = cms.EDAnalyzer(analyzer_[options.record],
record = cms.string(options.record+'Rcd'),
loggingOn= cms.untracked.bool(True),
SinceAppendMode=cms.bool(True),
Source=cms.PSet(
xmlFile = cms.untracked.string(options.file),
since = cms.untracked.int64(int(since_)) #python will make the int as
#long as needed
)
)
process.p = cms.Path(process.popconAnalyzer)
|