CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
makeHippyCampaign Namespace Reference

Functions

def cd
 
def cmsenv
 
def main
 
def mkdir_p
 

Variables

string basedir = "/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy"
 
tuple thisfile = os.path.abspath(__file__)
 

Function Documentation

def makeHippyCampaign.cd (   newdir)
http://stackoverflow.com/a/24176022/5228524

Definition at line 120 of file makeHippyCampaign.py.

Referenced by main().

121 def cd(newdir):
122  """http://stackoverflow.com/a/24176022/5228524"""
123  prevdir = os.getcwd()
124  os.chdir(os.path.expanduser(newdir))
125  try:
126  yield
127  finally:
128  os.chdir(prevdir)
def makeHippyCampaign.cmsenv ( )

Definition at line 129 of file makeHippyCampaign.py.

References submitPVValidationJobs.split().

Referenced by main().

130 def cmsenv():
131  output = subprocess.check_output(["scram", "ru", "-sh"])
132  for line in output.split(";\n"):
133  if not line.strip(): continue
134  match1 = re.match(r'^export (\w*)="([^"]*)"$', line)
135  match2 = re.match(r'^unset *((\w* *)*)$', line)
136  if match1:
137  variable, value = match1.groups()
138  os.environ[variable] = value
139  elif match2:
140  for variable in match2.group(1).split():
141  del os.environ[variable]
142  else:
143  raise ValueError("Bad scram ru -sh line:\n"+line)
144  sys.path[:] = eval(subprocess.check_output([thisfile, "dummy", "--print-sys-path"]))
def makeHippyCampaign.main ( )

Definition at line 18 of file makeHippyCampaign.py.

References cd(), cmsenv(), and mkdir_p().

