test
CMS 3D CMS Logo

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