Accumulator.pm 2.95 KB
Newer Older
1 2 3 4
=pod 

=head1 NAME

5
    Bio::EnsEMBL::Hive::Accumulator
6 7 8 9 10 11

=head1 DESCRIPTION

    A data container object that defines parameters for accumulated dataflow.
    This object is generated from specially designed datalow URLs.

12 13
=head1 LICENSE

14
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
nwillhoft's avatar
nwillhoft committed
15
    Copyright [2016-2021] EMBL-European Bioinformatics Institute
16 17 18 19 20 21 22 23 24 25

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License
    is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and limitations under the License.

26 27
=head1 CONTACT

28
  Please subscribe to the Hive mailing list:  http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users  to discuss Hive-related questions or to be notified of our updates
29 30 31

=cut

32

33 34 35
package Bio::EnsEMBL::Hive::Accumulator;

use strict;
36
use warnings;
37

38
use Bio::EnsEMBL::Hive::Utils ('stringify');
39

40
use base ( 'Bio::EnsEMBL::Hive::Storable' );
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


sub struct_name {
    my $self = shift @_;

    if(@_) {
        $self->{'_struct_name'} = shift @_;
    }
    return $self->{'_struct_name'};
}


sub signature_template {
    my $self = shift @_;

    if(@_) {
        $self->{'_signature_template'} = shift @_;
    }
    return $self->{'_signature_template'};
}


sub url {
    my $self    = shift @_;
    my $ref_dba = shift @_;     # if reference dba is the same as 'our' dba, a shorter url can be generated

    if(my $adaptor = $self->adaptor) {
        my $dbc_prefix = ($adaptor->db == $ref_dba) ? ':///' : $adaptor->db->dbc->url();
        return $dbc_prefix .'/accu?'.$self->struct_name(). '=' . $self->signature_template();
    } else {
        return;
    }
}


sub dataflow {
    my ( $self, $output_ids, $emitting_job ) = @_;

    my $sending_job_id      = $emitting_job->dbID();
    my $receiving_job_id    = $emitting_job->semaphored_job_id() || die "No semaphored job, cannot perform accumulated dataflow";

    my $struct_name         = $self->struct_name();
    my $signature_template  = $self->signature_template();

    my @rows = ();

    foreach my $output_id (@$output_ids) {

        my $key_signature = $signature_template;
90
        $key_signature=~s/(\w+)/$emitting_job->_param_possibly_overridden($1,$output_id)/eg;
91 92 93 94 95 96

        push @rows, {
            'sending_job_id'    => $sending_job_id,
            'receiving_job_id'  => $receiving_job_id,
            'struct_name'       => $struct_name,
            'key_signature'     => $key_signature,
97
            'value'             => stringify( $emitting_job->_param_possibly_overridden($struct_name, $output_id) ),
98 99 100 101 102 103 104 105
        };
    }

    $self->adaptor->store( \@rows );
}

1;