18 
19 def main():
20  parser = argparse.ArgumentParser()
21  parser.add_argument("foldername", help="folder name for the campaign. Example: CRUZET20xy")
22  parser.add_argument("--cmssw", default=os.environ["CMSSW_VERSION"])
23  parser.add_argument("--scram-arch", default=os.environ["SCRAM_ARCH"])
24  parser.add_argument("--subfolder", default="", help="subfolder within "+basedir+" to make 'foldername' in.")
25  parser.add_argument("--merge-topic", action="append", help="things to cms-merge-topic within the CMSSW release created", default=[])
26  parser.add_argument("--print-sys-path", action="store_true", help=argparse.SUPPRESS) #internal, don't use this
27  args = parser.parse_args()
28 
29  if args.print_sys_path:
30  print repr(sys.path)
31  return
32 
33  folder = os.path.join(basedir, args.subfolder, args.foldername)
34 
35  mkdir_p(folder)
36 
37  with cd(folder):
38  if not os.path.exists(args.cmssw):
39  os.environ["SCRAM_ARCH"] = args.scram_arch
40  subprocess.check_call(["scram", "p", "CMSSW", args.cmssw])
41  with cd(args.cmssw):
42  cmsenv()
43  for _ in args.merge_topic:
44  subprocess.check_call(["git", "cms-merge-topic", _])
45  os.system("eval $(scram ru -sh) && scram b -j 10") #my cmsenv function isn't quite good enough for scram b purposes. Also, http://stackoverflow.com/a/38792806/5228524
46 
47  if os.path.exists("src/Alignment/HIPAlignmentAlgorithm"):
48  HIPAlignmentAlgorithm = os.path.abspath("src/Alignment/HIPAlignmentAlgorithm")
49  else:
50  with cd(os.environ["CMSSW_RELEASE_BASE"]):
51  HIPAlignmentAlgorithm = os.path.abspath("src/Alignment/HIPAlignmentAlgorithm")
52 
53  assert os.path.exists(HIPAlignmentAlgorithm), HIPAlignmentAlgorithm
54 
55  mkdir_p("Jobs")
56  mkdir_p("run")
57 
58  with cd("run"):
59  subprocess.check_call(["git", "init"])
60 
61  mkdir_p("Configurations")
62  with cd("Configurations"):
63  if not os.path.exists("align_tpl_py.txt"):
64  shutil.copy(os.path.join(HIPAlignmentAlgorithm, "python", "align_tpl_py.txt"), ".")
65  subprocess.check_call(["git", "add", "align_tpl_py.txt"])
66  if not os.path.exists("common_cff_py_TEMPLATE.txt"):
67  shutil.copy(os.path.join(HIPAlignmentAlgorithm, "python", "common_cff_py.txt"), "common_cff_py_TEMPLATE.txt")
68  subprocess.check_call(["git", "add", "common_cff_py_TEMPLATE.txt"])
69  mkdir_p("TrackSelection")
70  with cd("TrackSelection"):
71  for _ in glob.iglob(os.path.join(HIPAlignmentAlgorithm, "python", "*TrackSelection_cff_py.txt")):
72  if not os.path.exists(os.path.basename(_)):
73  shutil.copy(_, ".")
74  subprocess.check_call(["git", "add", os.path.basename(_)])
75 
76  mkdir_p("DataFiles")
77  with cd("DataFiles"):
78  if not os.path.exists("data_example.lst"):
79  with open("data_example.lst", "w") as f:
80  f.write(os.path.join(os.getcwd(), "minbias.txt") + ",,MBVertex,Datatype:0\n")
81  f.write(os.path.join(os.getcwd(), "cosmics.txt") + ",,COSMICS,Datatype:1 APVMode:deco Bfield:3.8T\n")
82  f.write(os.path.join(os.getcwd(), "CDCs.txt") + ",,CDCS,Datatype:1 APVMode:deco Bfield:3.8T\n")
83  subprocess.check_call(["git", "add", "data_example.lst"])
84  if not os.path.exists("baddatafiles.txt"):
85  with open("baddatafiles.txt", "w") as f:
86  f.write("If any data files are bad (e.g. not at CERN), put them here,\n")
87  f.write("separated by newlines or spaces or nothing or whatever you like.\n")
88  f.write("Anything else in this file, like these lines, will be ignored.\n")
89  f.write("You can also run hippyaddtobaddatafiles.py .../align_cfg.py to automatically\n")
90  f.write("find bad data files.\n")
91  f.write("Running jobs will automatically pick up changes here next time they resubmit.")
92 
93  mkdir_p("IOV")
94  with cd("IOV"):
95  if not os.path.exists("RunXXXXXX"):
96  with open("RunXXXXXX", "w") as f:
97  f.write("XXXXXX")
98  subprocess.check_call(["git", "add", "RunXXXXXX"])
99 
100  if not os.path.exists("submit_template.sh"):
101  shutil.copy(os.path.join(HIPAlignmentAlgorithm, "test", "hippysubmittertemplate.sh"), "submit_template.sh")
102  os.chmod("submit_template.sh", os.stat("submit_template.sh").st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
103  subprocess.check_call(["git", "add", "submit_template.sh"])
104 
105  try:
106  subprocess.check_output(["git", "diff", "--staged", "--quiet"])
107  except subprocess.CalledProcessError:
108  subprocess.check_call(["git", "commit", "-m", "commit templates"])
def makeHippyCampaign.mkdir_p (   path)
http://stackoverflow.com/a/600612/5228524

Definition at line 109 of file makeHippyCampaign.py.

Referenced by main().

110 def mkdir_p(path):
111  """http://stackoverflow.com/a/600612/5228524"""
112  try:
113  os.makedirs(path)
114  except OSError as exc:
115  if exc.errno == errno.EEXIST and os.path.isdir(path):
116  pass
117  else:
118  raise
119 
@contextlib.contextmanager

Variable Documentation

string makeHippyCampaign.basedir = "/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy"

Definition at line 14 of file makeHippyCampaign.py.

Referenced by FastTimerService::PlotsPerPath.book(), FastTimerService::PlotsPerProcess.book(), FastTimerService::PlotsPerJob.book(), DTLocalTriggerBaseTest.bookCmsHistos(), DTTriggerLutTest.bookCmsHistos1d(), DTTriggerEfficiencyTest.bookHistos(), DTLocalTriggerBaseTest.bookSectorHistos(), DTTriggerEfficiencyTest.bookWheelHistos(), DTTriggerEfficiencyTask.bookWheelHistos(), DTLocalTriggerBaseTest.bookWheelHistos(), and TrackerOfflineValidation::DirectoryWrapper.DirectoryWrapper().

tuple makeHippyCampaign.thisfile = os.path.abspath(__file__)

Definition at line 16 of file makeHippyCampaign.py.