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