Skip to content

Commit

Permalink
Merge pull request #170 from JeffersonLab/pasteurize_rebased_mmi
Browse files Browse the repository at this point in the history
Pasteurize rebased mmi
  • Loading branch information
sdobbs authored Nov 18, 2020
2 parents bf0bc93 + 4ce2a73 commit 3144a32
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 1,425 deletions.
131 changes: 79 additions & 52 deletions src/SBMS/sbms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

from builtins import open
from builtins import filter
from builtins import int
from builtins import str
from future import standard_library
standard_library.install_aliases()
import os
import subprocess
import SCons
Expand Down Expand Up @@ -34,14 +44,14 @@ def library(env, libname=''):
# Add C/C++, and FORTRAN targets
env.AppendUnique(ALL_SOURCES = env.Glob('*.c'))
#env.AppendUnique(ALL_SOURCES = env.Glob('*.cc'))
env.AppendUnique(ALL_SOURCES = filter(IsNotSWIGWrapper,env.Glob('*.cc')))
env.AppendUnique(ALL_SOURCES = list(filter(IsNotSWIGWrapper,env.Glob('*.cc'))))
env.AppendUnique(ALL_SOURCES = env.Glob('*.cpp'))
env.AppendUnique(ALL_SOURCES = env.Glob('*.F'))
env.AppendUnique(ALL_SOURCES = env.Glob('*.f90'))

sources = env['ALL_SOURCES']
objects = env['MISC_OBJECTS']
if 'IGNORE_SOURCES' in env.Dictionary().keys():
if 'IGNORE_SOURCES' in list(env.Dictionary().keys()):
ignore = env['IGNORE_SOURCES']
sources = [s for s in env['ALL_SOURCES'] if s.name not in ignore]

Expand All @@ -50,7 +60,7 @@ def library(env, libname=''):
myobjs.extend(objects)
mylib = env.Library(target = libname, source = myobjs)

AddRECONPaths(env)
AddRECONPaths(env)

# Cleaning and installation are restricted to the directory
# scons was launched from or its descendents
Expand Down Expand Up @@ -92,15 +102,15 @@ def executable(env, exename=''):
ReorderCommonLibraries(env)

sources = env['ALL_SOURCES']
if 'IGNORE_SOURCES' in env.Dictionary().keys():
if 'IGNORE_SOURCES' in list(env.Dictionary().keys()):
ignore = env['IGNORE_SOURCES']
sources = [s for s in env['ALL_SOURCES'] if s.name not in ignore]

# Build program from all source
myobjs = env.Object(sources)
myexe = env.Program(target = exename, source = myobjs)

AddRECONPaths(env)
AddRECONPaths(env)

# Cleaning and installation are restricted to the directory
# scons was launched from or its descendents
Expand Down Expand Up @@ -217,7 +227,7 @@ def executables(env):

common_sources.extend(env['ALL_SOURCES'])

if 'IGNORE_SOURCES' in env.Dictionary().keys():
if 'IGNORE_SOURCES' in list(env.Dictionary().keys()):
ignore = env['IGNORE_SOURCES']
main_sources = [s for s in main_sources if s.name not in ignore]
common_sources = [s for s in common_sources if s.name not in ignore]
Expand Down Expand Up @@ -263,12 +273,12 @@ def plugin(env, pluginname=''):
#print str([x.rstr() for x in env.Glob('*.cc')])

sources = env['ALL_SOURCES']
if 'IGNORE_SOURCES' in env.Dictionary().keys():
if 'IGNORE_SOURCES' in list(env.Dictionary().keys()):
ignore = env['IGNORE_SOURCES']
sources = [s for s in env['ALL_SOURCES'] if s.name not in ignore]

