00001
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
00011
00012
00013 import Configuration.EventContent.EventContent_cff as eventContent
00014 import Configuration.EventContent.EventContentCosmics_cff as eventContent_cosmics
00015
00016
00017 EventContents_def = {
00018 "RECO": eventContent.RECOEventContent,
00019 "AOD": eventContent.AODEventContent,
00020 "RECO_COSMICS": eventContent_cosmics.RECOEventContent,
00021 "AOD_COSMICS": eventContent_cosmics.AODEventContent,
00022
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
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
00067
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
00073 (rule_name, rule_test) = rule.split()
00074
00075
00076
00077
00078 rule_parts =rule_test.split("_")
00079 if len(rule_parts) == 4 :
00080
00081 rule_parts[3] = "*"
00082 rule_test = "_".join(rule_parts)
00083
00084
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
00122 EventContents = {}
00123 for (ec_name, obj) in EventContents_def.items():
00124
00125 rules_txt = [a for a in obj.outputCommands]
00126
00127
00128 rules_regexp = map(rule_to_regexp, rules_txt)
00129
00130 EventContents[ec_name] = {"text_rules": rules_txt, "rules_regexp": rules_regexp}
00131
00132
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
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
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