Skip to content
Snippets Groups Projects
AccessConf.cpp 78.2 KiB
Newer Older
/*----- PROTECTED REGION ID(AccessConf.cpp) ENABLED START -----*/
//=============================================================================
//
// file :        AccessConf.cpp
//
// description : C++ source for the AccessConf and its commands.
//               The class is derived from Device. It represents the
//               CORBA servant object which will be accessed from the
//               network. All commands which can be executed on the
//               AccessConf are implemented in this file.
//
// project :     Storage Ring Access.
//
// $Author: graziano $
//
// $Revision: 1.18 $
// $Date: 2019-11-06 08:28:04 $
//
// SVN only:
// $HeadURL:  $
//
// CVS only:
// $Source: /home/cvsadm/cvsroot/fermi/servers/accessconf/src/AccessConf.cpp,v $
// $Log: AccessConf.cpp,v $
// Revision 1.18  2019-11-06 08:28:04  graziano
// fixed archive events thresholds
//
// Revision 1.17  2019-11-06 08:23:36  graziano
// Added cutoff_ind to change/disable index for cutoff
//
// Revision 1.16  2019-02-06 16:06:41  graziano
// fixed ValveStat[4] (abi) value if not spare
//
// Revision 1.15  2019-01-17 12:31:49  graziano
// fixed
//
// Revision 1.14  2019-01-17 12:28:38  graziano
// fixed initial state/status
//
// Revision 1.13  2019-01-17 11:38:51  graziano
// Initialized state/status
//
// Revision 1.12  2018-12-31 14:19:50  graziano
// fixed 101 commands
//
// Revision 1.11  2018-12-31 14:07:59  graziano
// in valvestat fixed limit of 7 for inverted bits
//
// Revision 1.10  2018-06-26 10:22:42  graziano
// removed push event on status
//
// Revision 1.9  2017-08-23 14:16:23  claudio
// #1554 tango-9.2.5a
//
// Revision 1.8  2017-08-09 12:09:00  graziano
// fixed string attributes
//
// Revision 1.7  2016-11-21 09:06:22  graziano
// added archive event
//
// Revision 1.6  2016-01-07 10:44:44  graziano
// fixed
//
// Revision 1.5  2014-05-12 14:21:33  graziano
// fixed event errors
//
// Revision 1.4  2014-04-24 13:35:13  graziano
// fixed sync read
//
// Revision 1.3  2013-08-20 07:06:01  graziano
// event support
//
// Revision 1.2  2012-10-31 17:40:12  graziano
// fixed for valves
//
// Revision 1.1  2012-10-30 09:29:15  graziano
// *** empty log message ***
//
//
//
//=============================================================================
//                This file is generated by POGO
//        (Program Obviously used to Generate tango Object)
//=============================================================================


#include <AccessConf.h>
#include <AccessConfClass.h>
#include <math.h>
#include <stdint.h>

const char srvver[] = RELEASE;

/*----- PROTECTED REGION END -----*/


/**
 *	AccessConf class description:
 *	
 */

//================================================================
//
//  The following table gives the correspondence
//  between command and method names.
//
//  Command name  |  Method name
//----------------------------------------------------------------
//  State         |  Inherited (no method)
//  Status        |  Inherited (no method)
//================================================================

namespace AccessConf_ns
{
	/*----- PROTECTED REGION ID(AccessConf::namespace_starting) ENABLED START -----*/

	//	static initializations
bool compare_attr_index (attr_desc_t i,attr_desc_t j) { return (i.attr_index < j.attr_index); }
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000

