ProcessSingleFileFromRunNum.sh
Go to the documentation of this file.
1 function echo-info(){
2  echo "INFO : $@" >&2
3 }
4 
5 function echo-error(){
6  echo "ERROR : $@" >&2
7 }
8 
9 function usage(){
10  echo-info "`basename $0` <runnum> <version> <qualifiers>"
11  echo-info "`basename $0` 1234 v04_30_03 e9"
12 }
13 
14 function parse_args(){
15  if [ $# -lt 3 ];then
16  usage
17  exit 1
18  fi
19  RUN=$1
20  VERSION=$2
21  QUALIFIERS=$3
22 
23  if [ $# -eq 4 ];then
24  DEBUG=1
25  else
26  DEBUG=0
27  fi
28 
29  RELEASE_DIR=/home/lbnedaq/nearline/nearline_test_release_${VERSION}
30  SCRIPT_PATH=${RELEASE_DIR}/srcs/dunetpc/dune/NearlineMonitor/scripts
31  PRODUCTS_DIR=${RELEASE_DIR}/localProducts_larsoft_${VERSION}_${QUALIFIERS}_prof
32  OUTPUT_PATH=/lbne/data2/users/lbnedaq/nearline/${VERSION}
33 
34  echo-info "RUN $RUN"
35  echo-info "RELEASE_DIR $RELEASE_DIR"
36  echo-info "SCRIPT_PATH $SCRIPT_PATH"
37  echo-info "PRODUCTS_DIR $PRODUCTS_DIR"
38  echo-info "OUTPUT_PATH $OUTPUT_PATH"
39 }
40 
41 function find_run_file(){
42  RUN_ZEROS=`printf %06i $RUN`
43  echo-info "RUN_ZEROS $RUN_ZEROS"
44  TRANSFERRED_DIR=/data/lbnedaq/data/transferred_files
45  NUM_FILES=`find ${TRANSFERRED_DIR}/lbne_r${RUN_ZEROS}_sr??_*.root 2>/dev/null | wc -l`
46 
47  if [ $NUM_FILES -eq 0 ];then
48  echo-error "Failed to find RUN $RUN_ZEROS"
49  exit 1
50  elif [ $NUM_FILES -gt 1 ];then
51  echo-error "Found more than one file for RUN $RUN_ZEROS : `find ${TRANSFERRED_DIR}/lbne_r${RUN_ZEROS}_sr??_*.root 2>/dev/null`"
52  exit 1
53  fi
54  FILE_FULL_PATH=`find ${TRANSFERRED_DIR}/lbne_r${RUN_ZEROS}_sr??_*.root 2>/dev/null`
55  echo-info "FILE_FULL_PATH $FILE_FULL_PATH"
56 }
57 
58 function process_file(){
59  FILE=`basename $FILE_FULL_PATH`
60  bigrun=${FILE:6:3}
61  run=${FILE:6:6}
62  subrun=${FILE:15:2}
63  RunDir=${OUTPUT_PATH}/$bigrun/$run
64  mkdir -p $RunDir
65  OLD_PWD=$PWD
66  cd $SCRIPT_PATH
67  echo-info "./ProcessSingleFile.sh $RunDir $FILE_FULL_PATH $PRODUCTS_DIR"
68 
69  if [ $DEBUG -eq 1 ];then
70  ./ProcessSingleFile.sh $RunDir $FILE_FULL_PATH $PRODUCTS_DIR
71  else
72  nohup ./ProcessSingleFile.sh $RunDir $FILE_FULL_PATH $PRODUCTS_DIR >> /dev/null 2>&1 &
73  fi
74 
75  cd $OLD_PWD
76 }
77 
78 parse_args "$@"
79 find_run_file
80 process_file
81