CMS 3D CMS Logo

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