IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 13, 2023, 9:30:40 AM (3 years ago)
Author:
eugene
Message:

split fix_chip_locations into parallel processes by chip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/eam/rawfix.20230221/src/fix_chip_locations.pl

    r42447 r42449  
    1212use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1313
    14 # USAGE: fix_chip_locations.pl --dateobs (night) --chiplist (file) --stage (0,1,etc)
     14# USAGE: fix_chip_locations.pl --dateobs (night) --stage (0,1,etc) [--chiplist (file) | --chipID (ID)]
    1515
    1616# we need to select targets for ITC copies of files currently only at ATRC:
     
    1818# for each chip, target a single host?
    1919
    20 my ($fulldate, $dateword, $chiplist, $stage, $topdir) = &parse_cmdopts;
     20my ($fulldate, $dateword, $chiplist, $chipID, $stage, $topdir) = &parse_cmdopts;
    2121my ($neb_dbh, $raw_dbh) = &parse_db_config ("$topdir/nebulous.config");
    22 
    23 # read the list of chip_ids:
    24 my @chip_ids = &load_chip_list ($chiplist);
    2522
    2623# choose ITC machines on which to place backup copies:
    2724my @vol_copy = &get_neb_volumes_copy; # array of neb hosts to copy data to at ITC
    2825my %vol_good = &get_neb_volumes_good; # hash of valid neb hosts
    29 my $volnum = 0;
    3026
    3127my $Ngood = 0;
     
    4137my $Ncul3 = 0;
    4238my $Nfail = 0;
     39
     40my $Nchip = 0; # counts the number of instances
    4341
    4442# load the lists of good and fail chips
     
    6967}
    7068
    71 my $Nchip = 0;
    72 
     69# read the list of chip_ids:
     70my @chip_ids = &load_chip_list ($chiplist);
     71
     72my $volnum = 0; # select the volume to be used from the list of @vol_copy
     73
     74# loop over all chip_ids so we can distribute the target volumes
    7375foreach my $chip_id (@chip_ids) {
     76    if (not defined $chipID or ($chipID eq $chip_id)) {
     77        &fix_chip_locations_chipID ($chip_id, $volnum);
     78    }
     79    $volnum ++;
     80    if ($volnum > @vol_copy) { $volnum = 0; }
     81}
     82
     83my $Ntotal = $Ngood + $Ngone + $Ndead + $Nsing + $Ndups + $Nsbck + $Nxbck + $Ncul1 + $Ncul2 + $Ncul3 + $Nfail;
     84if ($Ntotal != $Nchip) { die "ERROR: inconsistent count of chips\n"; }
     85
     86if (not defined $chipID) {
     87    # update the stats in the database
     88    my $sql_update_stats = "UPDATE nights set";
     89    $sql_update_stats .= "  Nchip = $Nchip";
     90    $sql_update_stats .= ", Ngood = $Ngood";
     91    $sql_update_stats .= ", Ndead = $Ndead";
     92    $sql_update_stats .= ", Ngone = $Ngone";
     93    $sql_update_stats .= ", Nsing = $Nsing";
     94    $sql_update_stats .= ", Ndups = $Ndups";
     95    $sql_update_stats .= ", Nsbck = $Nsbck";
     96    $sql_update_stats .= ", Nxbck = $Nxbck";
     97    $sql_update_stats .= ", Ncul1 = $Ncul1";
     98    $sql_update_stats .= ", Ncul2 = $Ncul2";
     99    $sql_update_stats .= ", Ncul3 = $Ncul3";
     100    $sql_update_stats .= ", Nfail = $Nfail";
     101    $sql_update_stats .= " WHERE dateobs = $dateword";
     102   
     103    my $query = $raw_dbh->prepare($sql_update_stats);
     104    $query->execute () or die "invalid response from RAW database\n";
     105} else {
     106
     107    open (OUTFILE, ">$topdir/$dateword/$chipID.stats.$stage.txt");
     108
     109    print OUTFILE "Nchip: $Nchip\n";
     110    print OUTFILE "Ngood: $Ngood\n";
     111    print OUTFILE "Ngone: $Ngone\n";
     112    print OUTFILE "Ndead: $Ndead\n";
     113    print OUTFILE "Nsing: $Nsing\n";
     114    print OUTFILE "Ndups: $Ndups\n";
     115    print OUTFILE "Nsbck: $Nsbck\n";
     116    print OUTFILE "Nxbck: $Nxbck\n";
     117    print OUTFILE "Ncul1: $Ncul1\n";
     118    print OUTFILE "Ncul2: $Ncul2\n";
     119    print OUTFILE "Ncul3: $Ncul3\n";
     120    print OUTFILE "Nfail: $Nfail\n";
     121
     122    close (OUTFILE);
     123}
     124
     125exit 0;
     126
     127sub fix_chip_locations_chipID {
     128
     129    my $chip_id = $_[0];
     130    my $volnum  = $_[1];
    74131
    75132    # read from chip_id file, update to next stage number
     
    216273        }
    217274    }
    218     $volnum ++;
    219 }
    220 
    221 print "Nchip: $Nchip\n";
    222 print "Ngood: $Ngood\n";
    223 print "Ngone: $Ngone\n";
    224 print "Ndead: $Ndead\n";
    225 print "Nsing: $Nsing\n";
    226 print "Ndups: $Ndups\n";
    227 print "Nsbck: $Nsbck\n";
    228 print "Nxbck: $Nxbck\n";
    229 print "Ncul1: $Ncul1\n";
    230 print "Ncul2: $Ncul2\n";
    231 print "Ncul3: $Ncul3\n";
    232 print "Nfail: $Nfail\n";
    233 
    234 my $Ntotal = $Ngood + $Ngone + $Ndead + $Nsing + $Ndups + $Nsbck + $Nxbck + $Ncul1 + $Ncul2 + $Ncul3 + $Nfail;
    235 if ($Ntotal != $Nchip) { die "ERROR: inconsistent count of chips\n"; }
    236 
    237 # update the stats in the database
    238 my $sql_update_stats = "UPDATE nights set";
    239 $sql_update_stats .= "  Nchip = $Nchip";
    240 $sql_update_stats .= ", Ngood = $Ngood";
    241 $sql_update_stats .= ", Ndead = $Ndead";
    242 $sql_update_stats .= ", Ngone = $Ngone";
    243 $sql_update_stats .= ", Nsing = $Nsing";
    244 $sql_update_stats .= ", Ndups = $Ndups";
    245 $sql_update_stats .= ", Nsbck = $Nsbck";
    246 $sql_update_stats .= ", Nxbck = $Nxbck";
    247 $sql_update_stats .= ", Ncul1 = $Ncul1";
    248 $sql_update_stats .= ", Ncul2 = $Ncul2";
    249 $sql_update_stats .= ", Ncul3 = $Ncul3";
    250 $sql_update_stats .= ", Nfail = $Nfail";
    251 $sql_update_stats .= " WHERE dateobs = $dateword";
    252 
    253 my $query = $raw_dbh->prepare($sql_update_stats);
    254 $query->execute () or die "invalid response from RAW database\n";
    255 
    256 exit 0;
     275}
    257276
    258277sub get_new_instance {
     
    412431sub parse_cmdopts {
    413432
    414     my ($dateobs, $chiplist, $stage, $topdir);
    415     GetOptions( 'dateobs=s' => \$dateobs, 'chiplist=s' => \$chiplist, 'topdir=s' => \$topdir, 'stage=s' => \$stage) || pod2usage(2);
     433    my ($dateobs, $chiplist, $chipID, $stage, $topdir);
     434    GetOptions( 'dateobs=s' => \$dateobs, 'chiplist=s' => \$chiplist, 'chipID=s' => \$chipID, 'topdir=s' => \$topdir, 'stage=s' => \$stage) || pod2usage(2);
    416435   
    417436    pod2usage( -msg => "Cannot determine target date, use --dateobs YYYY/MM/DD", -exitval => 2) unless defined $dateobs;
    418     pod2usage( -msg => "Provide a list of chips with --chiplist", -exitval => 2) unless defined $chiplist;
    419437    pod2usage( -msg => "Define the stage (0, 1, etc) with --stage", -exitval => 2) unless defined $stage;
    420438    pod2usage( -msg => "Specify the top-level output directory with --topdir", -exitval => 2) unless defined $topdir;
    421    
     439    pod2usage( -msg => "Provide a list of chips with --chiplist", -exitval => 2) unless defined $chiplist;
     440
    422441    # check that stage is an integer
    423442    unless (is_integer ($stage)) { die "stage must be a non-negative integer\n"; }
     
    435454    my $dateword = sprintf ("%4d%02d%02d", $date_year, $date_month, $date_day);
    436455
    437     return ($fulldate, $dateword, $chiplist, $stage, $topdir);
     456    return ($fulldate, $dateword, $chiplist, $chipID, $stage, $topdir);
    438457}
    439458
Note: See TracChangeset for help on using the changeset viewer.