Blame view

src/ExternLib/Spectrum/SpectrumProcess.cc 3.86 KB
b58d725b   Hacene SI HADJ MOHAND   adding plungin auto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   SpectrumProcess.cpp
 * Author: hacene
 * 
 * Created on December 31, 2020, 3:42 PM
 */


#include <stdlib.h>
#include <string>

#include <boost/lexical_cast.hpp>

#include "DicError.hh"
#include "AMDA_exception.hh"

#include "Operation.hh"
#include "ParameterManager.hh"
#include "ParamMgr.hh"
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
26
27
28
#include "ParamTable.hh"
#include "ParamInfo.hh"
#include "ParamMgr.hh"
b58d725b   Hacene SI HADJ MOHAND   adding plungin auto
29
30
31
32
33
34
35
36
37
38
#include "ParameterCreatorFromExpression.hh"

#include "SpectrumProcess.hh"


using namespace std;
using namespace boost;
using namespace log4cxx;

namespace AMDA {
d466ae92   Hacene SI HADJ MOHAND   progress
39
    namespace Parameters {
b58d725b   Hacene SI HADJ MOHAND   adding plungin auto
40

d466ae92   Hacene SI HADJ MOHAND   progress
41
        SpectrumProcess::SpectrumProcess(Parameter &parameter) : SingleParamProcess_CRTP(parameter) {
b58d725b   Hacene SI HADJ MOHAND   adding plungin auto
42

d466ae92   Hacene SI HADJ MOHAND   progress
43
            _type = SpectrumCreator::SpectrumType::FOURIER;
f3cd5351   Hacene SI HADJ MOHAND   us ok
44
45
            _paramInfoId = parameter.getId();
            parameter.setInfoId(_paramInfoId);
d466ae92   Hacene SI HADJ MOHAND   progress
46
        }
b58d725b   Hacene SI HADJ MOHAND   adding plungin auto
47

d466ae92   Hacene SI HADJ MOHAND   progress
48
49
        SpectrumProcess::SpectrumProcess(const SpectrumProcess& pProcess, Parameter &parameter) : SingleParamProcess_CRTP(pProcess, parameter) {
            _type = SpectrumCreator::SpectrumType::FOURIER;
f3cd5351   Hacene SI HADJ MOHAND   us ok
50
51
             _paramInfoId = parameter.getId();
            parameter.setInfoId(_paramInfoId);
d466ae92   Hacene SI HADJ MOHAND   progress
52
        }
b58d725b   Hacene SI HADJ MOHAND   adding plungin auto
53

d466ae92   Hacene SI HADJ MOHAND   progress
54
55
        SpectrumProcess::~SpectrumProcess() {
        }
b58d725b   Hacene SI HADJ MOHAND   adding plungin auto
56

d466ae92   Hacene SI HADJ MOHAND   progress
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        TimeStamp SpectrumProcess::init() {


            if (_attributList.size() < 1) {
                BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSpectrum::parse require 1 attribute'")));
            }
            _windowtime = atof(_attributList[0].c_str());

            _sampling = "center";
            if (_attributList.size() > 1)
                _sampling = _attributList[1];

            /*****/


            TimeStamp time = _parameterInput->init(this, _timeIntervalList);

            _paramInput = _parameterInput->getParamData(this).get();

66bd97e1   Hacene SI HADJ MOHAND   ok for test
76
77
78

            /**  in case we need to sample 
             ParameterSPtr sampledParamInput = _parameterInput->getParameterManager().getSampledParameter(_parameterInput->getId(), "classic", _parameterInput->getGapThreshold(), false);
d466ae92   Hacene SI HADJ MOHAND   progress
79
                
66bd97e1   Hacene SI HADJ MOHAND   ok for test
80
             sampledParamInput->openConnection(this);
d466ae92   Hacene SI HADJ MOHAND   progress
81
                
66bd97e1   Hacene SI HADJ MOHAND   ok for test
82
             time = sampledParamInput->init(this, _timeIntervalList);
d466ae92   Hacene SI HADJ MOHAND   progress
83
                
66bd97e1   Hacene SI HADJ MOHAND   ok for test
84
             ParamData* sampledParamData = sampledParamInput->getParamData(this).get();
d466ae92   Hacene SI HADJ MOHAND   progress
85
                
66bd97e1   Hacene SI HADJ MOHAND   ok for test
86
87
88
             SpectrumCreator lCreator(*this, _timeIntervalList, *sampledParamData, _type, _windowtime, _sampling);
             _operation = lCreator.getOperation();
             */
d466ae92   Hacene SI HADJ MOHAND   progress
89

66bd97e1   Hacene SI HADJ MOHAND   ok for test
90
91
            SpectrumCreator lCreator(*this, _timeIntervalList, *_paramInput, _type, _windowtime, _sampling);
            _operation = lCreator.getOperation();
d466ae92   Hacene SI HADJ MOHAND   progress
92
93
94

            _paramData = ParamDataSPtr(_operation->getParamOutput());

d466ae92   Hacene SI HADJ MOHAND   progress
95
            _paramData->setMinSampling(_paramInput->getMinSampling());
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
96
97
98
99
100

           
            int size_ = std::ceil(_windowtime/_paramInput->getMinSampling()) +1;
             std::vector<double> frequencies(size_); 
             for(int i =0; i<size_; i++ )
f3cd5351   Hacene SI HADJ MOHAND   us ok
101
                        frequencies[i] = (double) 1./_paramInput->getMinSampling()/(double) (i+1);
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
102

f3cd5351   Hacene SI HADJ MOHAND   us ok
103
            AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(_paramInfoId);
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
104
105

            boost::shared_ptr<AMDA::Info::ParamTable> table(new AMDA::Info::EmbeddedCenterTable(
91edc9c0   Benjamin Renard   Add process to tr...
106
                    _paramInfoId.c_str(), 0, frequencies,  false));
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
107

f3cd5351   Hacene SI HADJ MOHAND   us ok
108
            table->addTableParam(AMDA::Info::EmbeddedCenterTable::_paramKey,  _paramInfoId );
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
109
110
111
112
113
            table->setName("Frequencies");
            table->setUnits("Hz");
            table->setIsVariable(false);
            table->setIsFullVariable(false);

f3cd5351   Hacene SI HADJ MOHAND   us ok
114
            paramInfo->addTable(0, table);
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
115

d466ae92   Hacene SI HADJ MOHAND   progress
116
117
118
119
            return time;
        }

    }
b58d725b   Hacene SI HADJ MOHAND   adding plungin auto
120
}