1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include "DEventProcessor_run_summary.h" |
9 | #include "DEPICSstore.h" |
10 | |
11 | #include <DAQ/DEPICSvalue.h> |
12 | |
13 | #include <TDirectory.h> |
14 | |
15 | static int VERBOSE = 0; |
16 | |
17 | |
18 | |
19 | extern "C" |
20 | { |
21 | void InitPlugin(JApplication *locApplication) |
22 | { |
23 | InitJANAPlugin(locApplication); |
24 | locApplication->AddProcessor(new DEventProcessor_run_summary()); |
25 | } |
26 | } |
27 | |
28 | |
29 | |
30 | |
31 | jerror_t DEventProcessor_run_summary::init(void) |
32 | { |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | current_run_number = -1; |
43 | conditions_tree = NULL__null; |
44 | epics_info = NULL__null; |
45 | |
46 | |
47 | gPARMS->SetDefaultParameter("SUMMARY:VERBOSE", VERBOSE, |
48 | "Verbosity level for creating summary values. 0=no messages, 10=all messages"); |
49 | if(VERBOSE) |
50 | cout << "Run summary verbosity level = " << VERBOSE << endl; |
51 | |
52 | return NOERROR; |
53 | } |
54 | |
55 | |
56 | |
57 | |
58 | jerror_t DEventProcessor_run_summary::brun(jana::JEventLoop* locEventLoop, int locRunNumber) |
59 | { |
60 | |
61 | |
62 | current_run_number = locRunNumber; |
63 | |
64 | |
65 | japp->RootWriteLock(); |
66 | |
67 | |
68 | |
69 | TDirectory *main_dir = gDirectory(TDirectory::CurrentDirectory()); |
70 | gDirectory(TDirectory::CurrentDirectory())->cd("/"); |
71 | |
72 | TDirectory* plugin_dir = static_cast<TDirectory*>(gDirectory(TDirectory::CurrentDirectory())->GetDirectory("conditions")); |
73 | if(plugin_dir == NULL__null) |
74 | plugin_dir = gDirectory(TDirectory::CurrentDirectory())->mkdir("conditions"); |
75 | plugin_dir->cd(); |
76 | |
77 | if(gDirectory(TDirectory::CurrentDirectory())->Get("conditions") == NULL__null) |
78 | conditions_tree = new TTree("conditions",""); |
79 | else |
80 | conditions_tree = static_cast<TTree*>(gDirectory(TDirectory::CurrentDirectory())->Get("conditions")); |
81 | |
82 | japp->RootUnLock(); |
83 | |
84 | |
85 | if(epics_info) |
86 | delete epics_info; |
87 | epics_info = new DEPICSstore; |
88 | |
89 | main_dir->cd(); |
90 | return NOERROR; |
91 | } |
92 | |
93 | |
94 | |
95 | |
96 | jerror_t DEventProcessor_run_summary::evnt(jana::JEventLoop* locEventLoop, int locEventNumber) |
97 | { |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | vector<const DEPICSvalue*> epicsvalues; |
115 | locEventLoop->Get(epicsvalues); |
116 | |
117 | |
118 | for(vector<const DEPICSvalue*>::const_iterator val_itr = epicsvalues.begin(); |
119 | val_itr != epicsvalues.end(); val_itr++) { |
120 | const DEPICSvalue* epics_val = *val_itr; |
121 | if(VERBOSE) |
122 | cout << "EPICS: " << epics_val->name << " = " << epics_val->sval << endl; |
123 | |
124 | if(epics_info) |
125 | epics_info->AddValue(epics_val); |
126 | else |
127 | jerr << "EPICS store object not loaded!" << endl; |
128 | } |
129 | |
130 | return NOERROR; |
131 | } |
132 | |
133 | |
134 | |
135 | |
136 | jerror_t DEventProcessor_run_summary::erun(void) |
137 | { |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | if(conditions_tree == NULL__null) |
144 | return NOERROR; |
145 | |
146 | |
147 | TBranch *run_branch = conditions_tree->FindBranch("run_number"); |
148 | if(run_branch == NULL__null) |
149 | run_branch = conditions_tree->Branch("run_number", ¤t_run_number, "run_number/D"); |
150 | else |
151 | conditions_tree->SetBranchAddress("run_number", ¤t_run_number); |
152 | |
153 | |
154 | const map<string, DEPICSvalue_data_t> &epics_store = epics_info->GetStore(); |
155 | for(map<string, DEPICSvalue_data_t>::const_iterator epics_val_itr = epics_store.begin(); |
156 | epics_val_itr != epics_store.end(); epics_val_itr++) { |
157 | string branch_name = epics_val_itr->first; |
158 | TBranch *the_branch = conditions_tree->FindBranch(branch_name.c_str()); |
159 | if(the_branch == NULL__null) { |
160 | string branch_def = branch_name + "/D"; |
161 | the_branch = conditions_tree->Branch(branch_name.c_str(), &(epics_val_itr->second.value->fval), branch_def.c_str()); |
| Value stored to 'the_branch' is never read |
162 | } else { |
163 | conditions_tree->SetBranchAddress(branch_name.c_str(), &(epics_val_itr->second.value->fval)); |
164 | } |
165 | } |
166 | |
167 | |
168 | conditions_tree->Fill(); |
169 | |
170 | return NOERROR; |
171 | } |
172 | |
173 | |
174 | |
175 | |
176 | jerror_t DEventProcessor_run_summary::fini(void) |
177 | { |
178 | |
179 | return NOERROR; |
180 | } |
181 | |