2 from __future__
import print_function
3 from __future__
import absolute_import
5 from .
import parsingRulesHelper
7 """ a lambda fucntion which checks only two first parts of tuple: candle and step of the JobID""" 8 f_candle_and_step_inJobID =
lambda candle, step, x: x[0] == candle
and x[1] == step
12 Includes general functions to work with fileNames and related operations: 13 * getting candle, step etc - JobID from fileName and vice-versa 14 - includes conditions, pileup_type, event_content <-- read this from Simulationcandles [TODO: we have it in this module for simplicity, might be moved later] 15 * root file size from candle,step 16 * reads simulation candles to get release version 20 universal_candle_step_regs = {}
21 test_root_file = re.compile(
".root$", re.IGNORECASE)
25 We have Simulation candles lines in format like: 27 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 33 ((
"cms_driver_options", ),
r"""^cmsDriver.py(.+)$"""),
35 ((
"",
"conditions",
""),
r"""^cmsDriver.py(.*)--conditions ([^\s]+)(.*)$""",
"req"),
36 ((
"",
"pileup_type",
""),
r"""^cmsDriver.py(.*)--pileup=([^\s]+)(.*)$"""),
37 ((
"",
"step",
""),
r"""^cmsDriver.py(.*)--step=([^\s]+)(.*)$""",
"req"),
39 ((
"",
"event_content",
""),
r"""^cmsDriver.py(.*)--eventcontent ([^\s]+)(.*)$""",
"req"),
40 ((
"",
"num_events",
""),
r"""^cmsDriver.py(.*)-n ([^\s]+)(.*)$""",
"req"),
45 simCandlesRules =
map(parsingRulesHelper.rulesRegexpCompileFunction, simCandlesRules)
53 """ get the acual file """ 54 SimulationCandles_file = [os.path.join(path, f)
for f
in os.listdir(path)
55 if os.path.isfile(os.path.join(path, f))
and f.startswith(
"SimulationCandles_")][0]
59 """ read and parse it; format: #Version : CMSSW_3_2_0 """ 60 f = open(SimulationCandles_file,
'r') 62 lines = [s.strip() for s
in f.readlines()]
67 """ we call a shared helper to parse the file """ 76 if 'auto:' in info[
'conditions']:
78 info[
'conditions'] = autoCond[ info[
'conditions'].
split(
':')[1] ].
split(
"::")[0]
80 if 'FrontierConditions_GlobalTag' in info[
'conditions']:
81 info[
'conditions']=info[
'conditions'].
split(
",")[1]
84 if not missing_fields:
86 if info[
"step"].
strip() == step.strip()
and ((
not is_pileup
and not info[
"pileup_type"])
or (is_pileup
and info[
"pileup_type"])):
98 Returns the JobID (candle, step, pileup_type, conditions, event_content) out of filename 99 -- if no pile up returns empty string for pileup type 101 * the candle might include one optional underscore: 102 >>> getJobID_fromFileName("PI-_1000_GEN,SIM.root", "\.root") 103 ('PI-_1000', 'GEN,SIM', '', '') 105 * otherwise after candle we have two underscores: 106 >>> getJobID_fromFileName("MINBIAS__GEN,FASTSIM.root", "\.root") 107 ('MINBIAS', 'GEN,FASTSIM', '', '') 109 * and lastly we have the PILEUP possibility: 110 >>> getJobID_fromFileName("TTBAR__DIGI_PILEUP.root", "\.root") 111 ('TTBAR', 'DIGI', 'PILEUP', '') 116 (path, filename) = os.path.split(logfile_name)
120 if suffix
not in universal_candle_step_regs:
122 universal_candle_step_regs[suffix] = re.compile( \
124 #candle1_[opt:candle2]_ 129 """ % suffix , re.VERBOSE)
134 result = universal_candle_step_regs[suffix].
search(filename)
138 candle = result.groups()[0]
139 step = result.groups()[1].
replace(
'-',
',')
140 is_pileup = result.groups()[2]
146 """ if we had the candle without underscore inside (like TTBAR but not E_1000) 147 on the end of result and underscore which needs to be removed """ 149 if (candle[-1] ==
'_'):
150 candle = candle[0:-1]
152 """ try to fetch the conditions and real pileup type if the SimulationCandles.txt is existing """ 158 is_pileup = conf[
"pileup_type"]
159 conditions = conf[
"conditions"]
160 event_content = conf[
"event_content"]
164 return (candle, step, is_pileup, conditions, event_content)
166 return (
None,
None,
None,
None,
None)
171 Returns the candle and STEP out of filename: 173 * the candle might include one optional underscore: 174 >>> getJobID_fromRootFileName("PI-_1000_GEN,SIM.root") 175 ('PI-_1000', 'GEN,SIM', '', '') 177 * otherwise after candle we have two underscores: 178 >>> getJobID_fromRootFileName("MINBIAS__GEN,FASTSIM.root") 179 ('MINBIAS', 'GEN,FASTSIM', '', '') 181 * and lastly we have the PILEUP possibility: 182 >>> getJobID_fromRootFileName("TTBAR__DIGI_PILEUP.root") 183 ('TTBAR', 'DIGI', 'PILEUP', '') 189 Returns the candle and STEP out of filename: 191 * the candle might include one optional underscore: 192 >>> getJobID_fromEdmSizeFileName("E_1000_GEN,SIM_EdmSize") 193 ('E_1000', 'GEN,SIM', '', '') 195 * otherwise after candle we have two underscores: 196 >>> getJobID_fromEdmSizeFileName("TTBAR__RAW2DIGI,RECO_EdmSize") 197 ('TTBAR', 'RAW2DIGI,RECO', '', '') 199 * and lastly we have the PILEUP possibility: 200 >>> getJobID_fromEdmSizeFileName("TTBAR__GEN,SIM_PILEUP_EdmSize") 201 ('TTBAR', 'GEN,SIM', 'PILEUP', '') 207 Returns the candle and STEP out of filename: 209 * the candle might include one optional underscore: 210 >>> getJobID_fromTimeReportLogName("E_1000_GEN,SIM_TimingReport.log") 211 ('E_1000', 'GEN,SIM', '', '') 213 * otherwise after candle we have two underscores: 214 >>> getJobID_fromTimeReportLogName("test_data/TTBAR__RAW2DIGI,RECO_TimingReport.log") 215 ('TTBAR', 'RAW2DIGI,RECO', '', '') 217 * and lastly we have the PILEUP possibility: 218 >>> getJobID_fromTimeReportLogName("TTBAR__DIGI_PILEUP_TimingReport.log") 219 ('TTBAR', 'DIGI', 'PILEUP', '') 225 Returns the candle and STEP out of filename: 227 * otherwise after candle we have two underscores: 228 >>> getJobID_fromTimeReportLogName("test_data/TTBAR__RAW2DIGI,RECO_memcheck_vlgd.xml") 229 ('TTBAR', 'RAW2DIGI,RECO', '', '') 231 * and lastly we have the PILEUP possibility: 232 >>> getJobID_fromTimeReportLogName("TTBAR__DIGI_PILEUP_memcheck_vlgd.xml") 233 ('TTBAR', 'DIGI', 'PILEUP', '') 239 Returns the candle and STEP out of .sql3 filename: 241 everything is given, just have to split it... 243 TTbar___GEN,FASTSIM___LowLumiPileUp___MC_37Y_V5___RAWSIM___MEM_LIVE___1.sql3 244 and correct the conditions! 248 (path, filename) = os.path.split(logfile_name)
250 params = filename.split(
"___")
251 candle = params[0].
upper()
253 pileup_type = params[2]
254 if pileup_type ==
"NOPILEUP":
256 elif pileup_type ==
"LowLumiPileUp":
257 pileup_type =
"PILEUP" 264 is_pileup = conf[
"pileup_type"]
265 conditions = conf[
"conditions"]
266 event_content = conf[
"event_content"]
267 return (candle, step, is_pileup, conditions, event_content)
269 return (
None,
None,
None,
None,
None)
271 """ Get the root file size for the candle, step in current dir """ 273 files = os.listdir(path)
274 root_files = [os.path.join(path, f)
for f
in files
275 if test_root_file.search(f)
276 and os.path.isfile(os.path.join(path, f)) ]
278 """ get the size of file if it is the root file for current candle and step """ 280 size = [os.stat(f).st_size
for f
in root_files
282 except Exception
as e:
292 """ get the acual file """ 293 SimulationCandles_file = [os.path.join(path, f)
for f
in os.listdir(path)
294 if os.path.isfile(os.path.join(path, f))
and f.startswith(
"SimulationCandles_")][0]
296 """ read and parse it; format: #Version : CMSSW_3_2_0 """ 297 f = open(SimulationCandles_file,
'r') 298 lines = f.readlines() 301 release_version =[[a.strip() for a
in line.split(
":")]
for line
in lines
if line.startswith(
"#Version")][0][1]
302 return release_version
305 if __name__ ==
"__main__":
308 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 read_SimulationCandles(path)
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
def replace(string, replacements)
f_candle_and_step_inJobID
def getJobID_fromFileName(logfile_name, suffix, givenPath="")
S & print(S &os, JobReport::InputFile const &f)
def getJobID_fromIgProfLogName(logfile_name)
def getJobID_fromEdmSizeFileName(logfile_name)
def getRootFileSize(path, candle, step)
def getJobID_fromRootFileName(logfile_name)
def read_ConfigurationFromSimulationCandles(path, step, is_pileup)
def rulesParser(parsing_rules, lines, compileRules=True)
def getJobID_fromMemcheckLogName(logfile_name)
def getJobID_fromTimeReportLogName(logfile_name)