File indexing completed on 2024-04-06 12:03:27
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 3.8,
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('Fullname',
0029 None,
0030 opts.VarParsing.multiplicity.singleton,
0031 opts.VarParsing.varType.string,
0032 'The entire filename in case the options above are insufficient, i.e. "SiPixelTemplateDBObject_phase1_EoR3_HV600_Tr2000", etc.')
0033 options.register('Map',
0034 '../data/template1D_IOV0_preMC/IOV0_phase1_preMC_map.csv',
0035 opts.VarParsing.multiplicity.singleton,
0036 opts.VarParsing.varType.string,
0037 'Path to map file')
0038 options.register('Delimiter',
0039 ',',
0040 opts.VarParsing.multiplicity.singleton,
0041 opts.VarParsing.varType.string,
0042 'Delimiter in csv file')
0043 options.register('Quotechar',
0044 '"',
0045 opts.VarParsing.multiplicity.singleton,
0046 opts.VarParsing.varType.string,
0047 'Quotechar in csv file')
0048 options.register('TemplateFilePath',
0049 'CondTools/SiPixel/data/template1D_IOV0_preMC',
0050 opts.VarParsing.multiplicity.singleton,
0051 opts.VarParsing.varType.string,
0052 'Location of template files')
0053 options.register('GlobalTag',
0054 'auto:phase1_2017_realistic',
0055 opts.VarParsing.multiplicity.singleton,
0056 opts.VarParsing.varType.string,
0057 'Global tag for this run')
0058 options.register('useVectorIndices',
0059 False,
0060 opts.VarParsing.multiplicity.singleton,
0061 opts.VarParsing.varType.bool,
0062 'Switch on in case Morris uses vector indices in csv file, eg. [0,(N-1)] instead of [1,N]')
0063 options.parseArguments()
0064
0065 MagFieldValue = 10.*options.MagField
0066 print('\nMagField = %f deciTesla \n'%(MagFieldValue))
0067 version = options.Version
0068 print('\nVersion = %s \n'%(version))
0069 magfieldstrsplit = str(options.MagField).split('.')
0070 MagFieldString = magfieldstrsplit[0]
0071 if len(magfieldstrsplit)>1 :
0072 MagFieldString+=magfieldstrsplit[1]
0073
0074
0075 mapfile = open(options.Map,'r', newline='')
0076
0077 mapfilereader = csv.reader(mapfile,delimiter=options.Delimiter,quotechar=options.Quotechar)
0078
0079 barrel_rule_lines = []; endcap_rule_lines = []
0080 barrel_exception_lines = []; endcap_exception_lines = []
0081 sections = [barrel_rule_lines, endcap_rule_lines, barrel_exception_lines, endcap_exception_lines]
0082 i=0; line = next(mapfilereader)
0083 for i in range(len(sections)) :
0084 while line[0].find('TEMPLATE ID')==-1 :
0085 line=next(mapfilereader)
0086 try :
0087 line=next(mapfilereader)
0088 except StopIteration :
0089 print('Done reading input file')
0090 break
0091 while line[1]!='' :
0092 sections[i].append(line)
0093 try :
0094 line=next(mapfilereader)
0095 except StopIteration :
0096 print('Done reading input file')
0097 break
0098
0099
0100 barrel_locations = []
0101 barrel_template_IDs = []
0102 endcap_locations = []
0103 endcap_template_IDs = []
0104 template_filenames = []
0105 prefix = options.TemplateFilePath+'/template_summary_zp'
0106 suffix = '.out'
0107 for s in range(len(sections)) :
0108 for line in sections[s] :
0109
0110 template_ID_s = line[0]
0111 while len(template_ID_s)<4 :
0112 template_ID_s='0'+template_ID_s
0113 newtemplatefilename = prefix+template_ID_s+suffix
0114 template_ID = int(template_ID_s)
0115 if not newtemplatefilename in template_filenames :
0116 template_filenames.append(newtemplatefilename)
0117 if s%2==0 :
0118 lay, lad, mod = line[1], line[2], line[3]
0119
0120
0121 laysplit = lay.split('-'); firstlay=int(laysplit[0]); lastlay= int(laysplit[1])+1 if len(laysplit)>1 else firstlay+1
0122 for i in range(firstlay,lastlay) :
0123 lay_string = str(i)+'_'
0124 ladsplit = lad.split('-'); firstlad=int(ladsplit[0]); lastlad= int(ladsplit[1])+1 if len(ladsplit)>1 else firstlad+1
0125 for j in range(firstlad,lastlad) :
0126 lad_string = lay_string+str(j)+'_'
0127 modsplit = mod.split('-'); firstmod=int(modsplit[0]); lastmod= int(modsplit[1])+1 if len(modsplit)>1 else firstmod+1
0128 for k in range(firstmod,lastmod) :
0129 location_string = lad_string+str(k)
0130 if s==0 :
0131
0132 barrel_locations.append(location_string)
0133 barrel_template_IDs.append(template_ID)
0134 else :
0135 location_index = barrel_locations.index(location_string)
0136 barrel_template_IDs[location_index]=template_ID
0137 else :
0138 disk, blade, side, panel = line[1], line[2], line[3], line[4]
0139
0140 disksplit = disk.split('-'); firstdisk=int(disksplit[0]); lastdisk = int(disksplit[1])+1 if len(disksplit)>1 else firstdisk+1
0141 for i in range(firstdisk,lastdisk) :
0142 disk_string = str(i)+'_'
0143 bladesplit = blade.split('-'); firstblade=int(bladesplit[0]); lastblade = int(bladesplit[1])+1 if len(bladesplit)>1 else firstblade+1
0144 for j in range(firstblade,lastblade) :
0145 blade_string = disk_string+str(j)+'_'
0146 sidesplit = side.split('-'); firstside=int(sidesplit[0]); lastside = int(sidesplit[1])+1 if len(sidesplit)>1 else firstside+1
0147 for k in range(firstside,lastside) :
0148 side_string = blade_string+str(k)+'_'
0149 panelsplit = panel.split('-'); firstpanel=int(panelsplit[0]); lastpanel = int(panelsplit[1])+1 if len(panelsplit)>1 else firstpanel+1
0150 for m in range(firstpanel,lastpanel) :
0151 location_string = side_string+str(m)
0152 if s==1 :
0153 endcap_locations.append(location_string)
0154 endcap_template_IDs.append(template_ID)
0155 else :
0156 location_index = endcap_locations.index(location_string)
0157 endcap_template_IDs[location_index]=template_ID
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 from Configuration.StandardSequences.Eras import eras
0171
0172 process = cms.Process("SiPixelTemplateDBUpload",eras.Run2_2017)
0173 process.load("CondCore.CondDB.CondDB_cfi")
0174 process.load("FWCore.MessageService.MessageLogger_cfi")
0175 process.MessageLogger = cms.Service("MessageLogger",
0176 destinations = cms.untracked.vstring('SiPixelTemplateDBObjectUploader.log'))
0177 process.load('Configuration.Geometry.GeometryExtended2017Reco_cff')
0178 process.load('Configuration.Geometry.GeometryExtended2017_cff')
0179 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0180 from Configuration.AlCa.GlobalTag import GlobalTag
0181 process.GlobalTag = GlobalTag(process.GlobalTag, options.GlobalTag, '')
0182
0183 template_base=''
0184 if options.Fullname!=None :
0185 template_base=options.Fullname
0186 else :
0187 template_base = 'SiPixelTemplateDBObject_phase1_'+MagFieldString+'T_'+options.Year+'_v'+version
0188 if options.Append!=None :
0189 template_base+='_'+options.Append
0190
0191 sqlitefilename = 'sqlite_file:'+template_base+'.db'
0192
0193 print('\nUploading %s with record SiPixelTemplateDBObjectRcd in file %s\n' % (template_base,sqlitefilename))
0194
0195 process.source = cms.Source("EmptyIOVSource",
0196 timetype = cms.string('runnumber'),
0197 firstValue = cms.uint64(1),
0198 lastValue = cms.uint64(1),
0199 interval = cms.uint64(1)
0200 )
0201 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))
0202 process.PoolDBOutputService = cms.Service("PoolDBOutputService",
0203 DBParameters = cms.PSet(
0204 messageLevel = cms.untracked.int32(0),
0205 authenticationPath = cms.untracked.string('.')
0206 ),
0207 timetype = cms.untracked.string('runnumber'),
0208 connect = cms.string(sqlitefilename),
0209 toPut = cms.VPSet(cms.PSet(
0210 record = cms.string('SiPixelTemplateDBObjectRcd'),
0211 tag = cms.string(template_base)
0212 )
0213 )
0214 )
0215 process.uploader = cms.EDAnalyzer("SiPixelTemplateDBObjectUploader",
0216 siPixelTemplateCalibrations = cms.vstring(template_filenames),
0217 theTemplateBaseString = cms.string(template_base),
0218 Version = cms.double(3.0),
0219 MagField = cms.double(MagFieldValue),
0220 detIds = cms.vuint32(1,2),
0221 barrelLocations = cms.vstring(barrel_locations),
0222 endcapLocations = cms.vstring(endcap_locations),
0223 barrelTemplateIds = cms.vuint32(barrel_template_IDs),
0224 endcapTemplateIds = cms.vuint32(endcap_template_IDs),
0225 useVectorIndices = cms.untracked.bool(options.useVectorIndices),
0226 )
0227 process.myprint = cms.OutputModule("AsciiOutputModule")
0228 process.p = cms.Path(process.uploader)
0229 process.CondDB.connect = sqlitefilename
0230 process.CondDB.DBParameters.messageLevel = 0
0231 process.CondDB.DBParameters.authenticationPath = './'