From b15be79f9264083ae383bd9f5207f7b8b27f8d16 Mon Sep 17 00:00:00 2001
From: Andrea Sciaba <Andrea.Sciaba@cern.ch>
Date: Tue, 24 Sep 2019 18:13:23 +0200
Subject: [PATCH] Calculating no. of events in input file

---
 cms/digi/cms-digi/cms-digi-bmk.sh | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/cms/digi/cms-digi/cms-digi-bmk.sh b/cms/digi/cms-digi/cms-digi-bmk.sh
index 1d8eeea4..a121405a 100755
--- a/cms/digi/cms-digi/cms-digi-bmk.sh
+++ b/cms/digi/cms-digi/cms-digi-bmk.sh
@@ -36,6 +36,25 @@ function doOne(){
   return $status
 }
 
+function getEvents(){
+  export CMSSW_RELEASE=CMSSW_10_2_9
+  export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
+  source $VO_CMS_SW_DIR/cmsset_default.sh
+  export SCRAM_ARCH=slc6_amd64_gcc700
+  [[ ! -e ${CMSSW_RELEASE} ]] && scram project CMSSW ${CMSSW_RELEASE} &> /dev/null
+  (pushd ${CMSSW_RELEASE}; eval `scramv1 runtime -sh`; popd) &> /dev/null
+  ln -s ${BMKDIR}/data/*.root .
+  evts=`python -c "import ROOT;f=ROOT.TFile.Open('gensim.root');print f.Get('Events').GetEntries();"`
+  STATUS=$?
+  rm -rf ${CMSSW_RELEASE}
+  rm -f gensim.root
+  if [[ $STATUS != 0 ]] ; then
+      return 0
+  else
+      return $evts
+  fi
+}
+
 # Optional function validateInputArguments may be defined in each benchmark
 # If it exists, it is expected to set NCOPIES, NTHREADS, NEVENTS_THREAD
 # (based on previous defaults and on user inputs USER_NCOPIES, USER_NTHREADS, USER_NEVENTS_THREADS)
@@ -59,6 +78,17 @@ function validateInputArguments(){
   fi
   # Number of events per thread
   if [ "$USER_NEVENTS_THREAD" != "" ]; then NEVENTS_THREAD=$USER_NEVENTS_THREAD; fi
+  # Extract number of events in input file
+  getEvents
+  evts=$?
+  if [[ $evts == 0 ]] ; then
+      s_msg="[ERROR] Cannot extract number of events from input file"
+      return 1
+  fi
+  if [[ $((NEVENTS_THREAD * NTHREADS)) -gt $evts ]] ; then
+      s_msg="[ERROR] Requested number of events ($((NEVENTS_THREAD * NTHREADS))) exceeds number of input events ($evts)"
+      return 1
+  fi
   # Return 0 if input arguments are valid, 1 otherwise
   # Report any issues to parseResults via s_msg
   export s_msg="ok"
-- 
GitLab