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();
88 // fill the axisAdapter.
89 len
= HKL_LIST_LEN(_diffractometer
->geometry_r
->axes
);
90 axes_r
= _diffractometer
->geometry_r
->axes
;
91 axes_w
= _diffractometer
->geometry_w
->axes
;
92 axes_r_real
= _diffractometer
->geometry_r_real
->axes
;
93 axes_w_real
= _diffractometer
->geometry_w_real
->axes
;
95 _axes
.push_back(AxisAdapter(this, &axes_r
[i
], &axes_w
[i
], &axes_r_real
[i
], &axes_w_real
[i
]));
97 // hack to connect all axes the first time
98 _auto_update_from_proxies
= true;
99 this->connect_all_proxies();
100 _auto_update_from_proxies
= false;
102 // fill the pseudoAxesAdapters
104 omni_mutex_lock
lock(_lock
);
106 len
= HKL_LIST_LEN(_diffractometer
->engines_r
->engines
);
107 _pseudo_axes_proxies
.resize(len
, 1);
108 for(i
=0; i
<len
; ++i
){
109 PseudoAxesAdapter
*adapter
;
110 HklPseudoAxisEngine
*engine_r
= _diffractometer
->engines_r
->engines
[i
];
111 HklPseudoAxisEngine
*engine_w
= _diffractometer
->engines_w
->engines
[i
];
112 adapter
= new PseudoAxesAdapter(this, i
, engine_r
, engine_w
);
113 _pseudoAxesAdapters
.push_back(adapter
);
114 _pseudo_axes_proxies
.data
[i
] = const_cast<char *>(adapter
->_proxy_name
.c_str());
118 // create the dynamic attributes
119 this->create_axes_dynamic_attributes();
121 // set the default lambda
122 this->set_lambda(1.54);
125 TangoHKLAdapter::~TangoHKLAdapter(void)
129 this->destroy_axes_dynamic_attributes();
131 // remove all pseudo axis adapters
132 for(i
=0;i
<_pseudoAxisAdapters
.size();i
++)
133 delete _pseudoAxisAdapters
[i
];
135 // remove all pseudo axes adapters;
136 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
137 delete _pseudoAxesAdapters
[i
];
139 // remove all axisAdapter
142 if (_lambdaAttributeProxy
)
143 delete _lambdaAttributeProxy
;
145 // remove the hkl part
146 hkl_geometry_free(_diffractometer
->geometry_r
);
147 hkl_geometry_free(_diffractometer
->geometry_w
);
148 hkl_geometry_free(_diffractometer
->geometry_r_real
);
149 hkl_geometry_free(_diffractometer
->geometry_w_real
);
150 hkl_detector_free(_diffractometer
->detector
);
151 hkl_detector_free(_diffractometer
->detector_real
);
152 hkl_sample_list_free(_diffractometer
->samples
);
153 hkl_pseudo_axis_engine_list_free(_diffractometer
->engines_r
);
154 hkl_pseudo_axis_engine_list_free(_diffractometer
->engines_w
);
155 hkl_pseudo_axis_engine_list_free(_diffractometer
->engines_r_real
);
156 hkl_pseudo_axis_engine_list_free(_diffractometer
->engines_w_real
);
158 if(_diffractometer
) {
159 delete _diffractometer
;
160 _diffractometer
= NULL
;
164 void TangoHKLAdapter::connect_all_proxies(void)
166 omni_mutex_lock
lock(_lock
);
168 // connect the lambda proxy
169 if ((!_lambdaAttributeProxy
&& _auto_update_from_proxies
)
170 && _device
->lambdaAttributeProxy
!= "") {
173 _lambdaAttributeProxy
= new Tango::AttributeProxy(_device
->lambdaAttributeProxy
);
179 // connect the axes proxies
180 if (!this->ready
&& _auto_update_from_proxies
) {
183 nb
= _device
->realAxisProxies
.size();
184 if (nb
!= _axes
.size()) {
185 _wrong_nb_of_axis_proxies
= true;
191 for(i
=0; i
<nb
; ++i
) {
192 AxisAdapter
& axis
= _axes
[i
];
193 if (!axis
.is_ready()){
194 // Find axis in the proxy list
195 for(j
=0; j
<nb
; ++j
) {
196 char *line
= strdup(_device
->realAxisProxies
[j
].c_str());
198 char *axis_name
= strtok_r(line
, ":", &last
);
199 char *proxy_name
= strtok_r(NULL
, ":", &last
);
200 if (axis
.get_name() == axis_name
)
201 axis
.connect(proxy_name
);
204 if (!axis
.is_ready())
213 void TangoHKLAdapter::set_lambda(double lambda
)
215 omni_mutex_lock
lock(_lock
);
217 if ((!_auto_update_from_proxies
|| _device
->lambdaAttributeProxy
== "")
220 _diffractometer
->geometry_r
->source
.wave_length
= lambda
;
221 _diffractometer
->geometry_w
->source
.wave_length
= lambda
;
222 _diffractometer
->geometry_r_real
->source
.wave_length
= lambda
;
223 _diffractometer
->geometry_w_real
->source
.wave_length
= lambda
;
227 // this method connect engines to the right geometry, detector and sample
228 void TangoHKLAdapter::update_pseudo_axis_engines(void)
230 hkl_pseudo_axis_engine_list_init(_diffractometer
->engines_r
,
231 _diffractometer
->geometry_r
,
232 _diffractometer
->detector
,
233 _diffractometer
->samples
->current
);
235 hkl_pseudo_axis_engine_list_init(_diffractometer
->engines_w
,
236 _diffractometer
->geometry_w
,
237 _diffractometer
->detector
,
238 _diffractometer
->samples
->current
);
240 hkl_pseudo_axis_engine_list_init(_diffractometer
->engines_r_real
,
241 _diffractometer
->geometry_r_real
,
242 _diffractometer
->detector
,
243 _diffractometer
->samples
->current
);
245 hkl_pseudo_axis_engine_list_init(_diffractometer
->engines_w_real
,
246 _diffractometer
->geometry_w_real
,
247 _diffractometer
->detector
,
248 _diffractometer
->samples
->current
);
251 void TangoHKLAdapter::update_lambda(void)
253 if (_lambdaAttributeProxy
&& _auto_update_from_proxies
){
255 _lambdaAttributeProxy
->read() >> _lambda
;
256 _diffractometer
->geometry_r
->source
.wave_length
= _lambda
;
257 _diffractometer
->geometry_w
->source
.wave_length
= _lambda
;
258 _diffractometer
->geometry_r_real
->source
.wave_length
= _lambda
;
259 _diffractometer
->geometry_w_real
->source
.wave_length
= _lambda
;
261 catch (Tango::DevFailed
&){
264 _lambda
= _diffractometer
->geometry_r
->source
.wave_length
;
268 * this method update the angles attribut from the engines->geometry list
270 void TangoHKLAdapter::update_angles(void)
275 HklPseudoAxisEngine
*engine
;
277 HklGeometry
**geometries
;
279 if(!_auto_update_from_proxies
)
280 engine
= hkl_pseudo_axis_engine_list_get_by_name(_diffractometer
->engines_w
, "hkl");
282 engine
= hkl_pseudo_axis_engine_list_get_by_name(_diffractometer
->engines_w_real
, "hkl");
284 // update the computed_angles part
285 xdim
= 1 + HKL_LIST_LEN(_diffractometer
->geometry_r
->axes
);
286 ydim
= HKL_LIST_LEN(engine
->engines
->geometries
->geometries
);
288 _angles
.resize(xdim
, ydim
);
293 geometries
= engine
->engines
->geometries
->geometries
;
294 for(j
=0; j
<ydim
; ++j
){
295 HklGeometry
*geom
= geometries
[j
];
298 for(i
=1; i
<xdim
; ++i
)
299 data
[i
] = hkl_axis_get_value_unit(&geom
->axes
[i
-1]);
305 * this method update the reflections_angles when we change a sample parameter
307 void TangoHKLAdapter::update_reflections_angles(void)
309 HklSample
*sample
= _diffractometer
->samples
->current
;
315 // the reflection Angles
316 rdim
= HKL_LIST_LEN(sample
->reflections
);
317 _reflections_angles
.resize(rdim
, rdim
);
318 _reflections_angles
.clear();
320 data
= _reflections_angles
.data
;
321 for(i
=0; i
<rdim
; ++i
) {
322 for(j
=0; j
<rdim
; ++j
) {
325 angle
= hkl_sample_get_reflection_theoretical_angle(sample
, i
, j
);
327 angle
= hkl_sample_get_reflection_mesured_angle(sample
, i
, j
);
329 *data
= angle
* HKL_RADTODEG
;
336 void TangoHKLAdapter::update_reflections(void)
338 HklSample
*sample
= _diffractometer
->samples
->current
;
341 // Allocation of the image
342 unsigned int xdim
= 6 + HKL_LIST_LEN(_diffractometer
->geometry_r
->axes
);
343 unsigned int ydim
= HKL_LIST_LEN(sample
->reflections
);
344 _reflections
.resize(xdim
, ydim
);
347 double *data
= _reflections
.data
;
348 for(i
=0; i
<ydim
; ++i
) {
349 HklSampleReflection
*r
;
351 r
= hkl_sample_get_ith_reflection(sample
, i
);
354 HklAxis
*axes
= r
->geometry
->axes
;
357 data
[1] = r
->hkl
.data
[0];
358 data
[2] = r
->hkl
.data
[1];
359 data
[3] = r
->hkl
.data
[2];
361 data
[5] = (double)r
->flag
;
363 for(k
=0; k
<HKL_LIST_LEN(r
->geometry
->axes
); ++k
)
364 data
[6 + k
] = hkl_axis_get_value_unit(&axes
[k
]);
371 void TangoHKLAdapter::update_ub(void)
373 HklSample
const *sample
= _diffractometer
->samples
->current
;
376 _ub
.resize(dim
, dim
);
377 _ub
.set_data_from_buffer(&(sample
->UB
.data
[0][0]), dim
, dim
);
381 void TangoHKLAdapter::update_ux_uy_uz(void)
383 HklSample
*sample
= _diffractometer
->samples
->current
;
386 hkl_matrix_to_euler(&sample
->U
, &_ux
, &_uy
, &_uz
);
394 * this method update all the AxisAdapter from the proxy every 200 ms.
395 * this from_proxy get the real part from the proxy and the "sim" part
396 * from the HklAxis in simulated mode or from the proxy in real mode
397 * else it updates them from the HklAxis.
408 * simulated -> HklAxis
410 void TangoHKLAdapter::update_axis_adapters(void)
414 // first read from the proxy.
416 if(duration
.GetDurationInMs() >= 200) {
417 for(size_t i
=0; i
<_axes
.size(); ++i
)
418 _axes
[i
].from_proxy(!_auto_update_from_proxies
);
421 for(i
=0; i
<_axes
.size(); ++i
)
422 _axes
[i
].from_HklAxis();
425 void TangoHKLAdapter::update_hkl_from_axis_adapters(void)
430 for(i
=0; i
<_axes
.size(); ++i
)
431 _axes
[i
].to_HklAxis();
433 // update the pseudo axes
434 if(_diffractometer
&& _diffractometer
->samples
){
435 hkl_pseudo_axis_engine_list_get(_diffractometer
->engines_r
);
436 hkl_pseudo_axis_engine_list_get(_diffractometer
->engines_w
);
437 hkl_pseudo_axis_engine_list_get(_diffractometer
->engines_r_real
);
438 hkl_pseudo_axis_engine_list_get(_diffractometer
->engines_w_real
);
442 void TangoHKLAdapter::update_pseudo_axis_adapters_from_hkl(void)
444 for(size_t i
=0;i
<_pseudoAxisAdapters
.size();++i
)
445 _pseudoAxisAdapters
[i
]->update();
448 void TangoHKLAdapter::update_proxies_from_axis_adapters(void)
452 // first stop motion of all axes.
453 for(i
=0; i
<_axes
.size(); ++i
)
456 // then send write values to the proxies
457 for(i
=0; i
<_axes
.size(); ++i
)
461 void TangoHKLAdapter::update_proxies_from_pseudo_axis_adapters(PseudoAxisAdapter
*adapter
)
463 adapter
->to_proxies();
466 void TangoHKLAdapter::update_pseudo_axes_adapters_from_hkl(void)
468 for(size_t i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
469 _pseudoAxesAdapters
[i
]->update();
472 void TangoHKLAdapter::update_state_and_status(void)
474 Tango::DevState state
;
476 std::string extra_status
;
478 state
= Tango::STANDBY
;
479 if (!_auto_update_from_proxies
)
480 status
= "AutoUpdateFromProxies OFF";
482 status
= "AutoUpdateFromProxies ON";
485 state
= Tango::FAULT
;
486 extra_status
+= "\nCan not connect to axes proxies";
487 // update the monochromator proxy status.
488 if (!_lambdaAttributeProxy
&& _auto_update_from_proxies
) {
489 extra_status
+= "\nCan not connect to the lambdaAttributeProxy";
490 extra_status
+= "\nCheck also the lambdaAttributeProxy property";
494 for(unsigned int i
=0; i
<_axes
.size(); ++i
) {
495 AxisAdapter
const & axis
= _axes
[i
];
496 std::string proxy_name
= axis
.get_proxy_name();
497 Tango::DevState tmpState
= axis
.get_state();
499 ::compose_state(state
, tmpState
);
500 if (tmpState
!= Tango::STANDBY
)
501 extra_status
+= "\n" + proxy_name
+ " is in " + Tango::DevStateName
[tmpState
];
505 state
= Tango::FAULT
;
506 extra_status
+= "\nCan not connect to axes proxies";
512 if (_diffractometer
){
513 status
+= "\nSample: ";
514 if(!_diffractometer
->samples
->current
){
515 status
+= "Not yet Set";
516 state
= Tango::FAULT
;
518 status
+= _diffractometer
->samples
->current
->name
;
519 if (state
== Tango::STANDBY
)
520 extra_status
+= "\nready to compute hkl";
522 state
= Tango::FAULT
;
523 extra_status
+= "\nhkl core not yet initialized !!!";
525 status
+= "\nDiffractometer status: ";
526 status
+= Tango::DevStateName
[state
];
527 status
+= extra_status
;
529 _diffractometerConfig
.state
= state
;
530 _diffractometerConfig
.status
= status
;
533 void TangoHKLAdapter::update(void)
535 /**********************************************
537 **********************************************/
538 omni_mutex_lock
lock(_lock
);
540 this->update_lambda();
541 this->update_axis_adapters();
542 this->update_hkl_from_axis_adapters();
543 this->update_pseudo_axis_adapters_from_hkl();
544 this->update_pseudo_axes_adapters_from_hkl();
545 this->update_state_and_status();
546 /**********************************************
547 * END OF CRITICAL SECTION
548 **********************************************/
551 /********************/
552 /* State and status */
553 /********************/
554 void TangoHKLAdapter::get_diffractometer_config(DiffractometerConfig
& config
)
556 omni_mutex_lock
lock(_lock
);
558 config
= _diffractometerConfig
;
565 short & TangoHKLAdapter::get_angles_idx(void)
567 omni_mutex_lock
lock(_lock
);
572 void TangoHKLAdapter::set_angles_idx(short idx
)
574 omni_mutex_lock
lock(_lock
);
577 if(idx
>= 0 && idx
< (int)_angles
.ydim
){
582 values
= &_angles
.data
[1 + idx
* _angles
.xdim
];
583 for(i
=0; i
<_axes
.size(); ++i
)
584 this->write_axis_i(_axes
[i
], values
[i
]);
588 void TangoHKLAdapter::load(void)
593 void TangoHKLAdapter::load_1(void)
595 unsigned long nb_properties
;
597 // Get the Crystal Attributes properties.
598 Tango::DbData properties
;
599 properties
.push_back(Tango::DbDatum("Crystal"));
600 _device
->get_db_device()->get_attribute_property(properties
);
602 // the first one is the number of properties
603 properties
[0] >> nb_properties
;
605 if (nb_properties
> 1) {
607 HklGeometry
*geometry
;
608 HklDetector
*detector
;
610 geometry
= hkl_geometry_new_copy(_diffractometer
->geometry_r
);
611 detector
= hkl_detector_new_copy(_diffractometer
->detector
);
613 hkl_sample_list_clear(_diffractometer
->samples
);
614 for(i
=1; i
<=nb_properties
; ++i
) {
615 // skip the _ver property
616 if(!strcasecmp("_ver", properties
[i
].name
.c_str()))
621 // The name of the property name is the name of a crystal.
622 sample
= hkl_sample_new(properties
[i
].name
.c_str(), HKL_SAMPLE_MONOCRYSTAL
);
624 // Extract the lines store in the property
625 std::vector
<std::string
> lines
;
626 properties
[i
] >> lines
;
628 for(j
=0; j
<lines
.size(); j
++) {
629 char *line
= strdup(lines
[j
].c_str());
631 char *key
= strtok_r(line
, "=", &last
);
633 if (!strcmp(key
,"lattice")) {
634 double a
= atof(strtok_r(NULL
, ";", &last
));
635 double b
= atof(strtok_r(NULL
, ";", &last
));
636 double c
= atof(strtok_r(NULL
, ";", &last
));
637 double alpha
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
638 double beta
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
639 double gamma
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
640 hkl_sample_set_lattice(sample
, a
, b
, c
, alpha
, beta
, gamma
);
642 sample
->lattice
->a
->fit
= atoi(strtok_r(NULL
, ";", &last
));
643 sample
->lattice
->b
->fit
= atoi(strtok_r(NULL
, ";", &last
));
644 sample
->lattice
->c
->fit
= atoi(strtok_r(NULL
, ";", &last
));
645 sample
->lattice
->alpha
->fit
= atoi(strtok_r(NULL
, ";", &last
));
646 sample
->lattice
->beta
->fit
= atoi(strtok_r(NULL
, ";", &last
));
647 sample
->lattice
->gamma
->fit
= atoi(strtok_r(NULL
, ";", &last
));
648 } else if (!strcmp(key
, "uxuyuz")){
649 double ux
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
650 double uy
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
651 double uz
= atof(strtok_r(NULL
, ";", &last
)) * HKL_DEGTORAD
;
652 hkl_sample_set_U_from_euler(sample
, ux
, uy
, uz
);
653 } else if (!strcmp(key
,"reflection")) {
654 unsigned int idx
= 0;
655 HklSampleReflection
*reflection
;
657 double wavelength
= atof(strtok_r(NULL
, ";", &last
));
658 double h
= atof(strtok_r(NULL
, ";", &last
));
659 double k
= atof(strtok_r(NULL
, ";", &last
));
660 double l
= atof(strtok_r(NULL
, ";", &last
));
661 int flag
= atoi(strtok_r(NULL
, ";", &last
));
663 // first set the geometry axes
664 while(key
= strtok_r(NULL
, ";", &last
))
665 hkl_axis_set_value_unit(&geometry
->axes
[idx
++], atof(key
));
666 geometry
->source
.wave_length
= wavelength
;
668 reflection
= hkl_sample_add_reflection(sample
, geometry
, detector
, h
, k
, l
);
669 reflection
->flag
= flag
;
672 // End of key research
673 }// End for each parameters
674 hkl_sample_list_append(_diffractometer
->samples
, sample
);
675 }// End for each property
677 hkl_detector_free(detector
);
678 hkl_geometry_free(geometry
);
680 //_device->refresh_crystal_parameters();
684 void TangoHKLAdapter::save(void)
686 omni_mutex_lock
lock(_lock
);
690 Tango::DbData crystal_prop
;
691 Tango::DbData data_put
;
693 // Step 1 : clean all properties
694 // FP Le mieux serait sans doute de ne pas effacer les propriétés d'attribut
695 // avant d'avoir crée correctement un data_put.
696 crystal_prop
.push_back(Tango::DbDatum("Crystal"));
697 _device
->get_db_device()->get_attribute_property(crystal_prop
);
698 long number_of_prop
= 0;
699 crystal_prop
[0] >> number_of_prop
;
700 if( number_of_prop
> 0)
701 _device
->get_db_device()->delete_attribute_property(crystal_prop
);
703 // Step 2 : create the Crystal properties
704 Tango::DbDatum
properties("Crystal");
705 // Put number of properties (= nb of samples + 1)
706 len
= hkl_sample_list_len(_diffractometer
->samples
);
707 properties
<< (long)(len
+ 1);
708 data_put
.push_back(properties
);
710 // first property is the format version
711 Tango::DbDatum
version("_ver");
712 version
<< (long)FORMAT_VERSION
;
713 data_put
.push_back(version
);
716 for(k
=0; k
<len
; ++k
){
718 std::vector
<std::string
> lines
;
721 // the lattices values
722 sample
= hkl_sample_list_get_ith(_diffractometer
->samples
, k
);
723 double a
= hkl_parameter_get_value_unit(sample
->lattice
->a
);
724 double b
= hkl_parameter_get_value_unit(sample
->lattice
->b
);
725 double c
= hkl_parameter_get_value_unit(sample
->lattice
->c
);
726 double alpha
= hkl_parameter_get_value_unit(sample
->lattice
->alpha
);
727 double beta
= hkl_parameter_get_value_unit(sample
->lattice
->beta
);
728 double gamma
= hkl_parameter_get_value_unit(sample
->lattice
->gamma
);
730 int a_fit
= sample
->lattice
->a
->fit
;
731 int b_fit
= sample
->lattice
->b
->fit
;
732 int c_fit
= sample
->lattice
->c
->fit
;
733 int alpha_fit
= sample
->lattice
->alpha
->fit
;
734 int beta_fit
= sample
->lattice
->beta
->fit
;
735 int gamma_fit
= sample
->lattice
->gamma
->fit
;
737 snprintf(line
, 255, "lattice=%f;%f;%f;%f;%f;%f;%d;%d;%d;%d;%d;%d",
738 a
, b
, c
, alpha
, beta
, gamma
,
739 a_fit
, b_fit
, c_fit
, alpha_fit
, beta_fit
, gamma_fit
);
740 lines
.push_back(line
);
742 // the UxUyUz parameters
744 hkl_matrix_to_euler(&sample
->U
, &ux
, &uy
, &uz
);
749 snprintf(line
, 255, "uxuyuz=%f;%f;%f", ux
, uy
, uz
);
750 lines
.push_back(line
);
753 for(i
=0; i
<HKL_LIST_LEN(sample
->reflections
); ++i
) {
754 HklSampleReflection
*reflection
;
756 reflection
= hkl_sample_get_ith_reflection(sample
, i
);
757 double wavelength
= reflection
->geometry
->source
.wave_length
;
758 double h
= reflection
->hkl
.data
[0];
759 double k
= reflection
->hkl
.data
[1];
760 double l
= reflection
->hkl
.data
[2];
761 int flag
= reflection
->flag
;
763 snprintf(line
, 255, "reflection=%f;%f;%f;%f;%d",
764 wavelength
, h
, k
, l
, flag
);
765 // Extract values of each axes
766 for(j
=0; j
<HKL_LIST_LEN(reflection
->geometry
->axes
); ++j
) {
768 double rad
= hkl_axis_get_value_unit(&reflection
->geometry
->axes
[j
]);
769 snprintf(pos
, 255, ";%f", rad
);
770 strncat(line
, pos
, 255);
772 lines
.push_back(line
);
775 // Try to create property
777 Tango::DbDatum
property(sample
->name
);
779 data_put
.push_back(property
);
782 //update database for this property
783 _device
->get_db_device()->put_attribute_property(data_put
);
790 char const *TangoHKLAdapter::get_sample_name(void)
792 omni_mutex_lock
lock(_lock
);
794 HklSample
*sample
= _diffractometer
->samples
->current
;
801 void TangoHKLAdapter::set_current_sample(char const * name
)
803 omni_mutex_lock
lock(_lock
);
807 last
= _diffractometer
->samples
->current
;
808 if (HKL_SUCCESS
== hkl_sample_list_select_current(_diffractometer
->samples
, name
))
809 if (last
!= _diffractometer
->samples
->current
){
810 this->update_pseudo_axis_engines();
812 this->update_ux_uy_uz();
813 this->update_reflections_angles();
814 this->update_reflections();
815 this->update_state_and_status();
819 void TangoHKLAdapter::get_sample_lattices(double *a
, double *b
, double *c
,
820 double *alpha
, double *beta
, double *gamma
,
821 double *a_star
, double *b_star
, double *c_star
,
822 double *alpha_star
, double *beta_star
, double *gamma_star
)
824 omni_mutex_lock
lock(_lock
);
826 HklSample
* sample
= _diffractometer
->samples
->current
;
830 HklLattice
const *lattice
= sample
->lattice
;
831 HklLattice
*reciprocal
= hkl_lattice_new_copy(lattice
);
833 hkl_lattice_reciprocal(lattice
, reciprocal
);
836 *a
= hkl_parameter_get_value_unit(lattice
->a
);
837 *b
= hkl_parameter_get_value_unit(lattice
->b
);
838 *c
= hkl_parameter_get_value_unit(lattice
->c
);
839 *alpha
= hkl_parameter_get_value_unit(lattice
->alpha
);
840 *beta
= hkl_parameter_get_value_unit(lattice
->beta
);
841 *gamma
= hkl_parameter_get_value_unit(lattice
->gamma
);
844 *a_star
= hkl_parameter_get_value_unit(reciprocal
->a
);
845 *b_star
= hkl_parameter_get_value_unit(reciprocal
->b
);
846 *c_star
= hkl_parameter_get_value_unit(reciprocal
->c
);
847 *alpha_star
= hkl_parameter_get_value_unit(reciprocal
->alpha
);
848 *beta_star
= hkl_parameter_get_value_unit(reciprocal
->beta
);
849 *gamma_star
= hkl_parameter_get_value_unit(reciprocal
->gamma
);
851 hkl_lattice_free(reciprocal
);
854 void TangoHKLAdapter::get_sample_fit(bool *afit
, bool *bfit
, bool *cfit
,
855 bool *alphafit
, bool *betafit
, bool *gammafit
,
856 bool *uxfit
, bool *uyfit
, bool *uzfit
)
858 omni_mutex_lock
lock(_lock
);
860 HklSample
* sample
= _diffractometer
->samples
->current
;
864 HklLattice
const *lattice
= sample
->lattice
;
866 *afit
= lattice
->a
->fit
;
867 *bfit
= lattice
->b
->fit
;
868 *cfit
= lattice
->c
->fit
;
869 *alphafit
= lattice
->alpha
->fit
;
870 *betafit
= lattice
->beta
->fit
;
871 *gammafit
= lattice
->gamma
->fit
;
878 void TangoHKLAdapter::set_sample_Ux(double ux
)
882 sample
= _diffractometer
->samples
->current
;
884 if (HKL_SUCCESS
== hkl_sample_set_U_from_euler(sample
,
887 _uz
* HKL_DEGTORAD
)){
891 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set this Ux value",
892 "Set a correct value");
896 void TangoHKLAdapter::set_sample_Uy(double uy
)
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 Uy value",
910 "Set a correct value");
914 void TangoHKLAdapter::set_sample_Uz(double uz
)
918 sample
= _diffractometer
->samples
->current
;
920 if (HKL_SUCCESS
== hkl_sample_set_U_from_euler(sample
,
927 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set this Uz value",
928 "Set a correct value");
932 void TangoHKLAdapter::set_sample_AFit(bool fit
)
936 sample
= _diffractometer
->samples
->current
;
938 sample
->lattice
->a
->fit
= fit
;
941 void TangoHKLAdapter::set_sample_BFit(bool fit
)
945 sample
= _diffractometer
->samples
->current
;
947 sample
->lattice
->b
->fit
= fit
;
950 void TangoHKLAdapter::set_sample_CFit(bool fit
)
954 sample
= _diffractometer
->samples
->current
;
956 sample
->lattice
->c
->fit
= fit
;
959 void TangoHKLAdapter::set_sample_AlphaFit(bool fit
)
963 sample
= _diffractometer
->samples
->current
;
965 sample
->lattice
->alpha
->fit
= fit
;
968 void TangoHKLAdapter::set_sample_BetaFit(bool fit
)
972 sample
= _diffractometer
->samples
->current
;
974 sample
->lattice
->beta
->fit
= fit
;
977 void TangoHKLAdapter::set_sample_GammaFit(bool fit
)
981 sample
= _diffractometer
->samples
->current
;
983 sample
->lattice
->gamma
->fit
= fit
;
986 void TangoHKLAdapter::set_sample_UxFit(bool fit
)
990 sample
= _diffractometer
->samples
->current
;
992 _uxfit
= _uyfit
= _uzfit
= fit
;
995 void TangoHKLAdapter::set_sample_UyFit(bool fit
)
999 sample
= _diffractometer
->samples
->current
;
1001 _uxfit
= _uyfit
= _uzfit
= fit
;
1004 void TangoHKLAdapter::set_sample_UzFit(bool fit
)
1008 sample
= _diffractometer
->samples
->current
;
1010 _uxfit
= _uyfit
= _uzfit
= fit
;
1013 void TangoHKLAdapter::add_new_sample(std::string
const & name
)
1015 omni_mutex_lock
lock(_lock
);
1017 HklSample
*sample
= hkl_sample_new(name
.c_str(), HKL_SAMPLE_MONOCRYSTAL
);
1019 if (!hkl_sample_list_append(_diffractometer
->samples
, sample
)){
1020 hkl_sample_free(sample
);
1021 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not add a sample with this name",
1022 "A sample with the same name is already present in the sample list");
1026 void TangoHKLAdapter::copy_sample_as(Tango::DevString copy_name
)
1028 omni_mutex_lock
lock(_lock
);
1031 HklSample
const *current
;
1033 current
= _diffractometer
->samples
->current
;
1035 TANGO_EXCEPTION_THROW_WITHOUT_LOG("No current sample set",
1036 "Please set a current sample");
1038 sample
= hkl_sample_list_get_by_name(_diffractometer
->samples
, copy_name
);
1040 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not add a sample with this name",
1041 "A sample with the same name is already present in the sample list");
1043 sample
= hkl_sample_new_copy(current
);
1045 hkl_sample_set_name(sample
, copy_name
);
1046 hkl_sample_list_append(_diffractometer
->samples
, sample
);
1050 void TangoHKLAdapter::del_sample(void)
1052 omni_mutex_lock
lock(_lock
);
1054 HklSampleList
*samples
= _diffractometer
->samples
;
1055 hkl_sample_list_del(samples
, samples
->current
);
1057 // add a default sample if no more sample in the list
1058 if(hkl_sample_list_len(samples
) == 0){
1059 HklSample
*sample
= hkl_sample_new("default", HKL_SAMPLE_MONOCRYSTAL
);
1060 samples
->current
= hkl_sample_list_append(samples
, sample
);
1062 samples
->current
= hkl_sample_list_get_ith(samples
, 0);
1064 this->update_ux_uy_uz();
1065 this->update_reflections_angles();
1066 this->update_reflections();
1069 void TangoHKLAdapter::set_lattice(const Tango::DevVarDoubleArray
*argin
)
1071 omni_mutex_lock
lock(_lock
);
1073 if (argin
&& argin
->length() != 6)
1074 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1075 "Did not receive the exact amount of crystal parameters: A, B, C, alpha, beta, gamma");
1077 HklSample
*sample
= _diffractometer
->samples
->current
;
1078 if (HKL_FAIL
== hkl_sample_set_lattice(sample
,
1079 (*argin
)[0],(*argin
)[1], (*argin
)[2],
1080 (*argin
)[3] * HKL_DEGTORAD
,
1081 (*argin
)[4] * HKL_DEGTORAD
,
1082 (*argin
)[5] * HKL_DEGTORAD
))
1084 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set this lattice combination.",
1085 "Please set a good combination");
1087 this->update_reflections_angles();
1090 void TangoHKLAdapter::add_reflection(const Tango::DevVarDoubleArray
*argin
)
1092 omni_mutex_lock
lock(_lock
);
1094 HklSample
*sample
= _diffractometer
->samples
->current
;
1098 HklSampleReflection
*ref
;
1100 if(argin
&& argin
->length() == 3){
1105 HklPseudoAxisEngine
*engine
;
1107 engine
= hkl_pseudo_axis_engine_list_get_by_name(_diffractometer
->engines_r
, "hkl");
1109 h
= hkl_parameter_get_value_unit((HklParameter
*)engine
->pseudoAxes
[0]);
1110 k
= hkl_parameter_get_value_unit((HklParameter
*)engine
->pseudoAxes
[1]);
1111 l
= hkl_parameter_get_value_unit((HklParameter
*)engine
->pseudoAxes
[2]);
1114 ref
= hkl_sample_add_reflection(sample
,
1115 _diffractometer
->geometry_r
,
1116 _diffractometer
->detector
,
1119 this->update_reflections_angles();
1120 this->update_reflections();
1125 void TangoHKLAdapter::del_reflection(Tango::DevShort argin
)
1127 omni_mutex_lock
lock(_lock
);
1129 if (HKL_FAIL
== hkl_sample_del_reflection(_diffractometer
->samples
->current
, argin
))
1130 TANGO_EXCEPTION_THROW_WITHOUT_LOG("index out of range",
1131 "change the reflection index");
1132 this->update_reflections_angles();
1133 this->update_reflections();
1136 void TangoHKLAdapter::set_reflections(Matrix
<double> const & img
)
1138 omni_mutex_lock
lock(_lock
);
1140 HklSample
*sample
= _diffractometer
->samples
->current
;
1142 && img
.xdim
== _reflections
.xdim
1143 && img
.ydim
== _reflections
.ydim
) {
1147 for(i
=0; i
<HKL_LIST_LEN(sample
->reflections
); ++i
) {
1148 HklSampleReflection
*r
;
1150 r
= hkl_sample_get_ith_reflection(sample
, i
);
1152 hkl_sample_reflection_set_hkl(r
, img
.data
[j
+1], img
.data
[j
+2], img
.data
[j
+3]);
1153 hkl_sample_reflection_set_flag(r
, (int)img
.data
[j
+5]);
1154 if(!_device
->protectReflectionAxes
){
1159 len
= HKL_LIST_LEN(r
->geometry
->axes
);
1160 axes
= &r
->geometry
->axes
[0];
1162 for(k
=6; k
<6+len
; ++k
)
1163 hkl_axis_set_value_unit(axes
++, img
.data
[j
+k
]);
1165 hkl_geometry_update(r
->geometry
);
1166 hkl_sample_reflection_set_geometry(r
, r
->geometry
);
1169 j
+= _reflections
.xdim
;
1171 this->update_reflections();
1172 this->update_reflections_angles();
1176 double TangoHKLAdapter::affine_sample(std::string name
)
1178 omni_mutex_lock
lock(_lock
);
1183 sample
= hkl_sample_list_get_by_name(_diffractometer
->samples
, name
.c_str());
1187 // check if the affine sample is already in the HklSampleList
1188 std::string name
= sample
->name
;
1190 tmp
= hkl_sample_list_get_by_name(_diffractometer
->samples
, name
.c_str());
1191 hkl_sample_list_del(_diffractometer
->samples
, tmp
);
1193 tmp
= hkl_sample_new_copy(sample
);
1194 hkl_sample_set_name(tmp
, name
.c_str());
1195 res
= hkl_sample_affine(tmp
);
1197 hkl_sample_list_append(_diffractometer
->samples
, tmp
);
1198 _diffractometer
->samples
->current
= tmp
;
1201 this->update_ux_uy_uz();
1202 this->update_reflections_angles();
1209 std::vector
<std::string
> TangoHKLAdapter::get_samples_names(void)
1211 omni_mutex_lock
lock(_lock
);
1213 std::vector
<std::string
> names
;
1215 HklSampleList
*samples
= _diffractometer
->samples
;
1217 len
= hkl_sample_list_len(samples
);
1218 for(i
=0; i
<len
; ++i
)
1219 names
.push_back(hkl_sample_list_get_ith(samples
, i
)->name
);
1225 void TangoHKLAdapter::get_sample_parameter_values(Tango::DevVarDoubleStringArray
*argout
)
1227 omni_mutex_lock
lock(_lock
);
1230 HklParameter
*parameter
= NULL
;
1234 if (argout
->svalue
.length() != 1)
1235 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1236 "only one string = parameter name");
1238 sample
= _diffractometer
->samples
->current
;
1241 name
= argout
->svalue
[0];
1243 parameter
= sample
->lattice
->a
;
1244 else if(name
== "b")
1245 parameter
= sample
->lattice
->b
;
1246 else if(name
== "c")
1247 parameter
= sample
->lattice
->c
;
1248 else if(name
== "alpha")
1249 parameter
= sample
->lattice
->alpha
;
1250 else if(name
== "beta")
1251 parameter
= sample
->lattice
->beta
;
1252 else if(name
== "gamma")
1253 parameter
= sample
->lattice
->gamma
;
1256 argout
->dvalue
[0] = parameter
->range
.min
;
1257 argout
->dvalue
[1] = parameter
->range
.max
;
1258 argout
->dvalue
[2] = parameter
->fit
;
1260 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Wrong parameter name",
1261 "Select: a, b, c, alpha, beta, gamma");
1266 void TangoHKLAdapter::set_sample_parameter_values(Tango::DevVarDoubleStringArray
const *argin
)
1268 omni_mutex_lock
lock(_lock
);
1271 HklParameter
*parameter
= NULL
;
1275 if(argin
->dvalue
.length() != 3)
1276 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1277 "set_crystal_parameter_values did not receive the right amount of scalar parameters: min, max, flag");
1278 if((argin
->svalue
.length() ) != 1)
1279 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1280 "set_crystal_parameter_values did not receive the right amount of string parameters: parameter name");
1283 sample
= _diffractometer
->samples
->current
;
1285 TANGO_EXCEPTION_THROW_WITHOUT_LOG("No current sample set",
1286 "Please set a current sample");
1288 name
= argin
->svalue
[0];
1290 parameter
= sample
->lattice
->a
;
1291 else if(name
== "b")
1292 parameter
= sample
->lattice
->b
;
1293 else if(name
== "c")
1294 parameter
= sample
->lattice
->c
;
1295 else if(name
== "alpha")
1296 parameter
= sample
->lattice
->alpha
;
1297 else if(name
== "beta")
1298 parameter
= sample
->lattice
->beta
;
1299 else if(name
== "gamma")
1300 parameter
= sample
->lattice
->gamma
;
1303 parameter
->range
.min
= argin
->dvalue
[0];
1304 parameter
->range
.max
= argin
->dvalue
[1];
1305 parameter
->fit
= argin
->dvalue
[2] != 0.;
1307 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Wrong parameter name",
1308 "Select: a, b, c, alpha, beta, gamma");
1310 this->update_ux_uy_uz();
1311 this->update_reflections_angles();
1314 void TangoHKLAdapter::compute_u(const Tango::DevVarLongArray
*argin
)
1316 omni_mutex_lock
lock(_lock
);
1320 // is parameter ok ?
1321 if (argin
->length() != 2)
1322 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Need exactly two reflections indexes",
1323 "use the right number of parameters");
1325 sample
= _diffractometer
->samples
->current
;
1327 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not compute the U matrix without current sample set.",
1328 "Set a current sample");
1330 if (hkl_sample_compute_UB_busing_levy(sample
, (*argin
)[0], (*argin
)[1]))
1331 TANGO_EXCEPTION_THROW_WITHOUT_LOG("can not compute the UB matrix using thoses reflections index",
1332 "Use other reflections");
1334 this->update_ux_uy_uz();
1341 void TangoHKLAdapter::read_axis(int idx
, double & read
, double & write
)
1343 omni_mutex_lock
lock(_lock
);
1345 AxisAdapter
& axis
= _axes
[idx
];
1346 read
= axis
.get_read();
1347 write
= axis
.get_write();
1350 void TangoHKLAdapter::stop_all_axis(void)
1352 #ifdef WRITE_TO_PROXY_ALLOWED
1354 for(i
=0; i
<_axes
.size(); ++i
)
1359 void TangoHKLAdapter::write_axis(AxisAdapter
& axis
, double value
)
1361 omni_mutex_lock
lock(_lock
);
1365 this->write_axis_i(axis
, value
);
1367 // when we write on an Axis you must let all pseudo axes be synchronized
1368 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
1369 _pseudoAxesAdapters
[i
]->_synchronize
= true;
1372 void TangoHKLAdapter::write_axis_i(AxisAdapter
& axis
, double value
)
1374 axis
._read
= axis
._write
= value
;
1375 hkl_axis_set_value_unit(axis
._axis_r
, value
);
1376 hkl_axis_set_value_unit(axis
._axis_w
, value
);
1379 /*******************/
1380 /* pseudoAxis part */
1381 /*******************/
1383 std::vector
<std::string
> TangoHKLAdapter::pseudo_axis_get_names(void)
1385 omni_mutex_lock
lock(_lock
);
1387 std::vector
<std::string
> names
;
1390 for(i
=0; i
<HKL_LIST_LEN(_diffractometer
->engines_r_real
->engines
); ++i
){
1391 HklPseudoAxisEngine
*engine
;
1393 engine
= _diffractometer
->engines_r_real
->engines
[i
];
1394 for(j
=0; j
<HKL_LIST_LEN(engine
->pseudoAxes
); ++j
)
1395 names
.push_back(((HklParameter
*)(&engine
->pseudoAxes
[j
]))->name
);
1401 PseudoAxisAdapter
*TangoHKLAdapter::pseudo_axis_buffer_new(char const *name
)
1403 omni_mutex_lock
lock(_lock
);
1405 PseudoAxisAdapter
* buffer
= NULL
;
1406 HklPseudoAxis
*pseudo_r
;
1407 HklPseudoAxis
*pseudo_w
;
1409 pseudo_r
= hkl_pseudo_axis_engine_list_get_pseudo_axis_by_name(
1410 _diffractometer
->engines_r_real
, name
);
1411 pseudo_w
= hkl_pseudo_axis_engine_list_get_pseudo_axis_by_name(
1412 _diffractometer
->engines_w_real
, name
);
1414 if(pseudo_r
&& pseudo_w
) {
1417 buffer
= new PseudoAxisAdapter(*this, pseudo_r
, pseudo_w
);
1418 _pseudoAxisAdapters
.push_back(buffer
);
1420 catch (Tango::DevFailed
)
1429 void TangoHKLAdapter::pseudo_axis_set_initialized(PseudoAxisAdapter
*buffer
,
1430 Tango::DevBoolean initialized
)
1435 omni_mutex_lock
lock(_lock
);
1437 hkl_pseudo_axis_engine_initialize(buffer
->_pseudo_r
->engine
);
1438 hkl_pseudo_axis_engine_initialize(buffer
->_pseudo_w
->engine
);
1442 void TangoHKLAdapter::pseudo_axis_set_position(PseudoAxisAdapter
*buffer
,
1443 const Tango::DevDouble
& position
)
1445 omni_mutex_lock
lock(_lock
);
1447 double value
= position
- buffer
->_config
.offset
;
1450 HklPseudoAxisEngineList
*engines_w_real
= _diffractometer
->engines_w_real
;
1451 HklPseudoAxisEngine
*engine
= buffer
->_pseudo_w
->engine
;
1452 HklGeometry
*geometry_w_real
= _diffractometer
->geometry_w_real
;
1454 hkl_parameter_set_value_unit((HklParameter
*)buffer
->_pseudo_w
, value
);
1455 res
= hkl_pseudo_axis_engine_set(buffer
->_pseudo_w
->engine
);
1456 if (HKL_SUCCESS
== res
){
1457 hkl_geometry_init_geometry(geometry_w_real
, engine
->engines
->geometries
->geometries
[0]);
1458 hkl_pseudo_axis_engine_list_get(engines_w_real
);
1461 this->update_angles();
1462 buffer
->to_proxies();
1463 this->update_axis_adapters();
1464 this->update_pseudo_axis_adapters_from_hkl();
1465 this->update_pseudo_axes_adapters_from_hkl();
1467 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not write on this pseudo axis",
1468 "Check the sample");
1472 PseudoAxisConfig
TangoHKLAdapter::pseudo_axis_get_config(PseudoAxisAdapter
*buffer
)
1476 omni_mutex_lock
lock(_lock
);
1478 return buffer
->_config
;
1481 void TangoHKLAdapter::pseudo_axis_set_mode(PseudoAxisAdapter
*buffer
, Tango::DevString
const & mode
)
1483 omni_mutex_lock
lock(_lock
);
1487 len
= HKL_LIST_LEN(buffer
->_pseudo_r
->engine
->modes
);
1488 for(i
=0; i
<len
; ++i
)
1489 if(!strcasecmp(mode
, buffer
->_pseudo_r
->engine
->modes
[i
]->name
))
1492 hkl_pseudo_axis_engine_select_mode(buffer
->_pseudo_r
->engine
, i
);
1493 hkl_pseudo_axis_engine_select_mode(buffer
->_pseudo_w
->engine
, i
);
1497 void TangoHKLAdapter::pseudo_axis_get_mode_parameters(PseudoAxisAdapter
*buffer
, Tango::DevVarDoubleStringArray
*argout
)
1499 omni_mutex_lock
lock(_lock
);
1501 HklPseudoAxisEngine
*engine
= buffer
->_pseudo_r
->engine
;
1502 if (engine
&& engine
->mode
){
1504 size_t len
= HKL_LIST_LEN(engine
->mode
->parameters
);
1506 argout
->svalue
.length(len
);
1507 argout
->dvalue
.length(len
);
1508 for(i
=0; i
<len
; ++i
){
1509 argout
->svalue
[i
] = CORBA::string_dup(engine
->mode
->parameters
[i
].name
);
1510 argout
->dvalue
[i
] = hkl_parameter_get_value_unit(&engine
->mode
->parameters
[i
]);
1513 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not get the current Mode parameters values without a current mode set.",
1517 void TangoHKLAdapter::pseudo_axis_set_mode_parameters(PseudoAxisAdapter
*buffer
, const Tango::DevVarDoubleStringArray
*argin
)
1519 omni_mutex_lock
lock(_lock
);
1521 if(argin
->svalue
.length() != argin
->dvalue
.length())
1522 TANGO_EXCEPTION_THROW_WITHOUT_LOG("DATA_OUT_OF_RANGE",
1523 "set_mode_parameters_values did not receive the same amount between string and double values");
1525 HklPseudoAxisEngine
*engine_r
= buffer
->_pseudo_r
->engine
;
1526 HklPseudoAxisEngine
*engine_w
= buffer
->_pseudo_w
->engine
;
1527 if (engine_r
&& engine_w
){
1531 len
= argin
->svalue
.length();
1532 if (HKL_LIST_LEN(engine_r
->mode
->parameters
) != len
)
1533 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Not the right number of parameter",
1534 "gives the right number of parameters");
1536 for(i
=0; i
<len
; ++i
){
1537 double value
= argin
->dvalue
[i
];
1538 char const *name
= argin
->svalue
[i
];
1539 if(!strcmp(name
, engine_r
->mode
->parameters
[i
].name
)){
1540 hkl_parameter_set_value_unit(&engine_r
->mode
->parameters
[i
], value
);
1541 hkl_parameter_set_value_unit(&engine_w
->mode
->parameters
[i
], value
);
1545 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not set the current Mode parameters values without a current mode set.",
1549 void TangoHKLAdapter::pseudo_axis_on(PseudoAxisAdapter
*buffer
)
1551 omni_mutex_lock
lock(_lock
);
1553 for(size_t i
=0; i
<buffer
->_axes
.size(); ++i
)
1554 buffer
->_axes
[i
]->on();
1557 /*******************/
1558 /* pseudoAxes part */
1559 /*******************/
1561 PseudoAxesAdapter
*TangoHKLAdapter::pseudo_axes_adapter_get_by_name(std::string
const & name
)
1563 //omni_mutex_lock lock(_lock);
1566 PseudoAxesAdapter
*adapter
= NULL
;
1568 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
1569 if(_pseudoAxesAdapters
[i
]->get_name() == name
){
1570 adapter
= _pseudoAxesAdapters
[i
];
1576 PseudoAxesConfig
TangoHKLAdapter::pseudo_axes_get_config(size_t idx
)
1580 omni_mutex_lock
lock(_lock
);
1582 return _pseudoAxesAdapters
[idx
]->_config
;
1585 void TangoHKLAdapter::pseudo_axes_set_axis_value(size_t idx
, size_t p_idx
, double value
)
1587 omni_mutex_lock
lock(_lock
);
1591 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
1593 // first unsynchronize the current PseudoAxes
1594 _pseudoAxesAdapters
[i
]->_synchronize
= false;
1595 _pseudoAxesAdapters
[i
]->_config
.write
.data
[p_idx
] = value
;
1597 // resynchronize all other pseudoAxes
1598 _pseudoAxesAdapters
[i
]->_synchronize
= true;
1602 void TangoHKLAdapter::pseudo_axes_apply(size_t idx
, Matrix
<double> const & write
) throw (Tango::DevFailed
)
1604 omni_mutex_lock
lock(_lock
);
1608 HklPseudoAxisEngineList
*engines_r
, *engines_w
;
1609 HklGeometry
*geometry_r
, *geometry_w
;
1611 engines_r
= _diffractometer
->engines_r
;
1612 engines_w
= _diffractometer
->engines_w
;
1613 len
= HKL_LIST_LEN(engines_w
->engines
[idx
]->pseudoAxes
);
1615 geometry_r
= _diffractometer
->geometry_r
;
1616 geometry_w
= _diffractometer
->geometry_w
;
1618 for(i
=0; i
<len
; ++i
)
1619 hkl_parameter_set_value_unit((HklParameter
*)(engines_w
->engines
[idx
]->pseudoAxes
[i
]), write
.data
[i
]);
1621 res
= hkl_pseudo_axis_engine_set(engines_w
->engines
[idx
]);
1623 if (HKL_SUCCESS
== res
){
1624 // force auto update OFF when we write on a PseudoAxes.
1625 _auto_update_from_proxies
= false;
1627 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
1628 _pseudoAxesAdapters
[i
]->_synchronize
= true;
1630 hkl_geometry_init_geometry(geometry_w
, engines_w
->geometries
->geometries
[0]);
1631 hkl_pseudo_axis_engine_list_get(engines_w
);
1632 hkl_geometry_init_geometry(geometry_r
, engines_w
->geometries
->geometries
[0]);
1633 hkl_pseudo_axis_engine_list_get(engines_r
);
1636 this->update_angles();
1637 this->update_axis_adapters();
1638 this->update_pseudo_axis_adapters_from_hkl();
1639 this->update_pseudo_axes_adapters_from_hkl();
1641 TANGO_EXCEPTION_THROW_WITHOUT_LOG("Can not write on this pseudo axis",
1642 "Check the sample");
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();
1673 void TangoHKLAdapter::pseudo_axes_set_mode_parameters(size_t idx
, Matrix
<double> const & values
)
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 if(len
== values
.xdim
)
1681 for(i
=0; i
<len
; ++i
){
1682 double & value
= values
.data
[i
];
1684 hkl_parameter_set_value_unit(&_diffractometer
->engines_r
->engines
[idx
]->mode
->parameters
[i
],
1686 hkl_parameter_set_value_unit(&_diffractometer
->engines_w
->engines
[idx
]->mode
->parameters
[i
],
1688 hkl_parameter_set_value_unit(&_diffractometer
->engines_r_real
->engines
[idx
]->mode
->parameters
[i
],
1690 hkl_parameter_set_value_unit(&_diffractometer
->engines_w_real
->engines
[idx
]->mode
->parameters
[i
],
1695 void TangoHKLAdapter::pseudo_axes_init(size_t idx
)
1697 // temporary until the CAPOEIRA applycation has been modify
1698 if(_diffractometer
->engines_r
->engines
[idx
]->mode
->initialize
){
1699 omni_mutex_lock
lock(_lock
);
1701 HklPseudoAxisEngine
*engine_r
= _diffractometer
->engines_r
->engines
[idx
];
1702 HklPseudoAxisEngine
*engine_w
= _diffractometer
->engines_w
->engines
[idx
];
1703 HklPseudoAxisEngine
*engine_r_real
= _diffractometer
->engines_r_real
->engines
[idx
];
1704 HklPseudoAxisEngine
*engine_w_real
= _diffractometer
->engines_w_real
->engines
[idx
];
1706 hkl_pseudo_axis_engine_initialize(engine_r
);
1707 hkl_pseudo_axis_engine_initialize(engine_w
);
1708 hkl_pseudo_axis_engine_initialize(engine_r_real
);
1709 hkl_pseudo_axis_engine_initialize(engine_w_real
);
1711 this->pseudo_axes_apply(idx
, _pseudoAxesAdapters
[idx
]->_config
.write
);
1714 void TangoHKLAdapter::pseudo_axes_add_dynamic_attributes(size_t idx
)
1718 // check if all the PseudoAxes were instantiated
1719 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
1720 if(!_pseudoAxesAdapters
[i
]->_device
)
1724 * we need to attach the dynamic attributes after all instance of
1725 * the PseudoAxes devices were started. otherwise it cause problem.
1726 * only add the attributs if they were not already added.
1728 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
)
1729 _pseudoAxesAdapters
[i
]->add_dynamic_attributes_i();
1732 void TangoHKLAdapter::pseudo_axes_remove_dynamic_attributes(size_t idx
)
1735 PseudoAxesAdapter
*adapter
;
1737 adapter
= _pseudoAxesAdapters
[idx
];
1738 if(adapter
->_device
){
1739 for(i
=0; i
<adapter
->_dynamic_attribute_pseudo_axes_axis
.size(); ++i
)
1740 adapter
->_device
->remove_attribute(adapter
->_dynamic_attribute_pseudo_axes_axis
[i
], false);
1741 adapter
->_device
= NULL
;
1745 void TangoHKLAdapter::pseudo_axes_create_and_start_devices(void)
1747 omni_mutex_lock
lock(_lock
);
1751 Tango::Util
*tg
= Tango::Util::instance();
1752 Tango::Database
*db
= tg
->get_database();
1753 for(i
=0; i
<_pseudoAxesAdapters
.size(); ++i
){
1754 std::string dev_name
= _pseudoAxesAdapters
[i
]->get_proxy_name();
1756 // first check if the device is already defined in the database
1758 Tango::DbDevImportInfo my_device_import_info
;
1760 my_device_import_info
= db
->import_device(dev_name
);
1761 } catch (Tango::DevFailed
&) {
1762 Tango::DbDevInfo my_device_info
;
1764 // add the device to the database
1765 my_device_info
.name
= dev_name
.c_str();
1766 my_device_info
._class
= "PseudoAxes";
1767 my_device_info
.server
= tg
->get_ds_name().c_str();
1769 db
->add_device(my_device_info
);
1771 // add the right properties to that device
1772 Tango::DbDatum
DiffractometerProxy("DiffractometerProxy"), EngineName("EngineName");
1773 Tango::DbData properties
;
1774 DiffractometerProxy
<< _device
->name();
1775 EngineName
<< _pseudoAxesAdapters
[i
]->get_name();
1776 properties
.push_back(DiffractometerProxy
);
1777 properties
.push_back(EngineName
);
1778 db
->put_device_property(dev_name
,properties
);
1781 // now start the device
1782 const std::vector
<Tango::DeviceClass
*> *cl_list
= tg
->get_class_list();
1783 for(j
=0; j
<cl_list
->size(); ++j
){
1784 if((*cl_list
)[j
]->get_name() == "PseudoAxes"){
1786 Tango::DevVarStringArray na
;
1788 na
[0] = dev_name
.c_str();
1789 (*cl_list
)[j
]->device_factory(&na
);
1790 std::cout
<< "Started " << dev_name
<< std::endl
;
1793 catch (Tango::DevFailed
&e
)
1802 void TangoHKLAdapter::pseudo_axes_set_initialized(size_t idx
, bool initialized
)
1807 omni_mutex_lock
lock(_lock
);
1809 HklPseudoAxisEngine
*engine_r
= _diffractometer
->engines_r
->engines
[idx
];
1810 HklPseudoAxisEngine
*engine_w
= _diffractometer
->engines_w
->engines
[idx
];
1811 HklPseudoAxisEngine
*engine_r_real
= _diffractometer
->engines_r_real
->engines
[idx
];
1812 HklPseudoAxisEngine
*engine_w_real
= _diffractometer
->engines_w_real
->engines
[idx
];
1814 hkl_pseudo_axis_engine_initialize(engine_r
);
1815 hkl_pseudo_axis_engine_initialize(engine_w
);
1816 hkl_pseudo_axis_engine_initialize(engine_r_real
);
1817 hkl_pseudo_axis_engine_initialize(engine_w_real
);
1821 /**********************/
1822 /* Dynamic attributes */
1823 /**********************/
1825 void TangoHKLAdapter::create_axes_dynamic_attributes(void)
1828 size_t len
= _axes
.size();
1829 _dynamic_attribute_axes_names
.resize(len
, 1);
1830 for(i
=0; i
<len
; ++i
){
1835 // compute the diffractometer axis names
1838 name
+= _axes
[i
].get_name();
1839 name
[l
] = toupper(name
[l
]);
1841 // create the AxisAttrib to deal with the proxy connection.
1842 att
= new AxisAttrib(name
.c_str(), _axes
[i
]);
1843 _dynamic_attribute_axes
.push_back(att
);
1844 _dynamic_attribute_axes_names
.data
[i
] = const_cast<char *>(att
->get_name().c_str());
1848 void TangoHKLAdapter::destroy_axes_dynamic_attributes(void)
1851 size_t len
= _dynamic_attribute_axes
.size();
1853 for(i
=0; i
<len
; ++i
)
1854 delete _dynamic_attribute_axes
[i
];
1857 void TangoHKLAdapter::attach_dynamic_attributes_to_device(void)
1861 for(i
=0; i
<_dynamic_attribute_axes
.size(); ++i
)
1862 _device
->add_attribute(_dynamic_attribute_axes
[i
]);
1866 void TangoHKLAdapter::detach_dynamic_attributes_from_device(void)
1870 for(i
=0; i
<_dynamic_attribute_axes
.size(); ++i
)
1871 _device
->remove_attribute(_dynamic_attribute_axes
[i
], false);
1875 bool TangoHKLAdapter::get_auto_update_from_proxies(void)
1877 omni_mutex_lock
lock(_lock
);
1879 return _auto_update_from_proxies
;
1882 void TangoHKLAdapter::set_auto_update_from_proxies(bool update
)
1884 bool old
= _auto_update_from_proxies
;
1885 _auto_update_from_proxies
= update
;
1886 if(old
= false && update
== true)
1892 std::string
hkl_axes_consign_as_string(HklAxis
const **axes
, size_t axes_len
)
1897 std::ostringstream line
, tmp
;
1898 for(i
=0; i
<axes_len
; ++i
) {
1899 HklParameter
const *axis
= (HklParameter
const *)axes
[i
];
1900 double value
= hkl_parameter_get_value_unit(axis
);
1905 std::ostringstream tmp
;
1907 tmp
<< value
<< "°";