Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-28 23:10:44

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