File indexing completed on 2026-04-27 07:41:40
0001
0002
0003 from pathlib import Path
0004 from datetime import datetime
0005 import subprocess
0006 import sys
0007 import shutil
0008 import math
0009 from typing import Tuple,List
0010
0011 from sphenixdbutils import cnxn_string_map, dbQuery
0012
0013
0014
0015
0016 def shell_command(command: str) -> List[str]:
0017 """Minimal wrapper to hide away subbprocess tedium"""
0018
0019 ret=[]
0020 try:
0021 ret = subprocess.run(command, shell=True, check=True, capture_output=True).stdout.decode('utf-8').split()
0022 except subprocess.CalledProcessError as e:
0023 print("[shell_command] Command failed with exit code:", e.returncode)
0024 finally:
0025 pass
0026
0027 return ret
0028
0029
0030 def my_parse_spiderstuff(filename: str) -> Tuple[str,...] :
0031 try:
0032
0033 lfn = filename
0034 lfn=Path(lfn).name
0035 except Exception as e:
0036 print(f"Error: {e}")
0037 print(filename)
0038 print(filename.split(':'))
0039 exit(-1)
0040
0041 return lfn,-1,-1,-1,-1,-1
0042
0043
0044 def my_parse_lfn(lfn: str, outtriplet:str ):
0045 try:
0046 name=lfn.split(':')[0]
0047 name=Path(name).name
0048
0049 dsttype,runsegend=name.split(f'_run3auau_{outtriplet}')
0050 _,run,segend=runsegend.split('-')
0051 seg,end=segend.split('.')
0052 except ValueError as e:
0053 print(f"[parse_lfn] Caught error {e}")
0054 print(f"lfn = {lfn}")
0055 exit(-1)
0056 return dsttype,int(run),int(seg),end
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 update_files_tmpl="""
0087 update files
0088 set full_file_path='{full_file_path}'
0089 where lfn='{lfn}'
0090 ;
0091 """
0092
0093
0094
0095 def main():
0096 rungroup_tmpl = "run_{a:08d}_{b:08d}"
0097
0098 prod='physics'
0099 if prod=='physics':
0100 prodname='run3auau'
0101 elif prod=='cosmics':
0102 prodname='run3cosmics'
0103 elif prod=='line_laser':
0104 prodname='run3line_laser'
0105 else:
0106 print("don't know that prod")
0107 exit(-1)
0108
0109
0110 type='DST_STREAMING'
0111 outtriplet='new_nocdbtag_v001'
0112 if 'TRKR' in type:
0113 outtriplet='new_newcdbtag_v001'
0114 wrongdir=f'/sphenix/lustre01/sphnxpro/production/run3auau/{prod}/{outtriplet}'
0115 print(wrongdir)
0116 exit()
0117
0118 dpattern=f'{type}_\*'
0119
0120 cmd=f'find {wrongdir} -maxdepth 1 -type d -name {dpattern}'
0121 tdirs=shell_command(cmd)
0122 for tdir in tdirs:
0123 cmd=f'find {tdir} -maxdepth 1 -type d -name run_\*'
0124 rdirs=shell_command(cmd)
0125 for rdir in rdirs:
0126 print('--- Working on {rdir}')
0127 chunksize=10000
0128 chunkcmd = f'/usr/bin/ls -1 {rdir} | grep -v :: | head -n {chunksize}'
0129 while True:
0130 chunk=shell_command(chunkcmd)
0131 if len(chunk)==0:
0132 break
0133 for lfn in chunk:
0134 dsttype,run,seg,_=my_parse_lfn(lfn,outtriplet=outtriplet)
0135 leaf=dsttype.split(f"_{prodname}")[0]
0136 rungroup=rungroup_tmpl.format(a=100*math.floor(run/100), b=100*math.ceil((run+1)/100))
0137
0138
0139 exit()
0140
0141 foundhists = [ file for file in tmpfound ]
0142 print(f"Found {len(foundhists)} histograms to register and move.")
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185 if __name__ == '__main__':
0186 main()
0187 exit(0)
0188
0189
0190
0191