def closeOutStep0Requests(url, workflows):
	for workflow in workflows:
		#print workflow
		datasets=phedexSubscription.outputdatasetsWorkflow(url, workflow)
		closeOutWorkflow=True
		if getRequestTeam(url, workflow)!='analysis':#If request is not in special queue
			for dataset in datasets:
				closeOutDataset=False
				Percentage=PercentageCompletion(url, workflow, dataset)
				PhedexSubscription=CustodialMoveSubscriptionCreated(dataset)
				if PhedexSubscription!=False:
					site=PhedexSubscription
					TransPercen=TransferPercentage(url, dataset, site)
				duplicate=dbsTest.duplicateLumi(dataset)
				correctLumis=dbsTest.checkCorrectLumisEventGEN(dataset)
				if Percentage>=float(0.95) and PhedexSubscription!=False and not duplicate and correctLumis:
					closeOutDataset=True
				else:
		 			closeOutDataset=False
				closeOutWorkflow=closeOutWorkflow and closeOutDataset
				print '| %80s | %100s | %4s | %5s| %3s | %5s| %5s| ' % (workflow, dataset,str(int(Percentage*100)), str(PhedexSubscription), str(correctLumis), duplicate, closeOutDataset)
			if closeOutWorkflow:
				phedexSubscription.closeOutWorkflow(url, workflow)
		
	print'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
def closeOutMonterCarloRequests(url, workflows):
	for workflow in workflows:
		datasets=phedexSubscription.outputdatasetsWorkflow(url, workflow)
		closeOutWorkflow=True
		if getRequestTeam(url, workflow)!='analysis':#If request is not in special queue
			for dataset in datasets:
				ClosePercentage=0.90
				#if 'SMS' in dataset:
				#	ClosePercentage=1
				closeOutDataset=True
				Percentage=PercentageCompletion(url, workflow, dataset)
				PhedexSubscription=CustodialMoveSubscriptionCreated(dataset)
				TransPercen=0
				closedBlocks=False
				if PhedexSubscription!=False:
					site=PhedexSubscription
					TransPercen=TransferPercentage(url, dataset, site)
				duplicate=True
				if PhedexSubscription!=False and Percentage>=float(0.9):
					duplicate=dbsTest.duplicateLumi(dataset)
					closedBlocks = True #dbsTest.hasAllBlocksClosed(dataset)
				if Percentage>=float(ClosePercentage) and PhedexSubscription!=False and not duplicate:
					closeOutDataset=True
				else:
		 			closeOutDataset=False
				closeOutWorkflow=closeOutWorkflow and closeOutDataset
				print '| %80s | %100s | %4s | %5s| %3s | %5s|%5s| %5s|' % (workflow, dataset,str(int(Percentage*100)), str(PhedexSubscription), str(int(TransPercen*100)), duplicate, closedBlocks, closeOutDataset)
			if closeOutWorkflow:
				phedexSubscription.closeOutWorkflow(url, workflow)
		
	print'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------' 				    
def closeOutRedigiWorkflows(url, workflows):
	for workflow in workflows:
		closeOutWorkflow=True
		InputDataset=dbsTest.getInputDataSet(url, workflow)
		datasets=phedexSubscription.outputdatasetsWorkflow(url, workflow)
		for dataset in datasets:
			closeOutDataset=False
			Percentage=PercentageCompletion(url, workflow, dataset)
			PhedexSubscription=testOutputDataset(dataset)
			duplicate=True
			if PhedexSubscription!=False and Percentage>=float(0.95):
				duplicate=dbsTest.duplicateRunLumi(dataset)
			if Percentage>=float(0.95) and PhedexSubscription and not duplicate:
				closeOutDataset=True
			else:
		 		closeOutDataset=False
			closeOutWorkflow=closeOutWorkflow and closeOutDataset
			print '| %80s | %100s | %4s | %5s| %3s | %5s|%5s| ' % (workflow, dataset,str(int(Percentage*100)), str(PhedexSubscription), 100, duplicate, closeOutDataset)
		if closeOutWorkflow:
			phedexSubscription.closeOutWorkflow(url, workflow)
	print '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
def closeOutReRecoWorkflows(url, workflows):
	for workflow in workflows:
		if 'RelVal' in workflow:
			continue
    		if 'TEST' in workflow:
			continue
		datasets=phedexSubscription.outputdatasetsWorkflow(url, workflow)
		closeOutWorkflow=True
		InputDataset=dbsTest.getInputDataSet(url, workflow)
		for dataset in datasets:
			duplicate=False
			closeOutDataset=True
			Percentage=PercentageCompletion(url, workflow, dataset)
			PhedexSubscription=testOutputDataset(dataset)
			closeOutDataset=False
			if Percentage==1 and PhedexSubscription and not duplicate:
				closeOutDataset=True
			else:
         			closeOutDataset=False
			closeOutWorkflow=closeOutWorkflow and closeOutDataset
			print '| %80s | %100s | %4s | %5s| %3s | %5s|%5s| ' % (workflow, dataset,str(int(Percentage*100)), str(PhedexSubscription), 100, duplicate, closeOutDataset)
		if closeOutWorkflow:
			phedexSubscription.closeOutWorkflow(url, workflow)
	print '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
def closeOutTaskChainWorkflows(url, workflow):
    #for workflow in workflows:
    #print workflow + " can be closed-out"
    phedexSubscription.closeOutWorkflow(url, workflow)