Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#!/bin/bash
#
# Automatically extracts all histograms
# from a root file and saves them as image files.
# Creates a directory structure exactly as found
# in the root file itself.
#
# Michael Anderson
# May 22, 2008

plotMacro=./saveHistograms.C
defaultXsize=480
defaultYsize=360

printUsage() {
 echo
 echo "Saves all histograms from a root file into images"
 echo "Usage:  saveHistograms file.root"
 echo "        saveHistograms file.root imageType"
 echo "        saveHistograms file.root imageType xSize ySize"
 echo "example:"
 echo "        saveHistograms jets.root gif $defaultXsize $defaultYsize"
}

saveHistFromRootFile() {
  rootFile=$1
  imageType=$2
  xSize=$3
  ySize=$4

  echo "Saving histograms from $rootFile as $xSize x $ySize $imageType images."
  # call the root macro in batch mode and tell it to quit when it's done
  root -b -l -q "$plotMacro(\"$rootFile\",\"$imageType\",$xSize,$ySize)"
}

# Main method
if [ $# -eq 0 ]; then
  #for a in `ls | grep .root`; do
  #  saveHistFromRootFile $a gif $defaultXsize $defaultYsize
  #done
  #exit
  printUsage
  exit 2
else
  rootFile=$1
  imageType="gif"
  xSize=$defaultXsize
  ySize=$defaultYsize
fi

if [ $# -gt 0 ]; then
  rootFile=$1
fi
if [ $# -gt 1 ]; then
  imageType=$2
fi
if [ $# -gt 3 ]; then
  xSize=$3
  ySize=$4
fi

saveHistFromRootFile $rootFile $imageType $xSize $ySize