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)
39 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
42 "True if options were given"
43 for v
in self.__dict__.itervalues():
44 if v
is not None:
return True
47 optparse.Values.__nonzero__ = nonzero
54 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
56 def parse(docstring, arglist=None):
58 optionstring = docstring
59 match = USAGE.search(optionstring)
60 if not match:
raise ParsingError(
"Cannot find the option string")
61 optlines = match.group(1).splitlines()
63 p = optparse.OptionParser(optlines[0])
64 for line
in optlines[1:]:
65 opt, help=line.split(
':')[:2]
66 short,long=opt.split(
',')[:2]
69 long=long.split(
'=')[0]
72 p.add_option(short.strip(),long.strip(),
73 action = action, help = help.strip())
74 except (IndexError,ValueError):
75 raise ParsingError(
"Cannot parse the option string correctly")
76 return p.parse_args(arglist)
82 """pack high,low 32bit unsigned int to one unsigned 64bit long long
83 Note:the print value of result number may appear signed, if the sign bit is used.
89 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
96 """unpack 64bit lumiid to dictionary {'run','lumisection'}
99 return {
'run':j[0],
'lumisection':j[1]}
102 if __name__ ==
'__main__':
107 option,args =
parse(__doc__)
108 if not args
and not option:
exit()
113 if ((option.tag
and option.globaltag)) ==
False:
114 print " NEED to provide beam spot DB tag name, or global tag"
118 elif option.globaltag:
119 globaltag = option.globaltag
120 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'
121 outcmd = commands.getstatusoutput( cmd )
124 tagname = atag.replace(
"tag:",
"")
125 print " Global tag: "+globaltag+
" includes the beam spot tag: "+tagname
129 destDB =
'frontier://PromptProd/CMS_COND_31X_BEAMSPOT'
131 destDB = option.destDB
133 auth =
'/afs/cern.ch/cms/DB/conddb'
151 readdb_out =
"readDB_"+tagname+
".py"
153 rnewfile = open(readdb_out,
'w')
156 import FWCore.ParameterSet.Config as cms
158 process = cms.Process("readDB")
159 process.load("FWCore.MessageLogger.MessageLogger_cfi")
161 process.load("CondCore.DBCommon.CondDBSetup_cfi")
163 process.BeamSpotDBSource = cms.ESSource("PoolDBESSource",
165 toGet = cms.VPSet(cms.PSet(
166 record = cms.string('BeamSpotObjectsRcd'),
168 rnewfile.write(
'tag = cms.string(\''+tagname+
'\')\n')
169 rnewfile.write(
')),\n')
170 rnewfile.write(
'connect = cms.string(\''+destDB+
'\')\n')
179 rnewfile.write(
'process.BeamSpotDBSource.DBParameters.authenticationPath = cms.untracked.string(\"'+auth +
'\")')
183 process.source = cms.Source("EmptySource",
184 numberEventsInRun = cms.untracked.uint32(1),
186 rnewfile.write(
' firstRun = cms.untracked.uint32('+ run +
'),\n')
187 rnewfile.write(
' firstLuminosityBlock = cms.untracked.uint32('+ lumi +
')\n')
191 process.maxEvents = cms.untracked.PSet(
192 input = cms.untracked.int32(1)
194 process.beamspot = cms.EDAnalyzer("BeamSpotFromDB")
197 process.p = cms.Path(process.beamspot)
202 status_rDB = commands.getstatusoutput(
'cmsRun '+ readdb_out)
204 outtext = status_rDB[1]
return(e1-e2)*(e1-e2)+dp *dp