CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
parseEventContent.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import FWCore.ParameterSet.Config as cms
4 
5 import re
6 
7 
8 process = cms.Process("SIZE");
9 
10 # ========== DEFINITION OF EVENT CONTENTS =======
11 
12 # !!! to add more event contents load the file !!
14 import Configuration.EventContent.EventContentCosmics_cff as eventContent_cosmics
15 
16 # !!! and add the event contents to the list here !!
17 EventContents_def = {
18  "RECO": eventContent.RECOEventContent,
19  "AOD": eventContent.AODEventContent,
20  "RECO_COSMICS": eventContent_cosmics.RECOEventContent,
21  "AOD_COSMICS": eventContent_cosmics.AODEventContent,
22  #new output commands
23  "RECOSIM": eventContent.RECOSIMEventContent,
24  "AODSIM": eventContent.AODSIMEventContent,
25  "RAW": eventContent.RAWEventContent,
26  "RAWSIM": eventContent.RAWSIMEventContent,
27  "FEVTDEBUG": eventContent.FEVTDEBUGEventContent,
28  "FEVTDEBUGHLT": eventContent.FEVTDEBUGHLTEventContent
29 }
30 
31 
32 
33 """
34 process = cms.Process("SIZE");
35 process.load("Configuration.EventContent.EventContent_cff")
36 ## define event conent to be used
37 if options.event_content == "RECO" :
38  local_outputCommands = process.RECOEventContent.outputCommands; +
39 elif options.event_content == "RECOSIM" :
40  local_outputCommands = process.RECOSIMEventContent.outputCommands; +
41 elif options.event_content == "AOD" :
42  local_outputCommands = process.AODEventContent.outputCommands; +
43 elif options.event_content == "AODSIM" :
44  local_outputCommands = process.AODSIMEventContent.outputCommands; +
45 elif options.event_content == "RAW" :
46  local_outputCommands = process.RAWEventContent.outputCommands; +
47 elif options.event_content == "RAWSIM" :
48  local_outputCommands = process.RAWSIMEventContent.outputCommands;
49 elif options.event_content == "FEVTDEBUG" :
50  local_outputCommands = process.FEVTDEBUGEventContent.outputCommands;
51 elif options.event_content == "FEVTDEBUGHLT" :
52  local_outputCommands = process.FEVTDEBUGHLTEventContent.outputCommands;
53 elif options.event_content == "ALL" :
54  local_outputCommands = cms.untracked.vstring('keep *_*_*_*');
55  xchecksize = True;
56 
57 
58 """
59 # ========== END OF DEFINITION OF EVENT CONTENTS =======
60 
61 def rule_passes(rule_regexp, product_repr):
62  """
63  rule: rule(keep, drop)_A_B_C_D
64  product: A_B_C
65  """
66  #we have altered the rules to have "*" as the 4th parameter (if split by _)
67  # so all the D's will pass
68  return rule_regexp.match(product_repr+"_")
69 
70 def rule_to_regexp(rule):
71  """ returns a tuple (rule_name, rule_regexp) e.g. ("keep", <regexp for matching product names> """
72  #this part might be moved out and regular expression cached
73  (rule_name, rule_test) = rule.split()
74 
75  # we create a regexp out of rule
76 
77  #we ignore the 4th rule:
78  rule_parts =rule_test.split("_")
79  if len(rule_parts) == 4 :
80  # we replace the last one to asterix
81  rule_parts[3] = "*"
82  rule_test = "_".join(rule_parts)
83 
84  # make a regexp
85  rule_test = rule_test.replace("*", ".*")
86 
87  rule_regexp = re.compile("^"+rule_test+"$")
88 
89  return (rule_name, rule_regexp)
90 
91 def product_in_EventContent(rules, product):
92  """
93  products are in format {"cpp_type": cpp_type, "module_name": mod_name, "module_label": mod_label,
94  "size_uncompressed": size_uncomp, "size_compressed": size_comp}
95  --- Some simple doctests ---
96 
97  >>> 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'})
98  True
99 
100  >>> 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'})
101  False
102 
103  """
104 
105 
106  product_repr = "%(cpp_type)s_%(module_name)s_%(module_label)s" % product
107  result = "keep"
108 
109  """ rule is in format:
110  > keep *_nuclearInteractionMaker_*_*
111  > keep *_horeco_*_*
112  > drop *
113  """
114  for (rule_name, rule_regexp) in rules:
115 
116  if rule_passes(rule_regexp, product_repr):
117  result = rule_name
118  return result == "keep"
119 
120 
121 #initialize
122 EventContents = {}
123 for (ec_name, obj) in EventContents_def.items():
124  # I'm not sure if this is needed, but I feel more comfident dealing with Python objects that CMSSWs PSet
125  rules_txt = [a for a in obj.outputCommands]
126 
127  # we create a list of precompiled regexps for our rules
128  rules_regexp = map(rule_to_regexp, rules_txt)
129 
130  EventContents[ec_name] = {"text_rules": rules_txt, "rules_regexp": rules_regexp}
131 
132 #this will be used by importing script
133 def List_ECs_forProduct(product):
134  """ returns a list of EC titles the product belongs to """
135  EC_list = []
136  for (ec_name, ec) in EventContents.items():
137  if product_in_EventContent(ec["rules_regexp"], product):
138  EC_list.append(ec_name)
139  return EC_list
140 
142  #TODO: We should where to assign products to Event-Content, on harvesting or on importing part
143  """ returns a dictionary of lists with rules """
144  txt_rules = {}
145  for (ec_name, ec) in EventContents.items():
146  txt_rules[ec_name] = ec["text_rules"]
147  return txt_rules
148 
149 #a test
150 if __name__ == "__main__":
151  print "==== The event contents data is: === "
152  print EventContents
153  prod = {'module_name': 'hybridSuperClusters', 'module_label': 'hybridShapeAssoc', 'size_compressed': '65.4852', 'cpp_type': 'recoCaloClustersToOnerecoClusterShapesAssociation', 'size_uncompressed': '272.111'}
154  print List_ECs_forProduct(prod)
155 
dictionary map
Definition: Association.py:205
static std::string join(char **cmd)
Definition: RemoteFile.cc:18