File indexing completed on 2026-04-10 08:39:06
0001 """
0002 ddm endpoint specification object
0003
0004 """
0005
0006 import re
0007
0008
0009 class DdmSpec(object):
0010
0011 def __init__(self):
0012 self.all = {}
0013 self.local = set()
0014 self.default_read = None
0015 self.default_write = None
0016 self.tape = set()
0017
0018 def add(self, relation, endpoint_dictionary):
0019 """
0020 Add an endpoint to the DDM specification.
0021
0022 This method adds an endpoint to the DDM specification by copying all properties
0023 about the DDM endpoint and relation. It also updates local endpoints, default
0024 read/write endpoints, and tape endpoints.
0025
0026 Args:
0027 relation (dict): A dictionary containing the relation properties.
0028 endpoint_dictionary (dict): A dictionary containing the endpoint properties.
0029 """
0030 name = relation["ddm_endpoint_name"]
0031
0032
0033 if name not in endpoint_dictionary:
0034 return
0035
0036
0037 self.all[name] = {}
0038 for key in endpoint_dictionary[name]:
0039 value = endpoint_dictionary[name][key]
0040 self.all[name][key] = value
0041 for key in relation:
0042 value = relation[key]
0043 self.all[name][key] = value
0044
0045
0046 if relation["is_local"] != "N":
0047 self.local.add(name)
0048
0049
0050 if relation["default_read"] == "Y":
0051 self.default_read = name
0052 if relation["default_write"] == "Y":
0053 self.default_write = name
0054
0055
0056 if relation["is_tape"] == "Y":
0057 self.tape.add(name)
0058
0059 def getAllEndPoints(self):
0060 """
0061 Get all DDM endpoints. This method returns a list of all DDM endpoints.
0062
0063 Returns:
0064 list: A list of all DDM endpoints.
0065 """
0066 return list(self.all)
0067
0068 def getEndPoint(self, endpoint_name):
0069 """
0070 Get a specific DDM endpoint.
0071
0072 This method returns the properties of a specific DDM endpoint.
0073
0074 Args:
0075 endpoint_name (str): The name of the DDM endpoint.
0076 Returns:
0077 dict or None: A dictionary containing the properties of the DDM endpoint, or None if not found.
0078 """
0079 if endpoint_name in self.all:
0080 return self.all[endpoint_name]
0081 return None
0082
0083 def getLocalEndPoints(self):
0084 """
0085 This method returns a sorted list of local DDM endpoints.
0086
0087 Returns:
0088 list: A sorted list of local DDM endpoints.
0089 """
0090 sorted_endpoints = sorted(self.local)
0091 return sorted_endpoints
0092
0093 def getDefaultWrite(self):
0094 """
0095 This method returns the default write DDM endpoint.
0096
0097 Returns:
0098 str or None: The default write DDM endpoint, or None if not set.
0099 """
0100 return self.default_write
0101
0102 def getDefaultRead(self):
0103 """
0104 This method returns the default read DDM endpoint.
0105
0106 Returns:
0107 str or None: The default write DDM endpoint, or None if not set.
0108 """
0109 return self.default_read
0110
0111 def getTapeEndPoints(self):
0112 """
0113 This method returns a tuple of tape DDM endpoints.
0114
0115 Returns:
0116 tuple: A tuple of tape DDM endpoints.
0117 """
0118 return tuple(self.tape)
0119
0120 def isAssociated(self, endpoint_name):
0121 """
0122 This method checks if a given endpoint name is associated with any DDM endpoint.
0123
0124 Args:
0125 endpoint_name (str): The name of the DDM endpoint.
0126
0127 Returns:
0128 bool: True if the endpoint is associated, False otherwise.
0129 """
0130 return endpoint_name in self.all
0131
0132 def getAssociatedEndpoint(self, patt, mode="output"):
0133 """
0134 This method returns the DDM endpoint associated with a given pattern and of the lowest order.
0135
0136 Args:
0137 patt (str): The pattern to match.
0138 mode (str): The mode, either "input" or "output". Default is "output".
0139 Returns:
0140 dict or None: A dictionary containing the properties of the associated DDM endpoint, or None if not found.
0141 """
0142 patt = patt.split("/")[-1]
0143 if patt in self.all:
0144 return self.all[patt]
0145
0146 endpoint = None
0147 order = 10**6
0148 for tmp_ddm_endpoint_name in self.all:
0149 tmp_ddm_endpoint_dict = self.all[tmp_ddm_endpoint_name]
0150
0151 if mode == "input":
0152 tmp_order = tmp_ddm_endpoint_dict["order_read"]
0153 elif mode == "output":
0154 tmp_order = tmp_ddm_endpoint_dict["order_write"]
0155
0156 if tmp_order > order:
0157 continue
0158
0159
0160 if re.search(patt, tmp_ddm_endpoint_name) is not None:
0161 endpoint = self.all[tmp_ddm_endpoint_name]
0162 order = tmp_order
0163
0164
0165 pattern_without_vo = re.sub("ATLAS", "", patt)
0166 if self.all[tmp_ddm_endpoint_name]["type"] == pattern_without_vo:
0167 endpoint = self.all[tmp_ddm_endpoint_name]
0168 order = tmp_order
0169
0170 return endpoint
0171
0172 def getTokenMap(self, mode):
0173 """
0174 This method returns a mapping between space tokens and endpoint names based on the mode.
0175
0176 Args:
0177 mode (str): The mode, either "input" or "output".
0178 Returns:
0179 dict: A dictionary mapping tokens to endpoint names.
0180 """
0181 ret_map = {}
0182 orders = {}
0183 for tmp_ddm_endpoint_name in self.all:
0184 tmp_ddm_endpoint_dict = self.all[tmp_ddm_endpoint_name]
0185 token = tmp_ddm_endpoint_dict["ddm_spacetoken_name"]
0186
0187
0188 if mode == "input":
0189 order = tmp_ddm_endpoint_dict["order_read"]
0190 elif mode == "output":
0191 order = tmp_ddm_endpoint_dict["order_write"]
0192
0193
0194 if token in ret_map and orders[token] < order:
0195 continue
0196
0197
0198 ret_map[token] = tmp_ddm_endpoint_name
0199 orders[token] = order
0200
0201 return ret_map