CMS 3D CMS Logo

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