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 """
74 if 'auto:' in info[
'conditions']:
76 info[
'conditions'] = autoCond[ info[
'conditions'].
split(
':')[1] ].
split(
"::")[0]
78 if 'FrontierConditions_GlobalTag' in info[
'conditions']:
79 info[
'conditions']=info[
'conditions'].
split(
",")[1]
82 if not missing_fields:
84 if info[
"step"].strip() == step.strip()
and ((
not is_pileup
and not info[
"pileup_type"])
or (is_pileup
and info[
"pileup_type"])):
96 Returns the JobID (candle, step, pileup_type, conditions, event_content) out of filename
97 -- if no pile up returns empty string for pileup type
99 * the candle might include one optional underscore:
100 >>> getJobID_fromFileName("PI-_1000_GEN,SIM.root", "\.root")
101 ('PI-_1000', 'GEN,SIM', '', '')
103 * otherwise after candle we have two underscores:
104 >>> getJobID_fromFileName("MINBIAS__GEN,FASTSIM.root", "\.root")
105 ('MINBIAS', 'GEN,FASTSIM', '', '')
107 * and lastly we have the PILEUP possibility:
108 >>> getJobID_fromFileName("TTBAR__DIGI_PILEUP.root", "\.root")
109 ('TTBAR', 'DIGI', 'PILEUP', '')
114 (path, filename) = os.path.split(logfile_name)
118 if not universal_candle_step_regs.has_key(suffix):
120 universal_candle_step_regs[suffix] = re.compile( \
122 #candle1_[opt:candle2]_
127 """ % suffix , re.VERBOSE)
132 result = universal_candle_step_regs[suffix].
search(filename)
136 candle = result.groups()[0]
137 step = result.groups()[1].
replace(
'-',
',')
138 is_pileup = result.groups()[2]
144 """ if we had the candle without underscore inside (like TTBAR but not E_1000)
145 on the end of result and underscore which needs to be removed """
147 if (candle[-1] ==
'_'):
148 candle = candle[0:-1]
150 """ try to fetch the conditions and real pileup type if the SimulationCandles.txt is existing """
156 is_pileup = conf[
"pileup_type"]
157 conditions = conf[
"conditions"]
158 event_content = conf[
"event_content"]
162 return (candle, step, is_pileup, conditions, event_content)
164 return (
None,
None,
None,
None,
None)
169 Returns the candle and STEP out of filename:
171 * the candle might include one optional underscore:
172 >>> getJobID_fromRootFileName("PI-_1000_GEN,SIM.root")
173 ('PI-_1000', 'GEN,SIM', '', '')
175 * otherwise after candle we have two underscores:
176 >>> getJobID_fromRootFileName("MINBIAS__GEN,FASTSIM.root")
177 ('MINBIAS', 'GEN,FASTSIM', '', '')
179 * and lastly we have the PILEUP possibility:
180 >>> getJobID_fromRootFileName("TTBAR__DIGI_PILEUP.root")
181 ('TTBAR', 'DIGI', 'PILEUP', '')
187 Returns the candle and STEP out of filename:
189 * the candle might include one optional underscore:
190 >>> getJobID_fromEdmSizeFileName("E_1000_GEN,SIM_EdmSize")
191 ('E_1000', 'GEN,SIM', '', '')
193 * otherwise after candle we have two underscores:
194 >>> getJobID_fromEdmSizeFileName("TTBAR__RAW2DIGI,RECO_EdmSize")
195 ('TTBAR', 'RAW2DIGI,RECO', '', '')
197 * and lastly we have the PILEUP possibility:
198 >>> getJobID_fromEdmSizeFileName("TTBAR__GEN,SIM_PILEUP_EdmSize")
199 ('TTBAR', 'GEN,SIM', 'PILEUP', '')
205 Returns the candle and STEP out of filename:
207 * the candle might include one optional underscore:
208 >>> getJobID_fromTimeReportLogName("E_1000_GEN,SIM_TimingReport.log")
209 ('E_1000', 'GEN,SIM', '', '')
211 * otherwise after candle we have two underscores:
212 >>> getJobID_fromTimeReportLogName("test_data/TTBAR__RAW2DIGI,RECO_TimingReport.log")
213 ('TTBAR', 'RAW2DIGI,RECO', '', '')
215 * and lastly we have the PILEUP possibility:
216 >>> getJobID_fromTimeReportLogName("TTBAR__DIGI_PILEUP_TimingReport.log")
217 ('TTBAR', 'DIGI', 'PILEUP', '')
223 Returns the candle and STEP out of filename:
225 * otherwise after candle we have two underscores:
226 >>> getJobID_fromTimeReportLogName("test_data/TTBAR__RAW2DIGI,RECO_memcheck_vlgd.xml")
227 ('TTBAR', 'RAW2DIGI,RECO', '', '')
229 * and lastly we have the PILEUP possibility:
230 >>> getJobID_fromTimeReportLogName("TTBAR__DIGI_PILEUP_memcheck_vlgd.xml")
231 ('TTBAR', 'DIGI', 'PILEUP', '')
237 Returns the candle and STEP out of .sql3 filename:
239 everything is given, just have to split it...
241 TTbar___GEN,FASTSIM___LowLumiPileUp___MC_37Y_V5___RAWSIM___MEM_LIVE___1.sql3
242 and correct the conditions!
246 (path, filename) = os.path.split(logfile_name)
248 params = filename.split(
"___")
249 candle = params[0].
upper()
251 pileup_type = params[2]
252 if pileup_type ==
"NOPILEUP":
254 elif pileup_type ==
"LowLumiPileUp":
255 pileup_type =
"PILEUP"
262 is_pileup = conf[
"pileup_type"]
263 conditions = conf[
"conditions"]
264 event_content = conf[
"event_content"]
265 return (candle, step, is_pileup, conditions, event_content)
267 return (
None,
None,
None,
None,
None)
269 """ Get the root file size for the candle, step in current dir """
271 files = os.listdir(path)
272 root_files = [os.path.join(path, f)
for f
in files
273 if test_root_file.search(f)
274 and os.path.isfile(os.path.join(path, f)) ]
276 """ get the size of file if it is the root file for current candle and step """
278 size = [os.stat(f).st_size
for f
in root_files
290 """ get the acual file """
291 SimulationCandles_file = [os.path.join(path, f)
for f
in os.listdir(path)
292 if os.path.isfile(os.path.join(path, f))
and f.startswith(
"SimulationCandles_")][0]
294 """ read and parse it; format: #Version : CMSSW_3_2_0 """
295 f = open(SimulationCandles_file,
'r')
296 lines = f.readlines()
299 release_version =[[a.strip() for a
in line.split(
":")]
for line
in lines
if line.startswith(
"#Version")][0][1]
300 return release_version
303 if __name__ ==
"__main__":
306 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
def getJobID_fromIgProfLogName
list f_candle_and_step_inJobID
def read_SimulationCandles
def read_ConfigurationFromSimulationCandles
def getJobID_fromFileName
def getJobID_fromMemcheckLogName
def getJobID_fromEdmSizeFileName
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)