Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:19

0001 import sys
0002 
0003 from Configuration.AlCa.autoCond import aliases
0004 import Configuration.StandardSequences.FrontierConditions_GlobalTag_cff
0005 
0006 class GlobalTagBuilderException(Exception):
0007     def __init__(self, value):
0008         self.value = value
0009     def __str__(self):
0010         return repr(self.value)
0011         
0012 class GlobalTag:
0013     def __init__(self, inputGT = "", inputConnect = "", inputPfnPrefix = "", inputPfnPostfix = "", inputGTParams = []):
0014         if inputGTParams == []:
0015             self.gtParams = []
0016             localConnect = inputConnect
0017             if localConnect == "":
0018                 # print "No connection string specified for the GT. Using the default one:", Configuration.StandardSequences.FrontierConditions_GlobalTag_cff.GlobalTag.connect
0019                 localConnect = Configuration.StandardSequences.FrontierConditions_GlobalTag_cff.GlobalTag.connect.value()
0020                 # raise GlobalTagBuilderException("Error: no connection string specified.")
0021             localGT = inputGT
0022             # Expand the alias name
0023             if localGT in aliases:
0024                 localGT = aliases[localGT]
0025             if localGT.find("|") != -1 and localConnect.find("|") == -1:
0026                 # Fill a connection string for each GT
0027                 connect = localConnect
0028                 for i in range(1,len(localGT.split("|"))):
0029                     localConnect += "|"+connect
0030             self.gtParams.append([localGT, localConnect, inputPfnPrefix, inputPfnPostfix])
0031         else:
0032             self.gtParams = inputGTParams
0033         # print self.gtParams
0034     def __or__(self, other):
0035         if self.checkPrefix(other.gtParams) != -1:
0036             raise GlobalTagBuilderException("Error: trying to add the same GT component type \""+other.gtParams[0][0].split("_")[0]+"\" twice. This is not supported.")
0037         if len(other.gtParams) > 1:
0038             raise GlobalTagBuilderException("Error: the second GT has already a list. This is not supported.")
0039         tempGTParams = list(self.gtParams)
0040         tempGTParams.append(other.gtParams[0])
0041         return GlobalTag(inputGTParams = tempGTParams)
0042     def __add__(self, other):
0043         index = self.checkPrefix(other.gtParams)
0044         if index != -1:
0045             tempGTParams = list(self.gtParams)
0046             tempGTParams[index] = other.gtParams[0]
0047             return GlobalTag(inputGTParams = tempGTParams)
0048         else:
0049             exceptionString = "Error: replacement of GT "+other.gtParams[0][0]+" not allowed. No matching prefix found in existing GT components. Available components are:\n"
0050             for comp in self.gtParams:
0051                 exceptionString += comp[0] + "\n"
0052             raise GlobalTagBuilderException(exceptionString)
0053     def checkPrefix(self, inputGTParams):
0054         """ Compares two input GTs to see if they have the same prefix. Returns the index in the internal list of GTs of the match
0055         or -1 in case of no match. """
0056         if inputGTParams[0][0].find("_") == -1:
0057             print("Invalid GT name. It does not contain an _, it cannot be used for replacements.")
0058             sys.exit(1)
0059         prefix = inputGTParams[0][0].split("_")[0]
0060         for i in range(0, len(self.gtParams)):
0061             if self.gtParams[i][0].split("_")[0] == prefix:
0062                 return i
0063         return -1
0064     def buildString(self, index):
0065         outputString = ""
0066         # print "index =", index
0067         # print self.gtParams
0068         for elem in self.gtParams:
0069             outputString += elem[index]
0070             if elem != self.gtParams[len(self.gtParams)-1]:
0071                 outputString += "|"
0072         return outputString
0073         # return outputString.strip("|")
0074     def gt(self):
0075         return self.buildString(0)
0076     def connect(self):
0077         return self.buildString(1)
0078     def pfnPrefix(self):
0079         return self.buildString(2)
0080     def pfnPostfix(self):
0081         return self.buildString(3)