#!/usr/bin/perl -w # create_tab_sep_for_mysql [path] # # by: Jaideep Singh # # date: 02/02/2006 # # description: reduces all summary files into one big tab-separated text file to be loaded into mysql # combines all files in the [path] directory # does this for the prescalars and all variables that have numerical values # #getting name of path to files + ARGUMENT ERROR HANDLING $path = $ARGV[0]; die "error: Uh, what path do you want me to look at dude?: Too few arguments\n" unless ($path); die "error: Scared and confused: Too many arguments\n" unless (($#ARGV+1) < 2); #getting all sorted filenames in path and building run hash array $raw_files = qx(ls $path); @file_array = split(/\n/,$raw_files); $file_count = 0; $run_count = 0; foreach $file (@file_array) { $file_count++; chomp $file; if ($file =~ /gdh_(\d+)_epics_data_summary.txt/) { $run_hash{$1} = $file; $run_count++ } } #looping over each run RUN: foreach $run_num (sort keys %run_hash) { print "\n$run_num : "; $line_count = 0; open(IN_FILE,"$path$run_hash{$run_num}"); # looping for each line in the file while () { $line_count++; chomp; if (/\-\-\-\-\-/) { close(IN_FILE); print "$prescalars"; next RUN; } elsif (/(ps\d\=(\d+)\,ps\d\=(\d+)\,ps\d\=(\d+)\,ps\d\=(\d+)\,ps\d\=(\d+)\,ps\d\=(\d+)\,ps\d\=(\d+)\,ps\d\=(\d+))/) { # pulling out the prescalar string $prescalars = $1; $data{$run_num}{"ps1"} = $2; $data{$run_num}{"ps2"} = $3; $data{$run_num}{"ps3"} = $4; $data{$run_num}{"ps4"} = $5; $data{$run_num}{"ps5"} = $6; $data{$run_num}{"ps6"} = $7; $data{$run_num}{"ps7"} = $8; $data{$run_num}{"ps8"} = $9; } elsif ($_ ne "") { # pulling out the data @line_parts = split(/\t/); $var = $line_parts[0]; $data{$run_num}{$var."_mean"} = $line_parts[4]; $data{$run_num}{$var."_sigma"} = $line_parts[5]; $data{$run_num}{$var."_count"} = $line_parts[1]; $data{$run_num}{$var."_min"} = $line_parts[2]; $data{$run_num}{$var."_max"} = $line_parts[3]; } } } print "\n"; # creating and opening up file that will record all the information open(OUT_FILE,">gdh_epics_data_stream_summary.txt"); $sample_hash = $data{"4215"}; foreach $run_num (sort keys %data) { print OUT_FILE "$run_num"; foreach $var_name (sort keys %$sample_hash) { $temp = $data{$run_num}{$var_name}; if ($temp) { print OUT_FILE "\t$temp" } else {print OUT_FILE "\tNULL"} } print OUT_FILE "\n"; print "$run_num is written\n" } close(OUT_FILE); open(COL_FILE,">gdh_epics_data_stream_summary_columns.txt"); print COL_FILE "run_number\n"; foreach $var_name (sort keys %$sample_hash) { $out_var_name = $var_name; $out_var_name =~ s/\:/\_/; $out_var_name =~ s/\./\_/; $out_var_name =~ s/\+/\_/; print COL_FILE "$out_var_name\n"; } close(COL_FILE);