30 #ifndef _LibUtil_Sensor_hpp_
31 #define _LibUtil_Sensor_hpp_
49 #define CONSTRUCTOR_SPECIFICATION(OPT1, OPT2, OPT3, OPT4, OPT5) \
50 template <typename A, typename T, class R> \
52 Sensor::new_object(OPT1 A &r, OPT2 T OPT3 (R::*f)() OPT4, OPT5 label) \
54 std::function<T ()> bf(std::bind(f, std::ref(r))); \
55 Sensor::instanciate(bf, label); \
98 void write(std::ostream&);
102 static std::set<ArraySensor*>
_all;
121 static void open_file_out(
const std::string & file_name,
bool force =
false);
137 template <
typename A,
typename T,
class R>
static void new_object( A & r, T (R::*f)(),
const std::string & label);
138 template <
typename A,
typename T,
class R>
static void new_object(
const A & r, T (R::*f)()
const,
const std::string & label);
139 template <
typename A,
typename T,
class R>
static void new_object( A &r,
const T (R::*f)(),
const std::string& label);
140 template <
typename A,
typename T,
class R>
static void new_object(
const A &r,
const T (R::*f)()
const,
const std::string& label);
143 template <
typename A,
typename T,
class R>
static void new_object( A & r, T (R::*f)(),
const std::vector<std::string>&labelVector);
144 template <
typename A,
typename T,
class R>
static void new_object(
const A & r, T (R::*f)()
const,
const std::vector<std::string>&labelVector);
145 template <
typename A,
typename T,
class R>
static void new_object( A &r,
const T (R::*f)(),
const std::vector<std::string>& labelVector);
146 template <
typename A,
typename T,
class R>
static void new_object(
const A &r,
const T (R::*f)()
const,
const std::vector<std::string>& labelVector);
148 template <
typename T>
static void new_object(
const T (*f)(),
const std::string& label);
149 template <
typename T>
static void new_object(T (*f)(),
const std::string& label);
150 template <
typename T>
static void new_object(
const T& (*f)(),
const std::string& label);
151 template <
typename T>
static void new_object(T& (*f)(),
const std::string& label);
153 template <
typename T>
static void new_object(std::function<T ()> f,
const std::string& label);
155 template <
typename T>
static void instanciate(std::function<T ()>& f,
const std::string& label);
156 template <
typename T>
static void instanciate(std::function<T ()>& f,
const std::vector<std::string>& labelVector);
181 SensorT(std::function<T ()>&,
const std::string & label = std::string(
""));
192 std::function<T ()>
_f;
196 template<
class T,
class R>
201 TSensor(
const T &
t,
const R (T::*f)()
const,
const std::string & label = std::string(
""));
219 const R (T::*
_f)()
const;
236 Sensor::val_from_std_vector(std::function<std::vector<
double>()>& f, std::
size_t index) {
237 std::vector<double> vec = f();
238 return vec.at(index);
241 template <
typename T>
244 std::function<T ()> bf(f);
248 template <
typename T>
251 std::function<T ()> bf(f);
255 template <
typename T>
258 std::function<T ()> bf(f);
262 template <
typename T>
265 std::function<T ()> bf(f);
269 template <
typename T>
278 Sensor::instanciate<Geom::Vector >(std::function<
Geom::Vector ()>& f,
const std::string& label) {
279 const std::string label_x = label +
"_X";
280 const std::string label_y = label +
"_Y";
281 const std::string label_z = label +
"_Z";
286 std::function<double ()> bf_x = std::bind(FctX, std::bind(f));
287 std::function<double ()> bf_y = std::bind(FctY, std::bind(f));
288 std::function<double ()> bf_z = std::bind(FctZ, std::bind(f));
298 Sensor::instanciate<Geom::Vector& >(std::function<
Geom::Vector& ()>& f,
const std::string& label) {
299 const std::string label_x = label +
"_X";
300 const std::string label_y = label +
"_Y";
301 const std::string label_z = label +
"_Z";
306 std::function<double ()> bf_x = std::bind(FctX, std::bind(f));
307 std::function<double ()> bf_y = std::bind(FctY, std::bind(f));
308 std::function<double ()> bf_z = std::bind(FctZ, std::bind(f));
318 Sensor::instanciate<const Geom::Vector& >(std::function<
const Geom::Vector& ()>& f,
const std::string& label) {
319 const std::string label_x = label +
"_X";
320 const std::string label_y = label +
"_Y";
321 const std::string label_z = label +
"_Z";
326 std::function<double ()> bf_x = std::bind(FctX, std::bind(f));
327 std::function<double ()> bf_y = std::bind(FctY, std::bind(f));
328 std::function<double ()> bf_z = std::bind(FctZ, std::bind(f));
338 Sensor::instanciate<Geom::Quaternion >(std::function<
Geom::Quaternion ()>& f,
const std::string& label) {
339 const std::string label_x = label +
"_X";
340 const std::string label_y = label +
"_Y";
341 const std::string label_z = label +
"_Z";
342 const std::string label_r = label +
"_R";
348 std::function<double ()> bf_x = std::bind(FctX, std::bind(f));
349 std::function<double ()> bf_y = std::bind(FctY, std::bind(f));
350 std::function<double ()> bf_z = std::bind(FctZ, std::bind(f));
351 std::function<double ()> bf_r = std::bind(FctR, std::bind(f));
362 Sensor::instanciate<Geom::Quaternion& >(std::function<
Geom::Quaternion& ()>& f,
const std::string& label) {
363 const std::string label_x = label +
"_X";
364 const std::string label_y = label +
"_Y";
365 const std::string label_z = label +
"_Z";
366 const std::string label_r = label +
"_R";
372 std::function<double ()> bf_x = std::bind(FctX, std::bind(f));
373 std::function<double ()> bf_y = std::bind(FctY, std::bind(f));
374 std::function<double ()> bf_z = std::bind(FctZ, std::bind(f));
375 std::function<double ()> bf_r = std::bind(FctR, std::bind(f));
386 Sensor::instanciate<const Geom::Quaternion& >(std::function<
const Geom::Quaternion& ()>& f,
const std::string& label) {
387 const std::string label_x = label +
"_X";
388 const std::string label_y = label +
"_Y";
389 const std::string label_z = label +
"_Z";
390 const std::string label_r = label +
"_R";
396 std::function<double ()> bf_x = std::bind(FctX, std::bind(f));
397 std::function<double ()> bf_y = std::bind(FctY, std::bind(f));
398 std::function<double ()> bf_z = std::bind(FctZ, std::bind(f));
399 std::function<double ()> bf_r = std::bind(FctR, std::bind(f));
410 Sensor::instanciate<Geom::Tensor >(std::function<
Geom::Tensor ()>& f,
const std::string& label) {
411 const std::string label_xx = label +
"_XX";
412 const std::string label_yy = label +
"_YY";
413 const std::string label_zz = label +
"_ZZ";
415 const std::string label_xy = label +
"_XY";
416 const std::string label_yx = label +
"_YX";
418 const std::string label_xz = label +
"_XZ";
419 const std::string label_zx = label +
"_ZX";
421 const std::string label_yz = label +
"_YZ";
422 const std::string label_zy = label +
"_ZY";
440 std::function<double ()> bf_xx = std::bind(FctXX, std::bind(f));
441 std::function<double ()> bf_yy = std::bind(FctYY, std::bind(f));
442 std::function<double ()> bf_zz = std::bind(FctZZ, std::bind(f));
444 std::function<double ()> bf_xy = std::bind(FctXY, std::bind(f));
445 std::function<double ()> bf_yx = std::bind(FctYX, std::bind(f));
447 std::function<double ()> bf_xz = std::bind(FctXZ, std::bind(f));
448 std::function<double ()> bf_zx = std::bind(FctZX, std::bind(f));
450 std::function<double ()> bf_yz = std::bind(FctYZ, std::bind(f));
451 std::function<double ()> bf_zy = std::bind(FctZY, std::bind(f));
471 Sensor::instanciate<Geom::Tensor& >(std::function<
Geom::Tensor& ()>& f,
const std::string& label) {
472 const std::string label_xx = label +
"_XX";
473 const std::string label_yy = label +
"_YY";
474 const std::string label_zz = label +
"_ZZ";
476 const std::string label_xy = label +
"_XY";
477 const std::string label_yx = label +
"_YX";
479 const std::string label_xz = label +
"_XZ";
480 const std::string label_zx = label +
"_ZX";
482 const std::string label_yz = label +
"_YZ";
483 const std::string label_zy = label +
"_ZY";
501 std::function<double ()> bf_xx = std::bind(FctXX, std::bind(f));
502 std::function<double ()> bf_yy = std::bind(FctYY, std::bind(f));
503 std::function<double ()> bf_zz = std::bind(FctZZ, std::bind(f));
505 std::function<double ()> bf_xy = std::bind(FctXY, std::bind(f));
506 std::function<double ()> bf_yx = std::bind(FctYX, std::bind(f));
508 std::function<double ()> bf_xz = std::bind(FctXZ, std::bind(f));
509 std::function<double ()> bf_zx = std::bind(FctZX, std::bind(f));
511 std::function<double ()> bf_yz = std::bind(FctYZ, std::bind(f));
512 std::function<double ()> bf_zy = std::bind(FctZY, std::bind(f));
532 Sensor::instanciate<const Geom::Tensor& >(std::function<
const Geom::Tensor& ()>& f,
const std::string& label) {
533 const std::string label_xx = label +
"_XX";
534 const std::string label_yy = label +
"_YY";
535 const std::string label_zz = label +
"_ZZ";
537 const std::string label_xy = label +
"_XY";
538 const std::string label_yx = label +
"_YX";
540 const std::string label_xz = label +
"_XZ";
541 const std::string label_zx = label +
"_ZX";
543 const std::string label_yz = label +
"_YZ";
544 const std::string label_zy = label +
"_ZY";
562 std::function<double ()> bf_xx = std::bind(FctXX, std::bind(f));
563 std::function<double ()> bf_yy = std::bind(FctYY, std::bind(f));
564 std::function<double ()> bf_zz = std::bind(FctZZ, std::bind(f));
566 std::function<double ()> bf_xy = std::bind(FctXY, std::bind(f));
567 std::function<double ()> bf_yx = std::bind(FctYX, std::bind(f));
569 std::function<double ()> bf_xz = std::bind(FctXZ, std::bind(f));
570 std::function<double ()> bf_zx = std::bind(FctZX, std::bind(f));
572 std::function<double ()> bf_yz = std::bind(FctYZ, std::bind(f));
573 std::function<double ()> bf_zy = std::bind(FctZY, std::bind(f));
592 Sensor::instanciate<Geom::SymTensor >(std::function<
Geom::SymTensor ()>& f,
const std::string& label) {
593 const std::string label_xx = label +
"_XX";
594 const std::string label_yy = label +
"_YY";
595 const std::string label_zz = label +
"_ZZ";
597 const std::string label_xy = label +
"_XY";
598 const std::string label_yx = label +
"_YX";
600 const std::string label_xz = label +
"_XZ";
601 const std::string label_zx = label +
"_ZX";
603 const std::string label_yz = label +
"_YZ";
604 const std::string label_zy = label +
"_ZY";
622 std::function<double ()> bf_xx = std::bind(FctXX, std::bind(f));
623 std::function<double ()> bf_yy = std::bind(FctYY, std::bind(f));
624 std::function<double ()> bf_zz = std::bind(FctZZ, std::bind(f));
626 std::function<double ()> bf_xy = std::bind(FctXY, std::bind(f));
627 std::function<double ()> bf_yx = std::bind(FctYX, std::bind(f));
629 std::function<double ()> bf_xz = std::bind(FctXZ, std::bind(f));
630 std::function<double ()> bf_zx = std::bind(FctZX, std::bind(f));
632 std::function<double ()> bf_yz = std::bind(FctYZ, std::bind(f));
633 std::function<double ()> bf_zy = std::bind(FctZY, std::bind(f));
653 Sensor::instanciate<Geom::SymTensor& >(std::function<
Geom::SymTensor& ()>& f,
const std::string& label) {
654 const std::string label_xx = label +
"_XX";
655 const std::string label_yy = label +
"_YY";
656 const std::string label_zz = label +
"_ZZ";
658 const std::string label_xy = label +
"_XY";
659 const std::string label_yx = label +
"_YX";
661 const std::string label_xz = label +
"_XZ";
662 const std::string label_zx = label +
"_ZX";
664 const std::string label_yz = label +
"_YZ";
665 const std::string label_zy = label +
"_ZY";
683 std::function<double ()> bf_xx = std::bind(FctXX, std::bind(f));
684 std::function<double ()> bf_yy = std::bind(FctYY, std::bind(f));
685 std::function<double ()> bf_zz = std::bind(FctZZ, std::bind(f));
687 std::function<double ()> bf_xy = std::bind(FctXY, std::bind(f));
688 std::function<double ()> bf_yx = std::bind(FctYX, std::bind(f));
690 std::function<double ()> bf_xz = std::bind(FctXZ, std::bind(f));
691 std::function<double ()> bf_zx = std::bind(FctZX, std::bind(f));
693 std::function<double ()> bf_yz = std::bind(FctYZ, std::bind(f));
694 std::function<double ()> bf_zy = std::bind(FctZY, std::bind(f));
714 Sensor::instanciate<const Geom::SymTensor& >(std::function<
const Geom::SymTensor& ()>& f,
const std::string& label) {
715 const std::string label_xx = label +
"_XX";
716 const std::string label_yy = label +
"_YY";
717 const std::string label_zz = label +
"_ZZ";
719 const std::string label_xy = label +
"_XY";
720 const std::string label_yx = label +
"_YX";
722 const std::string label_xz = label +
"_XZ";
723 const std::string label_zx = label +
"_ZX";
725 const std::string label_yz = label +
"_YZ";
726 const std::string label_zy = label +
"_ZY";
744 std::function<double ()> bf_xx = std::bind(FctXX, std::bind(f));
745 std::function<double ()> bf_yy = std::bind(FctYY, std::bind(f));
746 std::function<double ()> bf_zz = std::bind(FctZZ, std::bind(f));
748 std::function<double ()> bf_xy = std::bind(FctXY, std::bind(f));
749 std::function<double ()> bf_yx = std::bind(FctYX, std::bind(f));
751 std::function<double ()> bf_xz = std::bind(FctXZ, std::bind(f));
752 std::function<double ()> bf_zx = std::bind(FctZX, std::bind(f));
754 std::function<double ()> bf_yz = std::bind(FctYZ, std::bind(f));
755 std::function<double ()> bf_zy = std::bind(FctZY, std::bind(f));
774 Sensor::instanciate<const Math::Stat&>(std::function<
const Math::Stat&()>& f,
const std::string& label) {
775 const std::string label_Ave = label +
"_Ave";
776 const std::string label_Std = label +
"_Std";
777 const std::string label_Min = label +
"_Min";
778 const std::string label_Max = label +
"_Max";
780 const double& (
Math::Stat::*Fct_Ave)()
const = &Math::Stat::average;
781 const double& (
Math::Stat::*Fct_Std)()
const = &Math::Stat::std;
784 std::function<double ()> bf_Ave = std::bind(Fct_Ave, std::bind(f));
785 std::function<double ()> bf_Std = std::bind(Fct_Std, std::bind(f));
786 std::function<double ()> bf_Max = std::bind(Fct_Max, std::bind(f));
787 std::function<double ()> bf_Min = std::bind(Fct_Min, std::bind(f));
798 Sensor::instanciate<std::vector<double > >(std::function< std::vector<double > ()>& f,
const std::vector<std::string>& labelVector) {
799 for (
unsigned int i = 0; i!=labelVector.size(); i++) {
816 :
Sensor(), _label(label), _rank(add(this)), _f(f) {
822 UserAssert(is_file_out_open(),
"can't open sensor file");
826 template<
typename T,
class R>
828 :
Sensor(), _label(label), _t(
t),_f(f), _rank(add(this)) {
831 template<
typename T,
class R>
834 UserAssert(is_file_out_open(),
"can't open sensor file");
835 _fout << (_t.*_f)()<<
"\t";
#define UserAssert(condition, message)
Definition: Macro.hpp:54
Definition: Sensor.hpp:93
~ArraySensor()
Definition: Sensor.cpp:51
static std::set< ArraySensor * > _all
Definition: Sensor.hpp:102
void write(std::ostream &)
Definition: Sensor.cpp:56
Math::Stat & _data
Definition: Sensor.hpp:107
const std::string _label
Definition: Sensor.hpp:106
static std::set< ArraySensor * > get_all()
Definition: Sensor.hpp:99
ArraySensor(Math::Stat &, const std::string &label)
Definition: Sensor.cpp:46
Definition: Sensor.hpp:112
static void new_object(const A &r, T(R::*f)() const, const std::string &label)
static void close_file_out()
Definition: Sensor.cpp:94
static void new_object(A &r, T(R::*f)(), const std::string &label)
static void flush_file_out()
Definition: Sensor.cpp:108
static void new_object(A &r, const T(R::*f)(), const std::vector< std::string > &labelVector)
virtual ~Sensor()
Definition: Sensor.cpp:90
static std::string _file_name
Definition: Sensor.hpp:168
static bool is_file_out_open()
Definition: Sensor.cpp:103
static double val_from_std_vector(std::function< std::vector< double >()> &f, std::size_t)
Definition: Sensor.hpp:236
static int _rank
Definition: Sensor.hpp:169
static std::vector< Sensor * > _sensor_table
Definition: Sensor.hpp:167
static void acquire_all_sensor_and_write()
Definition: Sensor.cpp:148
static std::ofstream & get_output_stream()
Definition: Sensor.hpp:129
static void new_object(const A &r, const T(R::*f)() const, const std::vector< std::string > &labelVector)
static void new_object(A &r, T(R::*f)(), const std::vector< std::string > &labelVector)
static void new_object(A &r, const T(R::*f)(), const std::string &label)
static void new_object(const A &r, const T(R::*f)() const, const std::string &label)
static void instanciate(std::function< T()> &f, const std::vector< std::string > &labelVector)
static void instanciate(std::function< T()> &f, const std::string &label)
Definition: Sensor.hpp:809
static void desactivate(Sensor *s)
Definition: Sensor.hpp:160
virtual const std::string & get_label() const =0
static void write_header()
Definition: Sensor.cpp:125
static bool _header_column_shape
Definition: Sensor.hpp:171
static std::ofstream _fout
Definition: Sensor.hpp:164
static std::string get_file_name()
Definition: Sensor.hpp:131
static void set_header_column_shape(const bool isColumn)
Definition: Sensor.cpp:120
virtual void acquire_and_write()=0
static bool _header_written
Definition: Sensor.hpp:170
virtual int get_rank() const =0
static void reset()
Definition: Sensor.cpp:64
static void open_file_out(const std::string &file_name, bool force=false)
Definition: Sensor.cpp:75
Sensor()
Definition: Sensor.cpp:87
static void write_data_in_file_out(const std::string &)
Definition: Sensor.cpp:115
static int add(Sensor *s)
Definition: Sensor.hpp:159
static void new_object(const A &r, T(R::*f)() const, const std::vector< std::string > &labelVector)
Definition: Sensor.hpp:179
std::function< T()> _f
Definition: Sensor.hpp:192
~SensorT()
Definition: Sensor.hpp:182
const std::string & get_label() const
Definition: Sensor.hpp:186
int get_rank() const
Definition: Sensor.hpp:185
void acquire_and_write()
Definition: Sensor.hpp:821
const std::string _label
Definition: Sensor.hpp:186
SensorT(std::function< T()> &, const std::string &label=std::string(""))
Definition: Sensor.hpp:815
const int _rank
Definition: Sensor.hpp:191
Definition: Sensor.hpp:198
const std::string _label
Definition: Sensor.hpp:212
const R(T::* _f)() const
Definition: Sensor.hpp:219
TSensor(const T &t, const R(T::*f)() const, const std::string &label=std::string(""))
Definition: Sensor.hpp:827
const int _rank
Definition: Sensor.hpp:220
~TSensor()
Definition: Sensor.hpp:202
const T & _t
Definition: Sensor.hpp:218
int get_rank() const
Definition: Sensor.hpp:207
void acquire_and_write()
Definition: Sensor.hpp:833
const std::string & get_label() const
Definition: Sensor.hpp:210
Definition: Quaternion.hpp:54
Definition: SymTensor.hpp:68
Definition: Tensor.hpp:62
Definition: Vector.hpp:75
const
Definition: Sensor.hpp:225
CONSTRUCTOR_SPECIFICATION(,,,, const std::string &) CONSTRUCTOR_SPECIFICATION(const
Definition: Common.hpp:198
T min(const T v0, const T v1)
Definition: Exprtk.hpp:1456
T max(const T v0, const T v1)
Definition: Exprtk.hpp:1463
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t t(t+t)") define_sfop3(16