Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-31 03:08:36

0001 from CondTools.CTPPS.mappings_PPSObjects_XML_cfi import *
0002 import FWCore.ParameterSet.Config as cms
0003 import os
0004 import re
0005 import subprocess
0006 import sys
0007 import shutil
0008 
0009 # Script which reads data from XML and drops objects to SQLite
0010 # Run with python3
0011 
0012 filesToWrite = [totemTiming, timingDiamond, trackingStrip, totemT2, analysisMask] 
0013 writeBothRecords = False
0014 
0015 if(len(sys.argv)>1 and sys.argv[1].lower()=='true'):
0016   writeBothRecords = True
0017 
0018 if(len(sys.argv)>2):
0019   filesToWrite = [filesMap[mapName] for mapName in sys.argv[2:]]
0020 
0021 
0022 # For each file change the variable values in the config so that they match the selected XML file and then run the config
0023 test_script = "write-ctpps-totem_daqmap_cfg.py"
0024 orig_script = os.path.join(os.path.dirname(os.path.realpath(__file__)),test_script)
0025 shutil.copyfile(orig_script, test_script)
0026 for fileContent in filesToWrite:
0027     for fileInfo in fileContent["configuration"]:
0028       with open(test_script, 'r+') as f:
0029           content = f.read()
0030           # replace values specific for selected detector
0031           content = re.sub(r'subSystemName =.*', f'subSystemName = "{fileContent["subSystemName"]}"', content)
0032           content = re.sub(r'process.CondDB.connect =.*', f'process.CondDB.connect = "{fileContent["dbConnect"]}"', content)
0033           content = re.sub(r'process.totemDAQMappingESSourceXML.multipleChannelsPerPayload =.*', 
0034                              f'process.totemDAQMappingESSourceXML.multipleChannelsPerPayload = {fileContent["multipleChannelsPerPayload"]}', 
0035                              content)
0036           content = re.sub(r'process.totemDAQMappingESSourceXML.sampicSubDetId =.*', 
0037                            f'process.totemDAQMappingESSourceXML.sampicSubDetId = {fileInfo["sampicSubDetId"]}',
0038                            content)
0039           
0040           # replace values specific for selected files
0041           content = re.sub(r'minIov =.*', f'minIov = {fileInfo["validityRange"].start()}', content)
0042           content = re.sub(r'maxIov =.*', f'maxIov = {fileInfo["validityRange"].end()}', content)
0043           content = re.sub(r'mappingFileNames =.*', f'mappingFileNames = {fileInfo["mappingFileNames"]},', content)
0044           content = re.sub(r'maskFileNames =.*', f'maskFileNames = {fileInfo["maskFileNames"]},', content)
0045           
0046           
0047           mapRcd = ''
0048           maskRcd = ''
0049           if writeBothRecords or fileContent != analysisMask:
0050             mapRcd = 'TotemReadoutRcd'
0051           if writeBothRecords or fileContent == analysisMask:
0052             maskRcd = 'TotemAnalysisMaskRcd'
0053             
0054             
0055           content = re.sub(r'recordMap = cms.string.*', f"recordMap = cms.string('{mapRcd}'),", content)
0056           content = re.sub(r'recordMask = cms.string.*', f"recordMask = cms.string('{maskRcd}'),", content)
0057             
0058             
0059           f.seek(0)
0060           f.write(content)
0061           f.truncate()
0062             
0063             
0064       subprocess.run(f'cmsRun ./{test_script}' , shell=True)
0065