18 A very simple script to retrieve from DB a beam spot payload for a given IOV.
19 usage: %prog -t <tag name> -r <run number = 1>
20 -a, --auth = AUTH: Authorization path: \"/afs/cern.ch/cms/DB/conddb\"(default), \"/nfshome0/popcondev/conddb\"
21 -d, --destDB = DESTDB: Destination string for DB connection: \"frontier://PromptProd/CMS_COND_31X_BEAMSPOT\"(default), \"oracle://cms_orcon_prod/CMS_COND_31X_BEAMSPOT\", \"sqlite_file:mysqlitefile.db\"
22 -g, --globaltag= GLOBALTAG: Name of Global tag. If this is provided, no need to provide beam spot tags.
23 -l, --lumi = LUMI: Lumi section.
24 -r, --run = RUN: Run number.
25 -t, --tag = TAG: Name of Beam Spot DB tag.
27 Francisco Yumiceva (yumiceva@fnal.gov)
31 from __future__
import print_function
40 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
43 "True if options were given"
44 for v
in self.__dict__.
values():
45 if v
is not None:
return True
48 optparse.Values.__nonzero__ = nonzero
55 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
57 def parse(docstring, arglist=None):
59 optionstring = docstring
60 match = USAGE.search(optionstring)
61 if not match:
raise ParsingError(
"Cannot find the option string")
62 optlines = match.group(1).splitlines()
64 p = optparse.OptionParser(optlines[0])
65 for line
in optlines[1:]:
66 opt, help=line.split(
':')[:2]
67 short,long=opt.split(
',')[:2]
70 long=long.split(
'=')[0]
73 p.add_option(short.strip(),long.strip(),
74 action = action, help = help.strip())
75 except (IndexError,ValueError):
76 raise ParsingError(
"Cannot parse the option string correctly")
77 return p.parse_args(arglist)
83 """pack high,low 32bit unsigned int to one unsigned 64bit long long
84 Note:the print value of result number may appear signed, if the sign bit is used.
90 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
97 """unpack 64bit lumiid to dictionary {'run','lumisection'}
100 return {
'run':j[0],
'lumisection':j[1]}
103 if __name__ ==
'__main__':
109 if not args
and not option:
exit()
114 if ((option.tag
and option.globaltag)) ==
False:
115 print(
" NEED to provide beam spot DB tag name, or global tag")
119 elif option.globaltag:
120 globaltag = option.globaltag
121 cmd =
'cmscond_tagtree_list -c frontier://cmsfrontier.cern.ch:8000/Frontier/CMS_COND_31X_GLOBALTAG -P /afs/cern.ch/cms/DB/conddb -T '+globaltag+
' | grep BeamSpot'
122 outcmd = commands.getstatusoutput( cmd )
125 tagname = atag.replace(
"tag:",
"")
126 print(
" Global tag: "+globaltag+
" includes the beam spot tag: "+tagname)
130 destDB =
'frontier://PromptProd/CMS_COND_31X_BEAMSPOT'
132 destDB = option.destDB
134 auth =
'/afs/cern.ch/cms/DB/conddb'
152 readdb_out =
"readDB_"+tagname+
".py"
154 rnewfile = open(readdb_out,
'w')
157 import FWCore.ParameterSet.Config as cms
159 process = cms.Process("readDB")
160 process.load("FWCore.MessageLogger.MessageLogger_cfi")
162 process.load("CondCore.DBCommon.CondDBSetup_cfi")
164 process.BeamSpotDBSource = cms.ESSource("PoolDBESSource",
166 toGet = cms.VPSet(cms.PSet(
167 record = cms.string('BeamSpotObjectsRcd'),
169 rnewfile.write(
'tag = cms.string(\''+tagname+
'\')\n')
170 rnewfile.write(
')),\n')
171 rnewfile.write(
'connect = cms.string(\''+destDB+
'\')\n')
180 rnewfile.write(
'process.BeamSpotDBSource.DBParameters.authenticationPath = cms.untracked.string(\"'+auth +
'\")')
184 process.source = cms.Source("EmptySource",
185 numberEventsInRun = cms.untracked.uint32(1),
187 rnewfile.write(
' firstRun = cms.untracked.uint32('+ run +
'),\n')
188 rnewfile.write(
' firstLuminosityBlock = cms.untracked.uint32('+ lumi +
')\n')
192 process.maxEvents = cms.untracked.PSet(
193 input = cms.untracked.int32(1)
195 process.beamspot = cms.EDAnalyzer("BeamSpotFromDB")
198 process.p = cms.Path(process.beamspot)
203 status_rDB = commands.getstatusoutput(
'cmsRun '+ readdb_out)
205 outtext = status_rDB[1]