CMS 3D CMS Logo

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