source: MML/trunk/machine/SOLEIL/common/synchro/switchsynchro.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 8.6 KB
Line 
1function switchsynchro(varargin)
2% switchsynchro - Switch timing for using the Machine study kickers (KEM) or
3% Normal injection mode or 3 Hz for BPMs
4%
5%  INPUTS
6%  Injection - Mode for standard injection into the storage ring
7%  KEM       - Mode for kicking the beam with a soft event
8%  3Hz       - Mode for conitnuous trigging BPM at 3 Hz
9
10%
11%  Written by Laurent S. Nadolski
12%  22 July 2008: Display and group added
13%  9 december 2010: Add 3 Hz for pseudo single bunch
14
15SynchroFlag = 'Injection';
16DisplayFlag = 1;
17
18% Input parser
19for i = length(varargin):-1:1,
20    if strcmpi(varargin{i},'Injection') || strcmpi(varargin{i},'Inj')
21        SynchroFlag = 'Injection';
22        varargin(i) = [];
23    elseif strcmpi(varargin{i},'KEM')
24        SynchroFlag = 'KEM';
25    elseif strcmpi(varargin{i},'3Hz')
26        SynchroFlag = '3Hz';
27    elseif strcmpi(varargin{i},'Display')
28        DisplayFlag = 1;
29        varargin(i) = [];
30    elseif strcmpi(varargin{i},'NoDisplay')
31        DisplayFlag = 0;
32        varargin(i) = [];
33    end
34end
35
36% switchyard for injection
37switch SynchroFlag
38    case 'KEM' % Switch Timing system for using KEMs
39        event = 16;
40        tango_write_attribute2('ANS/SY/CENTRAL','softEventAdress',int32(event));
41        tango_write_attribute2('ANS-C01/SY/LOCAL.DG.2','bpm.trigEvent',int32(event));
42        tango_write_attribute2('ANS-C02/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
43        tango_write_attribute2('ANS-C03/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
44        tango_write_attribute2('ANS-C04/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
45        tango_write_attribute2('ANS-C05/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
46        tango_write_attribute2('ANS-C06/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
47        tango_write_attribute2('ANS-C07/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
48        tango_write_attribute2('ANS-C08/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
49        tango_write_attribute2('ANS-C09/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
50        tango_write_attribute2('ANS-C10/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
51        tango_write_attribute2('ANS-C11/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
52        tango_write_attribute2('ANS-C12/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
53        tango_write_attribute2('ANS-C13/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
54        tango_write_attribute2('ANS-C14/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
55        tango_write_attribute2('ANS-C15/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
56        tango_write_attribute2('ANS-C16/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
57        tango_write_attribute2('ANS-C01/SY/LOCAL.EP.1','k-h.trigEvent',int32(event));
58        tango_write_attribute2('ANS-C01/SY/LOCAL.EP.1','k-v.trigEvent',int32(event));
59        pause(1)
60        checktimingconfig(event, 'KEM');
61       
62    case 'Injection'  % Switch back for injection anly for BPMs
63        eventInj = 3;
64        tango_write_attribute2('ANS/SY/CENTRAL','softEventAdress',int32(5));
65        tango_write_attribute2('ANS-C01/SY/LOCAL.DG.2','bpm.trigEvent',int32(eventInj));
66        tango_write_attribute2('ANS-C02/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
67        tango_write_attribute2('ANS-C03/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
68        tango_write_attribute2('ANS-C04/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
69        tango_write_attribute2('ANS-C05/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
70        tango_write_attribute2('ANS-C06/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
71        tango_write_attribute2('ANS-C07/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
72        tango_write_attribute2('ANS-C08/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
73        tango_write_attribute2('ANS-C09/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
74        tango_write_attribute2('ANS-C10/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
75        tango_write_attribute2('ANS-C11/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
76        tango_write_attribute2('ANS-C12/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
77        tango_write_attribute2('ANS-C13/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
78        tango_write_attribute2('ANS-C14/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
79        tango_write_attribute2('ANS-C15/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
80        tango_write_attribute2('ANS-C16/SY/LOCAL.DG.1','bpm.trigEvent',int32(eventInj));
81        pause(1)
82        checktimingconfig(eventInj);       
83    case '3Hz'  % Switch back for injection anly for BPMs
84        event = 4;
85        tango_write_attribute2('ANS/SY/CENTRAL','softEventAdress',int32(5));
86        tango_write_attribute2('ANS-C01/SY/LOCAL.DG.2','bpm.trigEvent',int32(event));
87        tango_write_attribute2('ANS-C02/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
88        tango_write_attribute2('ANS-C03/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
89        tango_write_attribute2('ANS-C04/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
90        tango_write_attribute2('ANS-C05/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
91        tango_write_attribute2('ANS-C06/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
92        tango_write_attribute2('ANS-C07/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
93        tango_write_attribute2('ANS-C08/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
94        tango_write_attribute2('ANS-C09/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
95        tango_write_attribute2('ANS-C10/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
96        tango_write_attribute2('ANS-C11/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
97        tango_write_attribute2('ANS-C12/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
98        tango_write_attribute2('ANS-C13/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
99        tango_write_attribute2('ANS-C14/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
100        tango_write_attribute2('ANS-C15/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
101        tango_write_attribute2('ANS-C16/SY/LOCAL.DG.1','bpm.trigEvent',int32(event));
102        pause(1)
103        checktimingconfig(event);       
104    otherwise
105        error('Wrong mode');
106end
107
108% Diagnostics for checking evering thing is OK
109
110devName={'ANS-C01/SY/LOCAL.DG.2'
111         'ANS-C02/SY/LOCAL.DG.1'
112         'ANS-C03/SY/LOCAL.DG.1'
113         'ANS-C04/SY/LOCAL.DG.1'
114         'ANS-C05/SY/LOCAL.DG.1'
115         'ANS-C06/SY/LOCAL.DG.1'
116         'ANS-C07/SY/LOCAL.DG.1'
117         'ANS-C08/SY/LOCAL.DG.1'
118         'ANS-C09/SY/LOCAL.DG.1'
119         'ANS-C10/SY/LOCAL.DG.1'
120         'ANS-C11/SY/LOCAL.DG.1'
121         'ANS-C12/SY/LOCAL.DG.1'
122         'ANS-C13/SY/LOCAL.DG.1'
123         'ANS-C14/SY/LOCAL.DG.1'
124         'ANS-C15/SY/LOCAL.DG.1'
125         'ANS-C16/SY/LOCAL.DG.1'
126    };
127
128if DisplayFlag
129    val =[];
130    for k=1:length(devName)
131        val(k) = readattribute([devName{k} '/bpm.trigEvent']);
132    end
133
134    figure
135    bar(val)
136    title('Trigger Event Value for BPM timing board')
137    xlabel('Cell number')
138    ylabel('Event value')
139end
140
141% subfunction
142function checktimingconfig(value, varargin)
143
144% Defaul flag
145KEMFlag = 0;
146
147for i = length(varargin):-1:1
148    if strcmpi(varargin{i},'NoKEM')
149        KEMFlag = 0;
150        varargin(i) = [];
151    else strcmpi(varargin{i},'KEM')
152        KEMFlag = 1;
153        varargin(i) = [];
154    end
155end
156
157
158if KEMFlag
159    val = ones(1,19)*NaN;
160else
161    val = ones(1,17)*NaN;
162end
163
164val(1) = readattribute(['ANS/SY/CENTRAL','/softEventAdress']);
165val(2) = readattribute(['ANS-C01/SY/LOCAL.DG.2','/bpm.trigEvent']);
166val(3) = readattribute(['ANS-C02/SY/LOCAL.DG.1','/bpm.trigEvent']);
167val(4) = readattribute(['ANS-C03/SY/LOCAL.DG.1','/bpm.trigEvent']);
168val(5) = readattribute(['ANS-C04/SY/LOCAL.DG.1','/bpm.trigEvent']);
169val(6) = readattribute(['ANS-C05/SY/LOCAL.DG.1','/bpm.trigEvent']);
170val(7) = readattribute(['ANS-C06/SY/LOCAL.DG.1','/bpm.trigEvent']);
171val(8) = readattribute(['ANS-C07/SY/LOCAL.DG.1','/bpm.trigEvent']);
172val(9) = readattribute(['ANS-C08/SY/LOCAL.DG.1','/bpm.trigEvent']);
173val(10) = readattribute(['ANS-C09/SY/LOCAL.DG.1','/bpm.trigEvent']);
174val(11) = readattribute(['ANS-C10/SY/LOCAL.DG.1','/bpm.trigEvent']);
175val(12) = readattribute(['ANS-C11/SY/LOCAL.DG.1','/bpm.trigEvent']);
176val(13) = readattribute(['ANS-C12/SY/LOCAL.DG.1','/bpm.trigEvent']);
177val(14) = readattribute(['ANS-C13/SY/LOCAL.DG.1','/bpm.trigEvent']);
178val(15) = readattribute(['ANS-C14/SY/LOCAL.DG.1','/bpm.trigEvent']);
179val(16) = readattribute(['ANS-C15/SY/LOCAL.DG.1','/bpm.trigEvent']);
180val(17) = readattribute(['ANS-C16/SY/LOCAL.DG.1','/bpm.trigEvent']);
181
182if KEMFlag
183    val(18) = readattribute(['ANS-C01/SY/LOCAL.EP.1','/k-h.trigEvent']);
184    val(19) = readattribute(['ANS-C01/SY/LOCAL.EP.1','/k-v.trigEvent']);
185end
186
187if mean(val(2:end)) ~= value
188    fprintf('At least one timing board is not set properly to %d soft address \n', value);
189end
190
Note: See TracBrowser for help on using the repository browser.