00001
00002
00003 import sys
00004 import getopt
00005 import os
00006 import string
00007
00008
00009
00010
00011
00012
00013 versions = {
00014 'cascade-version': '2.0.1',
00015 'clhep-version': '1.9.4.7',
00016 'hepmc-version': '2.03.11',
00017
00018 'heppdt-version': '3.04.01',
00019 'fastjet-version': '2.4.2p5',
00020 'gsl-version': '1.10',
00021 'pythia8-version': '142',
00022 'pythia6-version': '423.2',
00023 'alpgen-version': '2.1.3d.2',
00024 'herwigpp-version': '2.5.0',
00025 'herwig-version': '6.520.2',
00026 'jimmy-version': '4.31.3',
00027 'thepeg-version': '1.7.0',
00028 'lhapdf-version': '5.8.2',
00029 'tauola-version': '28.121.2',
00030 'photos-version': '215.5',
00031 'prefix': ''
00032 }
00033
00034
00035 colours = { 'default': '',
00036 'blue': '\x1b[01;34m',
00037 'cyan': '\x1b[01;36m',
00038 'green': '\x1b[01;32m',
00039 'red': '\x1b[01;05;37;41m',
00040 'end': '\x1b[00m' }
00041
00042
00043 envVarsFile = open( 'setupEnvVariables.sh', 'w' )
00044 gccSetupFile = open( 'setupGccVersion.sh', 'w' )
00045
00046
00047 def main():
00048 processOptions()
00049
00050 envVarsFile.write( '#!/bin/bash\n' )
00051 gccSetupFile.write( '#!/bin/bash\n' )
00052
00053
00054 location, curr_dir = detectLocation()
00055 envVarsFile.write( 'export MYCLASS_PATH=' + curr_dir + '\n' )
00056 location = location.rstrip( '\n' )
00057
00058 if location == 'desy.de':
00059 prefix, sysname = initializeDesySetup()
00060 elif location == 'naf.desy.de':
00061 prefix, sysname = initializeNafSetup()
00062 else:
00063 prefix, sysname = initializeCernSetup()
00064
00065 print "Prefix:", prefix, ", sysname:", sysname
00066 initializeStdLibs( prefix, sysname )
00067
00068 print 'Done!'
00069
00070
00071
00072
00073 def processOptions():
00074 options = ''
00075 longOptions = []
00076 for op in versions.keys():
00077 longOptions.append( op + '=' )
00078
00079
00080 longOptions.append( 'help' )
00081
00082
00083 try:
00084 optlist, args = getopt.getopt( sys.argv[1:], options, longOptions )
00085 except getopt.GetoptError, err:
00086 print str( err )
00087 print "For help use --help"
00088 sys.exit( 2 )
00089
00090 for op, ar in optlist:
00091 if op.startswith( '--' ):
00092 op = op.strip( '-' )
00093 if op in versions.keys():
00094 versions[ op ] = ar
00095 print colours[ 'blue' ]+"Overwriting default option '", op, "' with value:", ar, colours['end']
00096 if op == 'hepmc-version':
00097 print colours['blue']+"Be aware that other libraries could be compiled with different version of HepMC!", colours['end']
00098 if op == 'help':
00099 showHelp()
00100 sys.exit( 0 )
00101
00102
00103
00104
00105 def initializeDesySetup():
00106 print colours[ 'blue' ] + "[ Initialize DESY setup ]" + colours[ 'end' ]
00107
00108
00109
00110
00111
00112
00113
00114 sysArch = 0
00115 sysDsc = ''
00116 sysName = ''
00117 sysCmd = os.popen( 'fs sysname' ).readline()
00118
00119 if contains( sysCmd, 'i586_rhel40' ) or contains( sysCmd, 'i386_linux26' ):
00120 sysArch = 32
00121 sysDsc = 'SL4'
00122 sysName = 'i586_rhel40'
00123 elif contains( sysCmd, 'amd64_rhel40' ) or contains( sysCmd, 'amd64_linux26' ):
00124 sysArch = 64
00125 sysDsc = 'SL4'
00126 sysName = 'amd64_rhel40'
00127
00128 if contains( sysCmd, 'i586_rhel50' ):
00129 sysArch = 32
00130 sysDsc = 'SL5'
00131 sysName = 'i586_rhel50'
00132 elif contains( sysCmd, 'amd64_rhel50' ):
00133 sysArch = 64
00134 sysDsc = 'SL5'
00135 sysName = 'amd64_rhel50'
00136
00137 print 'System:', sysName, '(', sysDsc, '), architecture:', sysArch
00138 envVarsFile.write( 'export SYSNAME=' + sysName + '\n' )
00139
00140
00141 if sysDsc == 'SL4':
00142 print 'Initialize SL4 settings'
00143 envVarsFile.write( 'export CXX="/usr/bin/g++"\n' )
00144 envVarsFile.write( 'export F77="/usr/bin/g77"\n' )
00145 envVarsFile.write( 'export FLIBS="-lfrtbegin -lg2c"\n' )
00146
00147 elif sysDsc == 'SL5':
00148 print 'Initialize SL5 settings'
00149 envVarsFile.write( 'export CXX="/usr/bin/g++44"\n' )
00150 envVarsFile.write( 'export F77="/usr/bin/gfortran44"\n' )
00151 envVarsFile.write( 'export FLIBS="-lgfortran -lgfortranbegin"\n' )
00152 else:
00153 print 'Unknown system name:',sysname,
00154
00155
00156 if len( versions[ 'prefix' ] ) == 0:
00157 prefix = '/afs/desy.de/group/alliance/mcg/public'
00158 else:
00159 prefix = versions[ 'prefix' ]
00160 envVarsFile.write( 'export PREFIX=' + prefix + '\n' )
00161
00162
00163 envVarsFile.write( 'export CLHEPversion=' + versions[ 'clhep-version' ] + '\n' );
00164 clhepDir = prefix + '/CLHEP/' + versions[ 'clhep-version' ] + '/' + sysName
00165 print 'CLHEP directory:', clhepDir
00166 envVarsFile.write( 'export CLHEPdir=' + clhepDir + '\n' );
00167
00168
00169 if sysDsc == 'SL5':
00170 envVarsFile.write( 'export CERNLIB=' + prefix + '/' + sysName + '/lib/cernlib/2006a/lib\n' )
00171 elif sysDsc == 'SL4':
00172 envVarsFile.write( 'export CERNLIB=/opt/products/cernlib/2005/lib\n' )
00173
00174
00175 rootVersion = '5.22.00'
00176 print 'ROOT version:', rootVersion
00177 envVarsFile.write( 'export ROOTver=' + rootVersion + '\n' )
00178
00179 if sysName.find( 'amd64' ) != -1:
00180 rootSys = '/opt/products/root64/' + rootVersion
00181 rootLib = rootSys + '/lib64'
00182 else:
00183 rootSys = '/opt/products/root/' + rootVersion
00184 rootLib = rootSys + '/lib'
00185 envVarsFile.write( 'export ROOTSYS=' + rootSys + '\n' )
00186 envVarsFile.write( 'export ROOTLIB=' + rootLib + '\n' )
00187 envVarsFile.write( 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTLIB\n' )
00188 envVarsFile.write( 'export PATH=$ROOTSYS/bin:$PATH\n' )
00189
00190 envVarsFile.write( 'export PDFPATH=' + prefix + '/MCGenerators/cascade/' + versions[ 'cascade-version' ] + '/data\n' )
00191
00192 return prefix, sysName
00193
00194
00195
00196
00197 def initializeNafSetup():
00198 print '== Initialize NAF setup =='
00199
00200
00201 sysNameInfo = os.popen( 'source check_platform_desy' ).readlines()
00202 sysname = sysNameInfo[0]
00203 print 'System:', sysname,
00204 envVarsFile.write( 'export SYSNAME=' + sysname + '\n' )
00205
00206
00207 if len( versions[ 'prefix' ] ) == 0:
00208 prefix = '/afs/desy.de/group/alliance/mcg/public'
00209 else:
00210 prefix = versions[ 'prefix' ]
00211 envVarsFile.write( 'export PREFIX=' + prefix + '\n' )
00212
00213
00214 rootVersion = '5.22.00'
00215 print 'ROOT version:', rootVersion
00216 envVarsFile.write( 'export ROOTver=' + rootVersion + '\n' )
00217
00218 if sysname.find( 'amd64' ) != -1:
00219 rootSys = '/afs/naf.desy.de/products/root/' + rootVersion
00220 rootLib = rootSys + '/lib'
00221 else:
00222 print 'No 32 bit ROOT version at NAF!'
00223 sys.exit( 2 )
00224 envVarsFile.write( 'export ROOTSYS=' + rootSys + '\n' )
00225 envVarsFile.write( 'export ROOTLIB=' + rootLib + '\n' )
00226 envVarsFile.write( 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTLIB\n' )
00227 envVarsFile.write( 'export PATH=$ROOTSYS/bin:$PATH\n' )
00228
00229
00230 envVarsFile.write( 'export CLHEPversion=' + versions[ 'clhep-version' ] + '\n' );
00231 clhepDir = prefix + '/CLHEP/' + versions[ 'clhep-version' ] + '/' + sysname
00232 print 'CLHEP dir:', clhepDir,
00233 envVarsFile.write( 'export CLHEPdir=' + clhepDir + '\n' );
00234
00235 envVarsFile.write( 'export CERNLIB=/opt/products/cernlib/2005/lib\n' )
00236 envVarsFile.write( 'export PDFPATH=' + prefix + '/MCGenerators/cascade/' + versions[ 'cascade-version' ] + '/data\n' )
00237
00238 return prefix, sysname
00239
00240
00241
00242
00243 def initializeCernSetup():
00244 print colours[ 'blue' ] + "[ Initialize CERN setup ]" + colours[ 'end' ]
00245
00246
00247 sysNameInfo = os.popen( 'source check_platform' ).readlines()
00248 sysname = sysNameInfo[1].split()[2]
00249
00250
00251 print 'System:', sysname
00252 envVarsFile.write( 'export SYSNAME=' + sysname + '\n' )
00253
00254 tmpTab = sysname.split( '-' )
00255 if len( tmpTab ) > 1:
00256 arch = tmpTab[ 0 ]
00257 slcVer = tmpTab[ 1 ]
00258 print 'Architecture:', arch
00259 print 'SLC version:', slcVer
00260 if slcVer == 'slc5':
00261
00262 gccSetup = '/afs/cern.ch/sw/lcg/external/gcc/4.3.5/' + arch + '/setup.sh\n'
00263 print 'Gcc setup file:', gccSetup
00264 gccSetupFile.write( 'source %s' % gccSetup )
00265
00266
00267
00268 gccVersion = os.popen( 'g++ --version' ).readline().split()[2]
00269 if gccVersion.startswith( '4' ):
00270 envVarsFile.write( 'export GFORTRAN=1\n' )
00271 print 'GFORTRAN = 1'
00272 envVarsFile.write( 'export F77="/usr/bin/gfortran44"\n' )
00273 envVarsFile.write( 'export FLIBS="-lgfortran -lgfortranbegin"\n' )
00274 else:
00275 print 'GFORTRAN = 0'
00276 envVarsFile.write( 'export F77="/usr/bin/g77"\n' )
00277 envVarsFile.write( 'export FLIBS="-lfrtbegin -lg2c"\n' )
00278 print 'GCC version:', gccVersion
00279
00280
00281 if len( versions[ 'prefix' ] ) == 0:
00282 prefix = '/afs/cern.ch/sw/lcg/external'
00283 else:
00284 prefix = versions[ 'prefix' ]
00285 envVarsFile.write( 'export PREFIX=' + prefix + '\n' )
00286
00287
00288
00289 rootVersion = '5.28.00e'
00290 print 'ROOT version:', rootVersion
00291 envVarsFile.write( 'export ROOTver=' + rootVersion + '\n' )
00292 rootSys = '/afs/cern.ch/sw/lcg/app/releases/ROOT/' + rootVersion + '/' + sysname + '/root'
00293 print 'ROOT path:', rootSys
00294 envVarsFile.write( 'export ROOTSYS=' + rootSys + '\n' )
00295 rootLib = rootSys + '/lib'
00296 print 'ROOT lib:', rootLib
00297 envVarsFile.write( 'export ROOTLIB=' + rootLib + '\n' )
00298 envVarsFile.write( 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:' + rootLib + '\n' )
00299 envVarsFile.write( 'export PATH=' + rootSys + '/bin:$PATH\n' )
00300
00301
00302
00303 envVarsFile.write( 'export CLHEPversion=' + versions[ 'clhep-version' ] + '\n' );
00304 clhepDir = prefix + '/clhep/' + versions[ 'clhep-version' ] + '/' + sysname
00305 print 'CLHEP dir:', clhepDir
00306 envVarsFile.write( 'export CLHEPdir=' + clhepDir + '\n' );
00307
00308 envVarsFile.write( 'export CERNLIB=' + prefix + '/cernlib/2006b/' + sysname + '/lib' + '\n' )
00309 envVarsFile.write( 'export PDFPATH=' + prefix + '/MCGenerators/cascade/' + versions[ 'cascade-version' ] + '/share/data\n' )
00310 return prefix, sysname
00311
00312
00313
00314
00315 def initializeStdLibs( prefix, sysname ):
00316 hepmc_suff = ''
00317 pythia8_hepmc_suff = ''
00318 if ( versions[ 'hepmc-version' ] == '2.06.03' ):
00319 pythia8_hepmc_suff = '_hepmc20603'
00320
00321 envVarsFile.write( 'export HepMCdir=' + prefix + '/HepMC/' + versions[ 'hepmc-version' ] + '/' + sysname + '\n' )
00322 envVarsFile.write( 'export HepPDTdir=' + prefix + '/HepPDT/' + versions[ 'heppdt-version'] + '/' + sysname + '\n' )
00323
00324 envVarsFile.write( 'export FastJetdir=' + prefix + '/fastjet/' + versions[ 'fastjet-version'] + '/' + sysname + '\n' )
00325 envVarsFile.write( 'export GSLdir=' + prefix + '/GSL/' + versions[ 'gsl-version'] + '/' + sysname + '\n' )
00326
00327 envVarsFile.write( 'export Pythia8dir=' + prefix + '/MCGenerators' + pythia8_hepmc_suff + '/pythia8/' + versions[ 'pythia8-version'] + '/' + sysname + '\n' )
00328 envVarsFile.write( 'export Pythia8DATA=' + prefix + '/MCGenerators' + pythia8_hepmc_suff + '/pythia8/' + versions[ 'pythia8-version'] + '/share/xmldoc\n' )
00329
00330 envVarsFile.write( 'export Pythia6dir=' + prefix + '/MCGenerators' + hepmc_suff + '/pythia6/' + versions[ 'pythia6-version'] + '/' + sysname + '\n' )
00331 envVarsFile.write( 'export Alpgendir=' + prefix + '/MCGenerators' + hepmc_suff + '/alpgen/' + versions[ 'alpgen-version'] + '/' + sysname + '\n' )
00332
00333 envVarsFile.write( 'export Herwigppdir=' + prefix + '/MCGenerators' + hepmc_suff + '/herwig++/' + versions[ 'herwigpp-version'] + '/' + sysname + '\n' )
00334 envVarsFile.write( 'export ThePEGdir=' + prefix + '/MCGenerators' + hepmc_suff + '/thepeg/' + versions[ 'thepeg-version'] + '/' + sysname + '\n' )
00335 envVarsFile.write( 'export Herwigdir=' + prefix + '/MCGenerators' + hepmc_suff + '/herwig/' + versions[ 'herwig-version'] + '/' + sysname + '\n' )
00336 envVarsFile.write( 'export Jimmydir=' + prefix + '/MCGenerators' + hepmc_suff + '/jimmy/' + versions[ 'jimmy-version'] + '/' + sysname + '\n' )
00337 envVarsFile.write( 'export LHAPDFdir=' + prefix + '/MCGenerators' + hepmc_suff + '/lhapdf/' + versions[ 'lhapdf-version'] + '/' + sysname + '\n' )
00338 envVarsFile.write( 'export LHAPDFsets=' + prefix + '/MCGenerators' + hepmc_suff + '/lhapdf/' + versions[ 'lhapdf-version'] + '/share/PDFsets\n' )
00339 envVarsFile.write( 'export LHAPATH=' + prefix + '/MCGenerators' + hepmc_suff + '/lhapdf/' + versions[ 'lhapdf-version'] + '/share/PDFsets\n' )
00340 envVarsFile.write( 'export Cascadedir=' + prefix + '/MCGenerators' + hepmc_suff + '/cascade/' + versions[ 'cascade-version'] + '/' + sysname + '\n' )
00341 envVarsFile.write( 'export Tauoladir=' + prefix + '/MCGenerators' + hepmc_suff + '/tauola/' + versions[ 'tauola-version'] + '/' + sysname + '\n' )
00342 envVarsFile.write( 'export Photosdir=' + prefix + '/MCGenerators' + hepmc_suff + '/photos/' + versions[ 'photos-version'] + '/' + sysname + '\n' )
00343
00344
00345 envVarsFile.write( 'export Herwigppversion=' + versions[ 'herwigpp-version'] + '\n' )
00346
00347
00348 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Pythia8dir/lib\n" )
00349 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Pythia8DATA\n" )
00350 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Pythia6dir/lib\n" )
00351 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Alpgendir/lib\n" )
00352 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSLdir/lib/\n" )
00353 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HepMCdir/lib\n" )
00354 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HepPDTdir/lib\n" )
00355 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CLHEPdir/lib\n" )
00356 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FastJetdir/lib\n" )
00357 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LHAPDFdir/lib\n" )
00358 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Herwigppdir/lib/Herwig++\n" )
00359 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Herwigdir/lib\n" )
00360 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Jimmydir/lib\n" )
00361 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ThePEGdir/lib/ThePEG\n" )
00362 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Cascadedir/lib\n" )
00363 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Tauoladir/lib\n" )
00364 envVarsFile.write( "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Photosdir/lib\n" )
00365 envVarsFile.write( "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MYCLASS_PATH/lib\n" )
00366
00367 return
00368
00369
00370 def detectLocation():
00371 loc = os.popen( 'hostname -d' ).read()
00372 print 'Location:', loc,
00373 curr_dir = os.popen( 'pwd' ).read()
00374 print 'Current working directory:', curr_dir,
00375 return loc, curr_dir
00376
00377
00378 def contains( theString, theQueryValue ):
00379 return theString.find( theQueryValue ) > -1
00380
00381
00382 def showHelp():
00383 print 'configure.py - HepMCAnalysis tool configuration script (Version: 0.1)\n'
00384 print 'Usage: source configure [arguments]\n'
00385 print 'Arguments:'
00386 for arg in versions.keys():
00387 print ' --' + arg
00388 print '\nTo specify different version of a generator use command like:'
00389 print ' source configure --pythia8-version=135\n'
00390
00391
00392
00393
00394 if __name__ == "__main__":
00395 main()
00396 envVarsFile.close()
00397 gccSetupFile.close()
00398