ATLAS Offline Software
cmake_newskeleton.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2014 CERN for the benefit of the ATLAS collaboration
2 
3 # @file PyUtils.scripts.cmt_newanalysisalg
4 # @purpose streamline and ease the creation of new athena algs
5 # @author Will Buttinger
6 # @date February 2017
7 
8 #Note - this code could use a serious rewrite, I just hacked it together to get something working
9 
10 from __future__ import with_statement
11 
12 __version__ = "$Revision: 795362 $"
13 __author__ = "Will Buttinger"
14 __doc__ = "streamline and ease the creation of new AthAnalysisAlgorithm in a new package"
15 
16 
17 import os
18 import textwrap
19 import subprocess
20 import PyUtils.acmdlib as acmdlib
21 
22 
23 
24 
25 @acmdlib.command(
26  name='cmake.new-skeleton'
27  )
28 @acmdlib.argument(
29  'pkgname',
30  help="name of the new pkg"
31  )
32 
33 
34 def main(args):
35  """create a new skeleton package
36 
37  ex:
38  $ acmd cmake new-skeleton MyPackage
39  """
40  sc = 0
41 
42  full_pkg_name = args.pkgname
43 
44  #make new package
45  res = subprocess.getstatusoutput('acmd cmake new-pkg %s' % full_pkg_name)
46  if res[0]!=0:
47  print("::: ERROR could not create new package")
48  return -1
49 
50 
51  #add algorithm
52  res = subprocess.getstatusoutput('cd %s;acmd cmake new-analysisalg --newJobo %sAlg' % (full_pkg_name,full_pkg_name))
53  if res[0]!=0:
54  print("::: ERROR could not create new alg")
55  return -1
56 
57  pkg_name = full_pkg_name
58 
59  # overwrite CMakeLists with our skeleton
60  with open(os.path.join(full_pkg_name,'CMakeLists.txt'), 'w') as req:
61  print(textwrap.dedent("""\
62  ## automatically generated CMakeLists.txt file
63 
64  # Declare the package
65  atlas_subdir( %(pkg_name)s )
66 
67  # Declare external dependencies ... default here is to include ROOT
68  find_package( ROOT COMPONENTS MathCore RIO Core Tree Hist )
69 
70  # Declare package as a library
71  # Note the convention that library names get "Lib" suffix
72  # Any package you depend on you should add
73  # to LINK_LIBRARIES line below (see the example)
74  atlas_add_library( %(pkg_name)sLib src/*.cxx
75  PUBLIC_HEADERS %(pkg_name)s
76  INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
77  LINK_LIBRARIES ${ROOT_LIBRARIES}
78  AthAnalysisBaseCompsLib
79  )
80 
81  # if you add athena components (tools, algorithms) to this package
82  # these lines are needed so you can configure them in joboptions
83  atlas_add_component( %(pkg_name)s src/components/*.cxx
84  NOCLIDDB
85  LINK_LIBRARIES %(pkg_name)sLib
86  )
87 
88  # if you add an application (exe) to this package
89  # declare it like this (note convention that apps go in the util dir)
90  # atlas_add_executable( MyApp util/myApp.cxx
91  # LINK_LIBRARIES %(pkg_name)sLib
92  # )
93 
94  # Install python modules, joboptions, and share content
95  atlas_install_python_modules( python/*.py )
96  atlas_install_joboptions( share/*.py )
97  atlas_install_data( data/* )
98  atlas_install_scripts( scripts/* )
99  # You can access your data from code using path resolver, e.g.
100  # PathResolverFindCalibFile("%(pkg_name)s/file.txt")
101 
102 
103  """%locals()), file=req)
104 
105 
106 
107 
108  #need to reconfigure cmake so it knows about the new files
109  #rely on the WorkDir_DIR env var for this
110 # workDir = os.environ.get("WorkDir_DIR")
111 # if workDir == None:
112 # print("::: ERROR No WorkDir_DIR env var, did you forget to source the setup.sh script?")
113 # print("::: ERROR Please do this and reconfigure cmake manually!")
114 # else:
115 # print("::: INFO Reconfiguring cmake %s/../." % workDir)
116 # res = subprocess.getstatusoutput('cmake %s/../.' % workDir)
117 # if res[0]!=0:
118 # print ("::: WARNING reconfigure unsuccessful. Please reconfigure manually!")
119 
120 
python.scripts.cmake_newskeleton.main
def main(args)
Definition: cmake_newskeleton.py:34
Trk::open
@ open
Definition: BinningType.h:40
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70