1 |
|
#!/bin/bash |
2 |
+ |
#################################################################### |
3 |
+ |
## |
4 |
+ |
## Simple script to count the number of events of several root files |
5 |
+ |
## |
6 |
+ |
## Alejandro Gomez Espinosa |
7 |
+ |
## gomez@physics.rutgers.edu |
8 |
+ |
## |
9 |
+ |
## How to run: ./countNumberOfEvents.sh path/to/folder/ |
10 |
+ |
## |
11 |
+ |
##################################################################### |
12 |
|
|
3 |
– |
directory=$1 #'/uscms/home/algomez/nobackup/files/stops/AOD/st2_h_bb_st1_bj_250_100_AOD' |
13 |
|
|
14 |
< |
ls -1 $directory | while read line |
14 |
> |
directory=$1 #'/uscms/home/algomez/nobackup/files/stops/AOD/st2_h_bb_st1_bj_250_100_AOD' # Directory from argument 1 |
15 |
> |
|
16 |
> |
ls -1 $directory | while read line # List the files in folder and while each line |
17 |
|
do |
18 |
< |
totalevents=0 |
19 |
< |
events=$(edmEventSize -v ${directory}/${line} | grep Events | awk '{ print $4 }' ) |
20 |
< |
echo $events >> tmp.txt |
18 |
> |
events=$(edmEventSize -v ${directory}/${line} | grep Events | awk '{ print $4 }' ) |
19 |
> |
# edmEventsSize is CMSSW to create a list out of a root file, then search for the line displaying the Events, finally print only number of events |
20 |
> |
echo $events >> tmp.txt # create a tmp file with numbers |
21 |
|
done |
22 |
< |
|
22 |
> |
# Sum each number in the column (with awk) and print the total number of events |
23 |
|
echo "Total Number of events in " $1 " :" $(cat tmp.txt | awk '{ sum+=$1} END { print sum}') |
24 |
< |
rm tmp.txt |
24 |
> |
rm tmp.txt ## remove the tmp file |