20def configureFlagsAndArgsFromPartition(flags, args, partition, log):
21 """
22 Configure the flags and args from partition in online
23
24 Configure the following flags from partition in online:
25 run type, run number, beam type, beam energy, project
26
27 Configure the following args from partition in online: args.nsamples
28 """
29
30 from ipc import IPCPartition
31 from ispy import ISObject
32 ipcPartition = IPCPartition(partition)
33 if not ipcPartition.isValid():
34 log.error('Partition: ' + ipcPartition.name() + ' is not valid')
35 sys.exit(1)
36
37
38 runType = 'Physics'
39 beamType = 'collisions'
40 beamEnergy = 200 * GeV
41 runNumber = 2400000
42 project = 'data_H8'
43
44 try:
45 runParams = ISObject(ipcPartition, 'RunParams.SOR_RunParams', 'RunParams')
46 except Exception:
47 log.warning(f'No Run Parameters in IS => Set defaults: partition: {partition}, beam type: {beamType}'
48 + f', beam energy: {beamEnergy}, run number: {runNumber}, project tag: {project}')
49 else:
50 runParams.checkout()
51 beamType = runParams.beam_type
52 beamEnergy = runParams.beam_energy * GeV
53 runNumber = runParams.run_number
54 project = runParams.T0_project_tag
55 runType = runParams.run_type
56 log.info(f'RUN CONFIGURATION: run type: {runType}, beam type: {beamType}'
57 + f', beam energy: {beamEnergy}, run number: {runNumber}, project: {project}')
58
59 try:
60 cisParams = ISObject(ipcPartition, 'TileParams.cispar', 'TileCISparameters')
61 except Exception:
62 log.info('Could not find Tile Parameters in IS')
63 else:
64 try:
65 cisParams.checkout()
66 except Exception:
67 log.info("Could not get Tile Parameters from IS")
68 else:
69 log.info(f'TILE CONFIGURATION: CISPAR size: {len(cisParams.data)}')
70 cispar = 'TILE CONFIGURATION: CISPAR: '
71 for d in cisParams.data:
72 cispar += ' ' + str(d)
73 log.info(cispar)
74
75 if len(cisParams.data) == 16:
76 data = cisParams.data
77 if data[12] == 1:
78 runType = 'Physics'
79 elif data[12] == 2:
80 runType = 'Laser'
81 elif data[12] == 4:
82 runType = 'Pedestals'
83 elif data[12] == 8:
84 runType = runType if 'mono' in runType else 'CIS'
85
86 log.info(f'TILE CONFIGURATION: RunType: {runType}, Mode: {data[0]}, Samples: {data[1]}, Pipeline: {data[2]}'
87 + f', I3Delay: {data[3]}, Event: {data[4]}, Phase: {data[5]}, DAC: {data[6]}, Capacity: {data[7]}')
88
89
90 nSamples = 15
91 try:
92 dspConfig = ISObject(ipcPartition, 'TileParams.TileCal_DSPConfig', 'TileCal_IS_DSPConfig')
93 except Exception:
94 log.info(f"Could not find Tile DSP Config in IS => set default number of samples to {nSamples}")
95 else:
96 try:
97 dspConfig.checkout()
98 except Exception:
99 log.info(f"Could not get Tile DSP Config from IS => set default number of samples to {nSamples}")
100 else:
101 nSamples = dspConfig.samples
102 log.info(f"Set number of samples from DSP Config in IS: {nSamples}")
103
104 if 'Physics' in runType:
105 flags.Tile.RunType = TileRunType.PHY
106 elif 'CIS' in runType:
107 flags.Tile.RunType = TileRunType.MONOCIS if 'mono' in runType else TileRunType.CIS
108 elif 'Laser' in runType:
109 flags.Tile.RunType = TileRunType.LAS
110 elif 'Pedestals' in runType:
111 flags.Tile.RunType = TileRunType.PED
112
113 if beamType in ['collisions', 'singlebeam', 'cosmics', 'testbeam']:
114 flags.Beam.Type = BeamType(beamType)
115
116 flags.Beam.Energy = beamEnergy if beamEnergy > 1 * GeV else 200 * GeV
117 flags.Input.ProjectName = project
118 flags.Input.RunNumbers = [runNumber]
119 args.nsamples = nSamples
120
121