CMS 3D CMS Logo

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.

00046                                                                 :
00047     ''' Adds specified flag to severity level computer using specified severity level.
00048         If flag already exists at another severity level, it is removed from that level.
00049         '''
00050     
00051     AddedSeverity=False
00052     removeSeverity=-1
00053 
00054     allowedflags=[]
00055     for i in sevLevelComputer.SeverityLevels:
00056         for j in i.RecHitFlags.value():
00057             if j=="":
00058                 continue
00059             allowedflags.append(j)
00060             
00061     #print "Allowed flags = ",allowedflags
00062     if flag not in allowedflags:
00063         print "\n\n"
00064         for j in range(0,3):
00065             print "###################################################"
00066         print "\nWARNING!!!!!! You are adding a flag \n\t'%s' \nthat is not defined in the Severity Level Computer!"%flag
00067         print "This can be EXCEPTIONALLY dangerous if you do not \nknow what you are doing!\n"
00068         print "Proceed with EXTREME caution!\n"
00069         for j in range(0,3):
00070             print "###################################################"
00071         print "\n\n"
00072 
00073     #Loop over severity Levels
00074     for i in range(len(sevLevelComputer.SeverityLevels)):
00075         Level=sevLevelComputer.SeverityLevels[i].Level.value()
00076         Flags=sevLevelComputer.SeverityLevels[i].RecHitFlags.value()
00077         if Level==severity:  # Found the specified level
00078             if (Flags==['']):
00079                 Flags=[flag] # Create new vector for this flag
00080             else:
00081                 if flag not in Flags:  # don't need to add flag if it's already there
00082                     Flags.append(flag) # append flag to existing vector
00083             sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags  # Set new RecHitFlags vector
00084             AddedSeverity=True
00085         else:  # Found some other level; be sure to remove flag from it
00086             if flag not in Flags:
00087                 continue
00088             else:
00089                 Flags.remove(flag)
00090                 # Removing flag leaves nothing else:  need to remove this level completely
00091                 if len(Flags)==0 and ChanStat==['']:
00092                     removeSeverity=i
00093                 else:
00094                     sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags
00095 
00096     # Remove any newly-empty levels
00097     if (removeSeverity>-1):
00098         sevLevelComputer.SeverityLevels.remove(sevLevelComputer.SeverityLevels[removeSeverity])
00099 
00100     # No existing severity level for specified severity was found;
00101     # add a new one
00102     if (AddedSeverity==False):
00103         sevLevelComputer.SeverityLevels.append(cms.PSet(Level=cms.int32(severity),
00104                                                         RecHitFlags=cms.vstring(flag),
00105                                                         ChannelStatus=cms.vstring("")))
00106     return sevLevelComputer
00107 
00108 
    
def RemoveAddSevLevel::PrintLevels (   SLComp)

Definition at line 35 of file RemoveAddSevLevel.py.

00036                        :
00037     print "Severity Level Computer Levels and associated flags/Channel Status values:"
00038     for i in SLComp.SeverityLevels:
00039         print "\t Level = %i"%i.Level.value()
00040         print "\t\t RecHit Flags = %s"%i.RecHitFlags.value()
00041         print "\t\t Channel Status = %s"%i.ChannelStatus.value()
00042         print
00043     return
00044 

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.

00005                                                    :
00006     ''' Removes the specified flag from the Severity Level Computer,
00007     and returns the revised Computer.'''
00008     
00009     removeSeverity=-1 # Track which Severity Level has been modified
00010 
00011 
00012 
00013     # Loop over all levels
00014     for i in range(len(sevLevelComputer.SeverityLevels)):
00015         Flags=sevLevelComputer.SeverityLevels[i].RecHitFlags.value()
00016         if flag not in Flags:  # Flag not present for this level
00017             continue
00018         #Remove flag
00019         Flags.remove(flag)
00020         ChanStat=sevLevelComputer.SeverityLevels[i].ChannelStatus.value()
00021         # Check to see if Severity Level no longer contains any useful information
00022         if len(Flags)==0 and ChanStat==['']:
00023             removeSeverity=i
00024         else:
00025             # Set revised list of flags for this severity level
00026             sevLevelComputer.SeverityLevels[i].RecHitFlags=Flags
00027         break
00028 
00029     # Removing flag results in empty severity level; remove it
00030     if (removeSeverity>-1):
00031         sevLevelComputer.SeverityLevels.remove(sevLevelComputer.SeverityLevels[removeSeverity])
00032 
00033     return sevLevelComputer
00034