def sendToBatchSystem(self): #set project paths remote_se = False projectPath = os.path.join( os.path.expandvars(self._args.work), self._date_now + "_" + self._args.project_name) localProjectPath = projectPath if projectPath.startswith("srm://"): remote_se = True localProjectPath = os.path.join( os.path.expandvars(self._parser.get_default("work")), self._date_now + "_" + self._args.project_name) #create folders if not os.path.exists(localProjectPath): os.makedirs(localProjectPath) os.makedirs(os.path.join(localProjectPath, "output")) # write dbs file dbsFileContent = tools.write_dbsfile( self._gridControlInputFiles, max_files_per_nick=self._args.pilot_job_files) dbsFileBasename = "datasets.dbs" dbsFileBasepath = os.path.join(localProjectPath, dbsFileBasename) with open(dbsFileBasepath, "w") as dbsFile: dbsFile.write(dbsFileContent) gcConfigFilePath = os.path.expandvars(self._args.gc_config) gcConfigFile = open(gcConfigFilePath, "r") tmpGcConfigFileBasename = "grid-control_config.conf" tmpGcConfigFileBasepath = os.path.join(localProjectPath, tmpGcConfigFileBasename) # open base file and save it to a list tmpGcConfigFile = open(tmpGcConfigFileBasepath, "w") gcConfigFileContent = gcConfigFile.readlines() gcConfigFile.close() sepathRaw = os.path.join(projectPath, "output") epilogArguments = r"epilog arguments = " epilogArguments += r"-a %s " % self._args.analysis epilogArguments += r"--disable-repo-versions " epilogArguments += r"--log-level " + self._args.log_level + " " if self._args.log_to_se: epilogArguments += r"--log-files " + os.path.join( sepathRaw, "${DATASETNICK}", "${DATASETNICK}_job_${MY_JOBID}_log.log") + " " else: epilogArguments += r"--log-files log.log --log-stream stdout " epilogArguments += r"--print-envvars ROOTSYS CMSSW_BASE DATASETNICK FILE_NAMES LD_LIBRARY_PATH " #epilogArguments += r"-c " + os.path.basename(self._configFilename) + " " epilogArguments += "--nick $DATASETNICK " epilogArguments += "-i $FILE_NAMES " if self._args.copy_remote_files: epilogArguments += "--copy-remote-files " if not self._args.ld_library_paths is None: epilogArguments += ("--ld-library-paths %s" % " ".join(self._args.ld_library_paths)) sepath = "se path = " + (self._args.se_path if self._args.se_path else sepathRaw) workdir = "workdir = " + os.path.join(localProjectPath, "workdir") backend = open( os.path.expandvars( "$CMSSW_BASE/src/Artus/Configuration/data/grid-control_backend_" + self._args.batch + ".conf"), 'r').read() self.replacingDict = dict( include=("include = " + " ".join(self._args.gc_config_includes) if self._args.gc_config_includes else ""), epilogexecutable="epilog executable = " + os.path.basename(sys.argv[0]), sepath=sepath, workdir=workdir, jobs="" if self._args.fast is None else "jobs = " + str(self._args.fast), inputfiles="input files = \n\t" + os.path.expandvars( os.path.join("$CMSSW_BASE/bin/$SCRAM_ARCH", os.path.basename(sys.argv[0]))), filesperjob="files per job = " + str(self._args.files_per_job), areafiles=self._args.area_files if (self._args.area_files != None) else "", walltime="wall time = " + self._args.wall_time, memory="memory = " + str(self._args.memory), cmdargs="cmdargs = " + self._args.cmdargs.replace( "m 3", "m 3" if self._args.pilot_job_files is None else "m 0"), dataset="dataset = \n\t:ListProvider:" + dbsFileBasepath, epilogarguments=epilogArguments, seoutputfiles="se output files = *.root" if self._args.log_to_se else "se output files = *.log *.root", backend=backend, partitionlfnmodifier="partition lfn modifier = " + self._args.partition_lfn_modifier if (self._args.partition_lfn_modifier != None) else "") self.modify_replacing_dict() for line in range(len(gcConfigFileContent)): gcConfigFileContent[line] = Template( gcConfigFileContent[line]).safe_substitute(self.replacingDict) for index, line in enumerate(gcConfigFileContent): gcConfigFileContent[index] = line.replace( "$CMSSW_BASE", os.environ.get("CMSSW_BASE", "")) gcConfigFileContent[index] = line.replace( "$X509_USER_PROXY", os.environ.get("X509_USER_PROXY", "")) # save it for line in gcConfigFileContent: tmpGcConfigFile.write(line) tmpGcConfigFile.close() exitCode = 0 command = "go.py " + tmpGcConfigFileBasepath if not self._args.no_run: log.info("Execute \"%s\"." % command) exitCode = logger.subprocessCall(command.split()) log.info("Output is written to directory \"%s\"" % sepathRaw) log.info("\nMerge outputs in one file per nick using") if remote_se: log.info( "se_output_download.py -lmo %s %s [-t 4]" % (os.path.join( localProjectPath, "output"), tmpGcConfigFileBasepath)) log.info("artusMergeOutputs.py %s [-n 4]" % (localProjectPath if remote_se else projectPath)) else: log.info("Stopped before executing \"%s\"." % command) if exitCode != 0: log.error("Exit with code %s.\n\n" % exitCode) #log.info("Dump configuration:\n") #log.info(self._configFilename) return exitCode
def sendToBatchSystem(self): # write dbs file dbsFileContent = tools.write_dbsfile(self._gridControlInputFiles, max_files_per_nick=self._args.pilot_job_files) dbsFileBasename = "datasets.dbs" dbsFileBasepath = os.path.join(self.localProjectPath, dbsFileBasename) with open(dbsFileBasepath, "w") as dbsFile: dbsFile.write(dbsFileContent) gcConfigFilePath = os.path.expandvars(self._args.gc_config) with open(gcConfigFilePath,"r") as gcConfigFile: tmpGcConfigFileBasename = "grid-control_config.conf" tmpGcConfigFileBasepath = os.path.join(self.localProjectPath, tmpGcConfigFileBasename) # open base file and save it to a list tmpGcConfigFile = open(tmpGcConfigFileBasepath,"w") gcConfigFileContent = gcConfigFile.readlines() sepathRaw = os.path.join(self.projectPath, "output") epilogArguments = "" epilogArguments = self.createEpilogArguments() sepath = "se path = " + (self._args.se_path if self._args.se_path else sepathRaw) workdir = "workdir = " + os.path.join(self.localProjectPath, "workdir") backend = "" with open(os.path.expandvars("$CMSSW_BASE/src/Artus/Configuration/data/grid-control_backend_" + self._args.batch + ".conf"), 'r') as backend_config_file: backend = backend_config_file.read() self.replacingDict = dict( include = ("include = " + " ".join(self._args.gc_config_includes) if self._args.gc_config_includes else ""), epilogexecutable = "epilog executable = " + os.path.basename(sys.argv[0]), sepath = sepath, workdir = workdir, jobs = "" if self._args.fast is None else "jobs = " + str(self._args.fast), inputfiles = "input files = \n\t" + self._configFilename + "\n\t" + os.path.expandvars(os.path.join("$CMSSW_BASE/bin/$SCRAM_ARCH", os.path.basename(sys.argv[0]))), filesperjob = "files per job = " + str(self._args.files_per_job), areafiles = self._args.area_files if (self._args.area_files != None) else "", walltime = "wall time = " + self._args.wall_time, memory = "memory = " + str(self._args.memory), cmdargs = "cmdargs = " + self._args.cmdargs.replace("m 3", "m 3" if self._args.pilot_job_files is None else "m 0"), dataset = "dataset = \n\t:ListProvider:" + dbsFileBasepath, epilogarguments = epilogArguments, seoutputfiles = "se output files = *.root" if self._args.log_to_se else "se output files = *.log *.root", backend = backend, partitionlfnmodifier = "partition lfn modifier = " + self._args.partition_lfn_modifier if (self._args.partition_lfn_modifier != None) else "" ) self.modify_replacing_dict() self.replaceLines(gcConfigFileContent, self.replacingDict) for index, line in enumerate(gcConfigFileContent): gcConfigFileContent[index] = line.replace("$CMSSW_BASE", os.environ.get("CMSSW_BASE", "")) gcConfigFileContent[index] = line.replace("$X509_USER_PROXY", os.environ.get("X509_USER_PROXY", "")) # save it for line in gcConfigFileContent: tmpGcConfigFile.write(line) tmpGcConfigFile.close() exitCode = 1 command = "go.py " + tmpGcConfigFileBasepath log.info("Execute \"%s\"." % command) if not self._args.no_run: while exitCode != 0: exitCode = logger.subprocessCall(command.split()) log.info("Output is written to directory \"%s\"" % sepathRaw) log.info("\nMerge outputs in one file per nick using") if self.remote_se: log.info("se_output_download.py -lmo %s %s [-t 4]" % (os.path.join(self.localProjectPath, "output"), tmpGcConfigFileBasepath)) log.info("artusMergeOutputs.py %s [-n 4]" % (self.localProjectPath if self.remote_se else self.projectPath)) if exitCode != 0: log.error("Exit with code %s.\n\n" % exitCode) log.info("Dump configuration:\n") log.info(self._configFilename) return exitCode
default="-cG -m 3", help="Command line arguments for go.py. [Default: %(default)s]") #runningOptionsGroup.add_argument("--log-to-se", default=False, action="store_true", # help="Write logfile in batch mode directly to SE. Does not work with remote batch system") args = parser.parse_args() ProjectPath = os.path.expandvars(args.work) if not ProjectPath.startswith("/"): ProjectPath = os.path.join(os.getcwd(), ProjectPath) if not os.path.exists(ProjectPath): os.makedirs(ProjectPath) #write dbs file gridControlInputFiles = {} setInputFilenames(args.input_files, gridControlInputFiles) dbsFileContent = tools.write_dbsfile(gridControlInputFiles) dbsFileBasename = "datasets.dbs" dbsFileBasepath = os.path.join(ProjectPath, dbsFileBasename) with open(dbsFileBasepath, "w") as dbsFile: dbsFile.write(dbsFileContent) #read gc base config gcConfigFilePath = os.path.expandvars(args.gc_config) gcConfigFile = open(gcConfigFilePath, "r") gcConfigFileContent = gcConfigFile.readlines() gcConfigFile.close() tmpGcConfigFileBasename = "grid-control_config.conf" tmpGcConfigFileBasepath = os.path.join(ProjectPath, tmpGcConfigFileBasename) tmpGcConfigFile = open(tmpGcConfigFileBasepath, "w")
runningOptionsGroup.add_argument("--cmdargs", default="-cG -m 3", help="Command line arguments for go.py. [Default: %(default)s]") #runningOptionsGroup.add_argument("--log-to-se", default=False, action="store_true", # help="Write logfile in batch mode directly to SE. Does not work with remote batch system") args = parser.parse_args() ProjectPath = os.path.expandvars(args.work) if not ProjectPath.startswith("/"): ProjectPath = os.path.join(os.getcwd(), ProjectPath) if not os.path.exists(ProjectPath): os.makedirs(ProjectPath) #write dbs file gridControlInputFiles = {} setInputFilenames(args.input_files, gridControlInputFiles) dbsFileContent = tools.write_dbsfile(gridControlInputFiles) dbsFileBasename = "datasets.dbs" dbsFileBasepath = os.path.join(ProjectPath, dbsFileBasename) with open(dbsFileBasepath, "w") as dbsFile: dbsFile.write(dbsFileContent) #read gc base config gcConfigFilePath = os.path.expandvars(args.gc_config) gcConfigFile = open(gcConfigFilePath,"r") gcConfigFileContent = gcConfigFile.readlines() gcConfigFile.close() tmpGcConfigFileBasename = "grid-control_config.conf" tmpGcConfigFileBasepath = os.path.join(ProjectPath, tmpGcConfigFileBasename) tmpGcConfigFile = open(tmpGcConfigFileBasepath,"w")