Skip to content

Commit

Permalink
Merge branch 'develop' into remove_finaliseOnMaster
Browse files Browse the repository at this point in the history
  • Loading branch information
mesmith75 authored Jun 20, 2024
2 parents a14d57b + 8ea2af0 commit 7be0cca
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions ganga/GangaLHCb/Lib/LHCbDataset/BKQuery.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
import os
import datetime
# \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
from GangaCore.Core.exceptions import GangaException
from GangaCore.GPIDev.Schema import Schema, Version, SimpleItem, ComponentItem
from GangaCore.GPIDev.Base import GangaObject
from GangaCore.GPIDev.Base.Proxy import isType, stripProxy, addProxy
from GangaCore.GPIDev.Base.Proxy import isType, addProxy
from GangaCore.GPIDev.Credentials import require_credential
from GangaDirac.Lib.Credentials.DiracProxy import DiracProxy
from GangaDirac.Lib.Backends.DiracUtils import get_result
from GangaDirac.Lib.Utilities.DiracUtilities import GangaDiracError
from GangaDirac.Lib.Files.DiracFile import DiracFile
from GangaCore.Utility.logging import getLogger
from GangaLHCb.Lib.LHCbDataset import LHCbDataset, LHCbCompressedDataset
from GangaLHCb.Lib.Backends.Dirac import filterLFNsBySE
logger = getLogger()
#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
# \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#


class BKQuery(GangaObject):
Expand Down Expand Up @@ -101,7 +98,7 @@ class BKQuery(GangaObject):
schema['SMOG2'] = SimpleItem(defvalue='', typelist=['str', 'list'],
doc='Specify the state of SMOG2')
schema['retry_limit'] = SimpleItem(defvalue=1, typelist=['int'],
doc='Number of times to retry the DIRAC commands')
doc='Number of times to retry the DIRAC commands')
_schema = Schema(Version(1, 2), schema)
_category = 'query'
_name = "BKQuery"
Expand Down Expand Up @@ -129,16 +126,18 @@ def getDatasetMetadata(self):
msg = 'selection not supported for type="%s".' % self.type
raise GangaException(msg)
cmd = "getDataset('%s','%s','%s','%s','%s','%s', '%s')" % (self.path, self.dqflag,
self.type, self.startDate, self.endDate, self.selection, self.SMOG2)
self.type, self.startDate, self.endDate,
self.selection, self.SMOG2)
from GangaCore.GPIDev.Lib.GangaList.GangaList import GangaList
knownLists = [tuple, list, GangaList]
if isType(self.dqflag, knownLists):
cmd = "getDataset('%s',%s,'%s','%s','%s','%s', '%s')" % (self.path, self.dqflag,
self.type, self.startDate, self.endDate, self.selection, self.SMOG2)
self.type, self.startDate, self.endDate,
self.selection, self.SMOG2)

try:
value = get_result(cmd, 'BK query error.', credential_requirements=self.credential_requirements,
retry_limit = self.retry_limit)
retry_limit=self.retry_limit)
except GangaDiracError as err:
return {'OK': False, 'Value': str(err)}

Expand Down Expand Up @@ -173,13 +172,18 @@ def getDataset(self, compressed=True, SE=None):
msg = 'selection not supported for type="%s".' % self.type
raise GangaException(msg)
cmd = "getDataset('%s','%s','%s','%s','%s','%s', %s)" % (self.path, self.dqflag,
self.type, self.startDate, self.endDate, self.selection, self.SMOG2)
self.type, self.startDate, self.endDate,
self.selection, self.SMOG2)
from GangaCore.GPIDev.Lib.GangaList.GangaList import GangaList
knownLists = [tuple, list, GangaList]
if isType(self.dqflag, knownLists):
cmd = "getDataset('%s',%s,'%s','%s','%s','%s', %s)" % (self.path, self.dqflag, self.type, self.startDate,
self.endDate, self.selection, self.SMOG2)
result = get_result(cmd, 'BK query error.', credential_requirements=self.credential_requirements, retry_limit = self.retry_limit)
self.endDate, self.selection, self.SMOG2)
result = get_result(
cmd,
'BK query error.',
credential_requirements=self.credential_requirements,
retry_limit=self.retry_limit)
logger.debug("Finished Running Command")
files = []
value = result
Expand Down Expand Up @@ -209,7 +213,7 @@ def getDataset(self, compressed=True, SE=None):
logger.debug('Detected an MC data set. Checking if it has been archived')
all_reps = get_result("getReplicas(%s)" % files, 'Get replica error.',
credential_requirements=self.credential_requirements,
retry_limit = self.retry_limit)
retry_limit=self.retry_limit)
if 'Successful' in all_reps:
all_ses = set([])
for _lfn, _repz in all_reps['Successful'].items():
Expand All @@ -219,16 +223,18 @@ def getDataset(self, compressed=True, SE=None):
for _se in all_ses:
is_archived = get_result("isSEArchive('%s')" % _se, 'Check archive error.',
credential_requirements=self.credential_requirements,
retry_limit = self.retry_limit)
retry_limit=self.retry_limit)
if not is_archived:
all_archived = False
break
if all_archived and not self.ignore_archived:
raise GangaDiracError(
"All the files are only available on archive SEs. It is likely the data set has been archived. Contact data management to request that it be staged")
"All the files are only available on archive SEs. It is likely the data set has been archived. "
"Contact data management to request that it be staged")
elif all_archived:
logger.warning(
"All the files are only available on archive SEs. It is likely the data set has been archived. Contact data management to request that it be staged")
"All the files are only available on archive SEs. It is likely the data set has been archived. "
"Contact data management to request that it be staged")

if compressed:
ds = LHCbCompressedDataset(files)
Expand All @@ -246,7 +252,7 @@ def getDataset(self, compressed=True, SE=None):

return addProxy(ds)

#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
# \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#


class BKQueryDict(GangaObject):
Expand Down Expand Up @@ -300,8 +306,8 @@ def getDatasetMetadata(self):
cmd = 'bkQueryDict(%s)' % self.dict
try:
value = get_result(cmd, 'BK query error.', credential_requirements=self.credential_requirements,
retry_limit = self.retry_limit)
except GangaDiracError as err:
retry_limit=self.retry_limit)
except GangaDiracError:
return {'OK': False, 'Value': {}}

files = []
Expand All @@ -323,7 +329,7 @@ def getDataset(self):
return None
cmd = 'bkQueryDict(%s)' % self.dict
value = get_result(cmd, 'BK query error.', credential_requirements=self.credential_requirements,
retry_limit = self.retry_limit)
retry_limit=self.retry_limit)

files = []
if 'LFNs' in value:
Expand All @@ -338,4 +344,4 @@ def getDataset(self):

return addProxy(ds)

#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
# \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#

0 comments on commit 7be0cca

Please sign in to comment.