-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added python scripts by Danilo Piparo for automated report
- Loading branch information
Luca Lista
committed
Dec 12, 2007
1 parent
96db13a
commit 78fee6b
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#! /usr/bin/env python | ||
|
||
r''' | ||
cmsRun Configuration file that skims the data from the reconstructed events. | ||
It is very general and allows to set in the metaconfig the parameters for the skimming. | ||
''' | ||
|
||
import FWCore.ParameterSet.Config as cms | ||
# The meta configuration: 3 parameters | ||
import metaconfig | ||
print 'metaconfig.__dict__=%s'%metaconfig.__dict__ | ||
|
||
# The cff and cfi management | ||
import fragments | ||
|
||
process=cms.Process('RECOSIM') #The object that stores the configuration for cmsRun | ||
|
||
includes_list=['FWCore/MessageLogger/data/MessageLogger.cfi', | ||
'Configuration/EventContent/data/EventContent.cff'] | ||
|
||
for el in fragments.include(includes_list): | ||
process.extend(el) | ||
|
||
|
||
process.maxEvents=cms.untracked.PSet(input=cms.untracked.int32(metaconfig.nevts)) | ||
|
||
process.source=cms.Source('PoolSource', | ||
fileNames=cms.untracked.vstring('file:%s' %metaconfig.infile)) | ||
|
||
# We use a feature of python to make general the content of the skimmed data.. | ||
exec('custom_outputCommands=process.%s.outputCommands\n'%metaconfig.outputCommands) | ||
|
||
process.OutModule=cms.OutputModule('PoolOutputModule', | ||
fileName=cms.untracked.string('%s' %metaconfig.outfile), | ||
outputCommands=custom_outputCommands) | ||
|
||
process.printEventNumber=cms.OutputModule('AsciiOutputModule') | ||
|
||
process.out=cms.EndPath(process.OutModule+process.printEventNumber) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#! /usr/bin/env python | ||
|
||
r''' | ||
The Wrapper for makeSkim.py, the general config for cmsRun. | ||
''' | ||
|
||
import optparse | ||
import os | ||
|
||
def _green(string): | ||
return '%s%s%s' %('\033[1;32m',string,'\033[1;0m') | ||
|
||
# To parse commandline args | ||
|
||
usage='%prog -i inrootfile -o outrootfile -n number_of_events --outputcommands name_of_block' | ||
|
||
parser=optparse.OptionParser(usage) | ||
|
||
|
||
parser.add_option("-n", "--number", | ||
help="The number of evts. The default is 50.", | ||
default="50", | ||
dest="nevts") | ||
|
||
parser.add_option("-i", | ||
help="The infile name", | ||
default="", | ||
dest="infilename") | ||
|
||
parser.add_option("-o", | ||
help="The outfile name", | ||
default="", | ||
dest="outfilename") | ||
|
||
parser.add_option("--outputcommands", | ||
help='The outputcommands (i.e. RECOSIMEventContent, '+\ | ||
'AODSIMEventContent, FEVTSIMEventContent, '+\ | ||
'AODEventContent and all blocks in EventContent.cff)', | ||
default="", | ||
dest="outputCommands") | ||
|
||
options,args=parser.parse_args() | ||
|
||
if '' in (options.infilename, | ||
options.outfilename, | ||
options.outputCommands): | ||
raise ('Incomplete list of arguments!') | ||
|
||
# Construct and dump the metaconfiguration on disk as a python file | ||
metaconfig_content='nevts=%s\n' %options.nevts+\ | ||
'outputCommands="%s"\n' %options.outputCommands+\ | ||
'infile="%s"\n' %options.infilename+\ | ||
'outfile="%s"\n' %options.outfilename | ||
|
||
metaconfig_file=open('metaconfig.py','w') | ||
metaconfig_file.write(metaconfig_content) | ||
metaconfig_file.close() | ||
|
||
# print it to screen! | ||
print _green('\nThe Metaconfiguration:\n') | ||
print metaconfig_content | ||
|
||
|
||
# and now execute! | ||
command='cmsRun /afs/cern.ch/user/d/dpiparo/scratch0/CMSSW_releases/CMSSW_1_7_0_pre13/src/Configuration/EventContent/test_py/makeSkim.py' | ||
print _green('\nAnd now run %s ...\n' %command) | ||
os.environ['PYTHONPATH']+=':./' # to find the metaconfig.. | ||
os.system(command) | ||
|
||
|
||
|
||
|
||
|