####### J. Biteau, 2019-05-25 ######## ### to be executed from sedipcaa23 ### ###################################### import os import sys def copy_files(MMDD, XXXX, YYYY): if(len(MMDD)==4 and len(XXXX)==4 and len(YYYY)==4): path_data = "/data/ssd/ZFITS/2019/2019"+MMDD+"/" path_7X = "/data/NectarCAM/ZFITS/2019/2019"+MMDD+"/" #rename run XXXX.0000 into YYYY.0000 on dedippcaa74 command_74 = "ssh 10.10.4.234"+" " command_74 += "'" command_74 += "cd "+path_7X+";" command_74 += 'n=$(ls -1 *Run'+XXXX+'*.fz | wc -l); for i in $(seq 0 $(($n-1)) | tac); do s0=$(printf "%04d" $(($i))); s1=$(printf "%04d" $((2*$i+0))); mv NectarCAM.Run'+XXXX+'.$s0.fits.fz NectarCAM.Run'+YYYY+'.$s1.fits.fz; done' command_74 += "'" #rename run XXXX.0000 into YYYY.0001 on dedippcaa75 command_75 = "ssh 10.10.4.235"+" " command_75 += "'" command_75 += "cd "+path_7X+";" command_75 += 'n=$(ls -1 *Run'+XXXX+'*.fz | wc -l); for i in $(seq 0 $(($n-1)) | tac); do s0=$(printf "%04d" $(($i))); s1=$(printf "%04d" $((2*$i+1))); mv NectarCAM.Run'+XXXX+'.$s0.fits.fz NectarCAM.Run'+YYYY+'.$s1.fits.fz; done' command_75 += "'" #copy YYYY.0001 on dedippcaa74 command_data = "scp 10.10.4.235:"+path_7X+"NectarCAM.Run"+YYYY+".*.fits.fz 10.10.4.234:/data/NectarCAM/ZFITS/2019/2019"+MMDD+"/"+";" #create a directory MMDD on sedipcaa23 if does not exist command_data += "mkdir -p "+path_data+";" #copy YYYY.0000 and YYYY.0001 on sedipcaa23 command_data += "scp 10.10.4.234:"+path_7X+"NectarCAM.Run"+YYYY+".*.fits.fz "+path_data+";" #run the commands os.system(command_74) print("Renamed run "+XXXX+" into "+YYYY+" on 74") os.system(command_75) print("Renamed run "+XXXX+" into "+YYYY+" on 75") os.system(command_data) print("Copied files in data") else: print("# inputs != 3 OR # of characters per input != 4. NO COPY MADE!") def copy_files_to_server(MMDD, disk): if(len(MMDD)==4): path = "/data/ssd/ZFITS/2019/2019"+MMDD+"/" keys_input = "keys_data_2019"+MMDD+".dat" keys_output = "keys_disk_2019"+MMDD+".dat" # Generate the keys in sedipcaa23 command_server = "cd "+path+";" command_server += "md5sum *.fz > "+keys_input+";" # Copy data to disk command_server += "scp -r "+path+" 10.10.4.236:/"+disk+"/NectarCAM"+";" # Generate the keys on i3oss5 and compare to keys from data command_server += "ssh 10.10.4.236 " command_server += "'" command_server += "cd /"+disk+"/NectarCAM/2019"+MMDD+"/; md5sum *.fz > "+keys_output+";" command_server += "diff "+keys_input+" "+keys_output+" > output_diff.dat;" command_server += "';" command_server += "scp 10.10.4.236:/"+disk+"/NectarCAM/2019"+MMDD+"/output_diff.dat ."+";" os.system(command_server) print("Copied files from folder 2019"+MMDD+" on server disk "+disk) is_diff = os.path.getsize(path+"/output_diff.dat") > 0 if(not is_diff): print("---- keys match :-) ----") #clean data command_data = "rm "+path+"/output_diff.dat" os.system(command_data) #clean server command_server = "ssh 10.10.4.236 " command_server += "'" command_server += "rm /"+disk+"/NectarCAM/2019"+MMDD+"/"+keys_output+";" command_server += "rm /"+disk+"/NectarCAM/2019"+MMDD+"/output_diff.dat;" command_server += "';" os.system(command_server) else: print("---- keys do not match :-(. Check output_diff.dat ----") else: print("# of characters in DATE != 4. NO COPY MADE!") if __name__ == '__main__': if len(sys.argv) == 2: ################################################################### disk = "data03" #SHOULD BE CHANGED IF YOU WANT TO USE ANOTHER DISK# ################################################################### MMDD = sys.argv[1] #date MMDD, e.g 0529 for the 29th of May copy_files_to_server(MMDD, disk) print("### Please copy the corresponding XML file in each daily folder on i3oss5 ###") elif len(sys.argv) == 4: MMDD = sys.argv[1] #date MMDD, e.g 0529 for the 29th of May XXXX = sys.argv[2] #name of the input run, e.g. 0001 for the 1st run of the night YYYY = sys.argv[3] #name of the output run, e.g. 1260, based on the nomenclature of the shifters copy_files(MMDD, XXXX, YYYY) elif len(sys.argv) == 5: n = int(sys.argv[4]) #number of consecutive runs without interruption for i in range(n): MMDD = sys.argv[1] #date MMDD, e.g 0529 for the 29th of May XXXX = '{:04d}'.format(int(sys.argv[2])+i) #name of the input run, e.g. 0001 for the 1st run of the night YYYY = '{:04d}'.format(int(sys.argv[3])+i) #name of the output run, e.g. 1260, based on the nomenclature of the shifters copy_files(MMDD, XXXX, YYYY) else: print("") print("1) python transfer.py MMDD 000X 12XX") print(" 74+75->data #date #in #out") print("") print("2) python transfer.py MMDD 000X 12XX nruns") print(" 74+75->data #date #in #out #n") print("") print("3) python transfer.py MMDD") print(" data->server #date") print("")