14 thisfile = os.path.abspath(__file__)
17 parser = argparse.ArgumentParser()
18 parser.add_argument(
"foldername", help=
"folder name for the campaign. Example: CRUZET20xy")
19 parser.add_argument(
"--cmssw", default=os.environ[
"CMSSW_VERSION"])
20 parser.add_argument(
"--scram-arch", default=os.environ[
"SCRAM_ARCH"])
21 parser.add_argument(
"--subfolder", default=
"", help=
"subfolder within basedir to make 'foldername' in.")
22 parser.add_argument(
"--merge-topic", action=
"append", help=
"things to cms-merge-topic within the CMSSW release created", default=[])
23 parser.add_argument(
"--print-sys-path", action=
"store_true", help=argparse.SUPPRESS)
24 parser.add_argument(
'--basedir', default=
"/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy")
25 args = parser.parse_args()
27 basedir = args.basedir
28 if not os.path.exists(basedir):
29 raise FileExistsError(
"Base Directory does not exist!")
31 if basedir[-1] ==
'/':
32 basedir = basedir[:-1]
34 if args.print_sys_path:
38 folder = os.path.join(basedir, args.subfolder, args.foldername)
43 if not os.path.exists(args.cmssw):
44 os.environ[
"SCRAM_ARCH"] = args.scram_arch
45 subprocess.check_call([
"scram",
"p",
"CMSSW", args.cmssw])
48 for _
in args.merge_topic:
49 subprocess.check_call([
"git",
"cms-merge-topic", _])
50 os.system(
"eval $(scram ru -sh) && scram b -j 10")
52 if os.path.exists(
"src/Alignment/HIPAlignmentAlgorithm"):
53 HIPAlignmentAlgorithm = os.path.abspath(
"src/Alignment/HIPAlignmentAlgorithm")
55 with
cd(os.environ[
"CMSSW_RELEASE_BASE"]):
56 HIPAlignmentAlgorithm = os.path.abspath(
"src/Alignment/HIPAlignmentAlgorithm")
58 assert os.path.exists(HIPAlignmentAlgorithm), HIPAlignmentAlgorithm
64 subprocess.check_call([
"git",
"init"])
67 with
cd(
"Configurations"):
68 if not os.path.exists(
"align_tpl_py.txt"):
69 shutil.copy(os.path.join(HIPAlignmentAlgorithm,
"python",
"align_tpl_py.txt"),
".")
70 subprocess.check_call([
"git",
"add",
"align_tpl_py.txt"])
71 if not os.path.exists(
"common_cff_py_TEMPLATE.txt"):
72 shutil.copy(os.path.join(HIPAlignmentAlgorithm,
"python",
"common_cff_py.txt"),
"common_cff_py_TEMPLATE.txt")
73 subprocess.check_call([
"git",
"add",
"common_cff_py_TEMPLATE.txt"])
75 with
cd(
"TrackSelection"):
76 for _
in glob.iglob(os.path.join(HIPAlignmentAlgorithm,
"python",
"*TrackSelection_cff_py.txt")):
77 if not os.path.exists(os.path.basename(_)):
79 subprocess.check_call([
"git",
"add", os.path.basename(_)])
83 if not os.path.exists(
"data_example.lst"):
84 with open(
"data_example.lst",
"w")
as f:
85 f.write(os.path.join(os.getcwd(),
"minbias.txt") +
",,MBVertex,Datatype:0\n")
86 f.write(os.path.join(os.getcwd(),
"cosmics.txt") +
",,COSMICS,Datatype:1 APVMode:deco Bfield:3.8T\n")
87 f.write(os.path.join(os.getcwd(),
"CDCs.txt") +
",,CDCS,Datatype:1 APVMode:deco Bfield:3.8T\n")
88 subprocess.check_call([
"git",
"add",
"data_example.lst"])
89 if not os.path.exists(
"baddatafiles.txt"):
90 with open(
"baddatafiles.txt",
"w")
as f:
91 f.write(
"If any data files are bad (e.g. not at CERN), put them here,\n")
92 f.write(
"separated by newlines or spaces or nothing or whatever you like.\n")
93 f.write(
"Anything else in this file, like these lines, will be ignored.\n")
94 f.write(
"You can also run hippyaddtobaddatafiles.py .../align_cfg.py to automatically\n")
95 f.write(
"find bad data files.\n")
96 f.write(
"Running jobs will automatically pick up changes here next time they resubmit.")
100 if not os.path.exists(
"RunXXXXXX"):
101 with open(
"RunXXXXXX",
"w")
as f:
103 subprocess.check_call([
"git",
"add",
"RunXXXXXX"])
105 if not os.path.exists(
"submit_template.sh"):
106 shutil.copy(os.path.join(HIPAlignmentAlgorithm,
"test",
"hippysubmittertemplate.sh"),
"submit_template.sh")
107 os.chmod(
"submit_template.sh", os.stat(
"submit_template.sh").st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
108 subprocess.check_call([
"git",
"add",
"submit_template.sh"])
110 if not os.path.exists(
"submit_script.sh"):
111 shutil.copy(os.path.join(HIPAlignmentAlgorithm,
"test",
"hippysubmitterscript.sh"),
"submit_script.sh")
112 os.chmod(
"submit_script.sh", os.stat(
"submit_script.sh").st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
113 subprocess.check_call([
"git",
"add",
"submit_script.sh"])
115 print(
"Dumped files into ", folder)
118 subprocess.check_output([
"git",
"diff",
"--staged",
"--quiet"])
119 except subprocess.CalledProcessError:
120 subprocess.check_call([
"git",
"commit",
"-m",
"commit templates"])
123 """http://stackoverflow.com/a/600612/5228524""" 126 except OSError
as exc:
127 if exc.errno == errno.EEXIST
and os.path.isdir(path):
132 @contextlib.contextmanager
134 """http://stackoverflow.com/a/24176022/5228524""" 135 prevdir = os.getcwd()
136 os.chdir(os.path.expanduser(newdir))
143 output = subprocess.check_output([
"scram",
"ru",
"-sh"])
144 for line
in output.decode(
'utf8').
split(
";\n"):
145 if not line.strip():
continue 146 match1 = re.match(
r'^export (\w*)="([^"]*)"$', line)
147 match2 = re.match(
r'^unset *((\w* *)*)$', line)
149 variable, value = match1.groups()
150 os.environ[variable] = value
152 for variable
in match2.group(1).
split():
153 del os.environ[variable]
155 raise ValueError(
"Bad scram ru -sh line:\n"+line)
156 sys.path[:] = eval(subprocess.check_output([thisfile,
"dummy",
"--print-sys-path"]))
158 if __name__ ==
"__main__":
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def split(sequence, size)