File indexing completed on 2023-03-17 10:48:55
0001 from __future__ import print_function
0002 import FWCore.ParameterSet.Config as cms
0003 import os
0004 import pickle
0005
0006 def _yellow(string):
0007 return '%s%s%s' %('\033[1;33m',string,'\033[1;0m')
0008
0009 def include(includes_set):
0010 """
0011 It takes a string or a list of strings and returns a list of
0012 FWCore.ParameterSet.parseConfig._ConfigReturn objects.
0013 In the package directory it creates ASCII files in which the objects are coded. If
0014 the files exist already it symply loads them.
0015 """
0016
0017 func_id='[fragments.include]'
0018
0019
0020 packagedir='./'
0021
0022 if not isinstance(includes_set,list):
0023 includes_set=[includes_set]
0024
0025 object_list=[]
0026 for cf_file_name in includes_set:
0027 pkl_file_name=packagedir+os.path.basename(cf_file_name)[:-4]+".pkl"
0028
0029 cf_file_fullpath=""
0030
0031 for path in os.environ["CMSSW_SEARCH_PATH"].split(":"):
0032 cf_file_fullpath=path+"/"+cf_file_name
0033 if os.path.exists(cf_file_fullpath):
0034 break
0035
0036 pkl_file_exists=os.path.exists(pkl_file_name)
0037
0038 cff_age=0
0039 pkl_age=0
0040 if pkl_file_exists:
0041 cff_age=os.path.getctime(cf_file_fullpath)
0042 pkl_age=os.path.getctime(pkl_file_name)
0043 if cff_age>pkl_age:
0044 print(_yellow(func_id)+" Pickle object older than file ...")
0045
0046
0047 if not pkl_file_exists or cff_age>pkl_age:
0048 obj=cms.include(cf_file_name)
0049 file=open(pkl_file_name,"w")
0050 pickle.dump(obj,file)
0051 file.close()
0052 print(_yellow(func_id)+" Pickle object for "+cf_file_fullpath+" dumped as "+pkl_file_name+"...")
0053
0054 file=open(pkl_file_name,"r")
0055 object_list.append(pickle.load(file))
0056 file.close()
0057 print(_yellow(func_id)+" Pickle object for "+cf_file_fullpath+" loaded ...")
0058
0059 return object_list