Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:55

0001 #!/bin/bash
0002 
0003 # Accepts a DBS path, so use looks like:
0004 # runRelVal.sh /RelValZMM/CMSSW_3_1_1-STARTUP31X_V1-v2/GEN-SIM-RECO
0005 
0006 # This script creates a copy of hltMuonValidator_cfg.py and includes the
0007 # root files from the chosen sample in the PoolSource, then runs the new 
0008 # ana.py file.  It then runs the copies hltMuonPostProcessor_cfg.py into 
0009 # post.py using the ouput from the analyzer job.
0010 
0011 # Use the --post (or -p) option to only run the post processing, using
0012 # validation content already existing in the DBS dataset.
0013 
0014 # Use the -n option to specify how many events to run over
0015 
0016 
0017 
0018 getFiles () {
0019     FILE_NAMES=`mktemp`
0020     $DBS_CMD lsf --path=$1 | grep .root | \
0021         sed "s:\(/store/.*\.root\):'\1', :" >> $FILE_NAMES
0022     echo $FILE_NAMES
0023 }
0024 
0025 
0026 
0027 reduceToMuonContent () {
0028 
0029     if [ $# -ne 2 ]; then echo "Wrong number of arguments"; exit; fi
0030 
0031     cat >> reduceToMuonContent.C << EOF
0032 void CopyDir(TDirectory *source) {
0033    //copy all objects and subdirs of directory source as a subdir of the current directory   
0034    source->ls();
0035    TDirectory *savdir = gDirectory;
0036    TDirectory *adir = savdir->mkdir(source->GetName());
0037    adir->cd();
0038    //loop on all entries of this directory
0039    TKey *key;
0040    TIter nextkey(source->GetListOfKeys());
0041    while ((key = (TKey*)nextkey())) {
0042       const char *classname = key->GetClassName();
0043       TClass *cl = gROOT->GetClass(classname);
0044       if (!cl) continue;
0045       if (cl->InheritsFrom("TDirectory")) {
0046          source->cd(key->GetName());
0047          TDirectory *subdir = gDirectory;
0048          adir->cd();
0049          CopyDir(subdir);
0050          adir->cd();
0051       } else if (cl->InheritsFrom("TTree")) {
0052          TTree *T = (TTree*)source->Get(key->GetName());
0053          adir->cd();
0054          TTree *newT = T->CloneTree();
0055          newT->Write();
0056       } else {
0057          source->cd();
0058          TObject *obj = key->ReadObj();
0059          adir->cd();
0060          obj->Write();
0061          delete obj;
0062      }
0063   }
0064   adir->SaveSelf(kTRUE);
0065   savdir->cd();
0066 }
0067 
0068 void reduceToMuonContent(TString oldFileName, TString newFileName) {
0069 
0070   TFile *oldFile = new TFile(oldFileName);
0071   gDirectory->cd("/DQMData/Run 1/HLT/Run summary/Muon/");
0072   TDirectory *oldDir = gDirectory;
0073 
0074   TFile *newFile = new TFile(newFileName, "recreate");
0075   newFile->cd();
0076   TDirectory *newDir = newFile->mkdir("DQMData");
0077   newDir = newDir->mkdir("Run 1");
0078   newDir = newDir->mkdir("HLT");
0079   newDir = newDir->mkdir("Run summary");
0080   newDir->cd();
0081   CopyDir(oldDir);
0082 
0083   newFile->Save();
0084   newFile->Close();
0085 
0086 }
0087 
0088 EOF
0089 
0090     root -b -q "reduceToMuonContent.C(\"$1\",\"$2\")" &> /dev/null
0091     rm reduceToMuonContent.C
0092 
0093 }
0094 
0095 
0096 
0097 POST_ONLY=false
0098 N_EVENTS=-1
0099 
0100 LONGOPTSTRING=`getopt --long post -o pn: -- "$@"`
0101 eval set -- "$LONGOPTSTRING"
0102 while true ; do
0103     case "$1" in
0104         --post) POST_ONLY=true ; shift ;;
0105         -p)     POST_ONLY=true ; shift ;;
0106         -n)     shift ; N_EVENTS=$1 ; shift ;;
0107         --)     shift ; break ;;
0108         *)      echo "Internal error!" ; exit 1 ;;
0109     esac
0110 done
0111 
0112 
0113 
0114 if [ -z "$CMSSW_VERSION" ] ; then 
0115    echo "CMSSW environment not set up; run cmsenv"
0116    exit
0117 else
0118    DBS_CMD="python $DBSCMD_HOME/dbsCommandLine.py -c "
0119 fi
0120 
0121 if [[ $1 =~ .*GEN-SIM-RECO ]]; then
0122     HLTDEBUGPATH=`echo $1 | sed 's/GEN-SIM-RECO/GEN-SIM-DIGI-RAW-HLTDEBUG/'`
0123     RECOPATH=$1
0124 elif [[ $1 =~ .*HLTDEBUG ]]; then
0125     HLTDEBUGPATH=$1
0126     RECOPATH=`echo $1 | sed 's/GEN-SIM-DIGI-RAW-HLTDEBUG/GEN-SIM-RECO/'`
0127 elif [[ $1 =~ .*FastSim.* ]]; then
0128     HLTDEBUGPATH=
0129     RECOPATH=$1
0130 else
0131     echo "The given path does not appear to be valid.  Exiting."
0132     exit
0133 fi
0134 
0135 echo "Using dataset(s): "
0136 if [[ ! -z "$HLTDEBUGPATH" ]] ; then echo "    $HLTDEBUGPATH"; fi
0137 if [[ ! -z "$RECOPATH"     ]] ; then echo "    $RECOPATH    "; fi
0138 
0139 RECOFILES="$(getFiles $RECOPATH)"
0140 HLTDEBUGFILES="$(getFiles $HLTDEBUGPATH)"
0141 
0142 ORIGDIR=`pwd`
0143 TEMPDIR=`mktemp -d`
0144 ANA_PY="ana.py"
0145 POST_PY="post.py"
0146 cd $TEMPDIR
0147 
0148 if [ $POST_ONLY = true ]; then
0149     cp $ORIGDIR/hltMuonPostProcessor_cfg.py $POST_PY
0150     echo "" >> $POST_PY
0151     echo "process.source.fileNames = [" >> $POST_PY
0152     cat $RECOFILES >> $POST_PY
0153     echo "]" >> $POST_PY
0154     echo "" >> $POST_PY
0155     echo "process.maxEvents.input = $N_EVENTS" >> $POST_PY
0156     cmsRun $POST_PY
0157     LONGNAME=$RECOPATH
0158 else
0159     cp $ORIGDIR/hltMuonValidator_cfg.py $ANA_PY
0160     cp $ORIGDIR/hltMuonPostProcessor_cfg.py $POST_PY
0161     echo "" >> $ANA_PY
0162     echo "process.source.fileNames = [" >> $ANA_PY
0163     cat $RECOFILES >> $ANA_PY
0164     echo "]" >> $ANA_PY
0165     echo "process.source.secondaryFileNames = [" >> $ANA_PY
0166     cat $HLTDEBUGFILES >> $ANA_PY
0167     echo "]" >> $ANA_PY
0168     echo "process.maxEvents.input = $N_EVENTS" >> $ANA_PY
0169     cmsRun $ANA_PY
0170     cmsRun $POST_PY
0171     LONGNAME=$RECOPATH
0172 fi
0173 
0174 SHORTNAME=`echo $LONGNAME | sed "s/\/RelVal\(.*\)\/CMSSW_\(.*\)\/.*/\1_\2/"`
0175 mv DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root temp.root
0176 reduceToMuonContent temp.root $ORIGDIR/$SHORTNAME.root
0177 cd $ORIGDIR
0178 rm -r $TEMPDIR
0179 echo "Produced $SHORTNAME.root"