CMS 3D CMS Logo

RemoveAddSevLevel.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import FWCore.ParameterSet.Config as cms
3 
4 
5 def RemoveFlag(sevLevelComputer,flag="HFLongShort"):
6  ''' Removes the specified flag from the Severity Level Computer,
7  and returns the revised Computer.'''
8 
9  removeSeverity=-1 # Track which Severity Level has been modified
10 
11 
12 
13  # Loop over all levels
14  for i in range(len(sevLevelComputer.SeverityLevels)):
15  Flags=sevLevelComputer.SeverityLevels[i].RecHitFlags.value()
16  if flag not in Flags: # Flag not present for this level
17  continue
18  #Remove flag
19  Flags.remove(flag)
20  ChanStat=sevLevelComputer.SeverityLevels[i].ChannelStatus.value()
21  # Check to see if Severity Level no longer contains any useful information
22  if len(Flags)==0 and ChanStat==['']:
23  removeSeverity=i
24  else:
25  # Set revised list of flags for this severity level
26  sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags
27  break
28 
29  # Removing flag results in empty severity level; remove it
30  if (removeSeverity>-1):
31  sevLevelComputer.SeverityLevels.remove(sevLevelComputer.SeverityLevels[removeSeverity])
32 
33  return sevLevelComputer
34 
35 
36 def PrintLevels(SLComp):
37  print("Severity Level Computer Levels and associated flags/Channel Status values:")
38  for i in SLComp.SeverityLevels:
39  print("\t Level = %i"%i.Level.value())
40  print("\t\t RecHit Flags = %s"%i.RecHitFlags.value())
41  print("\t\t Channel Status = %s"%i.ChannelStatus.value())
42  print()
43  return
44 
45 
46 def AddFlag(sevLevelComputer,flag="UserDefinedBit0",severity=10,verbose=True):
47  ''' Adds specified flag to severity level computer using specified severity level.
48  If flag already exists at another severity level, it is removed from that level.
49  '''
50 
51  AddedSeverity=False
52  removeSeverity=-1
53 
54  allowedflags=[]
55  for i in sevLevelComputer.SeverityLevels:
56  for j in i.RecHitFlags.value():
57  if j=="":
58  continue
59  allowedflags.append(j)
60 
61  #print "Allowed flags = ",allowedflags
62  if flag not in allowedflags and verbose:
63  print("\n\n")
64  for j in range(0,3):
65  print("###################################################")
66  print("\nWARNING!!!!!! You are adding a flag \n\t'%s' \nthat is not defined in the Severity Level Computer!"%flag)
67  print("This can be EXCEPTIONALLY dangerous if you do not \nknow what you are doing!\n")
68  print("Proceed with EXTREME caution!\n")
69  for j in range(0,3):
70  print("###################################################")
71  print("\n\n")
72 
73  #Loop over severity Levels
74  for i in range(len(sevLevelComputer.SeverityLevels)):
75  Level=sevLevelComputer.SeverityLevels[i].Level.value()
76  Flags=sevLevelComputer.SeverityLevels[i].RecHitFlags.value()
77  if Level==severity: # Found the specified level
78  if (Flags==['']):
79  Flags=[flag] # Create new vector for this flag
80  else:
81  if flag not in Flags: # don't need to add flag if it's already there
82  Flags.append(flag) # append flag to existing vector
83  sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags # Set new RecHitFlags vector
84  AddedSeverity=True
85  else: # Found some other level; be sure to remove flag from it
86  if flag not in Flags:
87  continue
88  else:
89  Flags.remove(flag)
90  # Removing flag leaves nothing else: need to remove this level completely
91  if len(Flags)==0 and ChanStat==['']:
92  removeSeverity=i
93  else:
94  sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags
95 
96  # Remove any newly-empty levels
97  if (removeSeverity>-1):
98  sevLevelComputer.SeverityLevels.remove(sevLevelComputer.SeverityLevels[removeSeverity])
99 
100  # No existing severity level for specified severity was found;
101  # add a new one
102  if (AddedSeverity==False):
103  sevLevelComputer.SeverityLevels.append(cms.PSet(Level=cms.int32(severity),
104  RecHitFlags=cms.vstring(flag),
105  ChannelStatus=cms.vstring("")))
106  return sevLevelComputer
107 
108 
109 
110 ##########################
111 
112 if __name__=="__main__":
113  import hcalRecAlgoESProd_cfi as ES
114  ES.hcalRecAlgos=RemoveFlag(ES.hcalRecAlgos)
115  ES.hcalRecAlgos=AddFlag(ES.hcalRecAlgos,flag="HOBit",severity=5)
116  PrintLevels(ES.hcalRecAlgos)
117 
def PrintLevels(SLComp)
def RemoveFlag(sevLevelComputer, flag="HFLongShort")
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def AddFlag(sevLevelComputer, flag="UserDefinedBit0", severity=10, verbose=True)