def WriteMakefiles(self, option=""): from madanalysis.build.makefile_writer import MakefileWriter options = MakefileWriter.MakefileOptions() # Name of the Makefile filename = self.path + "/Build/Makefile" # Header title = 'MadAnalysis Job' # Options options.has_commons = True options.has_process = True if self.main.archi_info.has_root: options.has_root_inc = True options.has_root_lib = True #options.has_userpackage = True toRemove = [ 'Log/compilation.log', 'Log/linking.log', 'Log/cleanup.log', 'Log/mrproper.log' ] # File to compile cppfiles = ['Main/*.cpp', 'SampleAnalyzer/User/*/*.cpp'] hfiles = ['Main/*.h', 'SampleAnalyzer/User/*/*.h'] # Files to produce isLibrary = False ProductName = 'MadAnalysis5job' ProductPath = './' # Write makefile MakefileWriter.Makefile(filename, title, ProductName, ProductPath, isLibrary, cppfiles, hfiles, options, self.main.archi_info, toRemove, moreIncludes=['./']) # Setup from madanalysis.build.setup_writer import SetupWriter SetupWriter.WriteSetupFile(True, self.path + '/Build/', self.main.archi_info) SetupWriter.WriteSetupFile(False, self.path + '/Build/', self.main.archi_info) # Ok return True
def Activate(self): # output = 1: activation successfull. # output = 0: nothing is done. # output = -1: error user_info = UserInfo() user_info.ReadUserOptions( self.main.archi_info.ma5dir + '/madanalysis/input/installation_options.dat') checker = ConfigChecker(self.main.archi_info, user_info, self.main.session_info, self.main.script, False) hasdelphes = checker.checkDelphes(True) if hasdelphes: # Paths delpath = os.path.normpath( self.main.archi_info.delphes_lib_paths[0]) deldeac = delpath.replace("DEACT_", "") self.main.archi_info.delphes_lib = self.main.archi_info.delphes_lib.replace( "DEACT_", "") self.main.archi_info.delphes_original_libs =\ [x.replace("DEACT_","") for x in self.main.archi_info.delphes_original_libs] self.main.archi_info.delphes_inc_paths =\ [ x.replace("DEACT_","") for x in self.main.archi_info.delphes_inc_paths ] if len(self.main.archi_info.delphes_inc_paths) > 2: del self.main.archi_info.delphes_inc_paths[-1] del self.main.archi_info.delphes_inc_paths[-1] self.main.archi_info.delphes_lib_paths =\ list(set([ x.replace("DEACT_","") for x in self.main.archi_info.delphes_lib_paths ])) # do we have to activate delphes? if not 'DEACT' in delpath: return 0 self.logger.warning("Delphes is deactivated. Activating it.") # naming shutil.move(delpath, deldeac) # Compiler setup compiler = LibraryWriter('lib', self.main) ncores = compiler.get_ncores2() from madanalysis.build.setup_writer import SetupWriter SetupWriter.WriteSetupFile( True, self.main.archi_info.ma5dir + '/tools/SampleAnalyzer/', self.main.archi_info) SetupWriter.WriteSetupFile( False, self.main.archi_info.ma5dir + '/tools/SampleAnalyzer/', self.main.archi_info) # if ncores>1: # strcores='-j'+str(ncores) ToBuild = ['delphes', 'root', 'process'] # Makefile self.main.archi_info.has_delphes = True self.main.archi_info.delphes_priority = True dpath = os.path.normpath( os.path.join(self.main.archi_info.ma5dir, 'tools', 'delphes')) mylib = os.path.normpath(os.path.join(dpath, 'libDelphes.so')) self.main.archi_info.libraries['Delphes'] = mylib + ":" + str( os.stat(mylib).st_mtime) self.main.archi_info.toLDPATH1 = [ x for x in self.main.archi_info.toLDPATH1 if not 'MA5tune' in x ] self.main.archi_info.toLDPATH1.append(dpath) for mypackage in ToBuild: if not compiler.WriteMakefileForInterfaces(mypackage): self.logger.error("library building aborted.") return -1 # Cleaning for mypackage in ToBuild: myfolder = 'Process' if mypackage != 'process': myfolder = 'Interfaces' if not compiler.MrProper( mypackage, self.main.archi_info.ma5dir + '/tools/SampleAnalyzer/' + myfolder): self.logger.error("Library '" + mypackage + "' precleaning aborted.") return -1 # Compiling for mypackage in ToBuild: myfolder = 'Process' if mypackage != 'process': myfolder = 'Interfaces' if not compiler.Compile( ncores, mypackage, self.main.archi_info.ma5dir + '/tools/SampleAnalyzer/' + myfolder): self.logger.error("Library '" + mypackage + "' compilation aborted.") return -1 # Linking for mypackage in ToBuild: myfolder = 'Process' if mypackage != 'process': myfolder = 'Interfaces' if not compiler.Link( mypackage, self.main.archi_info.ma5dir + '/tools/SampleAnalyzer/' + myfolder): self.logger.error("Library '" + mypackage + "' linking aborted.") return -1 # Checking for mypackage in ToBuild: if mypackage == 'process': myfolder = 'Lib/libprocess_for_ma5.so' elif mypackage == 'root': myfolder = 'Lib/libroot_for_ma5.so' else: myfolder = 'Lib/libdelphes_for_ma5.so' if not os.path.isfile(self.main.archi_info.ma5dir + '/tools/SampleAnalyzer/' + myfolder): self.logger.error("Library '" + mypackage + "' checking aborted.") return -1 # Cleaning for mypackage in ToBuild: myfolder = 'Process' if mypackage != 'process': myfolder = 'Interfaces' if not compiler.Clean( mypackage, self.main.archi_info.ma5dir + '/tools/SampleAnalyzer/' + myfolder): self.logger.error("Library '" + mypackage + "' cleaning aborted.") return -1 # Paths lev = self.logger.getEffectiveLevel() self.logger.setLevel(100) checkup = CheckUp(self.main.archi_info, self.main.session_info, False, self.main.script) if not checkup.SetFolder(): self.logger.error("Problem with the path updates.") return -1 if not self.main.archi_info.save(self.main.archi_info.ma5dir + '/tools/architecture.ma5'): return -1 if not self.main.CheckConfig(): return -1 self.logger.setLevel(lev) return 1
def BuildLibrary(self, forced=False): builder = LibraryBuilder(self.archi_info) UpdateNeed = False FirstUse, Missing = builder.checkMA5() if not FirstUse and not Missing: UpdateNeed = not builder.compare() rebuild = forced or FirstUse or UpdateNeed or Missing if not rebuild: if not os.path.isfile( self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libprocess_for_ma5.so'): FirstUse = True rebuild = forced or FirstUse or UpdateNeed or Missing if not rebuild: self.logger.info(' => MadAnalysis libraries found.') # Test the program if not os.path.isfile( self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestSampleAnalyzer'): FirstUse = True precompiler = LibraryWriter('lib', self) if not precompiler.Run( 'TestSampleAnalyzer', [ self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/Process/dummy_list.txt' ], self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/', silent=True): UpdateNeed = True if not precompiler.CheckRun( 'TestSampleAnalyzer', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/', silent=True): UpdateNeed = True rebuild = forced or FirstUse or UpdateNeed or Missing if not rebuild: self.logger.info(' => MadAnalysis test program works.') return True # Compile library if FirstUse: self.logger.info( " => First use of MadAnalysis (or the library is missing).") elif Missing: self.logger.info( " => Libraries are missing or system configuration has changed. Need to rebuild the library." ) elif UpdateNeed: self.logger.info( " => System configuration has changed since the last use. Need to rebuild the library." ) elif forced: self.logger.info(" => The user forces to rebuild the library.") # Initializing the JobWriter compiler = LibraryWriter('lib', self) # Dumping architecture if not self.archi_info.save(self.archi_info.ma5dir + '/tools/architecture.ma5'): sys.exit() # Library to compiles # |- [0] = unique name # |- [1] = title of the library to display # |- [2] = # |- [3] = output file to cross-check # |- [4] = folder # |- [5] = False=Library, True=Executable libraries = [] libraries.append([ 'configuration', 'SampleAnalyzer configuration', 'configuration', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/PortabilityCheckup', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Configuration', True ]) libraries.append([ 'commons', 'SampleAnalyzer commons', 'commons', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libcommons_for_ma5.so', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Commons', False ]) libraries.append([ 'test_commons', 'SampleAnalyzer commons', 'test_commons', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestCommons', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/', True ]) # Zlib if self.archi_info.has_zlib: libraries.append([ 'zlib', 'interface to zlib', 'zlib', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libzlib_for_ma5.so', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Interfaces', False ]) libraries.append([ 'test_zlib', 'interface to zlib', 'test_zlib', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestZlib', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/', True ]) # Fastjet if self.archi_info.has_fastjet: libraries.append([ 'FastJet', 'interface to FastJet', 'fastjet', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libfastjet_for_ma5.so', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Interfaces', False ]) libraries.append([ 'test_fastjet', 'interface to Fastjet', 'test_fastjet', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestFastjet', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/', True ]) # Delphes if self.archi_info.has_delphes: libraries.append([ 'Delphes', 'interface to Delphes', 'delphes', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libdelphes_for_ma5.so', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Interfaces', False ]) libraries.append([ 'test_delphes', 'interface to Delphes', 'test_delphes', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestDelphes', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/', True ]) # DelphesMA5tune if self.archi_info.has_delphesMA5tune: libraries.append([ 'Delphes-MA5tune', 'interface to Delphes-MA5tune', 'delphesMA5tune', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libdelphesMA5tune_for_ma5.so', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Interfaces', False ]) libraries.append([ 'test_delphesMA5tune', 'interface to DelphesMA5tune', 'test_delphesMA5tune', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestDelphesMA5tune', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/', True ]) # Root if self.archi_info.has_root: libraries.append([ 'Root', 'interface to Root', 'root', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libroot_for_ma5.so', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Interfaces', False ]) libraries.append([ 'test_root', 'interface to Root', 'test_root', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestRoot', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/', True ]) # Process libraries.append([ 'process', 'SampleAnalyzer core', 'process', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libprocess_for_ma5.so', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Process', False ]) libraries.append([ 'test_process', 'SampleAnalyzer core', 'test_process', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestSampleAnalyzer', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/', True ]) # Writing the Makefiles self.logger.info("") self.logger.info( " **********************************************************") self.logger.info( " Building SampleAnalyzer libraries ") self.logger.info( " **********************************************************") # Getting number of cores ncores = compiler.get_ncores2() # Writing the main Makefile from madanalysis.build.makefile_writer import MakefileWriter options = MakefileWriter.UserfriendlyMakefileOptions() options.has_commons = True options.has_process = True options.has_test = True options.has_zlib = self.archi_info.has_zlib options.has_fastjet = self.archi_info.has_fastjet options.has_delphes = self.archi_info.has_delphes options.has_delphesMA5tune = self.archi_info.has_delphesMA5tune #MakefileWriter.UserfriendlyMakefileForSampleAnalyzer(self.archi_info.ma5dir+'/tools/SampleAnalyzer/Makefile',options) # Writing the setup self.logger.info(" Writing the setup files ...") from madanalysis.build.setup_writer import SetupWriter SetupWriter.WriteSetupFile( True, self.archi_info.ma5dir + '/tools/SampleAnalyzer/', self.archi_info) SetupWriter.WriteSetupFile( False, self.archi_info.ma5dir + '/tools/SampleAnalyzer/', self.archi_info) # Writing the makefile self.logger.info(" Writing all the Makefiles ...") for ind in range(0, len(libraries)): if not compiler.WriteMakefileForInterfaces(libraries[ind][2]): self.logger.error("library building aborted.") sys.exit() if not compiler.WriteMakefileForInterfaces('test'): self.logger.error("test program building aborted.") sys.exit() # Compiling the libraries for ind in range(0, len(libraries)): isLibrary = not libraries[ind][5] if isLibrary: product = 'library' else: product = 'test program' self.logger.info( " **********************************************************" ) self.logger.info(" Component " + str(ind + 1) + "/" + str(len(libraries)) + " - " + product + ": " + libraries[ind][1]) # Cleaning the project self.logger.info( " - Cleaning the project before building the " + product + " ...") if not compiler.MrProper(libraries[ind][2], libraries[ind][4]): self.logger.error("The " + product + " building aborted.") sys.exit() # Compiling self.logger.info(" - Compiling the source files ...") if not compiler.Compile(ncores, libraries[ind][2], libraries[ind][4]): self.logger.error("The " + product + " building aborted.") sys.exit() # Linking self.logger.info(" - Linking the " + product + " ...") if not compiler.Link(libraries[ind][2], libraries[ind][4]): self.logger.error("The " + product + " building aborted.") sys.exit() # Checking self.logger.info(" - Checking that the " + product + " is properly built ...") if not os.path.isfile(libraries[ind][3]): self.logger.error("The " + product + " '" + libraries[ind][3] + "' is not produced.") sys.exit() # Cleaning the project self.logger.info( " - Cleaning the project after building the " + product + " ...") if not compiler.Clean(libraries[ind][2], libraries[ind][4]): self.logger.error("library building aborted.") sys.exit() if not isLibrary: # Running the program test self.logger.info(" - Running the test program ...") program = libraries[ind][3].split('/')[-1] argv = [] if program == 'TestSampleAnalyzer': argv = [ self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/Process/dummy_list.txt' ] if not compiler.Run( program, argv, self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/'): self.logger.error("the test failed.") sys.exit() # Checking the program output self.logger.info(" - Checking the program output...") if libraries[ind][0] == "configuration": if not compiler.CheckRunConfiguration( program, self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/'): self.logger.error("the test failed.") sys.exit() else: if not compiler.CheckRun( program, self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/'): self.logger.error("the test failed.") sys.exit() # Print Ok self.logger.info(' => Status: \x1b[32m' + '[OK]' + '\x1b[0m') self.logger.info( " **********************************************************") self.logger.info("") return True