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
41 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
44 "True if options were given" 45 for v
in six.itervalues(self.__dict__):
46 if v
is not None:
return True 49 optparse.Values.__nonzero__ = nonzero
56 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
58 def parse(docstring, arglist=None):
60 optionstring = docstring
61 match = USAGE.search(optionstring)
62 if not match:
raise ParsingError(
"Cannot find the option string")
63 optlines = match.group(1).splitlines()
65 p = optparse.OptionParser(optlines[0])
66 for line
in optlines[1:]:
67 opt, help=line.split(
':')[:2]
68 short,long=opt.split(
',')[:2]
71 long=long.split(
'=')[0]
74 p.add_option(short.strip(),long.strip(),
75 action = action, help = help.strip())
76 except (IndexError,ValueError):
77 raise ParsingError(
"Cannot parse the option string correctly")
78 return p.parse_args(arglist)
84 """pack high,low 32bit unsigned int to one unsigned 64bit long long 85 Note:the print value of result number may appear signed, if the sign bit is used. 91 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low) 98 """unpack 64bit lumiid to dictionary {'run','lumisection'} 101 return {
'run':j[0],
'lumisection':j[1]}
104 if __name__ ==
'__main__':
110 if not args
and not option:
exit()
115 if ((option.tag
and option.globaltag)) ==
False:
116 print(
" NEED to provide beam spot DB tag name, or global tag")
120 elif option.globaltag:
121 globaltag = option.globaltag
122 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' 123 outcmd = commands.getstatusoutput( cmd )
126 tagname = atag.replace(
"tag:",
"")
127 print(
" Global tag: "+globaltag+
" includes the beam spot tag: "+tagname)
131 destDB =
'frontier://PromptProd/CMS_COND_31X_BEAMSPOT' 133 destDB = option.destDB
135 auth =
'/afs/cern.ch/cms/DB/conddb' 153 readdb_out =
"readDB_"+tagname+
".py" 155 rnewfile = open(readdb_out,
'w')
158 import FWCore.ParameterSet.Config as cms 160 process = cms.Process("readDB") 161 process.load("FWCore.MessageLogger.MessageLogger_cfi") 163 process.load("CondCore.DBCommon.CondDBSetup_cfi") 165 process.BeamSpotDBSource = cms.ESSource("PoolDBESSource", 167 toGet = cms.VPSet(cms.PSet( 168 record = cms.string('BeamSpotObjectsRcd'), 170 rnewfile.write(
'tag = cms.string(\''+tagname+
'\')\n')
171 rnewfile.write(
')),\n')
172 rnewfile.write(
'connect = cms.string(\''+destDB+
'\')\n')
181 rnewfile.write(
'process.BeamSpotDBSource.DBParameters.authenticationPath = cms.untracked.string(\"'+auth +
'\")')
185 process.source = cms.Source("EmptySource", 186 numberEventsInRun = cms.untracked.uint32(1), 188 rnewfile.write(
' firstRun = cms.untracked.uint32('+ run +
'),\n')
189 rnewfile.write(
' firstLuminosityBlock = cms.untracked.uint32('+ lumi +
')\n')
193 process.maxEvents = cms.untracked.PSet( 194 input = cms.untracked.int32(1) 196 process.beamspot = cms.EDAnalyzer("BeamSpotFromDB") 199 process.p = cms.Path(process.beamspot) 204 status_rDB = commands.getstatusoutput(
'cmsRun '+ readdb_out)
206 outtext = status_rDB[1]
S & print(S &os, JobReport::InputFile const &f)
def parse(docstring, arglist=None)