Go to the documentation of this file.00001 import FWCore.ParameterSet.Config as cms
00002
00003
00004 def RemoveFlag(sevLevelComputer,flag="HFLongShort"):
00005 ''' Removes the specified flag from the Severity Level Computer,
00006 and returns the revised Computer.'''
00007
00008 removeSeverity=-1
00009
00010
00011
00012
00013 for i in range(len(sevLevelComputer.SeverityLevels)):
00014 Flags=sevLevelComputer.SeverityLevels[i].RecHitFlags.value()
00015 if flag not in Flags:
00016 continue
00017
00018 Flags.remove(flag)
00019 ChanStat=sevLevelComputer.SeverityLevels[i].ChannelStatus.value()
00020
00021 if len(Flags)==0 and ChanStat==['']:
00022 removeSeverity=i
00023 else:
00024
00025 sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags
00026 break
00027
00028
00029 if (removeSeverity>-1):
00030 sevLevelComputer.SeverityLevels.remove(sevLevelComputer.SeverityLevels[removeSeverity])
00031
00032 return sevLevelComputer
00033
00034
00035 def PrintLevels(SLComp):
00036 print "Severity Level Computer Levels and associated flags/Channel Status values:"
00037 for i in SLComp.SeverityLevels:
00038 print "\t Level = %i"%i.Level.value()
00039 print "\t\t RecHit Flags = %s"%i.RecHitFlags.value()
00040 print "\t\t Channel Status = %s"%i.ChannelStatus.value()
00041 print
00042 return
00043
00044
00045 def AddFlag(sevLevelComputer,flag="UserDefinedBit0",severity=10):
00046 ''' Adds specified flag to severity level computer using specified severity level.
00047 If flag already exists at another severity level, it is removed from that level.
00048 '''
00049
00050 AddedSeverity=False
00051 removeSeverity=-1
00052
00053 allowedflags=[]
00054 for i in sevLevelComputer.SeverityLevels:
00055 for j in i.RecHitFlags.value():
00056 if j=="":
00057 continue
00058 allowedflags.append(j)
00059
00060
00061 if flag not in allowedflags:
00062 print "\n\n"
00063 for j in range(0,3):
00064 print "###################################################"
00065 print "\nWARNING!!!!!! You are adding a flag \n\t'%s' \nthat is not defined in the Severity Level Computer!"%flag
00066 print "This can be EXCEPTIONALLY dangerous if you do not \nknow what you are doing!\n"
00067 print "Proceed with EXTREME caution!\n"
00068 for j in range(0,3):
00069 print "###################################################"
00070 print "\n\n"
00071
00072
00073 for i in range(len(sevLevelComputer.SeverityLevels)):
00074 Level=sevLevelComputer.SeverityLevels[i].Level.value()
00075 Flags=sevLevelComputer.SeverityLevels[i].RecHitFlags.value()
00076 if Level==severity:
00077 if (Flags==['']):
00078 Flags=[flag]
00079 else:
00080 if flag not in Flags:
00081 Flags.append(flag)
00082 sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags
00083 AddedSeverity=True
00084 else:
00085 if flag not in Flags:
00086 continue
00087 else:
00088 Flags.remove(flag)
00089
00090 if len(Flags)==0 and ChanStat==['']:
00091 removeSeverity=i
00092 else:
00093 sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags
00094
00095
00096 if (removeSeverity>-1):
00097 sevLevelComputer.SeverityLevels.remove(sevLevelComputer.SeverityLevels[removeSeverity])
00098
00099
00100
00101 if (AddedSeverity==False):
00102 sevLevelComputer.SeverityLevels.append(cms.PSet(Level=cms.int32(severity),
00103 RecHitFlags=cms.vstring(flag),
00104 ChannelStatus=cms.vstring("")))
00105 return sevLevelComputer
00106
00107
00108
00109
00110
00111 if __name__=="__main__":
00112 import hcalRecAlgoESProd_cfi as ES
00113 ES.hcalRecAlgos=RemoveFlag(ES.hcalRecAlgos)
00114 ES.hcalRecAlgos=AddFlag(ES.hcalRecAlgos,flag="HOBit",severity=5)
00115 PrintLevels(ES.hcalRecAlgos)
00116