# Strip out libs that don't need to be linked in plugin
if 'OPTIONAL_PLUGIN_LIBS' in env.Dictionary().keys() :
if 'OPTIONAL_PLUGIN_LIBS' in list(env.Dictionary().keys()) :
REDUCED_LIBS = [s for s in env['LIBS'] if s not in env['OPTIONAL_PLUGIN_LIBS'] ]
env.Replace(LIBS=REDUCED_LIBS)

Expand Down Expand Up @@ -456,21 +466,22 @@ def ApplyPlatformSpecificSettings(env, platform):
# "."s. The Python module loader doesn't like these and we have to
# replace them with "-"s to appease it.

platform = str(platform)
platform = re.sub('\.', '-', platform)

modname = "sbms_%s" % platform
if (int(env['SHOWBUILD']) > 0):
print "looking for %s.py" % modname
print("looking for %s.py" % modname)
try:
InitENV = getattr(__import__(modname), "InitENV")

# Run the InitENV function (if found)
if(InitENV != None):
print "sbms : Applying settings for platform %s" % platform
print("sbms : Applying settings for platform %s" % platform)
InitENV(env)

except ImportError,e:
if (int(env['SHOWBUILD']) > 0): print "%s" % e
except ImportError as e:
if (int(env['SHOWBUILD']) > 0): print("%s" % e)
pass


Expand Down Expand Up @@ -553,8 +564,8 @@ def AddJANA(env):

# Only run jana-config the first time through
if "JANA_CFLAGS" not in AddJANA.__dict__:
AddJANA.JANA_CFLAGS = subprocess.Popen(["%s/bin/jana-config" % jana_home,"--jana-only","--cflags"], stdout=subprocess.PIPE).communicate()[0]
AddJANA.JANA_LINKFLAGS = subprocess.Popen(["%s/bin/jana-config" % jana_home,"--jana-only","--libs"], stdout=subprocess.PIPE).communicate()[0]
AddJANA.JANA_CFLAGS = str(subprocess.Popen(["%s/bin/jana-config" % jana_home,"--jana-only","--cflags"], stdout=subprocess.PIPE).communicate()[0], 'utf-8')
AddJANA.JANA_LINKFLAGS = str(subprocess.Popen(["%s/bin/jana-config" % jana_home,"--jana-only","--libs"], stdout=subprocess.PIPE).communicate()[0], 'utf-8')

AddCompileFlags(env, AddJANA.JANA_CFLAGS)
AddLinkFlags(env, AddJANA.JANA_LINKFLAGS)
Expand Down Expand Up @@ -584,8 +595,8 @@ def AddMySQL(env):

# Only run mysql_config the first time through
if "MYSQL_CFLAGS" not in AddMySQL.__dict__:
AddMySQL.MYSQL_CFLAGS = subprocess.Popen(["mysql_config","--cflags"], stdout=subprocess.PIPE).communicate()[0]
AddMySQL.MYSQL_LINKFLAGS = subprocess.Popen(["mysql_config","--libs"], stdout=subprocess.PIPE).communicate()[0]
AddMySQL.MYSQL_CFLAGS = str(subprocess.Popen(["mysql_config","--cflags"], stdout=subprocess.PIPE).communicate()[0], 'utf-8')
AddMySQL.MYSQL_LINKFLAGS = str(subprocess.Popen(["mysql_config","--libs"], stdout=subprocess.PIPE).communicate()[0], 'utf-8')
AddCompileFlags(env, AddMySQL.MYSQL_CFLAGS)
AddLinkFlags(env, AddMySQL.MYSQL_LINKFLAGS)

Expand All @@ -600,14 +611,14 @@ def AddRECONPaths(env):
env.AppendUnique(LIBPATH = ["%s/%s/lib" % (halld_recon_home, env['OSNAME'])])

# skip smearing DIRC if hit object doesn't exist in halld_recon (ie. it's an old version)
if os.path.exists(halld_recon_home+"/src/libraries/DIRC/DDIRCPmtHit.h"):
if os.path.exists(halld_recon_home+"/src/libraries/DIRC/DDIRCPmtHit.h"):
AddCompileFlags(env, "-DSMEARDIRC")

