configure.py

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

Generated on Tue Mar 1 01:18:30 2011 for HepMCAnalysis by  doxygen 1.4.7