-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfragments.py
58 lines (48 loc) · 2.08 KB
/
fragments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import FWCore.ParameterSet.Config as cms
import os
import pickle
def _yellow(string):
return '%s%s%s' %('\033[1;33m',string,'\033[1;0m')
def include(includes_set):
"""
It takes a string or a list of strings and returns a list of
FWCore.ParameterSet.parseConfig._ConfigReturn objects.
In the package directory it creates ASCII files in which the objects are coded. If
the files exist already it symply loads them.
"""
func_id='[fragments.include]'
#packagedir=os.environ["CMSSW_BASE"]+"/src/Configuration/PyReleaseValidation/data/"
packagedir='./'
#Trasform the includes_set in a list
if not isinstance(includes_set,list):
includes_set=[includes_set]
object_list=[]
for cf_file_name in includes_set:
pkl_file_name=packagedir+os.path.basename(cf_file_name)[:-4]+".pkl"
cf_file_fullpath=""
# Check the paths of the cffs
for path in os.environ["CMSSW_SEARCH_PATH"].split(":"):
cf_file_fullpath=path+"/"+cf_file_name
if os.path.exists(cf_file_fullpath):
break
pkl_file_exists=os.path.exists(pkl_file_name)
# Check the dates of teh cff and the corresponding pickle
cff_age=0
pkl_age=0
if pkl_file_exists:
cff_age=os.path.getctime(cf_file_fullpath)
pkl_age=os.path.getctime(pkl_file_name)
if cff_age>pkl_age:
print _yellow(func_id)+" Pickle object older than file ..."
if not pkl_file_exists or cff_age>pkl_age:
obj=cms.include(cf_file_name)
file=open(pkl_file_name,"w")
pickle.dump(obj,file)
file.close()
print _yellow(func_id)+" Pickle object for "+cf_file_fullpath+" dumped as "+pkl_file_name+"..."
# load the pkl files.
file=open(pkl_file_name,"r")
object_list.append(pickle.load(file))
file.close()
print _yellow(func_id)+" Pickle object for "+cf_file_fullpath+" loaded ..."
return object_list