	/*----- PROTECTED REGION END -----*/	//	AccessConf::namespace_starting



//--------------------------------------------------------
/**
 *	Method      : AccessConf::AccessConf()
 *	Description : Constructors for a Tango device
 *	              implementing the class AccessConf
 */
//--------------------------------------------------------
AccessConf::AccessConf(Tango::DeviceClass *cl, string &s)
 	: TANGO_BASE_CLASS(cl, s.c_str())
{
	/*----- PROTECTED REGION ID(AccessConf::constructor_1) ENABLED START -----*/

	init_device();

	/*----- PROTECTED REGION END -----*/	//	AccessConf::constructor_1
}
//--------------------------------------------------------
AccessConf::AccessConf(Tango::DeviceClass *cl, const char *s)
 	: TANGO_BASE_CLASS(cl, s)
{
	/*----- PROTECTED REGION ID(AccessConf::constructor_2) ENABLED START -----*/

	init_device();

	/*----- PROTECTED REGION END -----*/	//	AccessConf::constructor_2
}
//--------------------------------------------------------
AccessConf::AccessConf(Tango::DeviceClass *cl, const char *s, const char *d)
 	: TANGO_BASE_CLASS(cl, s, d)
{
	/*----- PROTECTED REGION ID(AccessConf::constructor_3) ENABLED START -----*/

	init_device();

	/*----- PROTECTED REGION END -----*/	//	AccessConf::constructor_3
}


//--------------------------------------------------------
/**
 *	Method      : AccessConf::delete_device()()
 *	Description : will be called at device destruction or at init command
 */
//--------------------------------------------------------
void AccessConf::delete_device()
{
	/*----- PROTECTED REGION ID(AccessConf::delete_device) ENABLED START -----*/

	//	Delete device allocated objects
	DEBUG_STREAM << __FUNCTION__<<": entering..." << endl;
	delete[] attr_status_read;

	/*----- PROTECTED REGION END -----*/	//	AccessConf::delete_device
	delete[] attr_BoolScalarDyn_read;
	delete[] attr_BoolSpectrumDyn_read;
	delete[] attr_StringSpectrumDyn_read;
	delete[] attr_Version_read;
	
	delete lldevice;

}


//--------------------------------------------------------
/**
 *	Method      : AccessConf::init_device()
 *	Description : //	will be called at device initialization.
 */
//--------------------------------------------------------
void AccessConf::init_device()
{
	DEBUG_STREAM << "AccessConf::init_device() create device " << device_name << endl;

	/*----- PROTECTED REGION ID(AccessConf::init_device_before) ENABLED START -----*/

	//	Initialization before get_device_property() call
	ValveStat_initialized = false;
	created_attr = false;
	set_change_event("State", true, false);		//attribute name, implemented, detect, if not setting detect=false have to set abs_change or
	set_archive_event("State", true, true);		//attribute name, implemented, detect, if not setting detect=false have to set abs_change or
	//set_change_event("Status", true, false);		//attribute name, implemented, detect, if not setting detect=false have to set abs_change or
	ecb.init(this);
	/*----- PROTECTED REGION END -----*/	//	AccessConf::init_device_before
	
	//	Get the device properties (if any) from database
	get_device_property();
	
	attr_BoolScalarDyn_read = new Tango::DevBoolean[1];
	attr_BoolSpectrumDyn_read = new Tango::DevBoolean[MAX_ATTR_SIZE];
	attr_StringSpectrumDyn_read = new Tango::DevString[MAX_ATTR_SIZE];
	attr_Version_read = new Tango::DevString[1];
	
	/*----- PROTECTED REGION ID(AccessConf::init_device) ENABLED START -----*/
	lldevice = new Tango::DeviceProxy(low_level_srv);
	try {
		if (lldevice->ping())
		{
			set_state(Tango::ON);
			set_status("Connected to device " + low_level_srv);
			state_event = Tango::ON;
			sprintf(status_str,"Connected to device %s", low_level_srv.c_str());
		}
	}
	catch(Tango::DevFailed &e)
	{
		set_state(Tango::UNKNOWN);
		set_status("Failed to connect to device " + low_level_srv);
		state_event = Tango::UNKNOWN;
		sprintf(status_str,"Failed to connect to device %s", low_level_srv.c_str());
	}

	attr_status_read = new Tango::DevString[1];
	attr_status_read[0] = (char *)status_str;
	//	Initialize device
	gettimeofday(&last_read, NULL);

	/*----- PROTECTED REGION END -----*/	//	AccessConf::init_device
}



//--------------------------------------------------------
/**
 *	Method      : AccessConf::get_device_property()
 *	Description : //	Add your own code to initialize
 */
//--------------------------------------------------------
void AccessConf::get_device_property()
{
	/*----- PROTECTED REGION ID(AccessConf::get_device_property_before) ENABLED START -----*/

	//	Initialize property data members

	/*----- PROTECTED REGION END -----*/	//	AccessConf::get_device_property_before


	//	Read device properties from database.
	Tango::DbData	dev_prop;
	dev_prop.push_back(Tango::DbDatum("Low_level_srv"));
	dev_prop.push_back(Tango::DbDatum("Attr_config_file"));
	dev_prop.push_back(Tango::DbDatum("Attr_config_prop"));
	dev_prop.push_back(Tango::DbDatum("Cutoff_ind"));

	//	is there at least one property to be read ?
	if (dev_prop.size()>0)
	{
		//	Call database and extract values
		if (Tango::Util::instance()->_UseDb==true)
			get_db_device()->get_property(dev_prop);
	
		//	get instance on AccessConfClass to get class property
		Tango::DbDatum	def_prop, cl_prop;
		AccessConfClass	*ds_class =
			(static_cast<AccessConfClass *>(get_device_class()));
		int	i = -1;

		//	Try to initialize Low_level_srv from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  low_level_srv;
		else {
			//	Try to initialize Low_level_srv from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  low_level_srv;
		}
		//	And try to extract Low_level_srv value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  low_level_srv;

		//	Try to initialize Attr_config_file from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  attr_config_file;
		else {
			//	Try to initialize Attr_config_file from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  attr_config_file;
		}
		//	And try to extract Attr_config_file value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  attr_config_file;

		//	Try to initialize Attr_config_prop from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  attr_config_prop;
		else {
			//	Try to initialize Attr_config_prop from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  attr_config_prop;
		}
		//	And try to extract Attr_config_prop value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  attr_config_prop;

		//	Try to initialize Cutoff_ind from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  cutoff_ind;
		else {
			//	Try to initialize Cutoff_ind from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  cutoff_ind;
		}
		//	And try to extract Cutoff_ind value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  cutoff_ind;


	}
	/*----- PROTECTED REGION ID(AccessConf::get_device_property_after) ENABLED START -----*/

	//	Check device property data members init

	/*----- PROTECTED REGION END -----*/	//	AccessConf::get_device_property_after

}

//--------------------------------------------------------
/**
 *	Method      : AccessConf::always_executed_hook()
 *	Description : method always executed before any command is executed
 */
//--------------------------------------------------------
void AccessConf::always_executed_hook()
{
	//INFO_STREAM << "AccessConf::always_executed_hook()  " << device_name << endl;
	/*----- PROTECTED REGION ID(AccessConf::always_executed_hook) ENABLED START -----*/

	//	code always executed before all requests
#if 0
	if(ValveStat_initialized)
	{
    map<string,attr_val_t >::iterator it_val = att_value.find("ValveStat");

	if((it_val->second.val[5])||(it_val->second.val[6])/*||(!valve_stat[2])*/)
	{//error occurred

		state_event = Tango::FAULT;
		if(it_val->second.val[5])
		{
			strcpy(status_str,"error opening");
		}
		if(it_val->second.val[6])
		{
			strcpy(status_str,"error closing");
		}
		set_state(state_event);
		set_status(status_str);
		DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING FAULT ("<<status_str<<") "<<endl;
		try {
			push_change_event("state");
			push_archive_event("state");
			push_change_event("status");
		} catch(Tango::DevFailed &e)
		{
			DEBUG_STREAM << __func__<<": error pushing state="<<e.errors[0].desc<<endl;
		}
		//	if(!valve_stat[2]){
		//		set_status("pressure not ok");
		//	}
	}
	else
	{//no errors
		if(it_val->second.val[0]){//opened?
			if(it_val->second.val[1])
			{//closed? error

				state_event = Tango::FAULT;
				strcpy(status_str,"SW both closed");
				set_state(state_event);
				set_status(status_str);
				DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING FAULT ("<<status_str<<") "<<endl;
				try {
					push_change_event("state");
					push_archive_event("state");
					push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
			}
			else
			{//opened

				state_event = Tango::OPEN;
				strcpy(status_str,"----");
				set_state(state_event);
				set_status(status_str);
				DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING OPEN ("<<status_str<<") "<<endl;
				try {
					push_change_event("state");
					push_archive_event("state");
					push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
			}
		}
		else
		{
			if(it_val->second.val[1])
			{//closed?

				state_event = Tango::CLOSE;
				strcpy(status_str,"----");
				set_state(state_event);
				set_status(status_str);
				DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING CLOSE ("<<status_str<<") "<<endl;
				try {
					push_change_event("state");
					push_archive_event("state");
					push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
			}
			else
			{//moving

				state_event = Tango::MOVING;
				strcpy(status_str,"SW both opened");
				set_state(state_event);
				set_status(status_str);
				DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING MOVING ("<<status_str<<") "<<endl;
				try {
					push_change_event("state");
					push_archive_event("state");
					push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
			}
		}
//		if(is_local_ctrl){
//			set_status("local");
//		}
		if(cutoff_ind >=0 && cutoff_ind < MAX_ATTR_SIZE)
		{
			if(!it_val->second.val[cutoff_ind]){
				strcpy(status_str,"cutoff");
				set_status(status_str);
				try {
					push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing status="<<e.errors[0].desc<<endl;
				}
			}
		}
	}
	}
#endif

	/*----- PROTECTED REGION END -----*/	//	AccessConf::always_executed_hook
}



//--------------------------------------------------------
/**
 *	Method      : AccessConf::read_attr_hardware()
 *	Description : Hardware acquisition for attributes.
 */
//--------------------------------------------------------
void AccessConf::read_attr_hardware(vector<long> &attr_list)
{
	//DEBUG_STREAM << "AccessConf::read_attr_hardware(vector<long> &attr_list) entering... " << endl;
	/*----- PROTECTED REGION ID(AccessConf::read_attr_hardware) ENABLED START -----*/

	//	Add your own code

	struct timeval now;
	gettimeofday(&now, NULL);
	double diff_time_s = fabs((now.tv_sec - last_read.tv_sec) + ((double)(now.tv_usec - last_read.tv_usec))/1000000.0);

	if(diff_time_s < 1)
	{
		return;
	}
	gettimeofday(&last_read, NULL);

	try
	{
		vector<Tango::DeviceAttribute> *Dout;
		//Tango::DeviceAttribute Dout;

		Dout = lldevice->read_attributes(remote_attr);
		//Dout = lldevice->read_attribute(remote_attr[0]);

		//map<string,vector<Tango::DevBoolean> >::iterator attr_it;
		map<string,rem_val_t >::iterator attr_it;
		unsigned int i =0;
		//for(attr_it=remote_att_value.begin(); attr_it != remote_att_value.end(); attr_it++)
		for(vector<string>::iterator it = remote_attr.begin(); it != remote_attr.end(); it++)
		{
			attr_it = remote_att_value.find(*it);
			if(attr_it == remote_att_value.end())
			{
				WARN_STREAM << __FUNCTION__ << " remote attr=" << *it << " not found!";
				continue;
			}
			if(attr_it->first != "state")
			{
				map<string,string>::iterator it_type = remote_type.find(attr_it->first);
				DEBUG_STREAM << __FUNCTION__ << " remote type=" << it_type->second;
				if(it_type != remote_type.end() && it_type->second == "bool")
				{
					(*Dout)[i++] >> attr_it->second.val_b;	//TODO: string
					//Dout >> attr_it->second.val_b;	//TODO: string
					DEBUG_STREAM << __FUNCTION__ << " remote type=" << it_type->second << " name="<<attr_it->first<<" copyed="<<attr_it->second.val_b.size();// << " dout len="<<(*Dout)[i-1].get_dim_x();
				}
				else if(it_type != remote_type.end() && it_type->second == "string")
				{
					//(*Dout)[i++] >> attr_it->second.val_s;	//TODO: string
					DEBUG_STREAM << __FUNCTION__ << " remote type=" << it_type->second << " name="<<attr_it->first<<" copyed="<<attr_it->second.val_s.size();// << " dout len="<<(*Dout)[i-1].get_dim_x();
					Tango::DeviceAttribute Dout2 = lldevice->read_attribute(attr_it->first.c_str());
					Dout2 >> attr_it->second.val_s;	//TODO: string
				}
			}
			else
			{
				(*Dout)[i++] >> ll_state;
				DEBUG_STREAM << __FUNCTION__ << " read state=" << (int)ll_state;
			}
		}
		delete Dout;
	}
	catch(Tango::DevFailed &e)
	{
		ll_state = Tango::FAULT;
		stringstream tmp;
		tmp << "error reading low level attributes err: " << e.errors[0].desc;
		INFO_STREAM << __FUNCTION__ << ":  " << tmp.str();
	}
#if 0

    for(int i=0; i<attr_list.size(); i++)
    {
		string attr_name = dev_attr->get_attr_by_ind(attr_list[0]).get_name();
		DEBUG_STREAM << __func__<<": for attr="<<attr_name;
		if(attr_name != "State")
			return;
    }
    DEBUG_STREAM << __func__<<": State!!!!!!!!";

    map<string,attr_val_t >::iterator it_val = att_value.find("ValveStat");

	if((it_val->second.val[5])||(it_val->second.val[6])/*||(!valve_stat[2])*/)
	{//error occurred
		set_state(Tango::FAULT);
		if(it_val->second.val[5]){
			set_status("error opening");
		}
		if(it_val->second.val[6]){
			set_status("error closing");
		}
#if _PUSH_EVENTS
		Tango::DevState sta = Tango::FAULT;
		try {
			push_change_event("state");
			push_archive_event("state");
		} catch(Tango::DevFailed &e)
		{
			DEBUG_STREAM << __func__<<": error pushing state="<<e.errors[0].desc<<endl;
		}
#endif
		//	if(!valve_stat[2]){
		//		set_status("pressure not ok");
		//	}
	}
	else
	{//no errors
		if(it_val->second.val[0]){//opened?
			if(it_val->second.val[1])
			{//closed? error
				set_state(Tango::FAULT);
				set_status("SW both closed");
#if _PUSH_EVENTS
				Tango::DevState sta = Tango::FAULT;
				try {
					push_change_event("state");
					push_archive_event("state");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
#endif
			}
			else
			{//opened
				set_state(Tango::OPEN);
				set_status("----");
#if _PUSH_EVENTS
				Tango::DevState sta = Tango::OPEN;
				try {
					push_change_event("state");
					push_archive_event("state");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
#endif
			}
		}
		else
		{
			if(it_val->second.val[1])
			{//closed?
				set_state(Tango::CLOSE);
				set_status("----");
#if _PUSH_EVENTS
				Tango::DevState sta = Tango::CLOSE;
				try {
					push_change_event("state");
					push_archive_event("state");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
#endif
			}
			else
			{//moving
				set_state(Tango::MOVING);
				set_status("SW both opened");
#if _PUSH_EVENTS
				Tango::DevState sta = Tango::MOVING;
				try {
					push_change_event("state");
					push_archive_event("state");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
#endif
			}
		}
//		if(is_local_ctrl){
//			set_status("local");
//		}
		if(cutoff_ind >=0 && cutoff_ind < MAX_ATTR_SIZE)
		{
			if(!it_val->second.val[cutoff_ind]){
				set_status("cutoff");
			}
		}
	}
#endif

	/*----- PROTECTED REGION END -----*/	//	AccessConf::read_attr_hardware

}


//--------------------------------------------------------
/**
 *	Read BoolScalarDyn attribute
 *	Description: 
 *
 *	Data type:	Tango::DevBoolean
 *	Attr type:	Scalar 
 */
//--------------------------------------------------------
void AccessConf::read_BoolScalarDyn(Tango::Attribute &attr)
{
	DEBUG_STREAM << "AccessConf::read_BoolScalarDyn(Tango::Attribute &attr) entering... " << endl;
	/*----- PROTECTED REGION ID(AccessConf::read_BoolScalarDyn) ENABLED START -----*/

	map<string,attr_val_t >::iterator it_val = att_value.find(attr.get_name());

	if(it_val == att_value.end())
	{
		Tango::Except::throw_exception( \
							(const char*)"Attribute Not Found", \
							(const char*)"Attribute Not Found", \
							__FUNCTION__, Tango::ERR);
	}

	map<string,vector<attr_desc_t> >::iterator it_data = att_data.find(attr.get_name());

	if(it_data == att_data.end())
	{
		Tango::Except::throw_exception( \
							(const char*)"Attribute Not Found", \
							(const char*)"Attribute Not Found", \
							__FUNCTION__, Tango::ERR);
	}

	for(vector<attr_desc_t>::iterator it_rem_attr = it_data->second.begin(); it_rem_attr != it_data->second.end(); it_rem_attr++)
	{
		DEBUG_STREAM << __FUNCTION__ << " looping " << it_rem_attr->remote_attr_name;
		//map<string,vector<Tango::DevBoolean> >::iterator ll_attr_it = remote_att_value.find(it_rem_attr->remote_attr_name);
		map<string,rem_val_t >::iterator ll_attr_it = remote_att_value.find(it_rem_attr->remote_attr_name);
		if(ll_attr_it != remote_att_value.end())
		{
			DEBUG_STREAM << __FUNCTION__ << " ll_attr_it->second.size()= " << ll_attr_it->second.val_b.size();
			DEBUG_STREAM << __FUNCTION__ << " " << attr.get_name() <<"["<< it_rem_attr->attr_index<<"]=" << it_rem_attr->remote_attr_name << "["<<it_rem_attr->remote_index<<"]";
			if(ll_attr_it->first != "state")
			{
				it_val->second.val[ it_rem_attr->attr_index ] = ll_attr_it->second.val_b.at(it_rem_attr->remote_index);
				if(it_rem_attr->remote_index == 0)
					it_val->second.val[ it_rem_attr->attr_index ] = true;
			}
			else
			{
				it_val->second.val[ it_rem_attr->attr_index ] = (ll_state == Tango::ON);
			}
		}
	}

    //	Set the attribute value
    attr.set_value(&(it_val->second.val[0]));

	/*----- PROTECTED REGION END -----*/	//	AccessConf::read_BoolScalarDyn
}
//--------------------------------------------------------
/**
 *	Read BoolSpectrumDyn attribute
 *	Description: 
 *
 *	Data type:	Tango::DevBoolean
 *	Attr type:	Spectrum  max = 1000
 */
//--------------------------------------------------------
void AccessConf::read_BoolSpectrumDyn(Tango::Attribute &attr)
{
	DEBUG_STREAM << "AccessConf::read_BoolSpectrumDyn(Tango::Attribute &attr) entering... " << endl;
	/*----- PROTECTED REGION ID(AccessConf::read_BoolSpectrumDyn) ENABLED START -----*/

	//	Set the attribute value
	map<string,attr_val_t >::iterator it_val = att_value.find(attr.get_name());

	if(it_val == att_value.end())
	{
		Tango::Except::throw_exception( \
							(const char*)"Attribute Not Found", \
							(const char*)"Attribute Not Found", \
							__FUNCTION__, Tango::ERR);
	}

	map<string,vector<attr_desc_t> >::iterator it_data = att_data.find(attr.get_name());

	if(it_data == att_data.end())
	{
		Tango::Except::throw_exception( \
							(const char*)"Attribute Not Found", \
							(const char*)"Attribute Not Found", \
							__FUNCTION__, Tango::ERR);
	}

	for(vector<attr_desc_t>::iterator it_rem_attr = it_data->second.begin(); it_rem_attr != it_data->second.end(); it_rem_attr++)
	{
		DEBUG_STREAM << __FUNCTION__ << " looping " << it_rem_attr->remote_attr_name;
		//map<string,vector<Tango::DevBoolean> >::iterator ll_attr_it = remote_att_value.find(it_rem_attr->remote_attr_name);
		map<string,rem_val_t >::iterator ll_attr_it = remote_att_value.find(it_rem_attr->remote_attr_name);
		if(ll_attr_it != remote_att_value.end())
		{
			//DEBUG_STREAM << __FUNCTION__ << " found value for " << it_rem_attr->remote_attr_name<<" attr idx="<<it_rem_attr->attr_index << " rem idx="<<it_rem_attr->remote_index;
			it_val->second.val[ it_rem_attr->attr_index ] = ll_attr_it->second.val_b.at(it_rem_attr->remote_index);
			DEBUG_STREAM << __FUNCTION__ << " " << attr.get_name() <<"["<< it_rem_attr->attr_index<<"]=" << it_rem_attr->remote_attr_name << "["<<it_rem_attr->remote_index<<"]="<<(int)ll_attr_it->second.val_b.at(it_rem_attr->remote_index);
			if(it_rem_attr->remote_index == 0)
				it_val->second.val[ it_rem_attr->attr_index ] = true;
			if(attr.get_name() == "ValveStat")
			{
				int i=it_rem_attr->attr_index;
				if(i==2 && it_rem_attr->remote_index == 0)
					it_val->second.val[i]=true;
				else if(i==4 && it_rem_attr->remote_index == 0 /*it_rem_attr->descr == "spare"*/)
					it_val->second.val[i]=false;
				else if(i>4 && i<=7)
					it_val->second.val[i]=!it_val->second.val[i];//invert logic of ERR_ signals in order to have true -> error
			}
		}
	}

	if(attr.get_name() == "ValveStat")
	{
		ValveStat_initialized = true;
	}

    //	Set the attribute value
    attr.set_value(&(it_val->second.val[0]), it_data->second.size());


	if(attr.get_name() == "ValveStat" && ValveStat_initialized)
	{
    map<string,attr_val_t >::iterator it_val = att_value.find("ValveStat");

	if((it_val->second.val[5])||(it_val->second.val[6])/*||(!valve_stat[2])*/)
	{//error occurred

		state_event = Tango::FAULT;
		set_state(state_event);
		if(it_val->second.val[5])
		{
			strcpy(status_str,"error opening");
		}
		if(it_val->second.val[6])
		{
			strcpy(status_str,"error closing");
		}
		set_status(status_str);
		DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING FAULT ("<<status_str<<") "<<endl;
		try {
			push_change_event("state");
			push_archive_event("state");
			//push_change_event("status");
		} catch(Tango::DevFailed &e)
		{
			DEBUG_STREAM << __func__<<": error pushing state="<<e.errors[0].desc<<endl;
		}
		//	if(!valve_stat[2]){
		//		set_status("pressure not ok");
		//	}
	}
	else
	{//no errors
		if(it_val->second.val[0]){//opened?
			if(it_val->second.val[1])
			{//closed? error

				state_event = Tango::FAULT;
				set_state(state_event);
				strcpy(status_str,"SW both closed");
				set_status(status_str);
				DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING FAULT ("<<status_str<<") "<<endl;
				try {
					push_change_event("state");
					push_archive_event("state");
					//push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
			}
			else
			{//opened

				state_event = Tango::OPEN;
				set_state(state_event);
				strcpy(status_str,"----");
				set_status(status_str);
				DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING OPEN ("<<status_str<<") "<<endl;
				try {
					push_change_event("state");
					push_archive_event("state");
					//push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
			}
		}
		else
		{
			if(it_val->second.val[1])
			{//closed?

				state_event = Tango::CLOSE;
				set_state(state_event);
				strcpy(status_str,"----");
				set_status(status_str);
				DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING CLOSE ("<<status_str<<") "<<endl;
				try {
					push_change_event("state");
					push_archive_event("state");
					//push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
			}
			else
			{//moving

				state_event = Tango::MOVING;
				set_state(state_event);
				strcpy(status_str,"SW both opened");
				set_status(status_str);
				DEBUG_STREAM << __FUNCTION__ << "    -> PUSHING MOVING ("<<status_str<<") "<<endl;
				try {
					push_change_event("state");
					push_archive_event("state");
					//push_change_event("status");
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing state="<<e.errors[0].desc<<endl;
				}
			}
		}
//		if(is_local_ctrl){
//			set_status("local");
//		}
		if(cutoff_ind >=0 && cutoff_ind < MAX_ATTR_SIZE)
		{
			if(!it_val->second.val[cutoff_ind]){
				strcpy(status_str,"cutoff");
				set_status(status_str);
				try {
					//push_change_event("status", attr_status_read, 1, 0, false);
				} catch(Tango::DevFailed &e)
				{
					DEBUG_STREAM << "AccessConf::always_executed_hook() error pushing status="<<e.errors[0].desc<<endl;
				}
			}
		}
	}
	}

	/*----- PROTECTED REGION END -----*/	//	AccessConf::read_BoolSpectrumDyn
}
//--------------------------------------------------------
/**
 *	Read StringSpectrumDyn attribute
 *	Description:
 *
 *	Data type:	Tango::DevString
 *	Attr type:	Spectrum  max = 1000
 */
//--------------------------------------------------------
void AccessConf::read_StringSpectrumDyn(Tango::Attribute &attr)
{
	//DEBUG_STREAM << "AccessConf::read_StringSpectrumDyn(Tango::Attribute &attr) entering... " << endl;
	/*----- PROTECTED REGION ID(AccessConf::read_StringSpectrumDyn) ENABLED START -----*/

	//	Set the attribute value
	map<string,attr_val_string_t >::iterator it_val = att_value_string.find(attr.get_name());

	if(it_val == att_value_string.end())
	{
		Tango::Except::throw_exception( \
							(const char*)"Attribute 1 Not Found", \
							(const char*)"Attribute 1 Not Found", \
							__FUNCTION__, Tango::ERR);
	}

	map<string,vector<attr_desc_t> >::iterator it_data = att_data.find(attr.get_name());

	if(it_data == att_data.end())
	{
		Tango::Except::throw_exception( \
							(const char*)"Attribute 2 Not Found", \
							(const char*)"Attribute 2 Not Found", \
							__FUNCTION__, Tango::ERR);
	}
	//DEBUG_STREAM << __FUNCTION__ << " 0";
	map<string,rem_val_t >::iterator ll_attr_it;
	for(vector<attr_desc_t>::iterator it_rem_attr = it_data->second.begin(); it_rem_attr != it_data->second.end(); it_rem_attr++)
	{
		//DEBUG_STREAM << __FUNCTION__ << " looping " << it_rem_attr->remote_attr_name;
		//map<string,vector<Tango::DevBoolean> >::iterator ll_attr_it = remote_att_value.find(it_rem_attr->remote_attr_name);
		ll_attr_it = remote_att_value.find(it_rem_attr->remote_attr_name);
		//DEBUG_STREAM << __FUNCTION__ << " 1";
		if(ll_attr_it != remote_att_value.end())
		{
			//DEBUG_STREAM << __FUNCTION__ << " 2 it_rem_attr->attr_index="<<it_rem_attr->attr_index<<" it_rem_attr->remote_index="<<it_rem_attr->remote_index;
			strcpy(&(it_val->second.val[ it_rem_attr->attr_index ][0]),ll_attr_it->second.val_s.at(it_rem_attr->remote_index).c_str());
			//DEBUG_STREAM << __FUNCTION__ << " " << attr.get_name() <<"["<< it_rem_attr->attr_index<<"]=" << it_rem_attr->remote_attr_name << "["<<it_rem_attr->remote_index<<"]";
			//DEBUG_STREAM << "ind=" << it_rem_attr->attr_index << " string=" << (char *) (it_val->second.val[ it_rem_attr->attr_index]) << " ind rem=" << it_rem_attr->remote_index << " rem size="<<ll_attr_it->second.val_s.size();
			attr_StringSpectrumDyn_read[it_rem_attr->attr_index] = (char *) (it_val->second.val[ it_rem_attr->attr_index]);
			//DEBUG_STREAM << __FUNCTION__ << " 3";
		}
	}

	//DEBUG_STREAM << __FUNCTION__ << " before set_value";
    //	Set the attribute value
    attr.set_value(attr_StringSpectrumDyn_read, it_data->second.size());
    //DEBUG_STREAM << __FUNCTION__ << " after set_value";
	/*----- PROTECTED REGION END -----*/	//	AccessConf::read_BoolSpectrumDyn
}

//--------------------------------------------------------
/**
 *	Read BoolScalarDyn attribute
 *	Description:
 *
 *	Data type:	Tango::DevBoolean
 *	Attr type:	Scalar
 */
//--------------------------------------------------------
void AccessConf::read_Version(Tango::Attribute &attr)