3 import parsingRulesHelper
5 """ a lambda fucntion which checks only two first parts of tuple: candle and step of the JobID"""
6 f_candle_and_step_inJobID =
lambda candle, step, x: x[0] == candle
and x[1] == step
10 Includes general functions to work with fileNames and related operations:
11 * getting candle, step etc - JobID from fileName and vice-versa
12 - includes conditions, pileup_type, event_content <-- read this from Simulationcandles [TODO: we have it in this module for simplicity, might be moved later]
13 * root file size from candle,step
14 * reads simulation candles to get release version
18 universal_candle_step_regs = {}
19 test_root_file = re.compile(
".root$", re.IGNORECASE)
23 We have Simulation candles lines in format like:
25 cmsDriver.py TTbar_Tauola.cfi -n 100 --step=DIGI --filein file:TTBAR__GEN,SIM_PILEUP.root --fileout=TTBAR__DIGI_PILEUP.root --customise=Validation/Performance/MixingModule.py --conditions FrontierConditions_GlobalTag,MC_31X_V3::All --eventcontent FEVTDEBUG --pileup=LowLumiPileUp @@@ Timing_Parser @@@ TTBAR__DIGI_PILEUP_TimingReport @@@ reuse
31 ((
"cms_driver_options", ),
r"""^cmsDriver.py(.+)$"""),
33 ((
"",
"conditions",
""),
r"""^cmsDriver.py(.*)--conditions ([^\s]+)(.*)$""",
"req"),
34 ((
"",
"pileup_type",
""),
r"""^cmsDriver.py(.*)--pileup=([^\s]+)(.*)$"""),
35 ((
"",
"step",
""),
r"""^cmsDriver.py(.*)--step=([^\s]+)(.*)$""",
"req"),
37 ((
"",
"event_content",
""),
r"""^cmsDriver.py(.*)--eventcontent ([^\s]+)(.*)$""",
"req"),
38 ((
"",
"num_events",
""),
r"""^cmsDriver.py(.*)-n ([^\s]+)(.*)$""",
"req"),
43 simCandlesRules =
map(parsingRulesHelper.rulesRegexpCompileFunction, simCandlesRules)
51 """ get the acual file """
52 SimulationCandles_file = [os.path.join(path, f)
for f
in os.listdir(path)
53 if os.path.isfile(os.path.join(path, f))
and f.startswith(
"SimulationCandles_")][0]
57 """ read and parse it; format: #Version : CMSSW_3_2_0 """
58 f = open(SimulationCandles_file,
'r')
60 lines = [s.strip() for s
in f.readlines()]
65 """ we call a shared helper to parse the file """
73 if 'auto:' in info[
'conditions']:
74 from Configuration.PyReleaseValidation.autoCond
import autoCond
75 info[
'conditions'] = autoCond[ info[
'conditions'].
split(
':')[1] ].
split(
"::")[0]
77 if 'FrontierConditions_GlobalTag' in info[
'conditions']:
78 info[
'conditions']=info[
'conditions'].
split(
",")[1]
81 if not missing_fields:
83 if info[
"step"].
strip() == step.strip()
and ((
not is_pileup
and not info[
"pileup_type"])
or (is_pileup
and info[
"pileup_type"])):
95 Returns the JobID (candle, step, pileup_type, conditions, event_content) out of filename
96 -- if no pile up returns empty string for pileup type
98 * the candle might include one optional underscore:
99 >>> getJobID_fromFileName("PI-_1000_GEN,SIM.root", "\.root")
100 ('PI-_1000', 'GEN,SIM', '', '')
102 * otherwise after candle we have two underscores:
103 >>> getJobID_fromFileName("MINBIAS__GEN,FASTSIM.root", "\.root")
104 ('MINBIAS', 'GEN,FASTSIM', '', '')
106 * and lastly we have the PILEUP possibility:
107 >>> getJobID_fromFileName("TTBAR__DIGI_PILEUP.root", "\.root")
108 ('TTBAR', 'DIGI', 'PILEUP', '')
113 (path, filename) = os.path.split(logfile_name)
117 if not universal_candle_step_regs.has_key(suffix):
119 universal_candle_step_regs[suffix] = re.compile( \
121 #candle1_[opt:candle2]_
126 """ % suffix , re.VERBOSE)
131 result = universal_candle_step_regs[suffix].
search(filename)
135 candle = result.groups()[0]
136 step = result.groups()[1]
137 is_pileup = result.groups()[2]
143 """ if we had the candle without underscore inside (like TTBAR but not E_1000)
144 on the end of result and underscore which needs to be removed """
146 if (candle[-1] ==
'_'):
147 candle = candle[0:-1]
149 """ try to fetch the conditions and real pileup type if the SimulationCandles.txt is existing """
155 is_pileup = conf[
"pileup_type"]
156 conditions = conf[
"conditions"]
157 event_content = conf[
"event_content"]
161 return (candle, step, is_pileup, conditions, event_content)
163 return (
None,
None,
None,
None,
None)
168 Returns the candle and STEP out of filename:
170 * the candle might include one optional underscore:
171 >>> getJobID_fromRootFileName("PI-_1000_GEN,SIM.root")
172 ('PI-_1000', 'GEN,SIM', '', '')
174 * otherwise after candle we have two underscores:
175 >>> getJobID_fromRootFileName("MINBIAS__GEN,FASTSIM.root")
176 ('MINBIAS', 'GEN,FASTSIM', '', '')
178 * and lastly we have the PILEUP possibility:
179 >>> getJobID_fromRootFileName("TTBAR__DIGI_PILEUP.root")
180 ('TTBAR', 'DIGI', 'PILEUP', '')
186 Returns the candle and STEP out of filename:
188 * the candle might include one optional underscore:
189 >>> getJobID_fromEdmSizeFileName("E_1000_GEN,SIM_EdmSize")
190 ('E_1000', 'GEN,SIM', '', '')
192 * otherwise after candle we have two underscores:
193 >>> getJobID_fromEdmSizeFileName("TTBAR__RAW2DIGI,RECO_EdmSize")
194 ('TTBAR', 'RAW2DIGI,RECO', '', '')
196 * and lastly we have the PILEUP possibility:
197 >>> getJobID_fromEdmSizeFileName("TTBAR__GEN,SIM_PILEUP_EdmSize")
198 ('TTBAR', 'GEN,SIM', 'PILEUP', '')
204 Returns the candle and STEP out of filename:
206 * the candle might include one optional underscore:
207 >>> getJobID_fromTimeReportLogName("E_1000_GEN,SIM_TimingReport.log")
208 ('E_1000', 'GEN,SIM', '', '')
210 * otherwise after candle we have two underscores:
211 >>> getJobID_fromTimeReportLogName("test_data/TTBAR__RAW2DIGI,RECO_TimingReport.log")
212 ('TTBAR', 'RAW2DIGI,RECO', '', '')
214 * and lastly we have the PILEUP possibility:
215 >>> getJobID_fromTimeReportLogName("TTBAR__DIGI_PILEUP_TimingReport.log")
216 ('TTBAR', 'DIGI', 'PILEUP', '')
221 """ Get the root file size for the candle, step in current dir """
223 files = os.listdir(path)
224 root_files = [os.path.join(path, f)
for f
in files
225 if test_root_file.search(f)
226 and os.path.isfile(os.path.join(path, f)) ]
228 """ get the size of file if it is the root file for current candle and step """
230 size = [os.stat(f).st_size
for f
in root_files
242 """ get the acual file """
243 SimulationCandles_file = [os.path.join(path, f)
for f
in os.listdir(path)
244 if os.path.isfile(os.path.join(path, f))
and f.startswith(
"SimulationCandles_")][0]
246 """ read and parse it; format: #Version : CMSSW_3_2_0 """
247 f = open(SimulationCandles_file,
'r')
248 lines = f.readlines()
251 release_version =[[a.strip() for a
in line.split(
":")]
for line
in lines
if line.startswith(
"#Version")][0][1]
252 return release_version
255 if __name__ ==
"__main__":
258 path = path =
"/home/vidma/Desktop/CERN_code/cmssw/data/CMSSW_3_2_0_--usersteps=GEN-SIM,DIGI_lxbuild106.cern.ch_relval/relval/CMSSW_3_2_0/workGENSIMDIGI/TTbar_PU_TimeSize"
def getJobID_fromTimeReportLogName
def getJobID_fromRootFileName
list f_candle_and_step_inJobID
def read_SimulationCandles
def read_ConfigurationFromSimulationCandles
def getJobID_fromFileName
def getJobID_fromEdmSizeFileName