Blame view

src/ExternLib/GetMavenStaticEnergy/GetMavenStaticEnergy.hh 3.86 KB
f2db3c16   Benjamin Renard   Support variable ...
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * GetMavenStaticEnergy.hh
 *
 *  Created on: Sep 23, 2015
 *      Author: AKKA
 */

#ifndef GetMavenStaticEnergy_HH_
#define GetMavenStaticEnergy_HH_

#include "vector"

#include <boost/algorithm/string.hpp>
1c0193a5   Benjamin Renard   Implement variabl...
14
#include <boost/lexical_cast.hpp>
f2db3c16   Benjamin Renard   Support variable ...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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

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

#include "Parameter.hh"
#include "ParamData.hh"
#include "Operation.hh"

using namespace std;
using namespace boost;
using namespace AMDA::Parameters;

namespace AMDA {
namespace MavenStatic {

namespace Base {
/**
 * @class Base::GetMavenStaticEnergy
 * @brief Compute Maven STATIC energy
 */
		class GetMavenStaticEnergy : public Operation {
		public:

			/**
			 * @brief Default Constructor.
			 */
			GetMavenStaticEnergy(Process& pProcess) : Operation(pProcess) {}

			/**
			 * @brief Destructor.
			 */
			virtual ~GetMavenStaticEnergy() {}

			/**
			 * @brief initialize the operation .
			 * @detail initialize the operation with information stored in pInput.getInfoList() and pAttribute.
			 */
			virtual void init(Parameter& input, Process::AttributeList& pAttribute)	= 0;

		protected:
		};
	}


/**
 * @class GetMavenStaticEnergy
 * @brief Compute Maven STATIC energy.
 */
template<class TParamData>
class GetMavenStaticEnergy : public Base::GetMavenStaticEnergy {
public:
	/**
	 * @brief Constructor.
	 * @details Create the ParamData type of the input ParamData.
	 */
	GetMavenStaticEnergy(Process& pProcess, TParamData& paramInput)
	: Base::GetMavenStaticEnergy(pProcess), _paramInput(paramInput), _paramOutput(new ParamDataTab1DDouble()) {
	  _paramDataOutput=_paramOutput;
	  }

  /**
   *
	 * @overload Base::GetMavenStaticEnergy::init()
   */
1c0193a5   Benjamin Renard   Implement variabl...
79
  void init(Parameter& pInput, Process::AttributeList& pAttribute) {
f2db3c16   Benjamin Renard   Support variable ...
80
81
82
83
84
	  Parameter::InfoList& lInfoList = pInput.getInfoList();

	  int nbMass   = (*lInfoList["nmass"].get())[0];
	  int nbSweep  = (*lInfoList["nswp"].get())[0];
	  int nbEnergy = (*lInfoList["nenergy"].get())[0];
fbf68003   Elena.Budnik   maven static corr...
85
86
	  
	  int fixedIndex = 0;
1c0193a5   Benjamin Renard   Implement variabl...
87
	  try {
fbf68003   Elena.Budnik   maven static corr...
88
		  fixedIndex = boost::lexical_cast<int>( pAttribute[0] );
1c0193a5   Benjamin Renard   Implement variabl...
89
	  } catch( boost::bad_lexical_cast const& ) {
fbf68003   Elena.Budnik   maven static corr...
90
91
92
93
94
95
96
97
		  fixedIndex = 0;
	  }
	  
          bool isMass = false;
	  try {
		  isMass = boost::lexical_cast<bool>( pAttribute[1] );
	  } catch( boost::bad_lexical_cast const& ) {
		  isMass = false;
1c0193a5   Benjamin Renard   Implement variabl...
98
99
	  }

fbf68003   Elena.Budnik   maven static corr...
100
          for (int i = 0; i < nbSweep; ++i)
f2db3c16   Benjamin Renard   Support variable ...
101
	  {
fbf68003   Elena.Budnik   maven static corr...
102
103
104
105
106
107
108
109
110
111
112
		  if (isMass) {
			for (int k = 0; k < nbMass; ++k)
			{
                          std::string infoKey = "mass_arr_";
                          infoKey += std::to_string(k * nbEnergy + fixedIndex);
                          _energyList[i].push_back((*lInfoList[infoKey].get())[i]);
			}
                  }
		  else {
		  	for (int k = 0; k < nbEnergy; ++k)
		  	{
1c0193a5   Benjamin Renard   Implement variabl...
113
			  std::string infoKey = "energy_";
fbf68003   Elena.Budnik   maven static corr...
114
			  infoKey += std::to_string(fixedIndex * nbEnergy + k);
1c0193a5   Benjamin Renard   Implement variabl...
115
			  _energyList[i].push_back((*lInfoList[infoKey].get())[i]);
fbf68003   Elena.Budnik   maven static corr...
116
		  	}
f2db3c16   Benjamin Renard   Support variable ...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
		  }
	  }
  }

  /**
	 * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
	 */
  void  write(ParamDataIndexInfo &pParamDataIndexInfo) {
    unsigned int index = pParamDataIndexInfo._startIndex;
    for (; index< pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; index++) {
    	_paramOutput->pushTime(_paramInput.getTime(index));
    	_paramOutput->getDataList().push_back((_energyList[(int)floor(_paramInput.getDataList()[index])]));
    }
  }

private:
	/**
	 * @brief It is the channel of calibration.
	 */
  TParamData &_paramInput;

	/**
	 * @brief It is the channel of the data shifted.
	 */
  ParamDataTab1DDouble *_paramOutput;


	/**
	 * @brief map of calibrationInfo.
	 * @detail for expression #getClbInfo($ETableN;0:ImaEner_0;1:ImaEner_1)
	 * the key of map is 0 respectively  1
	 * the value of map is  the value of attributes  ImaEner[0] respectively and ImaEner[0]
	 */
  std::map<unsigned int , std::vector<double>> _energyList;
};

} /* namespace MavenStatic */
} /* namespace AMDA */
#endif /* GetMavenStaticEnergy_HH_ */