File indexing completed on 2024-04-06 12:03:25
0001 import FWCore.ParameterSet.Config as cms
0002 import FWCore.ParameterSet.VarParsing as opts
0003 import csv
0004 from io import open
0005
0006 options = opts.VarParsing ('standard')
0007
0008 options.register('MagField',
0009 None,
0010 opts.VarParsing.multiplicity.singleton,
0011 opts.VarParsing.varType.float,
0012 'Magnetic field value in Tesla')
0013 options.register('Year',
0014 None,
0015 opts.VarParsing.multiplicity.singleton,
0016 opts.VarParsing.varType.string,
0017 'Current year for versioning')
0018 options.register('Version',
0019 None,
0020 opts.VarParsing.multiplicity.singleton,
0021 opts.VarParsing.varType.string,
0022 'Template DB object version')
0023 options.register('Append',
0024 None,
0025 opts.VarParsing.multiplicity.singleton,
0026 opts.VarParsing.varType.string,
0027 'Any additional string to add to the filename, i.e. "bugfix", etc.')
0028 options.register('Map',
0029 '../data/template2D_phase1_2017_IOV1/IOV1_phase1_map.csv',
0030 opts.VarParsing.multiplicity.singleton,
0031 opts.VarParsing.varType.string,
0032 'Path to map file')
0033 options.register('Delimiter',
0034 ',',
0035 opts.VarParsing.multiplicity.singleton,
0036 opts.VarParsing.varType.string,
0037 'Delimiter in csv file')
0038 options.register('Quotechar',
0039 '"',
0040 opts.VarParsing.multiplicity.singleton,
0041 opts.VarParsing.varType.string,
0042 'Quotechar in csv file')
0043 options.register('TemplateFilePath',
0044 'CondTools/SiPixel/data/template2D_phase1_2017_IOV1',
0045 opts.VarParsing.multiplicity.singleton,
0046 opts.VarParsing.varType.string,
0047 'Location of template files')
0048 options.register('GlobalTag',
0049 'auto:phase1_2017_realistic',
0050 opts.VarParsing.multiplicity.singleton,
0051 opts.VarParsing.varType.string,
0052 'Global tag for this run')
0053 options.register('numerator',
0054 False,
0055 opts.VarParsing.multiplicity.singleton,
0056 opts.VarParsing.varType.bool,
0057 'Switch on to produce the DB object for the numerators of the reweighting factors')
0058 options.register('denominator',
0059 False,
0060 opts.VarParsing.multiplicity.singleton,
0061 opts.VarParsing.varType.bool,
0062 'Switch on to produce the DB object for the denominators of the reweighting factors')
0063 options.register('useVectorIndices',
0064 False,
0065 opts.VarParsing.multiplicity.singleton,
0066 opts.VarParsing.varType.bool,
0067 'Switch on in case Morris uses vector indices in csv file, eg. [0,(N-1)] instead of [1,N]')
0068 options.parseArguments()
0069
0070 if options.numerator==False and options.denominator==False :
0071 print('ERROR: Neither numerator nor denominator option was selected. Please rerun with numerator/denominator=True options.')
0072 quit()
0073 if options.numerator==True and options.denominator==True :
0074 print('ERROR: Both numerator and denominator options are true. Please rerun with only one of numerator/denominator=True.')
0075 quit()
0076
0077 MagFieldValue = 10.*options.MagField
0078 print('\nMagField = %f deciTesla \n'%(MagFieldValue))
0079 version = options.Version
0080 print('\nVersion = %s \n'%(version))
0081 magfieldstrsplit = str(options.MagField).split('.')
0082 MagFieldString = magfieldstrsplit[0]
0083 if len(magfieldstrsplit)>1 :
0084 MagFieldString+=magfieldstrsplit[1]
0085
0086
0087 mapfile = open(options.Map,'r', newline='')
0088
0089 mapfilereader = csv.reader(mapfile,delimiter=options.Delimiter,quotechar=options.Quotechar)
0090
0091 barrel_rule_lines = []; endcap_rule_lines = []
0092 barrel_exception_lines = []; endcap_exception_lines = []
0093 sections = [barrel_rule_lines, endcap_rule_lines, barrel_exception_lines, endcap_exception_lines]
0094 i=0; line = next(mapfilereader)
0095 for i in range(len(sections)) :
0096 while line[0].find('TEMPLATE ID')==-1 :
0097 line=next(mapfilereader)
0098 try :
0099 line=next(mapfilereader)
0100 except StopIteration :
0101 print('Done reading input file')
0102 break
0103 while line[1]!='' :
0104 sections[i].append(line)
0105 try :
0106 line=next(mapfilereader)
0107 except StopIteration :
0108 print('Done reading input file')
0109 break
0110
0111
0112 barrel_locations = []
0113 barrel_template_IDs = []
0114 endcap_locations = []
0115 endcap_template_IDs = []
0116 template_filenames = []
0117 prefix = options.TemplateFilePath+'/template_summary2D_zp'
0118 suffix = '.out'
0119 for s in range(len(sections)) :
0120 for line in sections[s] :
0121
0122 template_ID_s = line[0]
0123 while len(template_ID_s)<4 :
0124 template_ID_s='0'+template_ID_s
0125 newtemplatefilename = prefix+template_ID_s+suffix
0126 template_ID = int(template_ID_s)
0127 if not newtemplatefilename in template_filenames :
0128 template_filenames.append(newtemplatefilename)
0129 if s%2==0 :
0130 lay, lad, mod = line[1], line[2], line[3]
0131
0132
0133 laysplit = lay.split('-'); firstlay=int(laysplit[0]); lastlay= int(laysplit[1])+1 if len(laysplit)>1 else firstlay+1
0134 for i in range(firstlay,lastlay) :
0135 lay_string = str(i)+'_'
0136 ladsplit = lad.split('-'); firstlad=int(ladsplit[0]); lastlad= int(ladsplit[1])+1 if len(ladsplit)>1 else firstlad+1
0137 for j in range(firstlad,lastlad) :
0138 lad_string = lay_string+str(j)+'_'
0139 modsplit = mod.split('-'); firstmod=int(modsplit[0]); lastmod= int(modsplit[1])+1 if len(modsplit)>1 else firstmod+1
0140 for k in range(firstmod,lastmod) :
0141 location_string = lad_string+str(k)
0142 if s==0 :
0143
0144 barrel_locations.append(location_string)
0145 barrel_template_IDs.append(template_ID)
0146 else :
0147 location_index = barrel_locations.index(location_string)
0148 barrel_template_IDs[location_index]=template_ID
0149 else :
0150 disk, blade, side, panel = line[1], line[2], line[3], line[4]
0151
0152 disksplit = disk.split('-'); firstdisk=int(disksplit[0]); lastdisk = int(disksplit[1])+1 if len(disksplit)>1 else firstdisk+1
0153 for i in range(firstdisk,lastdisk) :
0154 disk_string = str(i)+'_'
0155 bladesplit = blade.split('-'); firstblade=int(bladesplit[0]); lastblade = int(bladesplit[1])+1 if len(bladesplit)>1 else firstblade+1
0156 for j in range(firstblade,lastblade) :
0157 blade_string = disk_string+str(j)+'_'
0158 sidesplit = side.split('-'); firstside=int(sidesplit[0]); lastside = int(sidesplit[1])+1 if len(sidesplit)>1 else firstside+1
0159 for k in range(firstside,lastside) :
0160 side_string = blade_string+str(k)+'_'
0161 panelsplit = panel.split('-'); firstpanel=int(panelsplit[0]); lastpanel = int(panelsplit[1])+1 if len(panelsplit)>1 else firstpanel+1
0162 for m in range(firstpanel,lastpanel) :
0163 location_string = side_string+str(m)
0164 if s==1 :
0165 endcap_locations.append(location_string)
0166 endcap_template_IDs.append(template_ID)
0167 else :
0168 location_index = endcap_locations.index(location_string)
0169 endcap_template_IDs[location_index]=template_ID
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182 from Configuration.StandardSequences.Eras import eras
0183
0184 process = cms.Process("SiPixel2DTemplateDBUpload",eras.Run2_2017)
0185 process.load("CondCore.CondDB.CondDB_cfi")
0186 process.load("FWCore.MessageService.MessageLogger_cfi")
0187 process.MessageLogger = cms.Service("MessageLogger",
0188 destinations = cms.untracked.vstring('SiPixel2DTemplateDBObjectUploader.log'))
0189 process.load('Configuration.Geometry.GeometryExtended2017Reco_cff')
0190 process.load('Configuration.Geometry.GeometryExtended2017_cff')
0191 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0192 from Configuration.AlCa.GlobalTag import GlobalTag
0193 process.GlobalTag = GlobalTag(process.GlobalTag, options.GlobalTag, '')
0194
0195 template_base = 'SiPixel2DTemplateDBObject_phase1_'+MagFieldString+'T'+'_v'+version
0196 if options.numerator==True :
0197 template_base+='_num'
0198 elif options.denominator==True :
0199 template_base+='_den'
0200 if options.Append!=None :
0201 template_base+='_'+options.Append
0202
0203 sqlitefilename = 'sqlite_file:'+template_base+'.db'
0204
0205 print('\nUploading %s with record SiPixel2DTemplateDBObjectRcd in file %s\n' % (template_base,sqlitefilename))
0206
0207 process.source = cms.Source("EmptyIOVSource",
0208 timetype = cms.string('runnumber'),
0209 firstValue = cms.uint64(1),
0210 lastValue = cms.uint64(1),
0211 interval = cms.uint64(1)
0212 )
0213 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))
0214 if options.numerator==True :
0215 process.PoolDBOutputService = cms.Service("PoolDBOutputService",
0216 DBParameters = cms.PSet(messageLevel = cms.untracked.int32(0),
0217 authenticationPath = cms.untracked.string('.')
0218 ),
0219 timetype = cms.untracked.string('runnumber'),
0220 connect = cms.string(sqlitefilename),
0221 toPut = cms.VPSet(cms.PSet(record = cms.string('SiPixel2DTemplateDBObjectRcd'),
0222 tag = cms.string(template_base)
0223 )
0224 )
0225 )
0226 elif options.denominator==True :
0227 process.PoolDBOutputService = cms.Service("PoolDBOutputService",
0228 DBParameters = cms.PSet(messageLevel = cms.untracked.int32(0),
0229 authenticationPath = cms.untracked.string('.')
0230 ),
0231 timetype = cms.untracked.string('runnumber'),
0232 connect = cms.string(sqlitefilename),
0233 toPut = cms.VPSet(cms.PSet(record = cms.string('SiPixel2DTemplateDBObjectRcd'),
0234 label=cms.string('unirradiated'),
0235 tag = cms.string(template_base)
0236 )
0237 )
0238 )
0239 process.uploader = cms.EDAnalyzer("SiPixel2DTemplateDBObjectUploader",
0240 siPixelTemplateCalibrations = cms.vstring(template_filenames),
0241 theTemplateBaseString = cms.string(template_base),
0242 Version = cms.double(3.0),
0243 MagField = cms.double(MagFieldValue),
0244 detIds = cms.vuint32(1,2),
0245 barrelLocations = cms.vstring(barrel_locations),
0246 endcapLocations = cms.vstring(endcap_locations),
0247 barrelTemplateIds = cms.vuint32(barrel_template_IDs),
0248 endcapTemplateIds = cms.vuint32(endcap_template_IDs),
0249 useVectorIndices = cms.untracked.bool(options.useVectorIndices),
0250 )
0251 process.myprint = cms.OutputModule("AsciiOutputModule")
0252 process.p = cms.Path(process.uploader)
0253 process.CondDB.connect = sqlitefilename
0254 process.CondDB.DBParameters.messageLevel = 0
0255 process.CondDB.DBParameters.authenticationPath = './'