7source ${0%${script}}ulib.sh
9set_variable: DEBUG ARCHIVE_DEBUG 2
10set_variable VERSION ""
13 usage "$script <input file> <path> <detector identifier> <minimal run> <maximal run> <type> <version>"\
14 "\nUtility script to store file in archive."
18 7) set_variable INPUT_FILE $argv[1];
19 set_variable DIR $argv[2];
21 let MINRUN=" $argv[4]";
22 let MAXRUN=" $argv[5]";
23 set_variable TYPE $argv[6];
24 set_variable VERSION $argv[7];;
25 *) fatal "Wrong number of arguments."
28if [[ ! -d $DIR ]]; then
29 fatal "Invalid path $argv[2]"
32if [[ ! -f $INPUT_FILE ]]; then
33 fatal "File $INPUT_FILE does not exist."
36if (( $ID == 0 )); then
37 fatal "Invalid detector identifier $argv[3]"
40if (( $MINRUN == 0 )); then
41 fatal "Invalid minimal run $argv[4]"
44if (( $MAXRUN == 0 )); then
45 fatal "Invalid minimal run $argv[5]"
48if (( $MINRUN > $MAXRUN )); then
49 fatal "Invalid minimal / maximal run $argv[4] / $argv[5]"
52if [[ $VERSION == *[^[:alnum:_-]]* ]]; then
53 fatal "Invalid version $argv[7] (special characters not allowed)"
64if [[ -d $DIR/$ID/$TYPE ]]; then
66 typeset -T BUFFER ARRAY /
68 (ls -1 $DIR/$ID/$TYPE/_*/*/*/*) 2> /dev/null | while read BUFFER; do
70 set_variable A_ID ${ARRAY[-6]}
71 set_variable A_TYPE ${ARRAY[-5]}
72 set_variable A_VERSION ${ARRAY[-4]#_}
73 let A_MINRUN=" ${ARRAY[-3]}"
74 let A_MAXRUN=" ${ARRAY[-2]}"
75 set_variable A_FILENAME ${ARRAY[-1]}
77 let A_COUNTER="${A_FILENAME:r}"
79 if (( $MINRUN <= $A_MAXRUN && $MAXRUN >= $A_MINRUN )); then
80 if (( $A_COUNTER > $COUNTER )); then
81 let COUNTER="$A_COUNTER"
87let COUNTER="$COUNTER + 1"
89set_variable OUTPUT_FILE $DIR/$ID/$TYPE/_${VERSION}/$MINRUN/$MAXRUN/${COUNTER}.${INPUT_FILE:e}
91mkdir -p ${OUTPUT_FILE:h}
94 fatal "Path ${OUTPUT_FILE:h} not created."
97cp -p $INPUT_FILE $OUTPUT_FILE
100 notice "Stored $INPUT_FILE to archive:$OUTPUT_FILE"
102 fatal "File $INPUT_FILE not stored in archive."