CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Validation/Performance/python/parseEventContent.py

Go to the documentation of this file.
00001 #!/usr/bin/env python2.4
00002 import FWCore.ParameterSet.Config as cms
00003 from FWCore.ParameterSet.usedOutput import *
00004 
00005 import re
00006 
00007 
00008 process = cms.Process("SIZE");
00009 
00010 # ==========  DEFINITION OF EVENT CONTENTS =======
00011 
00012 # !!! to add more event contents load the file  !!
00013 import Configuration.EventContent.EventContent_cff as eventContent
00014 import Configuration.EventContent.EventContentCosmics_cff as eventContent_cosmics
00015 
00016 # !!! and add the event contents to the list here !!
00017 EventContents_def = {
00018         "RECO":                 eventContent.RECOEventContent, 
00019         "AOD":                  eventContent.AODEventContent,
00020         "RECO_COSMICS":         eventContent_cosmics.RECOEventContent, 
00021         "AOD_COSMICS":          eventContent_cosmics.AODEventContent,
00022         #new output commands
00023         "RECOSIM":              eventContent.RECOSIMEventContent,
00024         "AODSIM":               eventContent.AODSIMEventContent,
00025         "RAW":                  eventContent.RAWEventContent,
00026         "RAWSIM":               eventContent.RAWSIMEventContent,
00027         "FEVTDEBUG":            eventContent.FEVTDEBUGEventContent,
00028         "FEVTDEBUGHLT":         eventContent.FEVTDEBUGHLTEventContent
00029 }
00030 
00031 
00032 
00033 """
00034 process = cms.Process("SIZE");
00035 process.load("Configuration.EventContent.EventContent_cff")
00036 ## define event conent to be used
00037 if options.event_content == "RECO" :
00038     local_outputCommands = process.RECOEventContent.outputCommands;  +
00039 elif options.event_content == "RECOSIM" :
00040     local_outputCommands = process.RECOSIMEventContent.outputCommands; +
00041 elif options.event_content == "AOD" :
00042     local_outputCommands = process.AODEventContent.outputCommands; +
00043 elif options.event_content == "AODSIM" :
00044     local_outputCommands = process.AODSIMEventContent.outputCommands; +
00045 elif options.event_content == "RAW" :
00046     local_outputCommands = process.RAWEventContent.outputCommands; +
00047 elif options.event_content == "RAWSIM" :
00048     local_outputCommands = process.RAWSIMEventContent.outputCommands;
00049 elif options.event_content == "FEVTDEBUG" :
00050     local_outputCommands = process.FEVTDEBUGEventContent.outputCommands;
00051 elif options.event_content == "FEVTDEBUGHLT" :
00052     local_outputCommands = process.FEVTDEBUGHLTEventContent.outputCommands;
00053 elif options.event_content == "ALL" :
00054     local_outputCommands = cms.untracked.vstring('keep *_*_*_*');
00055     xchecksize = True;
00056 
00057 
00058 """
00059 # ==========  END OF DEFINITION OF EVENT CONTENTS =======
00060 
00061 def rule_passes(rule_regexp, product_repr):
00062         """ 
00063                 rule: rule(keep, drop)_A_B_C_D
00064                 product: A_B_C
00065         """     
00066         #we have altered the rules to have "*" as the 4th parameter (if split by _) 
00067         # so all the D's will pass
00068         return rule_regexp.match(product_repr+"_")
00069 
00070 def rule_to_regexp(rule):
00071         """ returns a tuple (rule_name, rule_regexp) e.g. ("keep", <regexp for matching product names>  """
00072         #this part might be moved out and regular expression cached
00073         (rule_name, rule_test) = rule.split()
00074         
00075         # we create a regexp out of rule
00076         
00077         #we ignore the 4th rule:
00078         rule_parts =rule_test.split("_")
00079         if len(rule_parts) == 4 :
00080                 # we replace the last one to asterix
00081                 rule_parts[3] = "*" 
00082         rule_test = "_".join(rule_parts) 
00083         
00084         # make a regexp
00085         rule_test = rule_test.replace("*", ".*")
00086 
00087         rule_regexp = re.compile("^"+rule_test+"$")
00088         
00089         return (rule_name, rule_regexp)
00090 
00091 def product_in_EventContent(rules, product):
00092         """
00093         products are in format {"cpp_type": cpp_type, "module_name": mod_name, "module_label": mod_label,
00094                 "size_uncompressed": size_uncomp, "size_compressed": size_comp}  
00095         --- Some simple doctests ---
00096 
00097         >>> product_in_EventContent(rules = rule_to_regexp(['drop *', 'keep *_logErrorHarvester_*_*', 'keep *_hybridSuperClusters_*_*', 'keep recoSuperClusters_correctedHybridSuperClusters_*_*']), product = {'module_name': 'hybridSuperClusters', 'module_label': 'hybridShapeAssoc', 'size_compressed': '65.4852', 'cpp_type': 'recoCaloClustersToOnerecoClusterShapesAssociation', 'size_uncompressed': '272.111'})
00098         True
00099         
00100         >>> product_in_EventContent(rules = rule_to_regexp(['drop *', 'keep *_logErrorHarvester_*_*', 'keep DetIdedmEDCollection_siStripDigis_*_*', 'keep *_siPixelClusters_*_*', 'keep *_siStripClusters_*_*']), product = {'module_name': 'hybridSuperClusters', 'module_label': 'hybridShapeAssoc', 'size_compressed': '65.4852', 'cpp_type': 'recoCaloClustersToOnerecoClusterShapesAssociation', 'size_uncompressed': '272.111'})
00101         False
00102         
00103         """
00104 
00105 
00106         product_repr = "%(cpp_type)s_%(module_name)s_%(module_label)s" % product
00107         result = "keep"
00108         
00109         """ rule is in format: 
00110                 > keep  *_nuclearInteractionMaker_*_*
00111                 > keep *_horeco_*_*
00112                 > drop *
00113         """
00114         for (rule_name, rule_regexp) in rules:
00115 
00116                 if rule_passes(rule_regexp, product_repr):
00117                         result = rule_name
00118         return result == "keep"
00119 
00120 
00121 #initialize
00122 EventContents = {}
00123 for (ec_name, obj) in EventContents_def.items():
00124         # I'm not sure if this is needed, but I feel more comfident dealing with Python objects that CMSSWs PSet
00125         rules_txt = [a for a in obj.outputCommands]
00126 
00127         # we create a list of precompiled regexps for our rules
00128         rules_regexp = map(rule_to_regexp, rules_txt)
00129 
00130         EventContents[ec_name] = {"text_rules": rules_txt, "rules_regexp": rules_regexp}
00131 
00132 #this will be used by importing script
00133 def List_ECs_forProduct(product):
00134         """ returns a list of EC titles the product belongs to """
00135         EC_list = []
00136         for (ec_name, ec) in EventContents.items():
00137                 if product_in_EventContent(ec["rules_regexp"], product):
00138                         EC_list.append(ec_name)
00139         return EC_list
00140 
00141 def getTxtEventContentRules():
00142         #TODO: We should where to assign products to Event-Content, on harvesting or on importing part
00143         """ returns a dictionary of lists with rules """
00144         txt_rules = {}
00145         for (ec_name, ec) in EventContents.items():
00146                 txt_rules[ec_name] = ec["text_rules"]
00147         return txt_rules
00148         
00149 #a test
00150 if __name__ == "__main__":
00151         print "==== The  event contents data is: === "
00152         print EventContents
00153         prod = {'module_name': 'hybridSuperClusters', 'module_label': 'hybridShapeAssoc', 'size_compressed': '65.4852', 'cpp_type': 'recoCaloClustersToOnerecoClusterShapesAssociation', 'size_uncompressed': '272.111'}
00154         print List_ECs_forProduct(prod)
00155