File size: 3,653 Bytes
29c8e15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash

# Exit script immediately if any command fails
set -e
# Ensure pipeline commands fail if any part fails (important for cat | zstd | tar)
set -o pipefail

# --- Configuration ---
DEFAULT_TARGET_DIR="/workspace/Pointcept/data/waymo"

# Define the pattern for the split training archive parts.
# Assumes parts are in the current directory where the script is run.
# Adjust the path if the parts are elsewhere, e.g., /path/to/parts/processed_waymo...
TRAINING_ARCHIVE_PATTERN="./processed_waymo_training.tar.zst.part.*"

# Define the single validation archive file.
# Assumes the file is in the current directory where the script is run.
# Adjust the path if the file is elsewhere, e.g., /path/to/file/processed_waymo...
VALIDATION_ARCHIVE="./processed_waymo_validation.tar.zst"

# --- Determine Target Directory ---
# Use the first command-line argument ($1) if provided, otherwise use the default.
if [[ -n "$1" ]]; then
    TARGET_DIR="$1"
    echo "Using custom target directory provided: $TARGET_DIR"
else
    TARGET_DIR="$DEFAULT_TARGET_DIR"
    echo "No custom target directory provided. Using default: $TARGET_DIR"
fi
echo # Blank line for spacing

# --- Script Start ---
echo "--- Waymo Data Extraction Script ---"
START_TIME=$SECONDS

# --- Check and Create Target Directory ---
echo "Ensuring target directory exists: $TARGET_DIR"
if [ ! -d "$TARGET_DIR" ]; then
    echo "Target directory does not exist. Creating..."
    # Create the directory, including any necessary parent directories (-p)
    mkdir -p "$TARGET_DIR"
    echo "Created directory: $TARGET_DIR"
else
    echo "Target directory already exists."
fi
echo # Blank line for spacing

# --- Extract Training Archive (Split) ---
echo "Starting extraction of TRAINING archive..."
echo "Source pattern: $TRAINING_ARCHIVE_PATTERN"
echo "This may take a while..."

# Check if any training parts exist before attempting cat
if ! ls $TRAINING_ARCHIVE_PATTERN > /dev/null 2>&1; then
    echo "ERROR: No files found matching training archive pattern: $TRAINING_ARCHIVE_PATTERN"
    exit 1
fi

# 1. Concatenate the parts using cat
# 2. Pipe the combined stream to zstd for decompression (-d = decompress, -c = to stdout)
# 3. Pipe the decompressed tar stream to tar for extraction
#    -x = extract
#    -v = verbose (shows files being extracted)
#    -f - = read archive from stdin (the pipe)
#    -C "$TARGET_DIR" = change directory to TARGET_DIR before extracting
cat $TRAINING_ARCHIVE_PATTERN | zstd -dc - | tar -xvf - -C "$TARGET_DIR"

echo "Training archive extraction complete."
echo # Blank line for spacing

# --- Extract Validation Archive (Single File) ---
echo "Starting extraction of VALIDATION archive..."
echo "Source file: $VALIDATION_ARCHIVE"
echo "This may take a while..."

# Check if validation archive exists
if [ ! -f "$VALIDATION_ARCHIVE" ]; then
    echo "ERROR: Validation archive file not found: $VALIDATION_ARCHIVE"
    exit 1
fi

# 1. Decompress the file with zstd (-d = decompress, -c = to stdout)
# 2. Pipe the decompressed tar stream to tar for extraction (same flags as above)
zstd -dc "$VALIDATION_ARCHIVE" | tar -xvf - -C "$TARGET_DIR"

echo "Validation archive extraction complete."
echo # Blank line for spacing

# --- Stats and Summary ---
END_TIME=$SECONDS
DURATION=$((END_TIME - START_TIME))

echo "--- Extraction Summary ---"
echo "Extraction process finished successfully."
echo "Total time taken: $DURATION seconds."
echo "Data extracted to: $TARGET_DIR"

# Show the top-level directories created inside the target directory
echo "Contents of target directory ($TARGET_DIR):"
ls -l "$TARGET_DIR"

echo "--------------------------"

exit 0