All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ListFCL.sh
Go to the documentation of this file.
1 #!/bin/bash
2 #
3 # Lists all the FCL files whose name matches the specified pattern.
4 #
5 # Usage: ListFCL.sh [Pattern]
6 #
7 # The pattern is a regex as interpreted by grep ("-e" option).
8 #
9 
10 SCRIPTNAME="$(basename "$0")"
11 
12 : ${FORMAT:="%f (in %h)"}
13 
14 function help() {
15  cat <<-EOH
16  Looks for FHICL files in the ART FHICL search directories.
17 
18  Usage: ${SCRIPTNAME} [options] [--] [Pattern]
19 
20  Options:
21  --format=FORMAT
22  use the specified format; the default format is "%f (in %h)";
23  the placeholder are as documented in find (1) manual
24  --name , -n
25  print the file name only
26  --path , -p
27  print the full path
28 
29  EOH
30 } # help()
31 
32 
33 function isFlagSet() {
34  local VarName="$1"
35  [[ -n "${!VarName//0}" ]]
36 } # isFlagSet()
37 
38 function STDERR() { echo "$*" >&2 ; }
39 function ERROR() { STDERR "ERROR: $@" ; }
40 function FATAL() {
41  local Code="$1"
42  shift
43  STDERR "FATAL ERROR (${Code}): $*"
44  exit $Code
45 } # FATAL()
46 function LASTFATAL() {
47  local Code="$?"
48  [[ "$Code" != 0 ]] && FATAL "$Code""$@"
49 } # LASTFATAL()
50 
51 function Filter() {
52  local Pattern="$1"
53  if [[ -n "$Pattern" ]]; then
54  grep -e "$Pattern"
55  else
56  cat
57  fi
58 } # Filter()
59 
60 function CleanSortKey() { sed -e 's/^[^ ]* \+//' ; }
61 
62 function ApplyFormat() {
63  local Format="$1"
64  local Data
65  while read Data ; do
66  local FileName="${Data%%/*}"
67  local Path="${Data#*/}"
68 
69  case "$Format" in
70  ( '' )
71  echo "${FileName} (in ${Path})"
72  ;;
73  ( * )
74  sed -e "s@\([^\]|\^\)%f@${FileName}@" -e "s@\([^\]|\^\)%h@${Path}@" <<< "$Format"
75  esac
76  done
77 }
78 
79 ################################################################################
80 
81 declare -i NoMoreOptions=0
82 declare -a Patterns
83 declare -i nPatterns=0
84 for (( iParam = 1 ; iParam <= $# ; ++iParam )); do
85  Param="${!iParam}"
86  if ! isFlagSet NoMoreOptions && [[ "${Param:0:1}" == '-' ]]; then
87  case "$Param" in
88  ( '--help' | '-h' | '-?' ) DoHelp=1 ;;
89 
90  ### format options
91  ( '--name' | '-n' ) FORMAT="%f" ;;
92  ( '--path' | '-p' ) FORMAT="%p" ;;
93  ( '--format='* ) FORMAT="${Param#--*=}" ;;
94 
95  ### other stuff
96  ( '-' | '--' )
97  NoMoreOptions=1
98  ;;
99  ( * )
100  echo "Unrecognized script option #${iParam} - '${Param}'"
101  exit 1
102  ;;
103  esac
104  else
105  NoMoreOptions=1
106  Patterns[nPatterns++]="$Param"
107  fi
108 done
109 
110 if isFlagSet DoHelp ; then
111  help
112  # set the exit code (0 for help option, 1 for missing parameters)
113  isFlagSet DoHelp
114  exit $?
115 fi
116 
117 # explanation:
118 # - start with paths in FHICL_FILE_PATH
119 # - split by ":"
120 # - find in all those directories (but not in their subdirectories),
121 # and in that order, all the FCL files
122 # - print for each its name and the string to be presented to the user as output
123 # - soft them by FCL file name, preserving the relative order of files with the
124 # same name from different directories
125 # - filter them on sort key (file name) by user's request
126 # - remove the sort key (file name) from the output
127 tr ':' "\n" <<< "$FHICL_FILE_PATH" | xargs -I SEARCHPATH find SEARCHPATH -maxdepth 1 -name "*.fcl" -printf "%f ${FORMAT}\n" 2> /dev/null | sort -s -k1,1 -u | Filter "^[^ ]*${Patterns[0]}[^ ]* " | CleanSortKey
then echo FATAL
function LASTFATAL()
Definition: utilities.sh:25
static std::string format(PyObject *obj, unsigned int pos, unsigned int indent, unsigned int maxlen, unsigned int depth)
Definition: fclmodule.cxx:374
then echo ERROR
Definition: grid_setup.sh:42
esac done echo Signal files are
Definition: TrainMVA.sh:25
* file
Definition: file_to_url.sh:69
pdgs p
Definition: selectors.fcl:22
#define the
do one_file $F done echo for F in find $TOP name CMakeLists txt print
SCRIPTNAME
Definition: publish.sh:21
function isFlagSet()
Definition: utilities.sh:7
function STDERR()
Definition: utilities.sh:17
shift
Definition: fcl_checks.sh:26
then echo Sam station was not specified(use option--sam_station)." exit 1 fi if [ x$SAM_GROUP
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
while getopts h
then local
BEGIN_PROLOG FileName
Definition: filemuons.fcl:10
then shift fi
do case in h help echo Usage
Definition: file_to_url.sh:42
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker options
do i e
then echo fcl name
echo Invalid option
Definition: TrainMVA.sh:17
BEGIN_PROLOG triggeremu_data_config_icarus settings sequence::triggeremu_data_config_icarus settings PMTADCthresholds sequence::triggeremu_data_config_icarus settings PMTADCthresholds sequence::triggeremu_data_config_icarus settings PMTADCthresholds Pattern
do Param