##################################
# DANA
##################################
def AddDANA(env):
AddRECONPaths(env)
AddRECONPaths(env)
AddHDDM(env)
AddROOT(env)
AddJANA(env)
Expand All @@ -624,16 +635,17 @@ def AddDANA(env):
DANA_LIBS += " DAQ JANA EVENTSTORE TRD"
DANA_LIBS += " expat"
env.PrependUnique(LIBS = DANA_LIBS.split())
env.Append(LIBS = 'DANA')
env.Append(LIBS = 'DANA')
env.PrependUnique(OPTIONAL_PLUGIN_LIBS = DANA_LIBS.split())

##################################
# xstream
##################################
def Add_xstream(env):
env.AppendUnique(CPPPATH = ['#external/xstream/include'])
env.AppendUnique(CPPPATH = ['/usr/include/tirpc'])
env.AppendUnique(CCFLAGS = ['-fPIC'])
env.AppendUnique(LIBS=['xstream', 'bz2', 'z'])
env.AppendUnique(LIBS=['xstream', 'tirpc', 'bz2', 'z'])
env.AppendUnique(OPTIONAL_PLUGIN_LIBS = ['xstream', 'bz2', 'z'])


Expand Down Expand Up @@ -787,6 +799,9 @@ def AddXERCES(env):
def AddCERNLIB(env):
env.PrependUnique(FORTRANFLAGS = ['-ffixed-line-length-0', '-fno-second-underscore'])
env.PrependUnique(FORTRANFLAGS = ['-fno-automatic'])
gccver = gcc_major_version()
if gccver >= 10:
env.PrependUnique(FORTRANFLAGS = ['-fallow-argument-mismatch'])
#env.PrependUnique(FORTRANPATH = ['include'])
cern = os.getenv('CERN', '/usr/local/cern/PRO')
cern_level = os.getenv('CERN_LEVEL', '2006')
Expand Down Expand Up @@ -818,14 +833,14 @@ def AddROOT(env):

rootsys = os.getenv('ROOTSYS', '/usr/local/root/PRO')
if not os.path.isdir(rootsys):
print 'ROOTSYS not defined or points to a non-existant directory!'
print('ROOTSYS not defined or points to a non-existant directory!')
sys.exit(-1)

# Only root-config the first time through
if "ROOT_CFLAGS" not in AddROOT.__dict__:
AddROOT.ROOT_CFLAGS = subprocess.Popen(["%s/bin/root-config" % rootsys, "--cflags"], stdout=subprocess.PIPE).communicate()[0]
AddROOT.ROOT_LINKFLAGS = subprocess.Popen(["%s/bin/root-config" % rootsys, "--glibs" ], stdout=subprocess.PIPE).communicate()[0]
has_tmva = subprocess.Popen(["%s/bin/root-config" % rootsys, "--has-tmva" ], stdout=subprocess.PIPE).communicate()[0]
AddROOT.ROOT_CFLAGS = str(subprocess.Popen(["%s/bin/root-config" % rootsys, "--cflags"], stdout=subprocess.PIPE).communicate()[0], 'utf-8')
AddROOT.ROOT_LINKFLAGS = str(subprocess.Popen(["%s/bin/root-config" % rootsys, "--glibs" ], stdout=subprocess.PIPE).communicate()[0], 'utf-8')
has_tmva = str(subprocess.Popen(["%s/bin/root-config" % rootsys, "--has-tmva" ], stdout=subprocess.PIPE).communicate()[0], 'utf-8')
if 'yes' in has_tmva:
AddROOT.ROOT_CFLAGS += ' -DHAVE_TMVA=1'
AddROOT.ROOT_LINKFLAGS += ' -lTMVA'
Expand Down Expand Up @@ -866,7 +881,7 @@ def AddROOT(env):
elif os.path.exists(rootcintpath):
bld = SCons.Script.Builder(action = rootcintaction, suffix='_Dict.cc', src_suffix='.h')
else:
print 'Neither rootcint nor rootcling exists. Unable to create ROOT dictionaries if any encountered.'
print('Neither rootcint nor rootcling exists. Unable to create ROOT dictionaries if any encountered.')
return

