1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include <stdint.h> |
9 | #include <vector> |
10 | #include <deque> |
11 | #include <string> |
12 | #include <iostream> |
13 | #include <algorithm> |
14 | #include <stdio.h> |
15 | #include <stdlib.h> |
16 | |
17 | #include "TH2I.h" |
18 | |
19 | #include "JEventProcessor_EPICS_dump.h" |
20 | #include <JANA/JApplication.h> |
21 | |
22 | #include "TRIGGER/DL1Trigger.h" |
23 | #include <DANA/DStatusBits.h> |
24 | #include "DAQ/DEPICSvalue.h" |
25 | |
26 | using namespace std; |
27 | using namespace jana; |
28 | |
29 | #include <TDirectory.h> |
30 | #include <TH1.h> |
31 | |
32 | |
33 | |
34 | static TH1I* h1epics_AD00 = NULL__null; |
35 | static TH2I* h2epics_pos_inner = NULL__null; |
36 | static TH2I* h2epics_pos_outer = NULL__null; |
37 | static TH1F* h1epics_AD00_VSevent = NULL__null; |
38 | static TH1F* h1epics_entries_VSevent = NULL__null; |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | extern "C"{ |
45 | void InitPlugin(JApplication *locApplication){ |
46 | InitJANAPlugin(locApplication); |
47 | locApplication->AddProcessor(new JEventProcessor_EPICS_dump()); |
48 | } |
49 | } |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | JEventProcessor_EPICS_dump::JEventProcessor_EPICS_dump() { |
56 | } |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | JEventProcessor_EPICS_dump::~JEventProcessor_EPICS_dump() { |
63 | } |
64 | |
65 | |
66 | |
67 | |
68 | jerror_t JEventProcessor_EPICS_dump::init(void) { |
69 | |
70 | |
71 | |
72 | if(h1epics_AD00 != NULL__null){ |
73 | return NOERROR; |
74 | } |
75 | |
76 | |
77 | TDirectory *main = gDirectory(TDirectory::CurrentDirectory()); |
78 | gDirectory(TDirectory::CurrentDirectory())->mkdir("EPICS_dump")->cd(); |
79 | |
80 | |
81 | int const nbins=100; |
82 | |
83 | h1epics_AD00 = new TH1I("h1epics_AD00", "Current AD00",nbins,0,500); |
84 | h1epics_AD00->SetXTitle("Current AD00 (nA)"); |
85 | h1epics_AD00->SetYTitle("counts"); |
86 | |
87 | h2epics_pos_inner = new TH2I("h1epics_pos_inner", "Position AC inner",nbins,-10,10,nbins,-10,10); |
88 | h2epics_pos_inner->SetXTitle("Position AC inner x (mm)"); |
89 | h2epics_pos_inner->SetYTitle("Position AC inner y (mm)"); |
90 | h2epics_pos_outer = new TH2I("h1epics_pos_outer", "Position AC outer",nbins,-20,20,nbins,-20,20); |
91 | h2epics_pos_outer->SetXTitle("Position AC outer x (mm)"); |
92 | h2epics_pos_outer->SetYTitle("Position AC outer y (mm)"); |
93 | |
94 | h1epics_AD00_VSevent = new TH1F("h1epics_AD00_VSevent", "Current AD00 (nA)",200,0,2e6); |
95 | h1epics_AD00_VSevent->SetXTitle("Event number"); |
96 | h1epics_AD00_VSevent->SetYTitle("Current (nA)"); |
97 | |
98 | h1epics_entries_VSevent = new TH1F("h1epics_entries_VSevent", "No epics events/bin",200,0,2e6); |
99 | h1epics_entries_VSevent->SetXTitle("Event number"); |
100 | h1epics_entries_VSevent->SetYTitle("No of epics events"); |
101 | |
102 | |
103 | main->cd(); |
104 | |
105 | return NOERROR; |
106 | } |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | jerror_t JEventProcessor_EPICS_dump::brun(jana::JEventLoop* locEventLoop, int locRunNumber) { |
113 | |
114 | return NOERROR; |
115 | } |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | jerror_t JEventProcessor_EPICS_dump::evnt(jana::JEventLoop* locEventLoop, uint64_t locEventNumber) { |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | vector<const DEPICSvalue*> epicsvalues; |
129 | locEventLoop->Get(epicsvalues); |
130 | |
131 | bool isEPICS = locEventLoop->GetJEvent().GetStatusBit(kSTATUS_EPICS_EVENT); |
132 | if(!isEPICS) |
133 | return NOERROR; |
134 | |
135 | |
136 | |
137 | japp->RootFillLock(this); |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | float pos_default=-1000.; |
146 | float xpos_inner = pos_default; |
147 | float ypos_inner = pos_default;; |
148 | float xpos_outer = pos_default; |
149 | float ypos_outer = pos_default; |
150 | for(vector<const DEPICSvalue*>::const_iterator val_itr = epicsvalues.begin(); |
151 | val_itr != epicsvalues.end(); val_itr++) { |
152 | const DEPICSvalue* epics_val = *val_itr; |
153 | |
154 | float fconv = atof(epics_val->sval.c_str()); |
155 | unsigned int iconv = atoi(epics_val->sval.c_str()); |
156 | bool isDigit = epics_val->name.length()> 12 && isdigit(epics_val->name[12]); |
157 | |
158 | if ((epics_val->name.substr(0,11) == "BCAL:pulser") & isdigit(epics_val->name[11])) { |
159 | val_itr++; |
160 | epics_val = *val_itr; |
161 | |
162 | unsigned int iconv_low = atoi(epics_val->sval.c_str()); |
163 | |
164 | |
165 | iconv_low = iconv_low >> 31; |
166 | iconv = ((iconv <<1) & 0XFFFF) + iconv_low; |
| Value stored to 'iconv' is never read |
167 | |
168 | |
169 | } |
170 | else if ((epics_val->name.substr(0,11) == "BCAL:pulser") & isDigit) { |
171 | |
172 | |
173 | } |
174 | else if (epics_val->name == "IBCAD00CRCUR6") { |
175 | h1epics_AD00->Fill(fconv); |
176 | h1epics_AD00_VSevent->Fill((float)locEventNumber,fconv); |
177 | h1epics_entries_VSevent->Fill((float)locEventNumber); |
178 | |
179 | } |
180 | else if (epics_val->name == "AC:inner:position:x") { |
181 | xpos_inner = fconv; |
182 | } |
183 | else if (epics_val->name == "AC:inner:position:y") { |
184 | ypos_inner = fconv; |
185 | } |
186 | else if (epics_val->name == "AC:outer:position:x") { |
187 | xpos_outer = fconv; |
188 | } |
189 | else if (epics_val->name == "AC:outer:position:y") { |
190 | ypos_outer = fconv; |
191 | } |
192 | } |
193 | if (xpos_inner> pos_default && ypos_inner > pos_default) { |
194 | h2epics_pos_inner->Fill(xpos_inner,ypos_inner); |
195 | } |
196 | if (xpos_outer> pos_default && ypos_outer > pos_default) { |
197 | h2epics_pos_outer->Fill(xpos_outer,ypos_outer); |
198 | } |
199 | |
200 | japp->RootFillUnLock(this); |
201 | |
202 | return NOERROR; |
203 | } |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | jerror_t JEventProcessor_EPICS_dump::erun(void) { |
210 | |
211 | |
212 | |
213 | return NOERROR; |
214 | } |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | jerror_t JEventProcessor_EPICS_dump::fini(void) { |
221 | |
222 | return NOERROR; |
223 | } |
224 | |
225 | |
226 | |
227 | |