|
ATLAS Offline Software
|
◆ dictionaryClasses()
def python.Helpers.dictionaryClasses |
( |
|
filenames | ) |
|
Function collecting the class names to create a dictionary for.
This function can parse all headers of the generated sources to collect the class names for which a CINT dictionary should be generated.
- Parameters
-
filenames | Header file names (as returned by dictionaryHeaders(...) ) |
- Returns
- A list with the class names
Definition at line 80 of file PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py.
83 from AthenaCommon.Logging
import logging
84 logger = logging.getLogger(
"dictionaryClasses" )
87 classnames = [
"D3PDReader::VarHandleBase",
88 "D3PDReader::VarProxyBase",
89 "D3PDReader::VariableStats",
90 "D3PDReader::D3PDReadStats",
91 "map<TString,D3PDReader::VariableStats>",
92 "pair<TString,D3PDReader::VariableStats>",
93 "map<TString,D3PDReader::VarHandleBase*>",
94 "pair<TString,D3PDReader::VarHandleBase*>",
95 "D3PDReader::UserD3PDObjectElement",
96 "D3PDReader::UserD3PDObject" ]
97 for header
in filenames:
99 hfile =
open( header,
"rU" )
101 logger.error(
"Couldn't open header file: %s", hfile )
105 m1 = re.match(
r".*ClassDef\( (\w+), 0 \)", line )
106 m2 = re.match(
".*(VarHandle< .* >).*", line )
107 m3 = re.match(
".*(VarProxy< .* >).*", line )
109 if not (
"D3PDReader::" + m1.group( 1 ) )
in classnames:
110 logger.verbose(
"Found class: " + m1.group( 1 ) )
111 classnames += [
"D3PDReader::" + m1.group( 1 ) ]
115 if m2.group( 1 ) ==
"VarHandle< T >":
continue
116 if not (
"D3PDReader::" + m2.group( 1 ) )
in classnames:
117 logger.verbose(
"Found class: " + m2.group( 1 ) )
118 classnames += [
"D3PDReader::" + m2.group( 1 ) ]
122 if m3.group( 1 ) ==
"VarProxy< T >":
continue
123 if not (
"D3PDReader::" + m3.group( 1 ) )
in classnames:
124 logger.verbose(
"Found class: " + m3.group( 1 ) )
125 classnames += [
"D3PDReader::" + m3.group( 1 ) ]
135 for cname
in classnames:
137 cname = re.sub(
r"std::",
"", cname )
139 cname = re.sub(
r"\s",
"", cname )
141 cname = re.sub(
r",allocator<\w*>",
"", cname )
142 cname = re.sub(
r",allocator<\w*<\w*>>",
"", cname )
143 cname = re.sub(
r",allocator<\w*<\w*<\w*>>>",
"", cname )
146 cname = re.sub(
r"unsigned",
"unsigned ", cname )
151 cname = re.sub(
r"long(?!>)",
"long ", cname )
153 while cname != re.sub(
r">>",
"> >", cname ):
154 cname = re.sub(
r">>",
"> >", cname )
156 finalnames += [ cname ]
◆ dictionaryHeaders()
def python.Helpers.dictionaryHeaders |
( |
|
filenames | ) |
|
Find the headers needed for dictionary generation.
This function can be used to find the headers from the specified file names that should be given to rootcint for dictionary generation.
- Parameters
-
filenames | A list of file names |
- Returns
- A list of header file names that should be given to rootcint
Definition at line 48 of file PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py.
52 for file
in filenames:
54 if file.lower().
find(
"linkdef" ) != -1
or file.lower().
find(
"dict" ) != -1:
57 if ( file.find(
"VarHandle.h" ) != -1
or
58 file.find(
"VarHandle.icc" ) != -1
or
59 file.find(
"VarProxy.h" ) != -1
or
60 file.find(
"VarProxy.icc" ) != -1 ):
63 if file.endswith(
".h" ):
64 header_files += [ file ]
◆ get_release_setup()
str python.Helpers.get_release_setup |
( |
Logger |
logger, |
|
|
|
no_setup = False |
|
) |
| |
Get release setup.
Definition at line 9 of file Tools/WorkflowTestRunner/python/Helpers.py.
10 """Get release setup."""
12 logger.info(
"No release information is available when a release is not set-up.\n")
15 current_nightly = environ[
"AtlasBuildStamp"]
16 release_base = environ[
"AtlasBuildBranch"]
17 release_head = environ[
"AtlasVersion"]
18 platform = environ[
"LCG_PLATFORM"]
19 project = environ[
"AtlasProject"]
20 builds_dir_search_str = f
"/cvmfs/atlas-nightlies.cern.ch/repo/sw/{release_base}_{project}_{platform}/[!latest_]*/{project}/{release_head}"
23 sorted_list =
sorted(glob(builds_dir_search_str), key=path.getmtime)
25 for folder
in reversed(sorted_list):
26 if not glob(f
"{folder}/../../{release_base}__{project}*-opt*.log"):
28 latest_nightly = folder.split(
"/")[-3]
31 if current_nightly != latest_nightly:
32 logger.info(f
"Please be aware that you are not testing your tags in the latest available nightly, which is {latest_nightly}")
34 setup =
"%s,%s,%s,Athena" % (release_base, platform.replace(
"-",
","), current_nightly)
36 logger.info(f
"Your tags will be tested in environment {setup}")
◆ list_changed_packages()
None python.Helpers.list_changed_packages |
( |
Logger |
logger, |
|
|
|
no_setup = False |
|
) |
| |
List packages that have changed.
Definition at line 41 of file Tools/WorkflowTestRunner/python/Helpers.py.
42 """List packages that have changed."""
44 logger.info(
"The list of changed packages is not available when the relase is not set-up.\n")
47 if "WorkDir_DIR" in environ:
48 logger.info(
"Changed packages in your build to be tested:\n")
49 file_path = Path(environ[
"WorkDir_DIR"])
50 fname = file_path /
"packages.txt"
51 with fname.open()
as fp:
52 lines = fp.readlines()
53 last_line = lines[-1].strip()
if lines
else None
58 logger.info(f
"{line}\n")
62 logger.warning(
"A release area with locally installed packages has not been setup.")
63 logger.warning(
"quit by executing <CONTROL-C> if this is not your intention, and")
64 logger.warning(
"source <YOUR_CMake_BUILD_AREA>/setup.sh")
65 logger.warning(
"to pickup locally built packages in your environment.\n")
◆ makeRootCorePackageSkeleton()
def python.Helpers.makeRootCorePackageSkeleton |
( |
|
directory, |
|
|
|
name |
|
) |
| |
Create the directory structure for a RootCore package.
This function can be used to create the directory structure for a RootCore package.
- Parameters
-
directory | The directory where the package is to be created |
name | The name for the RootCore package |
- Returns
0
in case of success, something else in case of failure
Definition at line 279 of file PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py.
282 from AthenaCommon.Logging
import logging
283 logger = logging.getLogger(
"makeRootCorePackageSkeleton" )
287 if not os.path.exists( directory ):
288 logger.error(
"The output directory (%s) doesn't exist!", directory )
292 if os.path.exists( directory +
"/" + name ):
293 logger.error(
"The directory for the package (%s/%s) already exists!", directory, name )
298 os.mkdir( directory +
"/" + name, 0o755 )
299 os.mkdir( directory +
"/" + name +
"/" + name, 0o755 )
300 os.mkdir( directory +
"/" + name +
"/Root", 0o755 )
301 os.mkdir( directory +
"/" + name +
"/cmt", 0o755 )
304 makefile =
open( directory +
"/" + name +
"/cmt/Makefile.RootCore",
"w" )
305 makefile.write(
"# $Id: Helpers.py 600807 2014-06-08 15:26:51Z krasznaa $\n\n" )
306 makefile.write(
"PACKAGE = %s\n" % name )
307 makefile.write(
"PACKAGE_PRELOAD = Tree\n" )
308 makefile.write(
"# Add the option -DACTIVATE_BRANCHES if your analysis framework\n" )
309 makefile.write(
"# disables all branches by default.\n" )
310 makefile.write(
"# Remove the COLLECT_D3PD_READING_STATISTICS option to gain a bit\n" )
311 makefile.write(
"# of performance...\n" )
312 makefile.write(
"PACKAGE_CXXFLAGS = -DCOLLECT_D3PD_READING_STATISTICS\n" )
313 makefile.write(
"PACKAGE_LDFLAGS =\n" )
314 makefile.write(
"PACKAGE_DEP =\n" )
315 makefile.write(
"PACKAGE_PEDANTIC = 1\n" )
316 makefile.write(
"PACKAGE_NOOPT = dict\n\n" )
317 makefile.write(
"include $(ROOTCOREDIR)/Makefile-common\n" )
321 requirements =
open( directory +
"/" + name +
"/cmt/requirements",
"w" )
322 requirements.write(
"package %s\n\n" % name )
323 requirements.write(
"use AtlasPolicy AtlasPolicy-*\n" )
324 requirements.write(
"use AtlasROOT AtlasROOT-* External\n\n" )
325 requirements.write(
"library %s ../Root/*.cxx\n" % name )
326 requirements.write(
"apply_pattern installed_library\n\n" )
327 requirements.write(
"apply_pattern have_root_headers root_headers=\"*.h " \
328 "../Root/LinkDef.h\" headers_lib=%s\n" % name )
◆ makeSFramePackageSkeleton()
def python.Helpers.makeSFramePackageSkeleton |
( |
|
directory, |
|
|
|
name |
|
) |
| |
Create an SFrame package skeleton.
This function can be used to create the directory structure for an SFrame package. It does as similar job as SFrame's sframe_new_package.sh script.
- Parameters
-
directory | The directory where the package is to be created |
name | The name for the SFrame package |
- Returns
0
in case of success, something else in case of failure
Definition at line 345 of file PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py.
348 from AthenaCommon.Logging
import logging
349 logger = logging.getLogger(
"makeSFramePackageSkeleton" )
353 if not os.path.exists( directory ):
354 logger.error(
"The output directory (%s) doesn't exist!", directory )
358 if os.path.exists( directory +
"/" + name ):
359 logger.error(
"The directory for the package (%s/%s) already exists!", directory, name )
364 os.mkdir( directory +
"/" + name, 0o755 )
365 os.mkdir( directory +
"/" + name +
"/include", 0o755 )
366 os.mkdir( directory +
"/" + name +
"/src", 0o755 )
367 os.mkdir( directory +
"/" + name +
"/proof", 0o755 )
370 makefile =
open( directory +
"/" + name +
"/Makefile",
"w" )
371 makefile.write(
"# $Id: Helpers.py 600807 2014-06-08 15:26:51Z krasznaa $\n\n" )
372 makefile.write(
"# Package information\n" )
373 makefile.write(
"LIBRARY = %s\n" % name )
374 makefile.write(
"OBJDIR = obj\n" )
375 makefile.write(
"DEPDIR = $(OBJDIR)/dep\n" )
376 makefile.write(
"SRCDIR = src\n" )
377 makefile.write(
"INCDIR = include\n\n" )
378 makefile.write(
"# Enable collecting D3PD reading statistics\n" )
379 makefile.write(
"INCLUDES += -DCOLLECT_D3PD_READING_STATISTICS\n\n" )
380 makefile.write(
"# Include the generic compilation rules\n" )
381 makefile.write(
"include $(SFRAME_DIR)/Makefile.common\n" )
385 setup =
open( directory +
"/" + name +
"/proof/SETUP.C",
"w" )
386 setup.write(
"// $Id: Helpers.py 600807 2014-06-08 15:26:51Z krasznaa $\n\n" )
387 setup.write(
"int SETUP() {\n\n" )
388 setup.write(
" if( gSystem->Load( \"libTree\" ) == -1 ) return -1;\n" )
389 setup.write(
" if( gSystem->Load( \"lib%s\" ) == -1 ) return -1;\n\n" % name )
390 setup.write(
" return 0;\n" )
394 build =
open( directory +
"/" + name +
"/proof/BUILD.sh",
"w" )
395 build.write(
"# $Id: Helpers.py 600807 2014-06-08 15:26:51Z krasznaa $\n\n" )
396 build.write(
"if [ \"$1\" = \"clean\" ]; then\n" )
397 build.write(
" make distclean\n" )
398 build.write(
" exit 0\n" )
399 build.write(
"fi\n\n" )
400 build.write(
"make default\n" )
402 os.chmod( directory +
"/" + name +
"/proof/BUILD.sh", 0o755 )
◆ MakexAODDataFrame()
def python.Helpers.MakexAODDataFrame |
( |
|
inputs | ) |
|
Helper function creating a ROOT::RDataFrame object reading xAOD files
The function returns an instance of ROOT::RDataFrame that uses
xAOD::RDataSource for reading its inputs.
Keyword arguments:
inputs -- A single string, or a list of string selecting the input file(s)
Note that the string(s) may contain wildcards and environment
variables as well.
Definition at line 6 of file Control/xAODDataSource/python/Helpers.py.
7 """Helper function creating a ROOT::RDataFrame object reading xAOD files
9 The function returns an instance of ROOT::RDataFrame that uses
10 xAOD::RDataSource for reading its inputs.
13 inputs -- A single string, or a list of string selecting the input file(s)
14 Note that the string(s) may contain wildcards and environment
19 ROOT.xAOD.ROOT6_xAODDataSource_WorkAround_Dummy()
22 return ROOT.xAOD.MakeDataFrame( inputs )
◆ release_metadata()
def python.Helpers.release_metadata |
( |
| ) |
|
Returns information about the current release based on ReleaseData
Definition at line 143 of file Tools/PyUtils/python/Helpers.py.
144 """Returns information about the current release based on ReleaseData"""
151 'nightly release':
'?',
157 for cmake_path
in os.environ[
'CMAKE_PREFIX_PATH'].
split(os.pathsep):
158 release_data = os.path.join(cmake_path,
'ReleaseData')
159 if os.path.exists(release_data):
161 cfg = configparser.ConfigParser()
163 cfg.read( release_data )
164 if cfg.has_section(
'release_metadata' ):
165 d1.update( dict( cfg.items(
'release_metadata' ) ) )
166 d1[
'platform'] = os.getenv(
'%s_PLATFORM' % d1[
'project name'],
168 release = d1[
'release'].
split(
'.')
169 base_release = d1[
'base release'].
split(
'.')
170 if len(release)>=3
or len(base_release)>=3:
◆ ROOT6Setup()
def python.Helpers.ROOT6Setup |
( |
|
batch = False | ) |
|
Definition at line 19 of file Tools/PyUtils/python/Helpers.py.
20 from AthenaCommon.Logging
import log
21 log.info(
'executing ROOT6Setup')
22 import builtins
as builtin_mod
23 oldimporthook = builtin_mod.__import__
24 autoload_var_name =
'ROOT6_NamespaceAutoloadHook'
25 batch_mode =
bool(batch)
27 def root6_importhook(name, globals={}, locals={}, fromlist=[], level=0):
31 if name==
'ROOT' or (name[0:4]==
'ROOT' and name!=
'ROOT.pythonization'):
35 m = oldimporthook(name, globals, locals, fromlist, level)
38 log.debug(
'Python import module=%s, fromlist=%s', name, fromlist)
40 log.debug(
'Setting ROOT batch mode to %s', bm)
45 vars = [
'.'.
join([
'', fl, autoload_var_name])
for fl
in fromlist]
47 vars = [
'.'.
join([name, autoload_var_name]) ]
53 for comp
in v.split(
'.')[1:]:
54 mm = getattr(mm, comp)
60 builtin_mod.__import__ = root6_importhook
◆ separateSources()
def python.Helpers.separateSources |
( |
|
filenames | ) |
|
Separate the source and header files based on their names.
This function can be used to separate a list of file names into header and source files just based on their names.
- Parameters
-
filename | A simple list of the names of all the files |
- Returns
- The a <code>(headers,sources)</code> pair of file name lists
Definition at line 17 of file PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py.
22 for file
in filenames:
24 if file.lower().
find(
"linkdef" ) != -1
or file.lower().
find(
"dict" ) != -1:
27 if file.endswith(
".h" )
or file.endswith(
".icc" ):
28 header_files += [ file ]
31 if file.endswith(
".cxx" )
or file.endswith(
".cpp" )
or file.endswith(
".C" ):
32 source_files += [ file ]
37 return ( header_files, source_files )
◆ warnings_count()
List[str] python.Helpers.warnings_count |
( |
Path |
file_name | ) |
|
Run a WARNING helper function.
Definition at line 69 of file Tools/WorkflowTestRunner/python/Helpers.py.
70 """Run a WARNING helper function."""
72 with file_name.open()
as file:
74 if "WARNING" in line
and "| WARNING |" not in line:
◆ writeLinkDefFile()
def python.Helpers.writeLinkDefFile |
( |
|
filename, |
|
|
|
classnames, |
|
|
|
headers = [] |
|
) |
| |
Function writing a LinkDef file.
This function can be used to generate a LinkDef file based on the class names for which a dictionary needs to be generated.
- Parameters
-
filename | The name of the output LinkDef file |
classname | A list of the class names to generate a dictionary for |
headers | Header file names that are to be included |
- Returns
0
in case of success, something else in case of failure
Definition at line 172 of file PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py.
175 from AthenaCommon.Logging
import logging
176 logger = logging.getLogger(
"writeLinkDefFile" )
179 linkdef =
open( filename,
"w" )
181 logger.error(
"Couldn't open %s for writing!", filename )
184 logger.info(
"Writing linkdef file to: %s", filename )
188 linkdef.write(
"// Dear emacs, this is -*- c++ -*-\n" )
189 linkdef.write(
"// $Id: Helpers.py 600807 2014-06-08 15:26:51Z krasznaa $\n" )
190 linkdef.write(
"#ifndef D3PDREADER_LINKDEF_H\n" )
191 linkdef.write(
"#define D3PDREADER_LINKDEF_H\n\n" )
194 for header
in headers:
195 linkdef.write(
"#include \"%s\"\n" % header )
199 linkdef.write(
"\n#ifdef __CINT__\n\n" )
200 linkdef.write(
"#pragma link off all globals;\n" )
201 linkdef.write(
"#pragma link off all classes;\n" )
202 linkdef.write(
"#pragma link off all functions;\n\n" )
203 linkdef.write(
"#pragma link C++ nestedclass;\n\n" )
206 for classname
in classnames:
207 linkdef.write(
"#pragma link C++ class %s+;\n" % classname )
211 linkdef.write(
"\n" )
212 linkdef.write(
"// You can disable the remaining lines if you don't\n" )
213 linkdef.write(
"// plan to use the library in CINT or PyROOT.\n" )
214 functions = [
"D3PDReader::UserD3PDObject::DeclareVariable<bool>",
215 "D3PDReader::UserD3PDObject::DeclareVariable<short>",
216 "D3PDReader::UserD3PDObject::DeclareVariable<unsigned short>",
217 "D3PDReader::UserD3PDObject::DeclareVariable<int>",
218 "D3PDReader::UserD3PDObject::DeclareVariable<unsigned int>",
219 "D3PDReader::UserD3PDObject::DeclareVariable<long long>",
220 "D3PDReader::UserD3PDObject::DeclareVariable<unsigned long long>",
221 "D3PDReader::UserD3PDObject::DeclareVariable<float>",
222 "D3PDReader::UserD3PDObject::DeclareVariable<double>",
231 "D3PDReader::UserD3PDObject::Variable<bool>",
232 "D3PDReader::UserD3PDObject::Variable<short>",
233 "D3PDReader::UserD3PDObject::Variable<unsigned short>",
234 "D3PDReader::UserD3PDObject::Variable<int>",
235 "D3PDReader::UserD3PDObject::Variable<unsigned int>",
236 "D3PDReader::UserD3PDObject::Variable<long long>",
237 "D3PDReader::UserD3PDObject::Variable<unsigned long long>",
238 "D3PDReader::UserD3PDObject::Variable<float>",
239 "D3PDReader::UserD3PDObject::Variable<double>",
248 "D3PDReader::UserD3PDObjectElement::Variable<short>",
249 "D3PDReader::UserD3PDObjectElement::Variable<unsigned short>",
250 "D3PDReader::UserD3PDObjectElement::Variable<int>",
251 "D3PDReader::UserD3PDObjectElement::Variable<unsigned int>",
252 "D3PDReader::UserD3PDObjectElement::Variable<long long>",
253 "D3PDReader::UserD3PDObjectElement::Variable<unsigned long long>",
254 "D3PDReader::UserD3PDObjectElement::Variable<float>",
255 "D3PDReader::UserD3PDObjectElement::Variable<double>" ]
256 for function
in functions:
257 linkdef.write(
"#pragma link C++ function %s;\n" % function )
261 linkdef.write(
"\n" )
262 linkdef.write(
"#endif // __CINT__\n" )
263 linkdef.write(
"#endif // D3PDREADER_LINKDEF_H\n" )
str get_release_setup(Logger logger, no_setup=False)
std::string find(const std::string &s)
return a remapped string
def makeRootCorePackageSkeleton(directory, name)
Create the directory structure for a RootCore package.
None list_changed_packages(Logger logger, no_setup=False)
def separateSources(filenames)
Separate the source and header files based on their names.
def dictionaryClasses(filenames)
Function collecting the class names to create a dictionary for.
def ROOT6Setup(batch=False)
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
def writeLinkDefFile(filename, classnames, headers=[])
Function writing a LinkDef file.
List[str] warnings_count(Path file_name)
std::string join(const std::vector< std::string > &v, const char c=',')
def MakexAODDataFrame(inputs)
setBGCode setTAP setLVL2ErrorBits bool
def makeSFramePackageSkeleton(directory, name)
Create an SFrame package skeleton.
def dictionaryHeaders(filenames)
Find the headers needed for dictionary generation.