Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-17 01:40:51

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/template1D_IOV0_phase1_MC/IOV0_phase1_MC_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('GenErrFilePath',
0044                      'CondTools/SiPixel/data/template1D_IOV0_phase1_MC',
0045                      opts.VarParsing.multiplicity.singleton,
0046                      opts.VarParsing.varType.string,
0047                      'Location of generr files')
0048 options.register('GlobalTag',
0049                      'auto:phase2_realistic',
0050                      opts.VarParsing.multiplicity.singleton,
0051                      opts.VarParsing.varType.string,
0052                      'Global tag for this run')
0053 options.register('useVectorIndices',
0054                      False,
0055                      opts.VarParsing.multiplicity.singleton,
0056                      opts.VarParsing.varType.bool,
0057                      'Switch on in case Morris uses vector indices in csv file, eg. [0,(N-1)] instead of [1,N]')
0058 options.register('geometry',
0059                  'T5',
0060                  opts.VarParsing.multiplicity.singleton,
0061                  opts.VarParsing.varType.string,
0062                  'Tracker Geometry Default = T5')
0063 options.parseArguments()
0064 
0065 MagFieldValue = 10.*options.MagField #code needs it in deciTesla
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 #open the map file
0075 mapfile = open(options.Map,'r', newline='')
0076 #read the csv file into a reader
0077 mapfilereader = csv.reader(mapfile,delimiter=options.Delimiter,quotechar=options.Quotechar)
0078 #separate into the different sections
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 : #skip to just before the section of info
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]!='' : #add the lines that are the barrel rules
0092         sections[i].append(line) 
0093         try :
0094             line=next(mapfilereader)
0095         except StopIteration :
0096             print('Done reading input file')
0097             break
0098 #print 'barrel rules = %s\nendcap rules = %s\nbarrel exceptions = %s\nendcap exceptions = %s'%(barrel_rule_lines,endcap_rule_lines,barrel_exception_lines,endcap_exception_lines) #DEBUG
0099 #Make the lists of location strings and template IDs
0100 barrel_locations = []
0101 barrel_generr_IDs = []
0102 endcap_locations = []
0103 endcap_generr_IDs = []
0104 template_filenames = []
0105 prefix = options.GenErrFilePath+'/generror_summary_zp'
0106 suffix = '.out'
0107 for s in range(len(sections)) :
0108     for line in sections[s] :
0109     #   print 'reading line: %s'%(line) #DEBUG
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     #       print ' lay = %s, lad = %s, mod = %s'%(lay, lad, mod) #DEBUG
0120             #barrel ID strings are "layer_ladder_module"
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     #                       print ' Adding with location string "%s" and template ID %d'%(location_string,template_ID) #DEBUG
0132                             barrel_locations.append(location_string)
0133                             barrel_generr_IDs.append(template_ID)
0134                         else :
0135                             location_index = barrel_locations.index(location_string)
0136                             barrel_generr_IDs[location_index]=template_ID
0137         else : 
0138             disk, blade, side, panel = line[1], line[2], line[3], line[4]
0139             #endcap ID strings are "disk_blade_side_panel_plaquette"
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_generr_IDs.append(template_ID)
0155                             else :
0156                                 location_index = endcap_locations.index(location_string)
0157                                 endcap_generr_IDs[location_index]=template_ID
0158 #Debug print out assignments
0159 #print 'BARREL ASSIGNMENTS:' #DEBUG
0160 #for i in range(len(barrel_locations)) : #DEBUG
0161 #   tempid = barrel_generr_IDs[i] #DEBUG
0162 #   lay, lad, mod = barrel_locations[i].split('_')[0], barrel_locations[i].split('_')[1], barrel_locations[i].split('_')[2] #DEBUG
0163 #   print ' layer %s, ladder %s, module %s will have template ID %d assigned to it'%(lay,lad,mod,tempid) #DEBUG
0164 #print 'ENDCAP ASSIGNMENTS:' #DEBUG
0165 #for i in range(len(endcap_locations)) : #DEBUG
0166 #   tempid = endcap_generr_IDs[i] #DEBUG
0167 #   disk, blade, side = endcap_locations[i].split('_')[0], endcap_locations[i].split('_')[1], endcap_locations[i].split('_')[2], endcap_locations[i].split('_')[3] #DEBUG
0168 #   print ' disk %s, blade %s, side %s, panel %s will have template ID %d assigned to it'%(disk,blade,side,panel,tempid) #DEBUG
0169 
0170 from Configuration.StandardSequences.Eras import eras
0171 
0172 process = cms.Process("SiPixelGenErrorDBUpload",eras.Phase2)#C2)
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('SiPixelGenErrorDBObjectUploader_Phase2.log'))
0177 
0178 geometry_cff = ''
0179 recoGeometry_cff = ''
0180 tGeometry = options.geometry
0181 if tGeometry == 'T5':
0182     geometry_cff = 'GeometryExtended2026D17_cff'
0183     recoGeometry_cff = 'GeometryExtended2026D17Reco_cff'
0184     LA_value = 0.106
0185     tag = 'SiPixelLorentzAngle_Phase2_T5'
0186 elif tGeometry == 'T6':
0187     geometry_cff = 'GeometryExtended2026D35_cff'
0188     recoGeometry_cff = 'GeometryExtended2026D35Reco_cff'
0189 elif tGeometry == 'T14':
0190     geometry_cff = 'GeometryExtended2026D43_cff'
0191     recoGeometry_cff = 'GeometryExtended2026D43Reco_cff'
0192 elif tGeometry == 'T15':
0193     geometry_cff = 'GeometryExtended2026D49_cff'
0194     recoGeometry_cff = 'GeometryExtended2026D49Reco_cff'
0195 elif tGeometry == 'T16':
0196     geometry_cff = 'GeometryExtended2026D48_cff'
0197     recoGeometry_cff = 'GeometryExtended2026D48Reco_cff'
0198 else:
0199     print("Unknown tracker geometry")
0200     print("What are you doing ?!?!?!?!")
0201     exit(1)
0202 geometry_cff = 'Configuration.Geometry.' + geometry_cff
0203 recoGeometry_cff = 'Configuration.Geometry.' + recoGeometry_cff
0204 process.load(geometry_cff)
0205 process.load(recoGeometry_cff)
0206 
0207 global_tag_name = options.GlobalTag+'_'+tGeometry
0208 #global_tag_name = options.GlobalTag+'_T15'
0209 
0210 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0211 from Configuration.AlCa.GlobalTag import GlobalTag
0212 process.GlobalTag = GlobalTag(process.GlobalTag, global_tag_name, '')
0213 
0214 generror_base = 'SiPixelGenErrorDBObject_phase2_'+tGeometry+'_v'+version
0215 if options.Append!=None :
0216     generror_base+='_'+options.Append
0217 #output SQLite filename
0218 sqlitefilename = 'sqlite_file:'+generror_base+'.db'
0219 
0220 print('\nUploading %s with record SiPixelGenErrorDBObjectRcd in file %s\n' % (generror_base,sqlitefilename))
0221 
0222 process.source = cms.Source("EmptyIOVSource",
0223                             timetype = cms.string('runnumber'),
0224                             firstValue = cms.uint64(1),
0225                             lastValue = cms.uint64(1),
0226                             interval = cms.uint64(1)
0227                             )
0228 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))
0229 process.PoolDBOutputService = cms.Service("PoolDBOutputService",
0230                                           DBParameters = cms.PSet(messageLevel = cms.untracked.int32(0),
0231                                                                   authenticationPath = cms.untracked.string('.')
0232                                                                 ),
0233                                           timetype = cms.untracked.string('runnumber'),
0234                                           connect = cms.string(sqlitefilename),
0235                                           toPut = cms.VPSet(cms.PSet(record = cms.string('SiPixelGenErrorDBObjectRcd'),
0236                                                                      tag = cms.string(generror_base)
0237                                                                     )
0238                                                             )
0239                                         )
0240 process.uploader = cms.EDAnalyzer("SiPixelGenErrorDBObjectUploader",
0241                                   siPixelGenErrorCalibrations = cms.vstring(template_filenames),
0242                                   theGenErrorBaseString = cms.string(generror_base),
0243                                   Version = cms.double(3.0),
0244                                   MagField = cms.double(MagFieldValue),
0245                                   detIds = cms.vuint32(1,2), #0 is for all, 1 is Barrel, 2 is EndCap
0246                                   barrelLocations = cms.vstring(barrel_locations),
0247                                   endcapLocations = cms.vstring(endcap_locations),
0248                                   barrelGenErrIds = cms.vuint32(barrel_generr_IDs),
0249                                   endcapGenErrIds = cms.vuint32(endcap_generr_IDs),
0250                                   useVectorIndices  = cms.untracked.bool(options.useVectorIndices),
0251                                 )
0252 process.myprint = cms.OutputModule("AsciiOutputModule")
0253 process.p = cms.Path(process.uploader)
0254 process.CondDB.connect = sqlitefilename
0255 process.CondDB.DBParameters.messageLevel = 0
0256 process.CondDB.DBParameters.authenticationPath = './'