test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
RemoveAddSevLevel Namespace Reference

Functions

def AddFlag
 
def PrintLevels
 
def RemoveFlag
 

Function Documentation

def RemoveAddSevLevel.AddFlag (   sevLevelComputer,
  flag = "UserDefinedBit0",
  severity = 10 
)
Adds specified flag to severity level computer using specified severity level.
    If flag already exists at another severity level, it is removed from that level.

Definition at line 45 of file RemoveAddSevLevel.py.

References PrintLevels(), and RemoveFlag().

45 
46 def AddFlag(sevLevelComputer,flag="UserDefinedBit0",severity=10):
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:
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 
def RemoveAddSevLevel.PrintLevels (   SLComp)

Definition at line 35 of file RemoveAddSevLevel.py.

Referenced by AddFlag().

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 
def RemoveAddSevLevel.RemoveFlag (   sevLevelComputer,
  flag = "HFLongShort" 
)
Removes the specified flag from the Severity Level Computer,
and returns the revised Computer.

Definition at line 4 of file RemoveAddSevLevel.py.

Referenced by AddFlag().

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