/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Mdc/DedxCalibAlg/DedxCalibAlg-00-01-15/share/shell/prepareCalib.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import os
00004 import sys
00005 
00006 calipath = os.environ["dedx"] + "/calib"
00007 configpath = os.environ["dedx"] + "/template/configure/"
00008 os.chdir(calipath)
00009 # prepare config dictionary
00010 config_filename = raw_input("Plase input the configure file name, which should be save at " + configpath )
00011 print "The config file is: " + config_filename
00012 config_file = open(configpath + config_filename, "r")
00013 line = config_file.readline()
00014 dict = {}
00015 while line:
00016     line = line.strip()
00017     break_line = line.split(" ");
00018     key = break_line[0]
00019     word = break_line[1]
00020     dict[key] = word
00021     print key + "  " + word
00022     line = config_file.readline()
00023 # mkdir directories
00024 bossversion = dict['bossversion']
00025 minrun = dict['minrun']
00026 maxrun = dict['maxrun']
00027 if(bossversion==""):
00028     bossversion = os.environ['bossversion']
00029 if not os.path.exists(bossversion):
00030    os.mkdir(bossversion)
00031 os.chdir(bossversion)
00032 strrun = minrun + "-" + maxrun
00033 if not os.path.exists(strrun):
00034    os.mkdir(strrun)
00035 os.chdir(strrun)
00036 
00037 
00038 os.system("cp $dedx/template/README ./")
00039 
00040 def replace_lines(path, dict):
00041     if not "check" in path:
00042         os.system("cp -rp $dedx/template/" + path + " ./")
00043     os.chdir(path)
00044     filenames = os.listdir("./")
00045     for filename in filenames:
00046         if(filename == "check"):
00047             replace_lines("check", dict)
00048         if("~" in filename):
00049             os.system("rm " + filename)
00050         elif(".txt" in filename or ".py" in filename or ".sh" in filename or ".csh" in filename or ".cxx" in filename):
00051             file = open(filename, "r")
00052             output = open("temp", "w")
00053             line = file.readline()
00054             while line:
00055                 for key in dict:
00056                     if(line.find(key)>-1):
00057                         line = line.replace(key,dict[key])
00058                         line = line + "\n" 
00059                 output.write(line)
00060                 line = file.readline()
00061             file.close()
00062             output.close()
00063             os.system("mv temp " + filename)
00064     os.chdir("../")
00065 
00066 pathlist = ["genNtuple", "select", "genNtuple_rBB", "FirstRung", "WireGain", "DocaEangle", "Eangle1D", "Costheta", "Eangle1DSec", "RungEangle", "CheckRung", "hadron_roots", "hadron_rawfiles", "hadron_recfiles"]
00067 
00068 for crpath in pathlist:
00069     if not os.path.exists(crpath):
00070         replace_lines(crpath, dict)
00071 
00072 
00073 
00074 

Generated on Tue Nov 29 23:12:45 2016 for BOSS_7.0.2 by  doxygen 1.4.7