next up previous contents
Next: Time Object Handling Up: Some Functions and Methods Previous: Creating Sequence Masks   Contents

Using Sequence Masks

The methods below show the use of sequence masks to subset both time lines and data sequences associated with them. The application of a mask to a data series has the effect that the sequence entry at index n is copied to the new sequence only if the mask value at index n is true.

$\bullet$
void get_subsequence( Sequence& seq, SequenceMask &msk);
The returned sequence seq is of the same type as the parent sequence, but contains only the entries in the parent sequence for which the value of the mask is true. Note this function returns a Sequence object not a var pointer to it, and so the var pointer passed into this function must be dereferenced.
  #include "qplug_if.h"
  #include "Qdos.h"
  using namespace QSAS;
  QdTimeSeq_var tt_out = new QdTimeSeq();
  QdObject_var input1 = (* object_list)[1]; 
  QdObject_var input2 = (* object_list)[2]; 
  QdTimeInterval_var interval = get_timeinterval(input1);
  QdTimeSeq_var tt = get_timetags(input2);
  SequenceMask msk(tt->get_mask(QdTimeSeq::InRange(interval->start(), 
                                                   interval->end()))); 
  
  // put timetags satisfying condition in tt_out
  // Note tt_out is a var pointer, so we pass in *tt_out
  tt_in->get_subsequence( *tt_out, msk);
  
  QdRScalar_var ds_out = new QdRScalarSeq();
  
  // put data objects satisfying condition in ds_out
  input2->get_subsequence( *ds_out, msk);
 
  set_timetags(ds_out, tt_out);

$\bullet$
SequenceMask operator!
A sequence mask may be negated to invert its operation.
input2->get_subsequence( *ds_out, !msk);
will create a sub-sequence containing elements in input2 for which the mask was false.

$\bullet$
SequenceMask operator &&, operator ||
The logical and and or operators are understood by sequence masks.
input2->get_subsequence( *ds_out, (msk1 && msk2) );
will create a sub-sequence containing elements in input2 for which the masks msk1 and msk2 were both true.


next up previous contents
Next: Time Object Handling Up: Some Functions and Methods Previous: Creating Sequence Masks   Contents
Anthony Allen 2005-11-07