Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:39

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