#!/bin/bash # # tpoltree.bash - run the TPOL_tree plugin over input evio files # and write the output root tree file back to srm. # The input files are accessed from a remote store # over xrootd, specified as a directory containing # multiple evio files. All files ending with .evio # are analyzed in a single run, and the output trees # are merged into a single output file. # # author: richard.t.jones at uconn.edu # version: april 22, 2019 # # change: may 24, 2019 [rtj] # * Some of these runs are too long and keep getting killed before they # can finish, so I need to break them down into smaller pieces. To do # this, I created a more elaborate scheme for how the list of input # files is specified. Under this scheme, the pathnames of the input # files to be processed can be listed directly on the commandline, or # they may be substituted with a list of keywords to be used to look # up the input filepaths in an indexed file. In the latter case, the # name of the index file must be given on the commandline using the # -f option. More than one input file can be associated with a keyword # to indicate that these input files should be processed together by # a single job. The index file is a plain text file consisting of # any number of lines with the following space-separated fields. # keyword dirfile [dirkey1 [dirkey2] ... ] # where dirfile is the name of yet another text file that contains # the path to all of the input files, one per line, formatted as # dirkey inputfilepath # Both keyword and dirkey must be unique strings in each of their # respective files, and should not contain spaces or characters that # have a special meaning in regular expressions, eg. *, ?, \, etc. # This scheme allows a single dirfile to serve as a common source of # input file paths for any number of production runs, each of which # would have its own individual index file to specify which input # files were processed in which order for that production run. function usage { echo "Usage: tpoltree.bash [options] [ ...]" echo " or: tpoltree.bash [options] -f [ ...]" echo "" echo " where options may be any of the following." echo " -d : dry run, print what would be done but do not do it." echo " -s : if processing is successful, save the output file" echo " under the name . If is an absolute" echo " path, push the output to the stated destination using" echo " uberftp, otherwise leave it in the working directory." exit 1 } nthreads=1 nevents=999999999 batch_mode=0 plugins=TPOL_tree JANA_CALIB_CONTEXT="variation=default" xrootdurl=root://nod28.phys.uconn.edu/ ftpserver=stat30.phys.uconn.edu if [[ $# = 0 ]]; then usage fi saveas="" indexfile="" inputlist="" dryrun="no" while [[ $# -gt 0 ]]; do if [[ $1 = "-s" ]]; then shift saveas=$1 elif [[ $1 = "-d" ]]; then dryrun="yes" elif [[ $1 = "-f" ]]; then shift indexfile=$1 elif [[ -n "$indexfile" ]]; then if [[ ! -r $indexfile ]]; then echo "Error - unable to access indexfile $indexfile, cannot continue." exit 1 fi indexdir=`dirname $indexfile` dirlist=`grep "^ *$1 " $indexfile` dirfile=`echo $dirlist | awk '{print $2}'` if [[ ! -r $dirfile ]]; then indexdir=`dirname $indexfile` if [[ -r $indexdir/$dirfile ]]; then dirfile=$indexdir/$dirfile else echo "Error - unable to access dirfile $dirfile, cannot continue." exit 1 fi fi for dirkey in `echo $dirlist | awk '{for(i=3;i<=NF;++i){print $i}}'`; do infile=`awk '/^'$dirkey' /{print $2}' $dirfile` if ls $1 >/dev/null 2>&1; then inputlist="$inputlist $infile" elif ls $xrootdurl/$infile >/dev/null 2>&1; then inputlist="$inputlist $xrootdurl/$infile" else echo "Error - unable to access input file $infile, cannot continue." exit 1 fi done elif ls $1 >/dev/null 2>&1; then inputlist="$inputlist $1" elif ls $xrootdurl/$1 >/dev/null 2>&1; then inputlist="$inputlist $xrootdurl/$1" else usage fi shift done if [[ -z "$inputlist" ]]; then echo "Nothing to do, bye!" exit 0 fi if [[ ! -x hd_ana ]]; then if [[ "$dryrun" = "yes" ]]; then echo wget http://zeus.phys.uconn.edu/halld/gridwork/hd_ana echo chmod +x hd_ana else wget http://zeus.phys.uconn.edu/halld/gridwork/hd_ana chmod +x hd_ana fi fi # execute the request echo "Executing on node" `hostname -f` hd_ana="./hd_ana -PJANA:BATCH_MODE=$batch_mode \ -PEVIO:NTHREADS=1 \ -PNTHREADS=$nthreads \ -PEVENTS_TO_SKIP=$nskip \ -PEVENTS_TO_KEEP=$nevents \ -PTHREAD_TIMEOUT_FIRST_EVENT=3600 \ -PTHREAD_TIMEOUT=600 \ -PEVIO:MAX_PARSED_EVENTS=10 \ -PEVIO:MAX_EVENT_RECYCLES=10 \ -PEVIO:MAX_OBJECT_RECYCLES=10 \ -PEVIO:TREAT_TRUNCATED_AS_ERROR=1 \ -PPLUGINS=$plugins \ -p --nthreads=$nthreads" if [[ "$dryrun" = "yes" ]]; then echo $OSG_CONTAINER_HELPER $hd_ana $inputlist touch tree_TPOL.root retcode=$? else $OSG_CONTAINER_HELPER $hd_ana $inputlist retcode=$? fi if [[ $retcode != 0 ]]; then echo "Error: hd_ana exited with error code $retcode, giving up." exit $retcode elif [[ ! -r "tree_TPOL.root" ]]; then echo "Error: hd_ana exited with success, but no output tree_TPOL.root file found!" echo "Nothing more to do, giving up." exit 2 fi # copy the output file back using gridftp if requested if [[ -n "$saveas" ]]; then if echo $saveas | grep -q "^/"; then rootdir=`dirname $saveas` rootfile=`basename $saveas` if [[ "$dryrun" = "yes" ]]; then echo "mv tree_TPOL.root $rootfile" echo $OSG_CONTAINER_HELPER uberftp $ftpserver "cd $rootdir; put $rootfile" echo "if [[ $? = 0 ]]; then" echo /bin/rm $rootfile echo "fi" else mv tree_TPOL.root $rootfile $OSG_CONTAINER_HELPER uberftp $ftpserver "cd $rootdir; put $rootfile" if [[ $? = 0 ]]; then /bin/rm $rootfile fi fi else if [[ "$dryrun" = "yes" ]]; then echo "mv tree_TPOL.root $saveas" else mv tree_TPOL.root $saveas fi fi fi exit $retcode