2 from __future__
import print_function
4 import parsingRulesHelper
6 """ a lambda fucntion which checks only two first parts of tuple: candle and step of the JobID""" 7 f_candle_and_step_inJobID =
lambda candle, step, x: x[0] == candle
and x[1] == step
11 Includes general functions to work with fileNames and related operations: 12 * getting candle, step etc - JobID from fileName and vice-versa 13 - includes conditions, pileup_type, event_content <-- read this from Simulationcandles [TODO: we have it in this module for simplicity, might be moved later] 14 * root file size from candle,step 15 * reads simulation candles to get release version 19 universal_candle_step_regs = {}
20 test_root_file = re.compile(
".root$", re.IGNORECASE)
24 We have Simulation candles lines in format like: 26 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 32 ((
"cms_driver_options", ),
r"""^cmsDriver.py(.+)$"""),
34 ((
"",
"conditions",
""),
r"""^cmsDriver.py(.*)--conditions ([^\s]+)(.*)$""",
"req"),
35 ((
"",
"pileup_type",
""),
r"""^cmsDriver.py(.*)--pileup=([^\s]+)(.*)$"""),
36 ((
"",
"step",
""),
r"""^cmsDriver.py(.*)--step=([^\s]+)(.*)$""",
"req"),
38 ((
"",
"event_content",
""),
r"""^cmsDriver.py(.*)--eventcontent ([^\s]+)(.*)$""",
"req"),
39 ((
"",
"num_events",
""),
r"""^cmsDriver.py(.*)-n ([^\s]+)(.*)$""",
"req"),
44 simCandlesRules =
map(parsingRulesHelper.rulesRegexpCompileFunction, simCandlesRules)
52 """ get the acual file """ 53 SimulationCandles_file = [os.path.join(path, f)
for f
in os.listdir(path)
54 if os.path.isfile(os.path.join(path, f))
and f.startswith(
"SimulationCandles_")][0]
58 """ read and parse it; format: #Version : CMSSW_3_2_0 """ 59 f = open(SimulationCandles_file,
'r') 61 lines = [s.strip() for s
in f.readlines()]
66 """ we call a shared helper to parse the file """ 75 if 'auto:' in info[
'conditions']:
77 info[
'conditions'] = autoCond[ info[
'conditions'].
split(
':')[1] ].
split(
"::")[0]
79 if 'FrontierConditions_GlobalTag' in info[
'conditions']:
80 info[
'conditions']=info[
'conditions'].
split(
",")[1]
83 if not missing_fields:
85 if info[
"step"].
strip() == step.strip()
and ((
not is_pileup
and not info[
"pileup_type"])
or (is_pileup
and info[
"pileup_type"])):
97 Returns the JobID (candle, step, pileup_type, conditions, event_content) out of filename 98 -- if no pile up returns empty string for pileup type 100 * the candle might include one optional underscore: 101 >>> getJobID_fromFileName("PI-_1000_GEN,SIM.root", "\.root") 102 ('PI-_1000', 'GEN,SIM', '', '') 104 * otherwise after candle we have two underscores: 105 >>> getJobID_fromFileName("MINBIAS__GEN,FASTSIM.root", "\.root") 106 ('MINBIAS', 'GEN,FASTSIM', '', '') 108 * and lastly we have the PILEUP possibility: 109 >>> getJobID_fromFileName("TTBAR__DIGI_PILEUP.root", "\.root") 110 ('TTBAR', 'DIGI', 'PILEUP', '') 115 (path, filename) = os.path.split(logfile_name)
119 if suffix
not in universal_candle_step_regs:
121 universal_candle_step_regs[suffix] = re.compile( \
123 #candle1_[opt:candle2]_ 128 """ % suffix , re.VERBOSE)
133 result = universal_candle_step_regs[suffix].
search(filename)
137 candle = result.groups()[0]
138 step = result.groups()[1].
replace(
'-',
',')
139 is_pileup = result.groups()[2]
145 """ if we had the candle without underscore inside (like TTBAR but not E_1000) 146 on the end of result and underscore which needs to be removed """ 148 if (candle[-1] ==
'_'):
149 candle = candle[0:-1]
151 """ try to fetch the conditions and real pileup type if the SimulationCandles.txt is existing """ 157 is_pileup = conf[
"pileup_type"]
158 conditions = conf[
"conditions"]
159 event_content = conf[
"event_content"]
163 return (candle, step, is_pileup, conditions, event_content)
165 return (
None,
None,
None,
None,
None)
170 Returns the candle and STEP out of filename: 172 * the candle might include one optional underscore: 173 >>> getJobID_fromRootFileName("PI-_1000_GEN,SIM.root") 174 ('PI-_1000', 'GEN,SIM', '', '') 176 * otherwise after candle we have two underscores: 177 >>> getJobID_fromRootFileName("MINBIAS__GEN,FASTSIM.root") 178 ('MINBIAS', 'GEN,FASTSIM', '', '') 180 * and lastly we have the PILEUP possibility: 181 >>> getJobID_fromRootFileName("TTBAR__DIGI_PILEUP.root") 182 ('TTBAR', 'DIGI', 'PILEUP', '') 188 Returns the candle and STEP out of filename: 190 * the candle might include one optional underscore: 191 >>> getJobID_fromEdmSizeFileName("E_1000_GEN,SIM_EdmSize") 192 ('E_1000', 'GEN,SIM', '', '') 194 * otherwise after candle we have two underscores: 195 >>> getJobID_fromEdmSizeFileName("TTBAR__RAW2DIGI,RECO_EdmSize") 196 ('TTBAR', 'RAW2DIGI,RECO', '', '') 198 * and lastly we have the PILEUP possibility: 199 >>> getJobID_fromEdmSizeFileName("TTBAR__GEN,SIM_PILEUP_EdmSize") 200 ('TTBAR', 'GEN,SIM', 'PILEUP', '') 206 Returns the candle and STEP out of filename: 208 * the candle might include one optional underscore: 209 >>> getJobID_fromTimeReportLogName("E_1000_GEN,SIM_TimingReport.log") 210 ('E_1000', 'GEN,SIM', '', '') 212 * otherwise after candle we have two underscores: 213 >>> getJobID_fromTimeReportLogName("test_data/TTBAR__RAW2DIGI,RECO_TimingReport.log") 214 ('TTBAR', 'RAW2DIGI,RECO', '', '') 216 * and lastly we have the PILEUP possibility: 217 >>> getJobID_fromTimeReportLogName("TTBAR__DIGI_PILEUP_TimingReport.log") 218 ('TTBAR', 'DIGI', 'PILEUP', '') 224 Returns the candle and STEP out of filename: 226 * otherwise after candle we have two underscores: 227 >>> getJobID_fromTimeReportLogName("test_data/TTBAR__RAW2DIGI,RECO_memcheck_vlgd.xml") 228 ('TTBAR', 'RAW2DIGI,RECO', '', '') 230 * and lastly we have the PILEUP possibility: 231 >>> getJobID_fromTimeReportLogName("TTBAR__DIGI_PILEUP_memcheck_vlgd.xml") 232 ('TTBAR', 'DIGI', 'PILEUP', '') 238 Returns the candle and STEP out of .sql3 filename: 240 everything is given, just have to split it... 242 TTbar___GEN,FASTSIM___LowLumiPileUp___MC_37Y_V5___RAWSIM___MEM_LIVE___1.sql3 243 and correct the conditions! 247 (path, filename) = os.path.split(logfile_name)
249 params = filename.split(
"___")
250 candle = params[0].
upper()
252 pileup_type = params[2]
253 if pileup_type ==
"NOPILEUP":
255 elif pileup_type ==
"LowLumiPileUp":
256 pileup_type =
"PILEUP" 263 is_pileup = conf[
"pileup_type"]
264 conditions = conf[
"conditions"]
265 event_content = conf[
"event_content"]
266 return (candle, step, is_pileup, conditions, event_content)
268 return (
None,
None,
None,
None,
None)
270 """ Get the root file size for the candle, step in current dir """ 272 files = os.listdir(path)
273 root_files = [os.path.join(path, f)
for f
in files
274 if test_root_file.search(f)
275 and os.path.isfile(os.path.join(path, f)) ]
277 """ get the size of file if it is the root file for current candle and step """ 279 size = [os.stat(f).st_size
for f
in root_files
281 except Exception
as e:
291 """ get the acual file """ 292 SimulationCandles_file = [os.path.join(path, f)
for f
in os.listdir(path)
293 if os.path.isfile(os.path.join(path, f))
and f.startswith(
"SimulationCandles_")][0]
295 """ read and parse it; format: #Version : CMSSW_3_2_0 """ 296 f = open(SimulationCandles_file,
'r') 297 lines = f.readlines() 300 release_version =[[a.strip() for a
in line.split(
":")]
for line
in lines
if line.startswith(
"#Version")][0][1]
301 return release_version
304 if __name__ ==
"__main__":
307 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)