1 #if ( _MSC_VER && _MSC_VER <= 1200 )
2 // Ce pragma ne devrait pas etre dans ce fichier car le warning ne s'affiche
3 // que si l'on compile une version DEBUG de la librairie.
4 // Il faut utiliser l'option de compilation \wd4786 mais elle n'est presente
5 // qu'à partir de VC++7
6 # pragma warning (disable : 4786)
11 #include <hkl/hkl-pseudoaxis.h>
14 #include "TangoHKLAdapter.h"
15 #include "Diffractometer.h"
16 #include "PseudoAxes.h"
17 #include "AxisAdapter.h"
18 #include "AxisAttrib.h"
19 #include "PseudoAxesAttrib.h"
23 # define STDOUT(stream) std::cout << stream
25 # define STDOUT(stream) {};
28 namespace Diffractometer_ns
30 //+----------------------------------------------------------------------------
32 // method : TangoHKLAdapter::TangoHKLAdapter(string &s)
34 // description : constructor for the adapter between HKl library and Tango
36 // in : - type : Type of diffractometer to instancate
38 //-----------------------------------------------------------------------------
39 TangoHKLAdapter::TangoHKLAdapter(Diffractometer
*device
, HklGeometryType type
) :
50 _auto_update_from_proxies
= false;
51 _lambdaAttributeProxy
= NULL
;
52 _wrong_nb_of_axis_proxies
= false;
63 // Create the hkl part
65 _diffractometer
= new HklDiffractometer
;
66 _diffractometer
->geometry_r
= hkl_geometry_factory_new(type
, 50 * HKL_DEGTORAD
);
67 _diffractometer
->geometry_w
= hkl_geometry_factory_new(type
, 50 * HKL_DEGTORAD
);
68 _diffractometer
->geometry_r_real
= hkl_geometry_factory_new(type
, 50 * HKL_DEGTORAD
);
69 _diffractometer
->geometry_w_real
= hkl_geometry_factory_new(type
, 50 * HKL_DEGTORAD
);
72 _diffractometer
->detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
73 _diffractometer
->detector
->idx
= 1;
75 _diffractometer
->detector_real
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
76 _diffractometer
->detector_real
->idx
= 1;
79 _diffractometer
->samples
= hkl_sample_list_new();
81 // the pseudoAxesenginesList (one per geometry)
82 _diffractometer
->engines_r
= hkl_pseudo_axis_engine_list_factory(type
);
83 _diffractometer
->engines_w
= hkl_pseudo_axis_engine_list_factory(type
);
84 _diffractometer
->engines_r_real
= hkl_pseudo_axis_engine_list_factory(type
);
85 _diffractometer
->engines_w_real
= hkl_pseudo_axis_engine_list_factory(type
);
86 this->update_pseudo_axis_engines();
89 Tango::GroupReply::enable_exception(true);
91 // fill the axisAdapter.
92 len
= HKL_LIST_LEN(_diffractometer
->geometry_r
->axes
);
93 axes_r
= _diffractometer
->geometry_r
->axes
;
94 axes_w
= _diffractometer
->geometry_w
->axes
;
95 axes_r_real
= _diffractometer
->geometry_r_real
->axes
;
96 axes_w_real
= _diffractometer
->geometry_w_real
->axes
;
98 _axes
.push_back(AxisAdapter(this, &axes_r
[i
], &axes_w
[i
], &axes_r_real
[i
], &axes_w_real
[i
]));
100 // hack to connect all axes the first time
101 _auto_update_from_proxies
= true;
102 this->connect_all_proxies();
103 _auto_update_from_proxies
= false;
105 // fill the pseudoAxesAdapters
107 omni_mutex_lock
lock(_lock
);
109 len
= HKL_LIST_LEN(_diffractometer
->engines_r
->engines
);
110 _pseudo_axes_proxies
.resize(len
, 1);
111 for(i
=0; i
<len
; ++i
){
112 PseudoAxesAdapter
*adapter
;
114 adapter
= new PseudoAxesAdapter(this, i
);
115 _pseudoAxesAdapters
.push_back(adapter
);
116 _pseudo_axes_proxies
.data
[i
] = const_cast<char *>(adapter
->_proxy_name
.c_str());
120 // create the dynamic attributes
121 this->create_axes_dynamic_attributes();
123 // set the default lambda
124 this->set_lambda(1.54);
127 TangoHKLAdapter::~TangoHKLAdapter(void)
131 this->destroy_axes_dynamic_attributes();
133 // remove all pseudo axis adapters
134 for(i
=0;i
<_pseudoAxisAdapters
.size();i
++)
135 delete _pseudoAxisAdapters
[i
];
137 // remove all pseudo axes adapters;
138 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
139 delete _pseudoAxesAdapters
[i
];
141 // remove all axisAdapter
144 if (_lambdaAttributeProxy
)
145 delete _lambdaAttributeProxy
;
147 // remove the hkl part
148 hkl_geometry_free(_diffractometer
->geometry_r
);
149 hkl_geometry_free(_diffractometer
->geometry_w
);
150 hkl_geometry_free(_diffractometer
->geometry_r_real
);
151 hkl_geometry_free(_diffractometer
->geometry_w_real
);
152 hkl_detector_free(_diffractometer
->detector
);
153 hkl_detector_free(_diffractometer
->detector_real
);
154 hkl_sample_list_free(_diffractometer
->samples
);
155 hkl_pseudo_axis_engine_list_free(_diffractometer
->engines_r
);
156 hkl_pseudo_axis_engine_list_free(_diffractometer
->engines_w
);
157 hkl_pseudo_axis_engine_list_free(_diffractometer
->engines_r_real
);
158 hkl_pseudo_axis_engine_list_free(_diffractometer
->engines_w_real
);
160 if(_diffractometer
) {
161 delete _diffractometer
;
162 _diffractometer
= NULL
;
166 void TangoHKLAdapter::connect_all_proxies(void)
168 omni_mutex_lock
lock(_lock
);
170 // connect the lambda proxy
171 if ((!_lambdaAttributeProxy
&& _auto_update_from_proxies
)
172 && _device
->lambdaAttributeProxy
!= "") {
175 _lambdaAttributeProxy
= new Tango::AttributeProxy(_device
->lambdaAttributeProxy
);
181 // connect the axes proxies
182 if (!this->ready
&& _auto_update_from_proxies
) {
185 nb
= _device
->realAxisProxies
.size();
186 if (nb
!= _axes
.size()) {
187 _wrong_nb_of_axis_proxies
= true;
193 for(i
=0; i
<nb
; ++i
) {
194 AxisAdapter
& axis
= _axes
[i
];
195 if (!axis
.is_ready()){
196 // Find axis in the proxy list
197 for(j
=0; j
<nb
; ++j
) {
198 char *line
= strdup(_device
->realAxisProxies
[j
].c_str());
200 char *axis_name
= strtok_r(line
, ":", &last
);
201 char *proxy_name
= strtok_r(NULL
, ":", &last
);
202 if (axis
.get_name() == axis_name
)
203 axis
.connect(proxy_name
);
206 if (!axis
.is_ready())
215 void TangoHKLAdapter::set_lambda(double lambda
)
217 omni_mutex_lock
lock(_lock
);
219 if ((!_auto_update_from_proxies
|| _device
->lambdaAttributeProxy
== "")
222 _diffractometer
->geometry_r
->source
.wave_length
= lambda
;
223 _diffractometer
->geometry_w
->source
.wave_length
= lambda
;
224 _diffractometer
->geometry_r_real
->source
.wave_length
= lambda
;
225 _diffractometer
->geometry_w_real
->source
.wave_length
= lambda
;
229 // this method connect engines to the right geometry, detector and sample
230 void TangoHKLAdapter::update_pseudo_axis_engines(void)
232 hkl_pseudo_axis_engine_list_init(_diffractometer
->engines_r
,
233 _diffractometer
->geometry_r
,
234 _diffractometer
->detector
,
235 _diffractometer
->samples
->current
);
237 hkl_pseudo_axis_engine_list_init(_diffractometer
->engines_w
,
238 _diffractometer
->geometry_w
,
239 _diffractometer
->detector
,
240 _diffractometer
->samples
->current
);
242 hkl_pseudo_axis_engine_list_init(_diffractometer
->engines_r_real
,
243 _diffractometer
->geometry_r_real
,
244 _diffractometer
->detector
,
245 _diffractometer
->samples
->current
);
247 hkl_pseudo_axis_engine_list_init(_diffractometer
->engines_w_real
,
248 _diffractometer
->geometry_w_real
,
249 _diffractometer
->detector
,
250 _diffractometer
->samples
->current
);
253 void TangoHKLAdapter::update_lambda(void)
255 if (_lambdaAttributeProxy
&& _auto_update_from_proxies
){
257 _lambdaAttributeProxy
->read() >> _lambda
;
258 _diffractometer
->geometry_r
->source
.wave_length
= _lambda
;
259 _diffractometer
->geometry_w
->source
.wave_length
= _lambda
;
260 _diffractometer
->geometry_r_real
->source
.wave_length
= _lambda
;
261 _diffractometer
->geometry_w_real
->source
.wave_length
= _lambda
;
263 catch (Tango::DevFailed
&){
266 _lambda
= _diffractometer
->geometry_r
->source
.wave_length
;
270 * this method update the angles attribut from the engines->geometry list
272 void TangoHKLAdapter::update_angles(void)
277 HklPseudoAxisEngine
*engine
;
279 HklGeometry
**geometries
;
281 if(!_auto_update_from_proxies
)
282 engine
= hkl_pseudo_axis_engine_list_get_by_name(_diffractometer
->engines_w
, "hkl");
284 engine
= hkl_pseudo_axis_engine_list_get_by_name(_diffractometer
->engines_w_real
, "hkl");
286 // update the computed_angles part
287 xdim
= 1 + HKL_LIST_LEN(_diffractometer
->geometry_r
->axes
);
288 ydim
= HKL_LIST_LEN(engine
->engines
->geometries
->geometries
);
290 _angles
.resize(xdim
, ydim
);
295 geometries
= engine
->engines
->geometries
->geometries
;
296 for(j
=0; j
<ydim
; ++j
){
297 HklGeometry
*geom
= geometries
[j
];
300 for(i
=1; i
<xdim
; ++i
)
301 data
[i
] = hkl_axis_get_value_unit(&geom
->axes
[i
-1]);
307 * this method update the reflections_angles when we change a sample parameter
309 void TangoHKLAdapter::update_reflections_angles(void)
311 HklSample
*sample
= _diffractometer
->samples
->current
;
317 // the reflection Angles
318 rdim
= HKL_LIST_LEN(sample
->reflections
);
319 _reflections_angles
.resize(rdim
, rdim
);
320 _reflections_angles
.clear();
322 data
= _reflections_angles
.data
;
323 for(i
=0; i
<rdim
; ++i
) {
324 for(j
=0; j
<rdim
; ++j
) {
327 angle
= hkl_sample_get_reflection_theoretical_angle(sample
, i
, j
);
329 angle
= hkl_sample_get_reflection_mesured_angle(sample
, i
, j
);
331 *data
= angle
* HKL_RADTODEG
;
338 void TangoHKLAdapter::update_reflections(void)
340 HklSample
*sample
= _diffractometer
->samples
->current
;
343 // Allocation of the image
344 unsigned int xdim
= 6 + HKL_LIST_LEN(_diffractometer
->geometry_r
->axes
);
345 unsigned int ydim
= HKL_LIST_LEN(sample
->reflections
);
346 _reflections
.resize(xdim
, ydim
);
349 double *data
= _reflections
.data
;
350 for(i
=0; i
<ydim
; ++i
) {
351 HklSampleReflection
*r
;
353 r
= hkl_sample_get_ith_reflection(sample
, i
);
356 HklAxis
*axes
= r
->geometry
->axes
;
359 data
[1] = r
->hkl
.data
[0];
360 data
[2] = r
->hkl
.data
[1];
361 data
[3] = r
->hkl
.data
[2];
363 data
[5] = (double)r
->flag
;
365 for(k
=0; k
<HKL_LIST_LEN(r
->geometry
->axes
); ++k
)
366 data
[6 + k
] = hkl_axis_get_value_unit(&axes
[k
]);
373 void TangoHKLAdapter::update_ub(void)
375 HklSample
const *sample
= _diffractometer
->samples
->current
;
378 _ub
.resize(dim
, dim
);
379 _ub
.set_data_from_buffer(&(sample
->UB
.data
[0][0]), dim
, dim
);
383 void TangoHKLAdapter::update_ux_uy_uz(void)
385 HklSample
*sample
= _diffractometer
->samples
->current
;
388 hkl_matrix_to_euler(&sample
->U
, &_ux
, &_uy
, &_uz
);
396 * this method update all the AxisAdapter from the proxy every 200 ms.
397 * this from_proxy get the real part from the proxy and the "sim" part
398 * from the HklAxis in simulated mode or from the proxy in real mode
399 * else it updates them from the HklAxis.
410 * simulated -> HklAxis
412 void TangoHKLAdapter::update_axis_adapters(void)
416 // first read from the proxy.
418 if(duration
.GetDurationInMs() >= 200) {
419 for(size_t i
=0; i
<_axes
.size(); ++i
)
420 _axes
[i
].from_proxy(!_auto_update_from_proxies
);
423 for(i
=0; i
<_axes
.size(); ++i
)
424 _axes
[i
].from_HklAxis();
427 void TangoHKLAdapter::update_hkl_from_axis_adapters(void)
432 for(i
=0; i
<_axes
.size(); ++i
)
433 _axes
[i
].to_HklAxis();
435 // update the pseudo axes
436 if(_diffractometer
&& _diffractometer
->samples
){
437 hkl_pseudo_axis_engine_list_get(_diffractometer
->engines_r
);
438 hkl_pseudo_axis_engine_list_get(_diffractometer
->engines_w
);
439 hkl_pseudo_axis_engine_list_get(_diffractometer
->engines_r_real
);
440 hkl_pseudo_axis_engine_list_get(_diffractometer
->engines_w_real
);
444 void TangoHKLAdapter::update_pseudo_axis_adapters_from_hkl(void)
446 for(size_t i
=0;i
<_pseudoAxisAdapters
.size();++i
)
447 _pseudoAxisAdapters
[i
]->update();
450 void TangoHKLAdapter::update_proxies_from_axis_adapters(void)
454 // first stop motion of all axes.
455 for(i
=0; i
<_axes
.size(); ++i
)
458 // then send write values to the proxies
459 for(i
=0; i
<_axes
.size(); ++i
)
463 void TangoHKLAdapter::update_proxies_from_pseudo_axis_adapters(PseudoAxisAdapter
*adapter
)
465 adapter
->to_proxies();
468 void TangoHKLAdapter::update_pseudo_axes_adapters_from_hkl(void)
471 HklPseudoAxisEngine
*engine_r
, *engine_w
;
473 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
){
474 PseudoAxesAdapter
*adapter
;
476 adapter
= _pseudoAxesAdapters
[i
];
477 engine_r
= _diffractometer
->engines_r
->engines
[i
];
478 engine_w
= _diffractometer
->engines_w
->engines
[i
];
479 len
= HKL_LIST_LEN(engine_r
->pseudoAxes
);
480 for(j
=0; j
<len
; ++j
){
481 adapter
->_read
.data
[j
] = hkl_parameter_get_value_unit((HklParameter
*)engine_r
->pseudoAxes
[j
]);
482 adapter
->_write
.data
[j
] = hkl_parameter_get_value_unit((HklParameter
*)engine_w
->pseudoAxes
[j
]);
486 adapter
->update_state_and_status_i();
490 void TangoHKLAdapter::update_state_and_status(void)
492 Tango::DevState state
;
494 std::string extra_status
;
496 state
= Tango::STANDBY
;
497 if (!_auto_update_from_proxies
)
498 status
= "AutoUpdateFromProxies OFF";
500 status
= "AutoUpdateFromProxies ON";
503 state
= Tango::FAULT
;
504 extra_status
+= "\nCan not connect to axes proxies";
505 // update the monochromator proxy status.
506 if (!_lambdaAttributeProxy
&& _auto_update_from_proxies
) {
507 extra_status
+= "\nCan not connect to the lambdaAttributeProxy";
508 extra_status
+= "\nCheck also the lambdaAttributeProxy property";
512 for(unsigned int i
=0; i
<_axes
.size(); ++i
) {
513 AxisAdapter
const & axis
= _axes
[i
];
514 std::string proxy_name
= axis
.get_proxy_name();
515 Tango::DevState tmpState
= axis
.get_state();
517 ::compose_state(state
, tmpState
);
518 if (tmpState
!= Tango::STANDBY
)
519 extra_status
+= "\n" + proxy_name
+ " is in " + Tango::DevStateName
[tmpState
];
523 state
= Tango::FAULT
;
524 extra_status
+= "\nCan not connect to axes proxies";
530 if (_diffractometer
){
531 status
+= "\nSample: ";
532 if(!_diffractometer
->samples
->current
){
533 status
+= "Not yet Set";
534 state
= Tango::FAULT
;
536 status
+= _diffractometer
->samples
->current
->name
;
537 if (state
== Tango::STANDBY
)
538 extra_status
+= "\nready to compute hkl";
540 state
= Tango::FAULT
;
541 extra_status
+= "\nhkl core not yet initialized !!!";
543 status
+= "\nDiffractometer status: ";
544 status
+= Tango::DevStateName
[state
];
545 status
+= extra_status
;
547 _diffractometerConfig
.state
= state
;
548 _diffractometerConfig
.status
= status
;
551 void TangoHKLAdapter::update(void)
553 /**********************************************
555 **********************************************/
556 omni_mutex_lock
lock(_lock
);
558 this->update_lambda();
559 this->update_axis_adapters();
560 this->update_hkl_from_axis_adapters();
561 this->update_pseudo_axis_adapters_from_hkl();
562 this->update_pseudo_axes_adapters_from_hkl();
563 this->update_state_and_status();
564 /**********************************************
565 * END OF CRITICAL SECTION
566 **********************************************/
569 /********************/
570 /* State and status */
571 /********************/
572 void TangoHKLAdapter::get_diffractometer_config(DiffractometerConfig
& config
)
574 omni_mutex_lock
lock(_lock
);
576 config
= _diffractometerConfig
;
583 short & TangoHKLAdapter::get_angles_idx(void)
585 omni_mutex_lock
lock(_lock
);
590 void TangoHKLAdapter::set_angles_idx(short idx
)
592 omni_mutex_lock
lock(_lock
);
595 if(idx
>= 0 && idx
< (int)_angles
.ydim
){
600 values
= &_angles
.data
[1 + idx
* _angles
.xdim
];
601 for(i
=0; i
<_axes
.size(); ++i
)
602 this->write_axis_i(_axes
[i
], values
[i
]);
606 void TangoHKLAdapter::load(void)
611 void TangoHKLAdapter::load_1(void)
613 unsigned long nb_properties
;
615 // Get the Crystal Attributes properties.
616 Tango::DbData properties
;
617 properties
.push_back(Tango::DbDatum("Crystal"));
618 _device
->get_db_device()->get_attribute_property(properties
);
620 // the first one is the number of properties
621 properties
[0] >> nb_properties
;
623 if (nb_properties
> 1) {
625 HklGeometry
*geometry
;
626 HklDetector
*detector
;
628 geometry
= hkl_geometry_new_copy(_diffractometer
->geometry_r
);
629 detector
= hkl_detector_new_copy(_diffractometer
->detector
);
631 hkl_sample_list_clear(_diffractometer
->samples
);
632 for(i
=1; i
<=nb_properties
; ++i
) {
633 // skip the _ver property
634 if(!strcasecmp("_ver", properties
[i
].name
.c_str()))
639 // The name of the property name is the name of a crystal.
640 sample
= hkl_sample_new(properties
[i
].name
.c_str(), HKL_SAMPLE_MONOCRYSTAL
);
642 // Extract the lines store in the property
643 std::vector
<std::string
> lines
;
644 properties
[i
] >> lines
;
646 for(j
=0; j
<lines
.size(); j
++) {
647 char *line
= strdup(lines
[j
].c_str());
649 char *key
= strtok_r(line
, "=", &last
);
651 if (!strcmp(key
,"lattice")) {
652 double a
= atof(strtok_r(NULL
, ";", &last
));
653 double b
= atof(strtok_r(NULL
, ";", &last
));
654 double c
= atof(strtok_r(NULL
, ";", &last
));
655 double alpha
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
656 double beta
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
657 double gamma
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
658 hkl_sample_set_lattice(sample
, a
, b
, c
, alpha
, beta
, gamma
);
660 sample
->lattice
->a
->fit
= atoi(strtok_r(NULL
, ";", &last
));
661 sample
->lattice
->b
->fit
= atoi(strtok_r(NULL
, ";", &last
));
662 sample
->lattice
->c
->fit
= atoi(strtok_r(NULL
, ";", &last
));
663 sample
->lattice
->alpha
->fit
= atoi(strtok_r(NULL
, ";", &last
));
664 sample
->lattice
->beta
->fit
= atoi(strtok_r(NULL
, ";", &last
));
665 sample
->lattice
->gamma
->fit
= atoi(strtok_r(NULL
, ";", &last
));
666 } else if (!strcmp(key
, "uxuyuz")){
667 double ux
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
668 double uy
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
669 double uz
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
670 hkl_sample_set_U_from_euler(sample
, ux
, uy
, uz
);
671 } else if (!strcmp(key
,"reflection")) {
672 unsigned int idx
= 0;
673 HklSampleReflection
*reflection
;
675 double wavelength
= atof(strtok_r(NULL
, ";", &last
));
676 double h
= atof(strtok_r(NULL
, ";", &last
));
677 double k
= atof(strtok_r(NULL
, ";", &last
));
678 double l
= atof(strtok_r(NULL
, ";", &last
));
679 int flag
= atoi(strtok_r(NULL
, ";", &last
));
681 // first set the geometry axes
682 while(key
= strtok_r(NULL
, ";", &last
))
683 hkl_axis_set_value_unit(&geometry
->axes
[idx
++], atof(key
));
684 geometry
->source
.wave_length
= wavelength
;
686 reflection
= hkl_sample_add_reflection(sample
, geometry
, detector
, h
, k
, l
);
687 reflection
->flag
= flag
;
690 // End of key research
691 }// End for each parameters
692 hkl_sample_list_append(_diffractometer
->samples
, sample
);
693 }// End for each property
695 hkl_detector_free(detector
);
696 hkl_geometry_free(geometry
);
698 //_device->refresh_crystal_parameters();
702 void TangoHKLAdapter::save(void)
704 omni_mutex_lock
lock(_lock
);
708 Tango::DbData crystal_prop
;
709 Tango::DbData data_put
;
711 // Step 1 : clean all properties
712 // FP Le mieux serait sans doute de ne pas effacer les propriétés d'attribut
713 // avant d'avoir crée correctement un data_put.
714 crystal_prop
.push_back(Tango::DbDatum("Crystal"));
715 _device
->get_db_device()->get_attribute_property(crystal_prop
);
716 long number_of_prop
= 0;
717 crystal_prop
[0] >> number_of_prop
;
718 if( number_of_prop
> 0)
719 _device
->get_db_device()->delete_attribute_property(crystal_prop
);
721 // Step 2 : create the Crystal properties
722 Tango::DbDatum
properties("Crystal");
723 // Put number of properties (= nb of samples + 1)
724 len
= hkl_sample_list_len(_diffractometer
->samples
);
725 properties
<< (long)(len
+ 1);
726 data_put
.push_back(properties
);
728 // first property is the format version
729 Tango::DbDatum
version("_ver");
730 version
<< (long)FORMAT_VERSION
;
731 data_put
.push_back(version
);
734 for(k
=0; k
<len
; ++k
){
736 std::vector
<std::string
> lines
;
739 // the lattices values
740 sample
= hkl_sample_list_get_ith(_diffractometer
->samples
, k
);
741 double a
= hkl_parameter_get_value_unit(sample
->lattice
->a
);
742 double b
= hkl_parameter_get_value_unit(sample
->lattice
->b
);
743 double c
= hkl_parameter_get_value_unit(sample
->lattice
->c
);
744 double alpha
= hkl_parameter_get_value_unit(sample
->lattice
->alpha
);
745 double beta
= hkl_parameter_get_value_unit(sample
->lattice
->beta
);
746 double gamma
= hkl_parameter_get_value_unit(sample
->lattice
->gamma
);
748 int a_fit
= sample
->lattice
->a
->fit
;
749 int b_fit
= sample
->lattice
->b
->fit
;
750 int c_fit
= sample
->lattice
->c
->fit
;
751 int alpha_fit
= sample
->lattice
->alpha
->fit
;
752 int beta_fit
= sample
->lattice
->beta
->fit
;
753 int gamma_fit
= sample
->lattice
->gamma
->fit
;
755 snprintf(line
, 255, "lattice=%f;%f;%f;%f;%f;%f;%d;%d;%d;%d;%d;%d",
756 a
, b
, c
, alpha
, beta
, gamma
,
757 a_fit
, b_fit
, c_fit
, alpha_fit
, beta_fit
, gamma_fit
);
758 lines
.push_back(line
);
760 // the UxUyUz parameters
762 hkl_matrix_to_euler(&sample
->U
, &ux
, &uy
, &uz
);
767 snprintf(line
, 255, "uxuyuz=%f;%f;%f", ux
, uy
, uz
);
768 lines
.push_back(line
);
771 for(i
=0; i
<HKL_LIST_LEN(sample
->reflections
); ++i
) {
772 HklSampleReflection
*reflection
;
774 reflection
= hkl_sample_get_ith_reflection(sample
, i
);
775 double wavelength
= reflection
->geometry
->source
.wave_length
;
776 double h
= reflection
->hkl
.data
[0];
777 double k
= reflection
->hkl
.data
[1];
778 double l
= reflection
->hkl
.data
[2];
779 int flag
= reflection
->flag
;
781 snprintf(line
, 255, "reflection=%f;%f;%f;%f;%d",
782 wavelength
, h
, k
, l
, flag
);
783 // Extract values of each axes
784 for(j
=0; j
<HKL_LIST_LEN(reflection
->geometry
->axes
); ++j
) {
786 double rad
= hkl_axis_get_value_unit(&reflection
->geometry
->axes
[j
]);
787 snprintf(pos
, 255, ";%f", rad
);
788 strncat(line
, pos
, 255);
790 lines
.push_back(line
);
793 // Try to create property
795 Tango::DbDatum
property(sample
->name
);
797 data_put
.push_back(property
);
800 //update database for this property
801 _device
->get_db_device()->put_attribute_property(data_put
);
808 char const *TangoHKLAdapter::get_sample_name(void)
810 omni_mutex_lock
lock(_lock
);
812 HklSample
*sample
= _diffractometer
->samples
->current
;
819 void TangoHKLAdapter::set_current_sample(char const * name
)
821 omni_mutex_lock
lock(_lock
);
825 last
= _diffractometer
->samples
->current
;
826 if (HKL_SUCCESS
== hkl_sample_list_select_current(_diffractometer
->samples
, name
))
827 if (last
!= _diffractometer
->samples
->current
){
828 this->update_pseudo_axis_engines();
830 this->update_ux_uy_uz();
831 this->update_reflections_angles();
832 this->update_reflections();
833 this->update_state_and_status();
837 void TangoHKLAdapter::get_sample_lattices(double *a
, double *b
, double *c
,
838 double *alpha
, double *beta
, double *gamma
,
839 double *a_star
, double *b_star
, double *c_star
,
840 double *alpha_star
, double *beta_star
, double *gamma_star
)
842 omni_mutex_lock
lock(_lock
);
844 HklSample
* sample
= _diffractometer
->samples
->current
;
848 HklLattice
const *lattice
= sample
->lattice
;
849 HklLattice
*reciprocal
= hkl_lattice_new_copy(lattice
);
851 hkl_lattice_reciprocal(lattice
, reciprocal
);
854 *a
= hkl_parameter_get_value_unit(lattice
->a
);
855 *b
= hkl_parameter_get_value_unit(lattice
->b
);
856 *c
= hkl_parameter_get_value_unit(lattice
->c
);
857 *alpha
= hkl_parameter_get_value_unit(lattice
->alpha
);
858 *beta
= hkl_parameter_get_value_unit(lattice
->beta
);
859 *gamma
= hkl_parameter_get_value_unit(lattice
->gamma
);
862 *a_star
= hkl_parameter_get_value_unit(reciprocal
->a
);
863 *b_star
= hkl_parameter_get_value_unit(reciprocal
->b
);
864 *c_star
= hkl_parameter_get_value_unit(reciprocal
->c
);
865 *alpha_star
= hkl_parameter_get_value_unit(reciprocal
->alpha
);
866 *beta_star
= hkl_parameter_get_value_unit(reciprocal
->beta
);
867 *gamma_star
= hkl_parameter_get_value_unit(reciprocal
->gamma
);
869 hkl_lattice_free(reciprocal
);
872 void TangoHKLAdapter::get_sample_fit(bool *afit
, bool *bfit
, bool *cfit
,
873 bool *alphafit
, bool *betafit
, bool *gammafit
,
874 bool *uxfit
, bool *uyfit
, bool *uzfit
)
876 omni_mutex_lock
lock(_lock
);
878 HklSample
* sample
= _diffractometer
->samples
->current
;
882 HklLattice
const *lattice
= sample
->lattice
;
884 *afit
= lattice
->a
->fit
;
885 *bfit
= lattice
->b
->fit
;
886 *cfit
= lattice
->c
->fit
;
887 *alphafit
= lattice
->alpha
->fit
;
888 *betafit
= lattice
->beta
->fit
;
889 *gammafit
= lattice
->gamma
->fit
;
896 void TangoHKLAdapter::set_sample_Ux(double ux
)
900 sample
= _diffractometer
->samples
->current
;
902 if (HKL_SUCCESS
== hkl_sample_set_U_from_euler(sample
,
905 _uz
* HKL_DEGTORAD
)){
909 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set this Ux value",
910 "Set a correct value");
914 void TangoHKLAdapter::set_sample_Uy(double uy
)
918 sample
= _diffractometer
->samples
->current
;
920 if (HKL_SUCCESS
== hkl_sample_set_U_from_euler(sample
,
923 _uz
* HKL_DEGTORAD
)){
927 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set this Uy value",
928 "Set a correct value");
932 void TangoHKLAdapter::set_sample_Uz(double uz
)
936 sample
= _diffractometer
->samples
->current
;
938 if (HKL_SUCCESS
== hkl_sample_set_U_from_euler(sample
,
945 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set this Uz value",
946 "Set a correct value");
950 void TangoHKLAdapter::set_sample_AFit(bool fit
)
954 sample
= _diffractometer
->samples
->current
;
956 sample
->lattice
->a
->fit
= fit
;
959 void TangoHKLAdapter::set_sample_BFit(bool fit
)
963 sample
= _diffractometer
->samples
->current
;
965 sample
->lattice
->b
->fit
= fit
;
968 void TangoHKLAdapter::set_sample_CFit(bool fit
)
972 sample
= _diffractometer
->samples
->current
;
974 sample
->lattice
->c
->fit
= fit
;
977 void TangoHKLAdapter::set_sample_AlphaFit(bool fit
)
981 sample
= _diffractometer
->samples
->current
;
983 sample
->lattice
->alpha
->fit
= fit
;
986 void TangoHKLAdapter::set_sample_BetaFit(bool fit
)
990 sample
= _diffractometer
->samples
->current
;
992 sample
->lattice
->beta
->fit
= fit
;
995 void TangoHKLAdapter::set_sample_GammaFit(bool fit
)
999 sample
= _diffractometer
->samples
->current
;
1001 sample
->lattice
->gamma
->fit
= fit
;
1004 void TangoHKLAdapter::set_sample_UxFit(bool fit
)
1008 sample
= _diffractometer
->samples
->current
;
1010 _uxfit
= _uyfit
= _uzfit
= fit
;
1013 void TangoHKLAdapter::set_sample_UyFit(bool fit
)
1017 sample
= _diffractometer
->samples
->current
;
1019 _uxfit
= _uyfit
= _uzfit
= fit
;
1022 void TangoHKLAdapter::set_sample_UzFit(bool fit
)
1026 sample
= _diffractometer
->samples
->current
;
1028 _uxfit
= _uyfit
= _uzfit
= fit
;
1031 void TangoHKLAdapter::add_new_sample(std::string
const & name
)
1033 omni_mutex_lock
lock(_lock
);
1035 HklSample
*sample
= hkl_sample_new(name
.c_str(), HKL_SAMPLE_MONOCRYSTAL
);
1037 if (!hkl_sample_list_append(_diffractometer
->samples
, sample
)){
1038 hkl_sample_free(sample
);
1039 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not add a sample with this name",
1040 "A sample with the same name is already present in the sample list");
1044 void TangoHKLAdapter::copy_sample_as(Tango::DevString copy_name
)
1046 omni_mutex_lock
lock(_lock
);
1049 HklSample
const *current
;
1051 current
= _diffractometer
->samples
->current
;
1053 TANGO_EXCEPTION_THROW_WITHOUT_LOG("No current sample set",
1054 "Please set a current sample");
1056 sample
= hkl_sample_list_get_by_name(_diffractometer
->samples
, copy_name
);
1058 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not add a sample with this name",
1059 "A sample with the same name is already present in the sample list");
1061 sample
= hkl_sample_new_copy(current
);
1063 hkl_sample_set_name(sample
, copy_name
);
1064 hkl_sample_list_append(_diffractometer
->samples
, sample
);
1068 void TangoHKLAdapter::del_sample(void)
1070 omni_mutex_lock
lock(_lock
);
1072 HklSampleList
*samples
= _diffractometer
->samples
;
1073 hkl_sample_list_del(samples
, samples
->current
);
1075 // add a default sample if no more sample in the list
1076 if(hkl_sample_list_len(samples
) == 0){
1077 HklSample
*sample
= hkl_sample_new("default", HKL_SAMPLE_MONOCRYSTAL
);
1078 samples
->current
= hkl_sample_list_append(samples
, sample
);
1080 samples
->current
= hkl_sample_list_get_ith(samples
, 0);
1082 this->update_ux_uy_uz();
1083 this->update_reflections_angles();
1084 this->update_reflections();
1087 void TangoHKLAdapter::set_lattice(const Tango::DevVarDoubleArray
*argin
)
1089 omni_mutex_lock
lock(_lock
);
1091 if (argin
&& argin
->length() != 6)
1092 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1093 "Did not receive the exact amount of crystal parameters: A, B, C, alpha, beta, gamma");
1095 HklSample
*sample
= _diffractometer
->samples
->current
;
1096 if (HKL_FAIL
== hkl_sample_set_lattice(sample
,
1097 (*argin
)[0],(*argin
)[1], (*argin
)[2],
1098 (*argin
)[3] * HKL_DEGTORAD
,
1099 (*argin
)[4] * HKL_DEGTORAD
,
1100 (*argin
)[5] * HKL_DEGTORAD
))
1102 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set this lattice combination.",
1103 "Please set a good combination");
1105 this->update_reflections_angles();
1108 void TangoHKLAdapter::add_reflection(const Tango::DevVarDoubleArray
*argin
)
1110 omni_mutex_lock
lock(_lock
);
1112 HklSample
*sample
= _diffractometer
->samples
->current
;
1116 HklSampleReflection
*ref
;
1118 if(argin
&& argin
->length() == 3){
1123 HklPseudoAxisEngine
*engine
;
1125 engine
= hkl_pseudo_axis_engine_list_get_by_name(_diffractometer
->engines_r
, "hkl");
1127 h
= hkl_parameter_get_value_unit((HklParameter
*)engine
->pseudoAxes
[0]);
1128 k
= hkl_parameter_get_value_unit((HklParameter
*)engine
->pseudoAxes
[1]);
1129 l
= hkl_parameter_get_value_unit((HklParameter
*)engine
->pseudoAxes
[2]);
1132 ref
= hkl_sample_add_reflection(sample
,
1133 _diffractometer
->geometry_r
,
1134 _diffractometer
->detector
,
1137 this->update_reflections_angles();
1138 this->update_reflections();
1143 void TangoHKLAdapter::del_reflection(Tango::DevShort argin
)
1145 omni_mutex_lock
lock(_lock
);
1147 if (HKL_FAIL
== hkl_sample_del_reflection(_diffractometer
->samples
->current
, argin
))
1148 TANGO_EXCEPTION_THROW_WITHOUT_LOG("index out of range",
1149 "change the reflection index");
1150 this->update_reflections_angles();
1151 this->update_reflections();
1154 void TangoHKLAdapter::set_reflections(Matrix
<double> const & img
)
1156 omni_mutex_lock
lock(_lock
);
1158 HklSample
*sample
= _diffractometer
->samples
->current
;
1160 && img
.xdim
== _reflections
.xdim
1161 && img
.ydim
== _reflections
.ydim
) {
1165 for(i
=0; i
<HKL_LIST_LEN(sample
->reflections
); ++i
) {
1166 HklSampleReflection
*r
;
1168 r
= hkl_sample_get_ith_reflection(sample
, i
);
1170 hkl_sample_reflection_set_hkl(r
, img
.data
[j
+1], img
.data
[j
+2], img
.data
[j
+3]);
1171 hkl_sample_reflection_set_flag(r
, (int)img
.data
[j
+5]);
1172 if(!_device
->protectReflectionAxes
){
1177 len
= HKL_LIST_LEN(r
->geometry
->axes
);
1178 axes
= &r
->geometry
->axes
[0];
1180 for(k
=6; k
<6+len
; ++k
)
1181 hkl_axis_set_value_unit(axes
++, img
.data
[j
+k
]);
1183 hkl_geometry_update(r
->geometry
);
1184 hkl_sample_reflection_set_geometry(r
, r
->geometry
);
1187 j
+= _reflections
.xdim
;
1189 this->update_reflections();
1190 this->update_reflections_angles();
1194 double TangoHKLAdapter::affine_sample(std::string name
)
1196 omni_mutex_lock
lock(_lock
);
1201 sample
= hkl_sample_list_get_by_name(_diffractometer
->samples
, name
.c_str());
1205 // check if the affine sample is already in the HklSampleList
1206 std::string name
= sample
->name
;
1208 tmp
= hkl_sample_list_get_by_name(_diffractometer
->samples
, name
.c_str());
1209 hkl_sample_list_del(_diffractometer
->samples
, tmp
);
1211 tmp
= hkl_sample_new_copy(sample
);
1212 hkl_sample_set_name(tmp
, name
.c_str());
1213 res
= hkl_sample_affine(tmp
);
1215 hkl_sample_list_append(_diffractometer
->samples
, tmp
);
1216 _diffractometer
->samples
->current
= tmp
;
1219 this->update_ux_uy_uz();
1220 this->update_reflections_angles();
1227 std::vector
<std::string
> TangoHKLAdapter::get_samples_names(void)
1229 omni_mutex_lock
lock(_lock
);
1231 std::vector
<std::string
> names
;
1233 HklSampleList
*samples
= _diffractometer
->samples
;
1235 len
= hkl_sample_list_len(samples
);
1236 for(i
=0; i
<len
; ++i
)
1237 names
.push_back(hkl_sample_list_get_ith(samples
, i
)->name
);
1243 void TangoHKLAdapter::get_sample_parameter_values(Tango::DevVarDoubleStringArray
*argout
)
1245 omni_mutex_lock
lock(_lock
);
1248 HklParameter
*parameter
= NULL
;
1252 if (argout
->svalue
.length() != 1)
1253 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1254 "only one string = parameter name");
1256 sample
= _diffractometer
->samples
->current
;
1259 name
= argout
->svalue
[0];
1261 parameter
= sample
->lattice
->a
;
1262 else if(name
== "b")
1263 parameter
= sample
->lattice
->b
;
1264 else if(name
== "c")
1265 parameter
= sample
->lattice
->c
;
1266 else if(name
== "alpha")
1267 parameter
= sample
->lattice
->alpha
;
1268 else if(name
== "beta")
1269 parameter
= sample
->lattice
->beta
;
1270 else if(name
== "gamma")
1271 parameter
= sample
->lattice
->gamma
;
1274 argout
->dvalue
[0] = parameter
->range
.min
;
1275 argout
->dvalue
[1] = parameter
->range
.max
;
1276 argout
->dvalue
[2] = parameter
->fit
;
1278 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Wrong parameter name",
1279 "Select: a, b, c, alpha, beta, gamma");
1284 void TangoHKLAdapter::set_sample_parameter_values(Tango::DevVarDoubleStringArray
const *argin
)
1286 omni_mutex_lock
lock(_lock
);
1289 HklParameter
*parameter
= NULL
;
1293 if(argin
->dvalue
.length() != 3)
1294 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1295 "set_crystal_parameter_values did not receive the right amount of scalar parameters: min, max, flag");
1296 if((argin
->svalue
.length() ) != 1)
1297 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1298 "set_crystal_parameter_values did not receive the right amount of string parameters: parameter name");
1301 sample
= _diffractometer
->samples
->current
;
1303 TANGO_EXCEPTION_THROW_WITHOUT_LOG("No current sample set",
1304 "Please set a current sample");
1306 name
= argin
->svalue
[0];
1308 parameter
= sample
->lattice
->a
;
1309 else if(name
== "b")
1310 parameter
= sample
->lattice
->b
;
1311 else if(name
== "c")
1312 parameter
= sample
->lattice
->c
;
1313 else if(name
== "alpha")
1314 parameter
= sample
->lattice
->alpha
;
1315 else if(name
== "beta")
1316 parameter
= sample
->lattice
->beta
;
1317 else if(name
== "gamma")
1318 parameter
= sample
->lattice
->gamma
;
1321 parameter
->range
.min
= argin
->dvalue
[0];
1322 parameter
->range
.max
= argin
->dvalue
[1];
1323 parameter
->fit
= argin
->dvalue
[2] != 0.;
1325 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Wrong parameter name",
1326 "Select: a, b, c, alpha, beta, gamma");
1328 this->update_ux_uy_uz();
1329 this->update_reflections_angles();
1332 void TangoHKLAdapter::compute_u(const Tango::DevVarLongArray
*argin
)
1334 omni_mutex_lock
lock(_lock
);
1338 // is parameter ok ?
1339 if (argin
->length() != 2)
1340 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Need exactly two reflections indexes",
1341 "use the right number of parameters");
1343 sample
= _diffractometer
->samples
->current
;
1345 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not compute the U matrix without current sample set.",
1346 "Set a current sample");
1348 if (hkl_sample_compute_UB_busing_levy(sample
, (*argin
)[0], (*argin
)[1]))
1349 TANGO_EXCEPTION_THROW_WITHOUT_LOG("can not compute the UB matrix using thoses reflections index",
1350 "Use other reflections");
1352 this->update_ux_uy_uz();
1359 void TangoHKLAdapter::read_axis(int idx
, double & read
, double & write
)
1361 omni_mutex_lock
lock(_lock
);
1363 AxisAdapter
& axis
= _axes
[idx
];
1364 read
= axis
.get_read();
1365 write
= axis
.get_write();
1368 void TangoHKLAdapter::stop_all_axis(void)
1370 #ifdef WRITE_TO_PROXY_ALLOWED
1372 for(i
=0; i
<_axes
.size(); ++i
)
1377 void TangoHKLAdapter::write_axis(AxisAdapter
& axis
, double value
)
1379 omni_mutex_lock
lock(_lock
);
1381 this->write_axis_i(axis
, value
);
1384 void TangoHKLAdapter::write_axis_i(AxisAdapter
& axis
, double value
)
1386 axis
._read
= axis
._write
= value
;
1387 hkl_axis_set_value_unit(axis
._axis_r
, value
);
1388 hkl_axis_set_value_unit(axis
._axis_w
, value
);
1391 /*******************/
1392 /* pseudoAxis part */
1393 /*******************/
1395 std::vector
<std::string
> TangoHKLAdapter::pseudo_axis_get_names(void)
1397 omni_mutex_lock
lock(_lock
);
1399 std::vector
<std::string
> names
;
1402 for(i
=0; i
<HKL_LIST_LEN(_diffractometer
->engines_r_real
->engines
); ++i
){
1403 HklPseudoAxisEngine
*engine
;
1405 engine
= _diffractometer
->engines_r_real
->engines
[i
];
1406 for(j
=0; j
<HKL_LIST_LEN(engine
->pseudoAxes
); ++j
)
1407 names
.push_back(((HklParameter
*)(&engine
->pseudoAxes
[j
]))->name
);
1413 PseudoAxisAdapter
*TangoHKLAdapter::pseudo_axis_buffer_new(char const *name
)
1415 omni_mutex_lock
lock(_lock
);
1417 PseudoAxisAdapter
* buffer
= NULL
;
1418 HklPseudoAxis
*pseudo_r
;
1419 HklPseudoAxis
*pseudo_w
;
1421 pseudo_r
= hkl_pseudo_axis_engine_list_get_pseudo_axis_by_name(
1422 _diffractometer
->engines_r_real
, name
);
1423 pseudo_w
= hkl_pseudo_axis_engine_list_get_pseudo_axis_by_name(
1424 _diffractometer
->engines_w_real
, name
);
1426 if(pseudo_r
&& pseudo_w
) {
1429 buffer
= new PseudoAxisAdapter(*this, pseudo_r
, pseudo_w
);
1430 _pseudoAxisAdapters
.push_back(buffer
);
1432 catch (Tango::DevFailed
)
1441 Tango::DevBoolean
TangoHKLAdapter::pseudo_axis_get_initialized(PseudoAxisAdapter
*buffer
)
1443 omni_mutex_lock
lock(_lock
);
1445 if(!buffer
->_pseudo_r
->engine
->mode
->initialize
)
1449 void TangoHKLAdapter::pseudo_axis_set_initialized(PseudoAxisAdapter
*buffer
,
1450 Tango::DevBoolean initialized
)
1455 omni_mutex_lock
lock(_lock
);
1457 hkl_pseudo_axis_engine_initialize(buffer
->_pseudo_r
->engine
);
1458 hkl_pseudo_axis_engine_initialize(buffer
->_pseudo_w
->engine
);
1462 void TangoHKLAdapter::pseudo_axis_write(PseudoAxisAdapter
* buffer
, double value
)
1464 omni_mutex_lock
lock(_lock
);
1468 HklPseudoAxisEngineList
*engines_w_real
= _diffractometer
->engines_w_real
;
1469 HklPseudoAxisEngine
*engine
= buffer
->_pseudo_w
->engine
;
1470 HklGeometry
*geometry_w_real
= _diffractometer
->geometry_w_real
;
1472 hkl_parameter_set_value_unit((HklParameter
*)buffer
->_pseudo_w
, value
);
1473 res
= hkl_pseudo_axis_engine_set(buffer
->_pseudo_w
->engine
);
1474 //hkl_pseudo_axis_engine_fprintf(stdout, buffer->_pseudo_w->engine);
1475 if (HKL_SUCCESS
== res
){
1476 hkl_geometry_init_geometry(geometry_w_real
, engine
->engines
->geometries
->geometries
[0]);
1477 hkl_pseudo_axis_engine_list_get(engines_w_real
);
1480 this->update_angles();
1481 buffer
->to_proxies();
1482 this->update_axis_adapters();
1483 this->update_pseudo_axis_adapters_from_hkl();
1484 this->update_pseudo_axes_adapters_from_hkl();
1486 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not write on this pseudo axis",
1487 "Check the sample");
1491 Tango::DevString
*TangoHKLAdapter::pseudo_axis_get_mode(PseudoAxisAdapter
const *buffer
)
1493 omni_mutex_lock
lock(_lock
);
1495 return const_cast<Tango::DevString
*>(&buffer
->_pseudo_r
->engine
->mode
->name
);
1498 void TangoHKLAdapter::pseudo_axis_set_mode(PseudoAxisAdapter
*buffer
, Tango::DevString
const & mode
)
1500 omni_mutex_lock
lock(_lock
);
1504 len
= HKL_LIST_LEN(buffer
->_pseudo_r
->engine
->modes
);
1505 for(i
=0; i
<len
; ++i
)
1506 if(!strcasecmp(mode
, buffer
->_pseudo_r
->engine
->modes
[i
]->name
))
1509 hkl_pseudo_axis_engine_select_mode(buffer
->_pseudo_r
->engine
, i
);
1510 hkl_pseudo_axis_engine_select_mode(buffer
->_pseudo_w
->engine
, i
);
1514 void TangoHKLAdapter::pseudo_axis_get_mode_parameters(PseudoAxisAdapter
*buffer
, Tango::DevVarDoubleStringArray
*argout
)
1516 omni_mutex_lock
lock(_lock
);
1518 HklPseudoAxisEngine
*engine
= buffer
->_pseudo_r
->engine
;
1519 if (engine
&& engine
->mode
){
1521 size_t len
= HKL_LIST_LEN(engine
->mode
->parameters
);
1523 argout
->svalue
.length(len
);
1524 argout
->dvalue
.length(len
);
1525 for(i
=0; i
<len
; ++i
){
1526 argout
->svalue
[i
] = CORBA::string_dup(engine
->mode
->parameters
[i
].name
);
1527 argout
->dvalue
[i
] = hkl_parameter_get_value_unit(&engine
->mode
->parameters
[i
]);
1530 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not get the current Mode parameters values without a current mode set.",
1534 void TangoHKLAdapter::pseudo_axis_set_mode_parameters(PseudoAxisAdapter
*buffer
, const Tango::DevVarDoubleStringArray
*argin
)
1536 omni_mutex_lock
lock(_lock
);
1538 if(argin
->svalue
.length() != argin
->dvalue
.length())
1539 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1540 "set_mode_parameters_values did not receive the same amount between string and double values");
1542 HklPseudoAxisEngine
*engine_r
= buffer
->_pseudo_r
->engine
;
1543 HklPseudoAxisEngine
*engine_w
= buffer
->_pseudo_w
->engine
;
1544 if (engine_r
&& engine_w
){
1548 len
= argin
->svalue
.length();
1549 if (HKL_LIST_LEN(engine_r
->mode
->parameters
) != len
)
1550 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Not the right number of parameter",
1551 "gives the right number of parameters");
1553 for(i
=0; i
<len
; ++i
){
1554 double value
= argin
->dvalue
[i
];
1555 char const *name
= argin
->svalue
[i
];
1556 if(!strcmp(name
, engine_r
->mode
->parameters
[i
].name
)){
1557 hkl_parameter_set_value_unit(&engine_r
->mode
->parameters
[i
], value
);
1558 hkl_parameter_set_value_unit(&engine_w
->mode
->parameters
[i
], value
);
1562 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set the current Mode parameters values without a current mode set.",
1566 void TangoHKLAdapter::pseudo_axis_on(PseudoAxisAdapter
*buffer
)
1568 omni_mutex_lock
lock(_lock
);
1570 for(size_t i
=0; i
<buffer
->_axes
.size(); ++i
)
1571 buffer
->_axes
[i
]->on();
1574 /*******************/
1575 /* pseudoAxes part */
1576 /*******************/
1578 PseudoAxesAdapter
*TangoHKLAdapter::pseudo_axes_adapter_get_by_name(std::string
const & name
)
1580 //omni_mutex_lock lock(_lock);
1583 PseudoAxesAdapter
*adapter
= NULL
;
1585 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
1586 if(_pseudoAxesAdapters
[i
]->get_name() == name
){
1587 adapter
= _pseudoAxesAdapters
[i
];
1594 void TangoHKLAdapter::pseudo_axes_write(size_t idx
, Matrix
<double> const & write
) throw (Tango::DevFailed
)
1596 omni_mutex_lock
lock(_lock
);
1600 HklPseudoAxisEngineList
*engines_r
, *engines_w
;
1601 HklGeometry
*geometry_r
, *geometry_w
;
1603 engines_r
= _diffractometer
->engines_r
;
1604 engines_w
= _diffractometer
->engines_w
;
1605 len
= HKL_LIST_LEN(engines_w
->engines
[idx
]->pseudoAxes
);
1607 geometry_r
= _diffractometer
->geometry_r
;
1608 geometry_w
= _diffractometer
->geometry_w
;
1610 for(i
=0; i
<len
; ++i
)
1611 hkl_parameter_set_value_unit((HklParameter
*)(engines_w
->engines
[idx
]->pseudoAxes
[i
]), write
.data
[i
]);
1613 res
= hkl_pseudo_axis_engine_set(engines_w
->engines
[idx
]);
1615 if (HKL_SUCCESS
== res
){
1616 // force auto update OFF when we write on a PseudoAxes.
1617 _auto_update_from_proxies
= false;
1619 hkl_geometry_init_geometry(geometry_w
, engines_w
->geometries
->geometries
[0]);
1620 hkl_pseudo_axis_engine_list_get(engines_w
);
1621 hkl_geometry_init_geometry(geometry_r
, engines_w
->geometries
->geometries
[0]);
1622 hkl_pseudo_axis_engine_list_get(engines_r
);
1625 this->update_angles();
1626 this->update_axis_adapters();
1627 this->update_pseudo_axis_adapters_from_hkl();
1628 this->update_pseudo_axes_adapters_from_hkl();
1630 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not write on this pseudo axis",
1631 "Check the sample");
1635 Tango::DevString
*TangoHKLAdapter::pseudo_axes_get_mode(size_t idx
)
1637 omni_mutex_lock
lock(_lock
);
1639 HklPseudoAxisEngine
*engine
= _diffractometer
->engines_r
->engines
[idx
];
1641 return const_cast<Tango::DevString
*>(&engine
->mode
->name
);
1646 void TangoHKLAdapter::pseudo_axes_set_mode(size_t idx
, const Tango::DevString name
)
1648 omni_mutex_lock
lock(_lock
);
1651 HklPseudoAxisEngine
*engine
= _diffractometer
->engines_r
->engines
[idx
];
1653 // check if we try to set the same mode than the current one
1655 if(!strcasecmp(name
, engine
->mode
->name
))
1658 // no so set the mode if possible
1659 size_t len
= HKL_LIST_LEN(engine
->modes
);
1660 for(i
=0; i
<len
; ++i
)
1661 if(!strcasecmp(name
, engine
->modes
[i
]->name
))
1664 hkl_pseudo_axis_engine_select_mode(_diffractometer
->engines_r
->engines
[idx
], i
);
1665 hkl_pseudo_axis_engine_select_mode(_diffractometer
->engines_w
->engines
[idx
], i
);
1666 hkl_pseudo_axis_engine_select_mode(_diffractometer
->engines_r_real
->engines
[idx
], i
);
1667 hkl_pseudo_axis_engine_select_mode(_diffractometer
->engines_w_real
->engines
[idx
], i
);
1668 _pseudoAxesAdapters
[idx
]->update_axes_i(engine
);
1669 _pseudoAxesAdapters
[idx
]->update_state_and_status_i();
1673 Matrix
<char *> & TangoHKLAdapter::pseudo_axes_get_mode_parameters_names(size_t idx
)
1675 omni_mutex_lock
lock(_lock
);
1678 HklPseudoAxisEngine
*engine
= _diffractometer
->engines_r
->engines
[idx
];
1679 size_t len
= HKL_LIST_LEN(engine
->mode
->parameters
);
1680 PseudoAxesAdapter
*adapter
= _pseudoAxesAdapters
[idx
];
1681 adapter
->_mode_parameters_names
.resize(len
, 1);
1682 for(i
=0; i
<len
; ++i
)
1683 adapter
->_mode_parameters_names
.data
[i
] = const_cast<char *>(engine
->mode
->parameters
[i
].name
);
1684 return adapter
->_mode_parameters_names
;
1687 Matrix
<double> const & TangoHKLAdapter::pseudo_axes_get_mode_parameters(size_t idx
)
1689 omni_mutex_lock
lock(_lock
);
1692 HklPseudoAxisEngine
*engine
= _diffractometer
->engines_r
->engines
[idx
];
1693 size_t len
= HKL_LIST_LEN(engine
->mode
->parameters
);
1694 PseudoAxesAdapter
*adapter
= _pseudoAxesAdapters
[idx
];
1695 adapter
->_mode_parameters
.resize(len
, 1);
1696 for(i
=0; i
<len
; ++i
)
1697 adapter
->_mode_parameters
.data
[i
] = hkl_parameter_get_value_unit(&engine
->mode
->parameters
[i
]);
1698 return adapter
->_mode_parameters
;
1701 void TangoHKLAdapter::pseudo_axes_set_mode_parameters(size_t idx
, Matrix
<double> const & values
)
1703 omni_mutex_lock
lock(_lock
);
1706 HklPseudoAxisEngine
*engine
= _diffractometer
->engines_r
->engines
[idx
];
1707 size_t len
= HKL_LIST_LEN(engine
->mode
->parameters
);
1708 if(len
== values
.xdim
)
1709 for(i
=0; i
<len
; ++i
){
1710 double & value
= values
.data
[i
];
1712 hkl_parameter_set_value_unit(&_diffractometer
->engines_r
->engines
[idx
]->mode
->parameters
[i
],
1714 hkl_parameter_set_value_unit(&_diffractometer
->engines_w
->engines
[idx
]->mode
->parameters
[i
],
1716 hkl_parameter_set_value_unit(&_diffractometer
->engines_r_real
->engines
[idx
]->mode
->parameters
[i
],
1718 hkl_parameter_set_value_unit(&_diffractometer
->engines_w_real
->engines
[idx
]->mode
->parameters
[i
],
1723 void TangoHKLAdapter::pseudo_axes_init(size_t idx
)
1725 omni_mutex_lock
lock(_lock
);
1727 HklPseudoAxisEngine
*engine_r
= _diffractometer
->engines_r
->engines
[idx
];
1728 HklPseudoAxisEngine
*engine_w
= _diffractometer
->engines_w
->engines
[idx
];
1729 HklPseudoAxisEngine
*engine_r_real
= _diffractometer
->engines_r_real
->engines
[idx
];
1730 HklPseudoAxisEngine
*engine_w_real
= _diffractometer
->engines_w_real
->engines
[idx
];
1732 hkl_pseudo_axis_engine_initialize(engine_r
);
1733 hkl_pseudo_axis_engine_initialize(engine_w
);
1734 hkl_pseudo_axis_engine_initialize(engine_r_real
);
1735 hkl_pseudo_axis_engine_initialize(engine_w_real
);
1738 void TangoHKLAdapter::pseudo_axes_add_dynamic_attributes(size_t idx
)
1740 //omni_mutex_lock lock(_lock);
1744 // check if all the PseudoAxes were instantiated
1745 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
1746 if(!_pseudoAxesAdapters
[i
]->_device
)
1750 * we need to attach the dynamic attributes after all instance of
1751 * the PseudoAxes devices were started. otherwise it cause problem.
1752 * only add the attributs if they were not already added.
1754 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
){
1755 PseudoAxesAdapter
*adapter
= _pseudoAxesAdapters
[i
];
1756 Tango::MultiAttribute
*multiattribute
= adapter
->_device
->get_device_attr();
1758 for(j
=0; j
<adapter
->_dynamic_attribute_pseudo_axes_axis
.size(); ++j
){
1760 multiattribute
->get_attr_by_name(adapter
->get_pseudo_axis_names().data
[j
]);
1761 }catch (Tango::DevFailed
){
1762 adapter
->_device
->add_attribute(adapter
->_dynamic_attribute_pseudo_axes_axis
[j
]);
1768 void TangoHKLAdapter::pseudo_axes_remove_dynamic_attributes(size_t idx
)
1771 PseudoAxesAdapter
*adapter
;
1773 adapter
= _pseudoAxesAdapters
[idx
];
1774 if(adapter
->_device
){
1775 for(i
=0; i
<adapter
->_dynamic_attribute_pseudo_axes_axis
.size(); ++i
)
1776 adapter
->_device
->remove_attribute(adapter
->_dynamic_attribute_pseudo_axes_axis
[i
], false);
1777 adapter
->_device
= NULL
;
1781 void TangoHKLAdapter::pseudo_axes_create_and_start_devices(void)
1783 omni_mutex_lock
lock(_lock
);
1787 Tango::Util
*tg
= Tango::Util::instance();
1788 Tango::Database
*db
= tg
->get_database();
1789 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
){
1790 std::string dev_name
= _pseudoAxesAdapters
[i
]->get_proxy_name();
1792 // first check if the device is already defined in the database
1794 Tango::DbDevImportInfo my_device_import_info
;
1796 my_device_import_info
= db
->import_device(dev_name
);
1797 } catch (Tango::DevFailed
&) {
1798 Tango::DbDevInfo my_device_info
;
1800 // add the device to the database
1801 my_device_info
.name
= dev_name
.c_str();
1802 my_device_info
._class
= "PseudoAxes";
1803 my_device_info
.server
= tg
->get_ds_name().c_str();
1805 db
->add_device(my_device_info
);
1807 // add the right properties to that device
1808 Tango::DbDatum
DiffractometerProxy("DiffractometerProxy"), EngineName("EngineName");
1809 Tango::DbData properties
;
1810 DiffractometerProxy
<< _device
->name();
1811 EngineName
<< _pseudoAxesAdapters
[i
]->get_name();
1812 properties
.push_back(DiffractometerProxy
);
1813 properties
.push_back(EngineName
);
1814 db
->put_device_property(dev_name
,properties
);
1817 // now start the device
1818 const std::vector
<Tango::DeviceClass
*> *cl_list
= tg
->get_class_list();
1819 for(j
=0; j
<cl_list
->size(); ++j
){
1820 if((*cl_list
)[j
]->get_name() == "PseudoAxes"){
1822 Tango::DevVarStringArray na
;
1824 na
[0] = dev_name
.c_str();
1825 (*cl_list
)[j
]->device_factory(&na
);
1826 std::cout
<< "Started " << dev_name
<< std::endl
;
1829 catch (Tango::DevFailed
&e
)
1838 Tango::DevBoolean
TangoHKLAdapter::pseudo_axes_get_initialized(size_t idx
)
1840 omni_mutex_lock
lock(_lock
);
1842 if(!_diffractometer
->engines_r
->engines
[idx
]->mode
->initialize
)
1846 void TangoHKLAdapter::pseudo_axes_set_initialized(size_t idx
, bool initialized
)
1851 omni_mutex_lock
lock(_lock
);
1853 HklPseudoAxisEngine
*engine_r
= _diffractometer
->engines_r
->engines
[idx
];
1854 HklPseudoAxisEngine
*engine_w
= _diffractometer
->engines_w
->engines
[idx
];
1855 HklPseudoAxisEngine
*engine_r_real
= _diffractometer
->engines_r_real
->engines
[idx
];
1856 HklPseudoAxisEngine
*engine_w_real
= _diffractometer
->engines_w_real
->engines
[idx
];
1858 hkl_pseudo_axis_engine_initialize(engine_r
);
1859 hkl_pseudo_axis_engine_initialize(engine_w
);
1860 hkl_pseudo_axis_engine_initialize(engine_r_real
);
1861 hkl_pseudo_axis_engine_initialize(engine_w_real
);
1865 /**********************/
1866 /* Dynamic attributes */
1867 /**********************/
1869 void TangoHKLAdapter::create_axes_dynamic_attributes(void)
1872 size_t len
= _axes
.size();
1873 _dynamic_attribute_axes_names
.resize(len
, 1);
1874 for(i
=0; i
<len
; ++i
){
1879 // compute the diffractometer axis names
1882 name
+= _axes
[i
].get_name();
1883 name
[l
] = toupper(name
[l
]);
1885 // create the AxisAttrib to deal with the proxy connection.
1886 att
= new AxisAttrib(name
.c_str(), _axes
[i
]);
1887 _dynamic_attribute_axes
.push_back(att
);
1888 _dynamic_attribute_axes_names
.data
[i
] = const_cast<char *>(att
->get_name().c_str());
1892 void TangoHKLAdapter::destroy_axes_dynamic_attributes(void)
1895 size_t len
= _dynamic_attribute_axes
.size();
1897 for(i
=0; i
<len
; ++i
)
1898 delete _dynamic_attribute_axes
[i
];
1901 void TangoHKLAdapter::attach_dynamic_attributes_to_device(void)
1905 for(i
=0; i
<_dynamic_attribute_axes
.size(); ++i
)
1906 _device
->add_attribute(_dynamic_attribute_axes
[i
]);
1910 void TangoHKLAdapter::detach_dynamic_attributes_from_device(void)
1914 for(i
=0; i
<_dynamic_attribute_axes
.size(); ++i
)
1915 _device
->remove_attribute(_dynamic_attribute_axes
[i
], false);
1919 bool TangoHKLAdapter::get_auto_update_from_proxies(void)
1921 omni_mutex_lock
lock(_lock
);
1923 return _auto_update_from_proxies
;
1926 void TangoHKLAdapter::set_auto_update_from_proxies(bool update
)
1928 bool old
= _auto_update_from_proxies
;
1929 _auto_update_from_proxies
= update
;
1930 if(old
= false && update
== true)
1936 std::string
hkl_axes_consign_as_string(HklAxis
const **axes
, size_t axes_len
)
1941 std::ostringstream line
, tmp
;
1942 for(i
=0; i
<axes_len
; ++i
) {
1943 HklParameter
const *axis
= (HklParameter
const *)axes
[i
];
1944 double value
= hkl_parameter_get_value_unit(axis
);
1949 std::ostringstream tmp
;
1951 tmp
<< value
<< "°";