Changeset 2301

Show
Ignore:
Timestamp:
12/01/06 13:38:37 (6 years ago)
Author:
balister
Message:

Code complete, needs testing.

Location:
components/FileOutput/trunk/FileOutput
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • components/FileOutput/trunk/FileOutput/FileOutput.cpp

    r2298 r2301  
    2424#include <string> 
    2525#include <iostream> 
     26#include <sstream> 
     27#include <fstream> 
     28 
    2629#include "FileOutput.h" 
    2730 
     
    119122} 
    120123 
     124static void write_data(std::ofstream  *fname, PortTypes::ShortSequence &I_in, PortTypes::ShortSequence &Q_in) 
     125{ 
     126 
     127    for (unsigned int i(0); i < I_in.length(); ++i) { 
     128        (*fname) << I_in[i] << " " << Q_in[i] << std::endl; 
     129    } 
     130} 
     131 
     132 
    121133void FileOutput_i::process_data() 
    122134{ 
    123135    std::cout << "FileOutput's process_data thread started" << std::endl; 
    124136 
     137    PortTypes::ShortSequence *I_in(NULL), *Q_in(NULL); 
     138    unsigned int len(0); 
     139    bool trigger(false), last_trigger(false); 
     140    unsigned int numberEvents(0); 
     141    std::ofstream *outFile(NULL); 
    125142 
    126143 
    127     PortTypes::ShortSequence *I_in_0(NULL), *Q_in_0(NULL); 
    128     CORBA::UShort I_in_0_length, Q_in_0_length; 
     144    while(1) { 
     145        dataIn_0->getData(I_in, Q_in); 
    129146 
    130     while(1) 
    131     { 
    132         dataIn_0->getData(I_in_0, Q_in_0); 
     147        len = I_in->length(); 
    133148 
    134         I_in_0_length = I_in_0->length(); 
    135         Q_in_0_length = Q_in_0->length(); 
     149        if (numberEvents > NumberFiles) { 
     150            dataIn_0->bufferEmptied(); 
     151            continue; 
     152        } 
    136153 
    137         /*insert code here to do work*/ 
     154        // calculate energy 
     155        unsigned int energy(0); 
     156        for (unsigned int i(0); i < len; ++i) { 
     157            if (abs((*I_in)[i]) > abs((*Q_in)[i]))  
     158                energy += (*I_in)[i]; 
     159            else 
     160                energy += (*Q_in)[i]; 
     161        } 
     162        energy /= len; 
    138163 
     164        // Do we write data? 
     165        if (energy > TriggerThreshold) 
     166            trigger = true; 
     167        else 
     168            trigger = false; 
    139169 
     170        // Handle file state 
     171        if (trigger == true && last_trigger == false) {// Open file and write data 
     172            numberEvents++; 
     173            std::ostringstream fname; 
     174            fname << FileName << numberEvents << ".dat";  
     175            outFile = new std::ofstream(fname.str().c_str()); 
    140176 
    141  
    142  
     177            write_data(outFile, *I_in, *Q_in); 
     178        } else if (trigger == true && last_trigger == true) { // Write data 
     179            write_data(outFile, *I_in, *Q_in); 
     180        } else if (trigger == false && last_trigger == true) { // Write data and close 
     181            write_data(outFile, *I_in, *Q_in); 
     182            delete(outFile); 
     183        } 
     184        last_trigger = trigger; 
    143185 
    144186        dataIn_0->bufferEmptied(); 
  • components/FileOutput/trunk/FileOutput/FileOutput.h

    r2298 r2301  
    6969         
    7070        std::string FileName; 
    71         short TriggerThreshold; 
    72         short NumberFiles; 
     71        unsigned short TriggerThreshold; 
     72        unsigned short NumberFiles; 
    7373        std::string FileFormat; 
    7474 
  • components/FileOutput/trunk/FileOutput/FileOutput.prf.xml

    r2296 r2301  
    66    <simple type="string" id="DCE:c2654772-ac2c-42be-8f0b-d6c7a4b0fa49" name="FileName" mode="readonly"> 
    77        <description>File Name for output data</description>  
    8         <value>myData.dat</value>  
     8        <value>myData</value>  
    99        <kind kindtype="configure"/> 
    1010    </simple>