env.Append(BUILDERS = {'ROOTDict' : bld})
Expand All @@ -883,13 +898,13 @@ def AddROOT(env):
curpath = os.getcwd()
srcpath = env.Dir('.').srcnode().abspath
if(int(env['SHOWBUILD'])>1):
print "---- Scanning for headers to generate ROOT dictionaries in: %s" % srcpath
print("---- Scanning for headers to generate ROOT dictionaries in: %s" % srcpath)
os.chdir(srcpath)
for f in glob.glob('*.[h|hh|hpp]'):
if 'ClassDef' in open(f).read():
env.AppendUnique(ALL_SOURCES = env.ROOTDict(f))
if(int(env['SHOWBUILD'])>1):
print " ROOT dictionary for %s" % f
print(" ROOT dictionary for %s" % f)
os.chdir(curpath)


Expand Down Expand Up @@ -970,11 +985,11 @@ def AddROOTSpyMacros(env):
curpath = os.getcwd()
srcpath = env.Dir('.').srcnode().abspath
if(int(env['SHOWBUILD'])>1):
print "---- Looking for ROOT macro files (*.C) in: %s" % srcpath
print("---- Looking for ROOT macro files (*.C) in: %s" % srcpath)
os.chdir(srcpath)
for f in glob.glob('*.C'):
env.AppendUnique(ALL_SOURCES = env.ROOTSpyMacro(f))
if(int(env['SHOWBUILD'])>1) : print " ROOTSpy Macro for %s" % f
if(int(env['SHOWBUILD'])>1) : print(" ROOTSpy Macro for %s" % f)

os.chdir(curpath)

Expand All @@ -989,8 +1004,8 @@ def AddSWIG(env):
if ProgramExists("swig"):
env.AppendUnique(SWIG_EXISTS = "1")
if not env['BUILDSWIG'] or int(env['BUILDSWIG']) != 1:
print '-- NOTE: swig exists but will not be used unless you --'
print '-- add "BUILDSWIG=1" to the scons command line. --'
print('-- NOTE: swig exists but will not be used unless you --')
print('-- add "BUILDSWIG=1" to the scons command line. --')
else:
env.AppendUnique(SWIG_EXISTS = "0")
# TEMPORARILY DISABLE
Expand Down Expand Up @@ -1033,7 +1048,7 @@ def AddCUDA(env):
srcpath = env.Dir('.').srcnode().abspath
os.chdir(srcpath)
for f in glob.glob('*.cu'):
if env['SHOWBUILD']>0 : print 'Adding %s' % f
if env['SHOWBUILD']>0 : print('Adding %s' % f)
env.AppendUnique(MISC_OBJECTS = env.CUDA(f))
os.chdir(curpath)

Expand All @@ -1052,10 +1067,10 @@ def AddAmpTools(env):
# printed and env left unchanged.
AMPTOOLS = os.getenv('AMPTOOLS')
if AMPTOOLS==None:
print ''
print 'AmpTools is being requested but the AMPTOOLS environment variable'
print 'is not set. Expect to see an error message below....'
print ''
print('')
print('AmpTools is being requested but the AMPTOOLS environment variable')
print('is not set. Expect to see an error message below....')
print('')
else:
env.AppendUnique(CUDAFLAGS=['-I%s -I%s/src/libraries' % (AMPTOOLS, os.getenv('HALLD_SIM_HOME',os.getcwd()))])
AddCUDA(env)
Expand All @@ -1064,9 +1079,9 @@ def AddAmpTools(env):
AMPTOOLS_LIBS = 'AmpTools'
if os.getenv('CUDA')!=None and os.path.exists('%s/lib/libAmpTools_GPU.a' % AMPTOOLS):
AMPTOOLS_LIBS = 'AmpTools_GPU'
print 'Using GPU enabled AMPTOOLS library'
print('Using GPU enabled AMPTOOLS library')

