Project

General

Profile

DocReadMITBT.txt

Kyle Hazelwood, 01/15/2015 11:59 AM

 
1

    
2
Following note show how to read MI BPM TBT data:(see >>> for steps)
3
extern "C" int bpm0_init(void)
4
{
5
 int				sts;
6

    
7
>>> init the machine, once at begining
8

    
9
 sts = bpm_machine_c(BPM_MAIN_INJECTOR);
10
 if (sts < 0) return(util_errpost(sts,"Err:bpm_machine_c in bpm0_init"));
11

    
12
>>> specify BPM names, spec parameters
13

    
14
 mi_rd_spec.buffer_number = 0;  /* batch number, start at 0 for first batch */
15
 if (jline == LINE_BO_MI_P) {
16
    sprintf(tbt_name[HORZ],"H202");
17
    sprintf(tbt_name[VERT],"V201");
18
    mi_rd_spec.buffer_number = 1;  /* batch number, start at 0 for first batch */
19
  }
20
 else if (jline == LINE_TV_MI_REVP) {
21
    sprintf(tbt_name[HORZ],"H304");
22
    sprintf(tbt_name[VERT],"V305");
23
  }
24

    
25
 mi_rd_spec.state_number = lpar.mode;  /* temp state_number */
26
 mi_rd_spec.calib_data = 0;
27
 mi_rd_spec.data_type = BPM_INJECTION_TBT_DATA;
28

    
29
 return(0);
30
}
31

    
32
extern "C" int cali_daq_wait(void)
33
{
34
 int		sts;
35

    
36
 sts = abort_init("",MAGENTA,8,C_ABOR);
37
 wai:
38
 
39
 >>> wait a event
40
 
41
 sts = wait_evt(wait_event[0],wait_event[1]);
42
 if (!(sts == 0 || sts == 1)) {
43
    if (abort_check()) {
44
       abort_cancel();
45
       return(TRUE);
46
     }
47
    else goto wai;
48
  }
49

    
50
 >>> wait for end of event, which signals data movements in BPM system is ready to read.
51
 
52
 if (jline == LINE_BO_MI_P || jline == LINE_TV_MI_REVP) {
53
    lckclk_c(MI_BEAM_END_EVENT);
54
    sts = bpm0_wait_beam_end();
55
  }
56
 else if (jline == LINE_TV_MI_DVOY) {
57
    sts = 0;
58
  }
59
 else sts = 0;
60

    
61
 pause_c(4);
62
 abort_cancel();
63
 return(sts);
64
}
65

    
66
#define INJ_TBT_BUFFER_LEN 512
67
#define STALE_TIME_CUT 120
68
#define MAX_NUM_TRIES 3
69
/******************************************************************************/
70
/*+ int bpm0_get_tbt(void)
71
	return FALSE if got data from both planes.
72
        
73
-*/
74
/******************************************************************************/
75
extern "C" int bpm0_get_tbt(void)
76
{
77
 int				pl,ntries,sts;
78
 unsigned int			start_t,t0;
79
 char				ct0[21],ct1[21],ct2[21],ct3[21];
80
 float				intensities[BPM_NUM_TBT_VALUES];
81
 /* 7 integers: ...reset_event,machine_state */
82
 char				mes[80];
83

    
84
 /* data options for test */
85
 if (tbt_from_log_file) {
86
    tbt_time[HORZ] = tbt_time[VERT] = clinks_now();
87
    sts = get_logged_tbt_data(tbt_dat[HORZ],tbt_dat[VERT]);
88
    return(sts);
89
  }
90

    
91
/* memset_float_c(tbt_dat[0],0.,10);
92
 memset_float_c(tbt_dat[1],0.,10);
93
 */
94
 t0 = clinks_now();
95
 for (pl = 0; pl < 2; pl++) {
96

    
97
    ntries = 0;
98
    my_try:
99

    
100
	>>> call bpm_get_tbt_data_c to get data
101
	
102
    sts = bpm_get_tbt_data_c(tbt_name[pl],tbt_dat[pl],tbt_timestamps[pl],
103
                      &tbt_num_turns[pl],FALSE,&tbt_time[pl],
104
                      intensities,TRUE,&mi_rd_spec,NULL,&mi_meta,
105
		      INJ_TBT_BUFFER_LEN);
106

    
107
    if (sts == DPM_PEND) {
108
	ntries++;
109
	if (ntries < MAX_NUM_TRIES) {
110
           error_message_c("Err:DPM_PEND from bpm_get_tbt_data_c,try again" ,
111
                           0,MAGENTA,TRUE); 
112
           goto my_try;
113
         }
114
     }
115

    
116
    if (sts != DIO_OK) 
117
       return(util_errpost(sts,"Err:bpm_get_tbt_data_c in bpm0_get_tbt"));
118

    
119
    if (mi_rd_spec.state_number !=  mi_meta.machine_state) {
120
       sprintf(mes,"Err:state number %d returned,not as asked %d",
121
               mi_meta.machine_state,mi_rd_spec.state_number);
122
       return(util_errpost(MYERR,mes));
123
     } 
124

    
125
    start_t = clinks_now();
126
    if (start_t - tbt_time[pl] > STALE_TIME_CUT) {
127
       sprintf(mes,"Err:stale data, %d seconds old!",start_t - tbt_time[pl]);
128
       return(util_errpost(DIO_STALE,mes));
129
     } 
130

    
131

    
132
    if (tbt_time[pl] == last_tbt_time[pl]) {
133
       clinks_to_date(tbt_time[pl],ct0);
134
       sprintf(mes,"Err:stale data, %.4s time stamp %.20s",
135
               (pl==HORZ)?"horz":"vert",ct0);
136
       return(util_errpost(DIO_STALE,mes));
137
     }  
138
    last_tbt_time[pl] = tbt_time[pl];
139

    
140
  }
141

    
142
 if (!sts) {
143
    memset(mes,BLANK,80);
144
    clinks_to_date(t0,ct0);
145
    clinks_to_date(start_t,ct1);
146
    clinks_to_date(tbt_time[0],ct2);
147
    clinks_to_date(tbt_time[1],ct3);
148
    sprintf(mes,"TBT start %.20s end %.8s,OK, %.8s(H) %.8s(V)",
149
              ct0,&ct1[12],&ct2[12],&ct3[12]);
150
    error_message_c(mes,0,GREEN,TRUE); 
151
  }
152

    
153
 return(0);
154
}
155