env.AppendUnique(CXXFLAGS = ['-DHAVE_AMPTOOLS_MCGEN'])
env.AppendUnique(CXXFLAGS = ['-DHAVE_AMPTOOLS_MCGEN'])
env.AppendUnique(CPPPATH = AMPTOOLS_CPPPATH)
env.AppendUnique(LIBPATH = AMPTOOLS_LIBPATH)
env.AppendUnique(LIBS = AMPTOOLS_LIBS)
Expand All @@ -1091,10 +1106,10 @@ def AddAmpPlotter(env):
def AddHepMC(env):
HEPMC_HOME = os.getenv('HEPMCDIR')
if HEPMC_HOME==None:
print ''
print 'HepMC is being requested but the HEPMCDIR environment variable is not set!'
print ''
else:
print('')
print('HepMC is being requested but the HEPMCDIR environment variable is not set!')
print('')
else:
HEPMC_CPPPATH = "%s/include" % (HEPMC_HOME)
HEPMC_LIBPATH = "%s/lib" % (HEPMC_HOME)
HEPMC_LIBS = "HepMC"
Expand All @@ -1109,10 +1124,10 @@ def AddHepMC(env):
def AddPhotos(env):
PHOTOS_HOME = os.getenv('PHOTOSDIR')
if PHOTOS_HOME==None:
print ''
print 'Photos is being requested but the PHOTOSDIR environment variable is not set!'
print ''
else:
print('')
print('Photos is being requested but the PHOTOSDIR environment variable is not set!')
print('')
else:
PHOTOS_CPPPATH = "%s/include" % (PHOTOS_HOME)
PHOTOS_LIBPATH = "%s/lib" % (PHOTOS_HOME)
PHOTOS_LIBS = [ "Photospp", "PhotosppHepMC" ]
Expand All @@ -1128,10 +1143,10 @@ def AddPhotos(env):
def AddEvtGen(env):
EVTGEN_HOME = os.getenv('EVTGENDIR')
if EVTGEN_HOME==None:
print ''
print 'EvtGen is being requested but the EVTGENDIR environment variable is not set!'
print ''
else:
print('')
print('EvtGen is being requested but the EVTGENDIR environment variable is not set!')
print('')
else:
AddHepMC(env)
AddPhotos(env)
EVTGEN_CPPPATH = "%s/" % (EVTGEN_HOME)
Expand All @@ -1149,10 +1164,22 @@ def AddEvtGen(env):
##################################
def AddUtilities(env):
AddCCDB(env)
pyincludes = subprocess.Popen(["python-config", "--includes" ], stdout=subprocess.PIPE).communicate()[0]
pythonconfig = env['PYTHONCONFIG']
pyincludes = str(subprocess.Popen([pythonconfig, "--includes" ], stdout=subprocess.PIPE).communicate()[0], 'utf-8')
env.AppendUnique(CCFLAGS = pyincludes.rstrip().split())
# BOOST is required by cobrems and if it is not installed in /usr or /usr/local then we must get it from the environment
boost_root = os.getenv('BOOST_ROOT')
if boost_root != None:
env.AppendUnique(CPPPATH = [boost_root + "/include"])

##################################
# miscellanous
##################################
def gcc_major_version():
outstr = str(subprocess.Popen(["gcc", "--version" ], stdout=subprocess.PIPE).communicate()[0], 'utf-8')
tokens = outstr.split()
version = tokens[2]
vtokens = version.split('.')
version_major_str = vtokens[0]
major_version = int(version_major_str)
return major_version
Loading

0 comments on commit 3144a32

Please sign in to comment.