JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwBeamLine.cc
Go to the documentation of this file.
1/*!
2 * \file QwBeamLine.cc
3 * \brief Beam line subsystem implementation for full beam instrumentation
4 *
5 * Subsystem managing the full beam instrumentation line: creation from map
6 * files, geometry input, mock-data parameters, event processing, event cuts,
7 * error propagation, publication of variables, and data encoding/decoding.
8 * Documentation-only edits; runtime behavior unchanged.
9 */
10
11#include "QwBeamLine.h"
12
13// System headers
14#include <iostream>
15#include <stdexcept>
16
17#ifdef HAS_RNTUPLE_SUPPORT
18// ROOT headers for RNTuple support
19#include <ROOT/RNTupleModel.hxx>
20#include <ROOT/RNTupleWriter.hxx>
21#endif
22
23// Qweak headers
24#include "QwLog.h"
25#ifdef __USE_DATABASE__
26#include "QwParitySchema.h"
27#include "QwParityDB.h"
28#endif // __USE_DATABASE__
29
30#include "QwPromptSummary.h"
31
32// Forward declarations
33#ifdef __USE_DATABASE__
34class QwParityDB;
35//class QwDBInterface;
36#endif // __USE_DATABASE__
37
38// Register this subsystem with the factory
40
41//*****************************************************************//
42/** Parse and handle beamline-specific command-line options. */
44 //Handle command line options
45}
46
47//*****************************************************************//
48template <>
49Int_t QwBeamLine::AddToElementList<VQwClock_ptr>(std::vector<VQwClock_ptr> &elementlist,
50 QwBeamDetectorID &detector_id)
51{
52 if (detector_id.fTypeID == kQwClock){
53 VQwClock_ptr element(
55 detector_id.fdetectorname,
56 detector_id.fmoduletype) );
57 elementlist.push_back(element);
58 }
59 detector_id.fIndex = elementlist.size()-1;
60 return detector_id.fIndex;
61}
62//*****************************************************************//
63template <>
64Int_t QwBeamLine::AddToElementList<VQwBCM_ptr>(std::vector<VQwBCM_ptr> &elementlist,
65 QwBeamDetectorID &detector_id)
66{
67 if (detector_id.fTypeID == kQwBCM){
68 VQwBCM_ptr element(
70 detector_id.fdetectorname,
71 detector_id.fmoduletype) );
72 elementlist.push_back(element);
73 }
74 detector_id.fIndex = elementlist.size()-1;
75 return detector_id.fIndex;
76}
77//*****************************************************************//
78template <>
79Int_t QwBeamLine::AddToElementList<VQwBPM_ptr>(std::vector<VQwBPM_ptr> &elementlist,
80 QwBeamDetectorID &detector_id)
81{
82 if (detector_id.fTypeID == kQwBPMStripline){
83 VQwBPM_ptr element(
85 detector_id.fdetectorname,
86 detector_id.fmoduletype) );
87 elementlist.push_back(element);
88 }
89 detector_id.fIndex = elementlist.size()-1;
90 return detector_id.fIndex;
91}
92
93//*****************************************************************//
94template <typename TT>
95Int_t QwBeamLine::AddToElementList(std::vector<TT> &elementlist,
96 QwBeamDetectorID &detector_id)
97{
98 TT element(GetName(), detector_id.fdetectorname);
99 elementlist.push_back(element);
100 detector_id.fIndex = elementlist.size()-1;
101 return detector_id.fIndex;
102}
103
104
105
106//*****************************************************************//
107/**
108 * Load and decode the beamline channel map, creating physical and combined
109 * devices, recording detector IDs, and wiring publish lists and clocks.
110 *
111 * @param mapfile Path to the map file.
112 * @return 0 on success.
113 */
114Int_t QwBeamLine::LoadChannelMap(TString mapfile)
115{
116 Bool_t ldebug=kFALSE;
117
118 TString varname, varvalue;
119
120 TString combotype, comboname, dev_name;
121
122 Int_t index = 0;
123 Bool_t combolistdecoded;
124 Bool_t deviceok;
125
126 std::vector<TString> fDeviceName;
127 std::vector<TString> fProperty;
128 std::vector<TString> fType;
129 std::vector<Double_t> fQWeight;
130 std::vector<Double_t> fXWeight;
131 std::vector<Double_t> fYWeight;
132 Double_t sumQweights = 0.0;
133
134 std::vector<QwBeamDetectorID> clock_needed_list;
135
136 QwParameterFile mapstr(mapfile.Data()); //Open the file
138 mapstr.EnableGreediness();
139 mapstr.SetCommentChars("!");
140 mapstr.AddBreakpointKeyword("begin");
141 mapstr.AddBreakpointKeyword("end");
142
143 Int_t buffer_offset = 0; /* Allow some extra words at the start of a bank.
144 * The buffer_offset value will be reset at the
145 * start of each ROC or bank declaration, so should
146 * be relisted for each bank.
147 */
148 while (mapstr.ReadNextLine() && mapstr.SkipSection("PUBLISH")) {
149 RegisterRocBankMarker(mapstr);
150 // Remove the "vqwk_buffer_offset" and "scaler_buffer_offset"
151 // keywords from the parameter file's listing
152 if (mapstr.ReturnValue("vqwk_buffer_offset",buffer_offset)) {
153 QwDebug << "QwBeamLine::LoadChannelMap: "
154 << "ROC " << fCurrentROC_ID
155 << ", Bank " << fCurrentBank_ID
156 << "; vqwk_buffer_offset: " << buffer_offset << QwLog::endl;
157 }
158
159 if (mapstr.HasVariablePair("=",varname,varvalue)){ // This is a declaration line. Decode it.
160 varname.ToLower();
161
162 if (varname=="begin"){
163
164 // Start to decode derived beamline devices combined+energy
165 deviceok = kTRUE;
166 combotype = varvalue;
167 combolistdecoded = kFALSE;
168
169 TString dettype;
170
171 while(mapstr.ReadNextLine()&&!combolistdecoded) {
172 if (mapstr.HasVariablePair("=",varname,varvalue)) {
173 varname.ToLower();
174 if (varname=="end"){
175 // calculate the total weights of the charge
176 sumQweights = 0.0;
177 for(size_t i=0;i<fDeviceName.size();i++)
178 sumQweights+=fabs(fQWeight[i]);
179 combolistdecoded = kTRUE;
180 break;
181 }
182 }
183
184 if (mapstr.PopValue("name",varvalue)) {
185 comboname = varvalue;
186 }
187
188 dev_name = mapstr.GetTypedNextToken<TString>();
189 dev_name.ToLower();
190 dettype = mapstr.GetTypedNextToken<TString>();
191 dettype.ToLower();
192
193 // Check to see if the device being read is a valid physical device.
194 // If not, discard the combination.
195 index=GetDetectorIndex(GetQwBeamInstrumentType(dettype),dev_name);
196
197 if (index == -1) {
198 QwError << "QwBeamLine::LoadChannelMap: Unknown device: "
199 << dev_name <<" used in "<< comboname
200 <<". This combination will not be decoded!"
201 << QwLog::endl;
202 deviceok = kFALSE;
203 combolistdecoded = kTRUE;
204 }else{
205 // Found the device
206 // Add to the array of names
207 fDeviceName.push_back(dev_name);
208
209 // Read in the weights.
210 // For combined bpms and combined bcms these are charge weights.
211 // For the energy calculator these are the ratios of the transport matrix elements.
212 fQWeight.push_back(mapstr.GetTypedNextToken<Double_t>());
213
214 // For combined BPMs,in addition, there are weights for the X & Y positions.
215 if(combotype == "combinedbpm"){
216 fXWeight.push_back(mapstr.GetTypedNextToken<Double_t>());
217 fYWeight.push_back(mapstr.GetTypedNextToken<Double_t>());
218 }
219
220 // For the enrgy calculator there are device type and the specified beam parameters.
221 if(combotype == "energycalculator"){
222 fType.push_back(dettype);
223 fProperty.push_back(mapstr.GetTypedNextToken<TString>());
224 }
225 }
226 }
227
228 // Now create the combined device
229 QwBeamDetectorID localComboID(-1, -1, comboname, combotype,
230 fBeamDetectorID.at(index).fmoduletype );
231
232 localComboID.fdetectorname=comboname(0,comboname.Sizeof()-1);
233 localComboID.fIndex = GetDetectorIndex(localComboID.fTypeID,localComboID.fdetectorname);
234
235 if(localComboID.fTypeID==kQwUnknownDeviceType){
236 QwError << "QwBeamLine::LoadChannelMap: Unknown detector type: "
237 << combotype <<", the detector "<<comboname<<" will not be decoded "
238 << QwLog::endl;
239 deviceok = kFALSE;
240 continue;
241 }
242
243 if((localComboID.fIndex==-1) && deviceok) {
244
245 // Decoding combined BCM array
246 if (localComboID.fTypeID == kQwCombinedBCM){
247
248 VQwBCM_ptr localbcmcombo(
250 localComboID.fdetectorname,localComboID.fmoduletype));
251 fBCMCombo.push_back(localbcmcombo);
252
253 for(size_t i=0;i<fDeviceName.size();i++){
254 index=GetDetectorIndex(GetQwBeamInstrumentType(dettype),fDeviceName[i]);
255 fBCMCombo[fBCMCombo.size()-1].get()->SetBCMForCombo(fBCM.at(index).get(),
256 fQWeight[i],sumQweights );
257 }
258 fDeviceName.clear();
259 fQWeight.clear();
260 localComboID.fIndex=fBCMCombo.size()-1;
261 }
262
263 // Decoding combined BPM array.
264 if(localComboID.fTypeID== kQwCombinedBPM){
265 VQwBPM_ptr localbpmcombo(
267 localComboID.fdetectorname,localComboID.fmoduletype));
268 fBPMCombo.push_back(localbpmcombo);
269
270 for(size_t i=0;i<fDeviceName.size();i++){
271 index=GetDetectorIndex(GetQwBeamInstrumentType(dettype),fDeviceName[i]);
272 fBPMCombo[fBPMCombo.size()-1].get()->SetBPMForCombo(
273 fStripline.at(index).get(), fQWeight[i],fXWeight[i],
274 fYWeight[i],sumQweights );
275
276 }
277 fDeviceName.clear();
278 fQWeight.clear();
279 fXWeight.clear();
280 fYWeight.clear();
281 localComboID.fIndex=fBPMCombo.size()-1;
282 }
283
284 // Decoding energy calculator.
285 if(localComboID.fTypeID== kQwEnergyCalculator){
286
287 QwEnergyCalculator localecalculator(GetName(), localComboID.fdetectorname);
288 fECalculator.push_back(localecalculator);
289
290 for(size_t i=0;i<fDeviceName.size();i++){
291 index=GetDetectorIndex(GetQwBeamInstrumentType(fType[i]),fDeviceName[i]);
292
294 fECalculator[fECalculator.size()-1].Set(fStripline.at(index).get(),fType[i],fProperty[i],fQWeight[i]);
295
296 if ( GetQwBeamInstrumentType(fType[i]) == kQwCombinedBPM)
297 fECalculator[fECalculator.size()-1].Set(fBPMCombo.at(index).get(),fType[i],fProperty[i],fQWeight[i]);
298
299 }
300
301 fDeviceName.clear();
302 fQWeight.clear();
303
304 fProperty.clear();
305 fType.clear();
306 localComboID.fIndex=fECalculator.size()-1;
307 }
308 }
309 // Use only the combinations that are of known type and has known physical devices.
310 if(deviceok)
311 fBeamDetectorID.push_back(localComboID);
312 }
313
314 QwDebug << "At end of processing the combined device " << QwLog::endl;
315
316 } else{
317 // Start to decode the physical beamline devices
318 QwBeamDetectorID localBeamDetectorID(GetSubbankIndex(), mapstr);
319 Bool_t lineok = localBeamDetectorID.ReportInitErrors();
320 if (! lineok) continue;
321
322 localBeamDetectorID.fIndex=
323 GetDetectorIndex(localBeamDetectorID.fTypeID,
324 localBeamDetectorID.fdetectorname);
325
326 if(localBeamDetectorID.fIndex==-1){
327 Int_t index;
328 VQwDataElement* local_element = NULL;
329
330 if(localBeamDetectorID.fTypeID == kQwHaloMonitor){
331 index = AddToElementList(fHaloMonitor, localBeamDetectorID);
332 local_element = &(fHaloMonitor.at(index));
333 }
334 if(localBeamDetectorID.fTypeID==kQwBPMCavity){
335 index = AddToElementList(fCavity, localBeamDetectorID);
336 local_element = &(fCavity.at(index));
337 }
338 if(localBeamDetectorID.fTypeID== kQwBPMStripline){
339 index = AddToElementList(fStripline, localBeamDetectorID);
340 local_element = fStripline.at(index).get();
341 }
342 if(localBeamDetectorID.fTypeID== kQwBCM){
343 index = AddToElementList(fBCM, localBeamDetectorID);
344 local_element = fBCM.at(index).get();
345 }
346 if(localBeamDetectorID.fTypeID== kQwClock ) {
347 index = AddToElementList(fClock, localBeamDetectorID);
348 local_element = fClock.at(index).get();
349 }
350 if(localBeamDetectorID.fTypeID== kQwQPD){
351 index = AddToElementList(fQPD, localBeamDetectorID);
352 local_element = &(fQPD.at(index));
353 }
354 if(localBeamDetectorID.fTypeID== kQwLinearArray){
355 index = AddToElementList(fLinearArray, localBeamDetectorID);
356 local_element = &(fLinearArray.at(index));
357 }
358
359 local_element->LoadChannelParameters(mapstr);
360 if (local_element->NeedsExternalClock()){
361 QwDebug << "Try to push device "
362 << local_element->GetElementName()
363 << " (address=" << std::hex << local_element << std::dec
364 << ") onto the clock_needed_list"
365 << QwLog::endl;
366 clock_needed_list.push_back(localBeamDetectorID);
367 }
368 }
369
370
371
372 fBeamDetectorID.push_back(localBeamDetectorID);
373 }
374 }
375
376 // Now load the variables to publish
377 mapstr.RewindToFileStart();
378 std::unique_ptr<QwParameterFile> section;
379 std::vector<TString> publishinfo;
380 while ((section=mapstr.ReadNextSection(varvalue))) {
381 if (varvalue == "PUBLISH") {
382 fPublishList.clear();
383 while (section->ReadNextLine()) {
384 section->TrimComment(); // Remove everything after a comment character
385 section->TrimWhitespace(); // Get rid of leading and trailing spaces
386 for (int ii = 0; ii < 4; ii++) {
387 varvalue = section->GetTypedNextToken<TString>();
388 if (varvalue.Length()) {
389 publishinfo.push_back(varvalue);
390 }
391 }
392 if (publishinfo.size() == 4)
393 fPublishList.push_back(publishinfo);
394 publishinfo.clear();
395 }
396 }
397 }
398 // Print list of variables to publish
399 if (fPublishList.size()>0){
400 QwMessage << "Variables to publish:" << QwLog::endl;
401 for (size_t jj = 0; jj < fPublishList.size(); jj++)
402 QwMessage << fPublishList.at(jj).at(0) << " " << fPublishList.at(jj).at(1) << " "
403 << fPublishList.at(jj).at(2) << " " << fPublishList.at(jj).at(3) << QwLog::endl;
404 }
405
406 if(ldebug){
407 std::cout<<"QwBeamLine::Done with Load map channel \n";
408 for(size_t i=0;i<fBeamDetectorID.size();i++)
409 fBeamDetectorID[i].Print();
410 }
411
412 // Now propagate clock pointers to those channels that need it
413 index = 0;
414 VQwDataElement* local_element;
415 std::string clockname;
416 for (size_t i=0; i<clock_needed_list.size();i++ ) {
417 local_element = GetElement(clock_needed_list[i]);
418 clockname = local_element->GetExternalClockName();
419 if (clockname.empty()){
420 QwWarning << "QwBeamLine::LoadChannelMap "
421 << "Device, " << local_element->GetElementName()
422 << " needs a reference clock, but the reference clock name is empty"
423 << QwLog::endl;
424 } else {
425 index = GetDetectorIndex(kQwClock,clockname);
426 if( index >= 0 ){
427 QwMessage << "QwBeamLine::LoadChannelMap "
428 << "Setting " << fClock.at(index).get()->GetElementName()
429 << " as the reference clock for channel "
430 << local_element->GetElementName()
431 << QwLog::endl;
432 local_element->SetExternalClockPtr(fClock.at(index).get()->GetTime());
433 } else {
434 QwWarning << "QwBeamLine::LoadChannelMap "
435 << "Cannot find clock, " << local_element->GetExternalClockName()
436 << ", needed by device, " << local_element->GetElementName()
437 << QwLog::endl;
438 }
439 }
440 }
441 ldebug=kFALSE;
442
443 mapstr.Close(); // Close the file (ifstream)
444 return 0;
445}
446
447
448//*****************************************************************//
449/**
450 * Decode a single event-cuts line for devices and subchannels, routing the
451 * resulting thresholds and error flags to the proper element.
452 */
453void QwBeamLine::LoadEventCuts_Line(QwParameterFile &mapstr, TString &varvalue, Int_t &eventcut_flag) {
454 TString device_type = mapstr.GetTypedNextToken<TString>();
455 device_type.ToLower();
456 TString device_name = mapstr.GetTypedNextToken<TString>();
457 device_name.ToLower();
458
459 Int_t det_index = GetDetectorIndex(GetQwBeamInstrumentType(device_type),device_name);
460 if (det_index == -1) {
461 QwWarning << " Device not found " << device_name << " of type " << device_type << QwLog::endl;
462 //continue;
463 }
464
465 TString channel_name;
466
467 if(device_type == GetQwBeamInstrumentTypeName(kQwBPMStripline) ||
468 device_type == GetQwBeamInstrumentTypeName(kQwQPD) ||
472
473 channel_name = mapstr.GetTypedNextToken<TString>();
474 channel_name.ToLower();
475 }
476
477 Double_t LLX = mapstr.GetTypedNextToken<Double_t>(); //lower limit for BCM value
478 Double_t ULX = mapstr.GetTypedNextToken<Double_t>(); //upper limit for BCM value
479 varvalue = mapstr.GetTypedNextToken<TString>();//global/local
480 varvalue.ToLower();
481
482 Double_t stabilitycut = mapstr.GetTypedNextToken<Double_t>();
483 Double_t burplevel = mapstr.GetTypedNextToken<Double_t>();
484
485
486 if (device_type == GetQwBeamInstrumentTypeName(kQwBCM)){
487 QwMessage<<"QwBeamLine Error Code passing to QwBCM "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<", burp = "<<burplevel<<QwLog::endl;
488 fBCM[det_index].get()->SetSingleEventCuts(GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut),LLX,ULX,stabilitycut,burplevel);//(fBCMEventCuts);
489
490 } else if (device_type == GetQwBeamInstrumentTypeName(kQwHaloMonitor)){
491 QwMessage<<"QwBeamLine Error Code passing to QwHaloMonitor "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<QwLog::endl;
492 fHaloMonitor[det_index].SetSingleEventCuts(GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut),LLX,ULX,stabilitycut,burplevel);//(fBCMEventCuts);
493
494 } else if (device_type == GetQwBeamInstrumentTypeName(kQwEnergyCalculator)){
495 QwMessage<<"QwBeamLine Error Code passing to QwEnergyCalculator "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<QwLog::endl;
496 fECalculator[det_index].SetSingleEventCuts(GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut),LLX,ULX,stabilitycut,burplevel);//(fEnergyEventCuts);
497
498 } else if (device_type == GetQwBeamInstrumentTypeName(kQwBPMStripline)){
499 QwMessage<<"QwBeamLine:QwBPMStripline "<<channel_name<<" "<<varvalue<<" "<<stabilitycut<<QwLog::endl;
500 //QwMessage<<"QwBeamLine Error Code passing to QwBPMStripline "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<" stability "<<stabilitycut <<QwLog::endl;
501 fStripline[det_index].get()->SetSingleEventCuts(channel_name, GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut), LLX, ULX, stabilitycut, burplevel);
502
503 } else if (device_type == GetQwBeamInstrumentTypeName(kQwQPD)){
504 QwMessage<<"QwBeamLine Error Code passing to QwQPD "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<QwLog::endl;
505 fQPD[det_index].SetSingleEventCuts(channel_name, GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut), LLX, ULX, stabilitycut, burplevel);
506
507 } else if (device_type == GetQwBeamInstrumentTypeName(kQwLinearArray)){
508 QwMessage<<"QwBeamLine Error Code passing to QwLinearArray "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<QwLog::endl;
509 fLinearArray[det_index].SetSingleEventCuts(channel_name, GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut), LLX, ULX, stabilitycut, burplevel);
510
511 } else if (device_type == GetQwBeamInstrumentTypeName(kQwBPMCavity)){
512 varvalue.ToLower();
513 QwMessage<<"QwBeamLine Error Code passing to QwBPMCavity "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<" "<<det_index<<QwLog::endl;
514 fCavity[det_index].SetSingleEventCuts(channel_name, GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut), LLX, ULX, stabilitycut, burplevel);
515
516 } else if (device_type == GetQwBeamInstrumentTypeName(kQwCombinedBCM)){
517 varvalue.ToLower();
518 QwMessage<<"QwBeamLine Error Code passing to QwCombinedBCM "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<QwLog::endl;
519 fBCMCombo[det_index].get()->PrintInfo();
520 fBCMCombo[det_index].get()->SetSingleEventCuts(GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut), LLX, ULX, stabilitycut, burplevel);
521
522 } else if (device_type == GetQwBeamInstrumentTypeName(kQwCombinedBPM)){
523 varvalue.ToLower();
524 QwMessage<<"QwBeamLine Error Code passing to QwCombinedBPM "<<GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut)<<QwLog::endl;
525 fBPMCombo[det_index].get()->SetSingleEventCuts(channel_name, GetGlobalErrorFlag(varvalue,eventcut_flag,stabilitycut), LLX, ULX, stabilitycut, burplevel);
526 }
527}
528
529/** Apply the event-cut mode bitmask to all managed devices. */
530void QwBeamLine::LoadEventCuts_Fin(Int_t &eventcut_flag) {
531 for (size_t i=0;i<fStripline.size();i++)
532 fStripline[i].get()->SetEventCutMode(eventcut_flag);
533
534 for (size_t i=0;i<fQPD.size();i++)
535 fQPD[i].SetEventCutMode(eventcut_flag);
536
537 for (size_t i=0;i<fLinearArray.size();i++)
538 fLinearArray[i].SetEventCutMode(eventcut_flag);
539
540 for (size_t i=0;i<fCavity.size();i++)
541 fCavity[i].SetEventCutMode(eventcut_flag);
542
543 for (size_t i=0;i<fBCM.size();i++)
544 fBCM[i].get()->SetEventCutMode(eventcut_flag);
545
546 for (size_t i=0;i<fClock.size();i++)
547 fClock[i].get()->SetEventCutMode(eventcut_flag);
548
549 for (size_t i=0;i<fHaloMonitor.size();i++)
550 fHaloMonitor[i].SetEventCutMode(eventcut_flag);
551
552 for (size_t i=0;i<fBCMCombo.size();i++)
553 fBCMCombo[i].get()->SetEventCutMode(eventcut_flag);
554
555 for (size_t i=0;i<fBPMCombo.size();i++)
556 fBPMCombo[i].get()->SetEventCutMode(eventcut_flag);
557
558 for (size_t i=0;i<fECalculator.size();i++)
559 fECalculator[i].SetEventCutMode(eventcut_flag);
560
561 fQwBeamLineErrorCount=0; //set the error counter to zero
562}
563
564//*****************************************************************//
565/**
566 * Load geometry and electronics calibration parameters from a map file and
567 * apply them to the proper devices (offsets, rotation, gains).
568 */
570 Bool_t ldebug=kFALSE;
571 TString varname, varvalue;
572 Int_t lineread=1;
573 Int_t index = 0;
574 TString devname,devtype;
575 TString melement;
576 Double_t devOffsetX = 0,devOffsetY = 0, devOffsetZ = 0;
577 Double_t devSENfactor = 0, devAlphaX = 0, devAlphaY = 0;
578 TString rotation_stat;
579 VQwBPM * bpm = NULL;
580
581 if(ldebug)std::cout<<"QwBeamLine::LoadGeometryParameters("<< mapfile<<")\n";
582
583 QwParameterFile mapstr(mapfile.Data()); //Open the file
585 while (mapstr.ReadNextLine()){
586 lineread+=1;
587 if(ldebug)std::cout<<" line read so far ="<<lineread<<"\n";
588 mapstr.TrimComment('!');
589 mapstr.TrimWhitespace();
590
591 if (mapstr.LineIsEmpty()) continue;
592
593 Bool_t notfound=kTRUE;
594
595 devtype = mapstr.GetTypedNextToken<TString>();
596 devtype.ToLower();
597 devtype.Remove(TString::kBoth,' ');
598 devname = mapstr.GetTypedNextToken<TString>();
599 devname.ToLower();
600 devname.Remove(TString::kBoth,' ');
601
603 QwError << "Error! Unknown detector type '"<<devtype
604 << "' in Geometry file!"<<QwLog::endl;
605 /*If the device type is unknown there is no point in going through the rest of the specs for that device*/
606 continue;
607 }
608
609 index=GetDetectorIndex(GetQwBeamInstrumentType(devtype),devname);
610 if( index<0 ) {
611 /*Detector name isn't recognized. Ignore it!*/
612 QwWarning << "Unrecognized detector name '" << devname
613 << "' in Geometry file. This may not be a problem, "
614 << "if we're using a reduced channel map."
615 << QwLog::endl;
616 }
617 else {
618 devOffsetX = mapstr.GetTypedNextToken<Double_t>(); // X offset
619 devOffsetY = mapstr.GetTypedNextToken<Double_t>(); // Y offset
620 devOffsetZ = mapstr.GetTypedNextToken<Double_t>(); // Z offset
621 devSENfactor = mapstr.GetTypedNextToken<Double_t>(); // sensitivity scaling factor
622 devAlphaX = mapstr.GetTypedNextToken<Double_t>(); // alpha X
623 devAlphaY = mapstr.GetTypedNextToken<Double_t>(); // alpha Y
624
625
626 /*If the device is a bpm stripline, assign the rotations and gains*/
628 bpm = fStripline.at(index).get();
629 AssignGeometry(&mapstr,bpm);
630 }
631
632
633 if(ldebug==1){
634 std::cout<<"####################\n";
635 std::cout<<"! device type, device_name, Xoffset, Yoffset, Zoffset, BSEN scaling factor, AlpaX, AlpaY\n"<<std::endl;
636 std::cout<<GetQwBeamInstrumentType(devtype)<<" / "
637 <<devname <<" / "
638 <<devOffsetX <<" / "
639 <<devOffsetY <<" / "
640 <<devOffsetZ <<" / "
641 <<devSENfactor <<" / "
642 <<devAlphaX <<" / "
643 <<devAlphaY <<" / "
644 <<std::endl;
645 }
646
647
648 while(notfound){
650 //Load bpm offsets
651 if(index == -1){
652 QwWarning << "QwBeamLine::LoadGeometryDefinition: Unknown bpm in qweak_beamline_geometry.map: "
653 <<devname
654 <<QwLog::endl;
655 notfound=kFALSE;
656 continue;
657 }
658
659 TString localname = fStripline.at(index).get()->GetElementName();
660 localname.ToLower();
661 if(ldebug) std::cout<<"element name =="<<localname
662 <<"== to be compared to =="<<devname<<"== \n";
663
664 if(localname==devname){
665 if(ldebug) std::cout<<" I found the bpm !\n";
666 bpm->GetSurveyOffsets(devOffsetX,devOffsetY,devOffsetZ);
667 bpm->GetElectronicFactors(devSENfactor,devAlphaX, devAlphaY);
668
669 // If nothing is specified, a default rotation of 45 degrees is implied.
670 notfound=kFALSE;
671 }
672 }
673 else if (GetQwBeamInstrumentType(devtype)==kQwCombinedBPM){
674 //Load combined bpm offsets which are, ofcourse, target position in the beamline
675 if(index == -1){
676 QwError << "QwBeamLine::LoadGeometryDefinition: Unknown combined bpm in qweak_beamline_geometry.map: "
677 <<devname<<" Check the combined bpm names!\n "
678 << QwLog::endl;
679 notfound=kFALSE;
680 continue;
681 }
682
683 TString localname = fBPMCombo.at(index).get()->GetElementName();
684 localname.ToLower();
685 if(ldebug)
686 std::cout<<"element name =="<<localname<<"== to be compared to =="<<devname<<"== \n";
687
688 if(localname==devname){
689 if(ldebug) std::cout<<" I found the combinedbpm !\n";
690 fBPMCombo.at(index).get()->GetSurveyOffsets(devOffsetX,devOffsetY,devOffsetZ);
691 notfound=kFALSE;
692 }
693 }
694 else if(GetQwBeamInstrumentType(devtype)==kQwBPMCavity){
695 //Load cavity bpm offsets
696 if(index == -1){
697 QwError << "QwBeamLine::LoadGeometryDefinition: Unknown bpm : "
698 <<devname<<" will not be assigned with geometry parameters. \n"
699 <<QwLog::endl;
700 notfound=kFALSE;
701 continue;
702 }
703 TString localname = fCavity.at(index).GetElementName();
704 localname.ToLower();
705 if(ldebug) std::cout<<"element name =="<<localname
706 <<"== to be compared to =="<<devname<<"== \n";
707
708 if(localname==devname){
709 if(ldebug) std::cout<<" I found the cavity bpm !\n";
710 fCavity.at(index).GetSurveyOffsets(devOffsetX,devOffsetY,devOffsetZ);
711 notfound=kFALSE;
712 }
713 }
714 else if(GetQwBeamInstrumentType(devtype)==kQwQPD){
715 //Load QPD calibration factors
716 if(index == -1){
717 QwError << "QwBeamLine::LoadGeometryDefinition: Unknown QPD : "
718 <<devname<<" will not be assigned with calibration factors. \n"
719 <<QwLog::endl;
720 notfound=kFALSE;
721 continue;
722 }
723 TString localname = fQPD.at(index).GetElementName();
724 localname.ToLower();
725 if(ldebug) std::cout<<"element name =="<<localname
726 <<"== to be compared to =="<<devname<<"== \n";
727
728 if(localname==devname){
729 if(ldebug) std::cout<<"I found the QPD !\n";
730 fQPD.at(index).GetCalibrationFactors(devAlphaX, devAlphaY);
731 notfound=kFALSE;
732 }
733 }
734 else QwError << "QwBeamLine::LoadGeometryDefinition: Unknown device type : "<< devtype <<
735 ". Are you sure we have this in the beamline? I am skipping this."<< QwLog::endl;
736 }
737 }
738 }
739
740 if(ldebug) std::cout << "line read in the geometry file = " << lineread<< " \n";
741
742 ldebug=kFALSE;
743 mapstr.Close(); // Close the file (ifstream)
744 return 0;
745
746}
747
748//--------------------------------------------------------------------------------------------------------
749/** Load per-device mock-data generation parameters from a file. */
751
752 Bool_t ldebug=kFALSE;
753 TString varname, varvalue;
754 Int_t lineread=1;
755 Int_t index = 0;
756 TString devname, devtype;
757 TString melement;
758
759 if(ldebug) std::cout << "QwBeamLine::LoadMockDataParameters(" << mapfile << ") \n" << std::endl;
760
761 QwParameterFile mapstr(mapfile.Data()); //Open the file
763
764 while (mapstr.ReadNextLine()) {
765 lineread+=1;
766 // std::cerr << "Line: " << mapstr.GetLine() << std::endl;
767 if(ldebug) std::cout << "Line read so far = " << lineread << "\n" << std::endl;
768 mapstr.TrimComment('!');
769 mapstr.TrimWhitespace();
770
771 if(mapstr.LineIsEmpty()) continue;
772
773 devtype = mapstr.GetTypedNextToken<TString>();
774 devtype.ToLower();
775 devtype.Remove(TString::kBoth,' ');
776 devname = mapstr.GetTypedNextToken<TString>();
777 devname.ToLower();
778 devname.Remove(TString::kBoth,' ');
779
781 /*If the device type is unknown there is no point in going through the rest of the specs for that device*/
782 QwError << "Error! Unknown detector type '" << devtype << "' in MockDataParameters file!" << QwLog::endl;
783 continue;
784 }
785 index = GetDetectorIndex(GetQwBeamInstrumentType(devtype),devname);
786 if (index<0) {
787 /*Detector name isn't recognized. Ignore it!*/
788 QwWarning << "Unrecognized detector name '" << devname << "' in MockDataParameters file." << QwLog::endl;
789 continue;
790 }
791 // The device should process the reminder of this line.
793 }
794}
795
796//--------------------------------------------------------------------------------------------------------
797
798/** Parse rotation and gain tokens for a BPM and apply to the instance. */
800{
801
802 Bool_t ldebug = kFALSE;
803
804 TString token = "0";
805 TString angle,xgain,ygain;
806 Double_t rotation_angle = 0;
807
808 while(token!=""){
809 token= mapstr->GetTypedNextToken<TString>();
810 token.Remove(TString::kBoth,'\0');
811
812 if(token.Contains("unrotated")){
813 if(ldebug) std::cout<<" unrotated "<<std::endl;
814 bpm->SetRotationOff();
815 }
816 else if(token.Contains("rotation")){
817 // If the status is 'rotated'
818
819 // If a specific rotation angle is given read that
820 if(token.Contains("=")){
821 angle = token.Remove(0,9);
822 rotation_angle = atof(angle);
823 if(ldebug) std::cout<<"Rotation angle = "<<rotation_angle<<std::endl;
824 bpm->SetRotation(rotation_angle);
825 }
826 }
827 // If nothing is specified for rotation, a default rotation of 45 degrees is implied.
828
829 if(token.Contains("xgain")){
830 xgain = token.Remove(0,6);
831 if(ldebug) std::cout<<" xgain ="<<xgain<<std::endl;
832 bpm->SetGains("X", atof(xgain));
833 }
834
835 if(token.Contains("ygain")){
836 ygain = token.Remove(0,6);
837 if(ldebug) std::cout<<" ygain ="<<ygain<<std::endl;
838 bpm->SetGains("Y", atof(ygain));
839 }
840 }
841}
842
843//*****************************************************************//
844/**
845 * Load pedestals and calibration factors per subelement/device.
846 *
847 * @param pedestalfile Path to the input parameter file.
848 * @return 0 on success.
849 */
850Int_t QwBeamLine::LoadInputParameters(TString pedestalfile)
851{
852 Bool_t ldebug=kFALSE;
853
854 Int_t lineread=1;
855
856 if(ldebug)std::cout<<"QwBeamLine::LoadInputParameters("<< pedestalfile<<")\n";
857
858 QwParameterFile mapstr(pedestalfile.Data()); //Open the file
860
861 while (mapstr.ReadNextLine())
862 {
863 lineread+=1;
864 if(ldebug)std::cout<<" line read so far ="<<lineread<<"\n";
865 mapstr.TrimComment('!'); // Remove everything after a '!' character.
866 mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
867 if (mapstr.LineIsEmpty()) continue;
868 else
869 {
870 TString varname = mapstr.GetTypedNextToken<TString>(); //name of the channel
871 varname.ToLower();
872 varname.Remove(TString::kBoth,' ');
873 Double_t varped = mapstr.GetTypedNextToken<Double_t>(); // value of the pedestal
874 Double_t varcal = mapstr.GetTypedNextToken<Double_t>(); // value of the calibration factor
875 /*Double_t varweight = */ mapstr.GetTypedNextToken<Double_t>(); // value of the statistical weight
876
877 //if(ldebug) std::cout<<"inputs for channel "<<varname
878 // <<": ped="<<varped<<": cal="<<varcal<<": weight="<<varweight<<"\n";
879 Bool_t notfound=kTRUE;
880
881 if(notfound) {
882 for(size_t i=0;i<fStripline.size();i++)
883 {
884 for(int j=0;j<4;j++)
885 {
886 TString localname = fStripline[i].get()->GetSubElementName(j);
887 localname.ToLower();
888 if(ldebug) std::cout<<"Stripline element name =="<<localname
889 <<"== to be compared to =="<<varname<<"== \n";
890 if(localname==varname)
891 {
892 if(ldebug) std::cout<<" I found it !\n";
893 fStripline[i].get()->SetSubElementPedestal(j,varped);
894 fStripline[i].get()->SetSubElementCalibrationFactor(j,varcal);
895 notfound=kFALSE;
896 j=5;
897 i=fStripline.size()+1;
898 }
899 }
900 }
901 for(size_t i=0;i<fQPD.size();i++)
902 {
903 for(int j=0;j<4;j++)
904 {
905 TString localname = fQPD[i].GetSubElementName(j);
906 localname.ToLower();
907 if(ldebug) std::cout<<"QPD element name =="<<localname
908 <<"== to be compared to =="<<varname<<"== \n";
909 if(localname==varname)
910 {
911 if(ldebug) std::cout<<" I found it !\n";
912 fQPD[i].SetSubElementPedestal(j,varped);
913 fQPD[i].SetSubElementCalibrationFactor(j,varcal);
914 notfound=kFALSE;
915 j=5;
916 i=fQPD.size()+1;
917 }
918 }
919 }
920 for(size_t i=0;i<fLinearArray.size();i++)
921 {
922 for(int j=0;j<8;j++)
923 {
924 TString localname = fLinearArray[i].GetSubElementName(j);
925 localname.ToLower();
926 if(ldebug) std::cout<<"LinearArray element name =="<<localname
927 <<"== to be compared to =="<<varname<<"== \n";
928 if(localname==varname)
929 {
930 if(ldebug) std::cout<<" I found it !\n";
931 fLinearArray[i].SetSubElementPedestal(j,varped);
932 fLinearArray[i].SetSubElementCalibrationFactor(j,varcal);
933 notfound=kFALSE;
934 j=9;
935 i=fLinearArray.size()+1;
936 }
937 }
938 }
939 for(size_t i=0;i<fCavity.size();i++)
940 {
941 for(size_t j=0;j<QwBPMCavity::kNumElements;j++)
942 {
943 TString localname = fCavity[i].GetSubElementName(j);
944 localname.ToLower();
945 if(ldebug) std::cout<<"Cavity element name =="<<localname
946 <<"== to be compared to =="<<varname<<"== \n";
947 if(localname==varname)
948 {
949 if(ldebug) std::cout<<" I found it !\n";
950 fCavity[i].SetSubElementPedestal(j,varped);
951 fCavity[i].SetSubElementCalibrationFactor(j,varcal);
952 notfound=kFALSE;
953 j=3;
954 i=fCavity.size()+1;
955 }
956 }
957 }
958 for(size_t i=0;i<fBCM.size();i++) {
959 if(fBCM[i].get()->GetElementName()==varname)
960 {
961 fBCM[i].get()->SetPedestal(varped);
962 fBCM[i].get()->SetCalibrationFactor(varcal);
963 i=fBCM.size()+1;
964 notfound=kFALSE;
965 i=fBCM.size()+1;
966 }
967 }
968 for(size_t i=0;i<fClock.size();i++) {
969 if(fClock[i].get()->GetElementName()==varname)
970 {
971 fClock[i].get()->SetPedestal(varped);
972 fClock[i].get()->SetCalibrationFactor(varcal);
973 i=fClock.size()+1;
974 notfound=kFALSE;
975 i=fClock.size()+1;
976 }
977 }
978 for(size_t i=0;i<fHaloMonitor.size();i++) {
979 if(fHaloMonitor[i].GetElementName()==varname)
980 {
981 std::cout<<varname<<" I found it ! "<<varcal<<" ped. "<<varped<<"\n";
982 fHaloMonitor[i].SetPedestal(varped);
983 fHaloMonitor[i].SetCalibrationFactor(varcal);
984 i=fHaloMonitor.size()+1;
985 notfound=kFALSE;
986 i=fHaloMonitor.size()+1;
987 }
988 }
989 }
990 }
991 }
992 if(ldebug) std::cout<<" line read in the pedestal + cal file ="<<lineread<<" \n";
993
994 ldebug=kFALSE;
995 mapstr.Close(); // Close the file (ifstream)
996 return 0;
997}
998
999
1000//*****************************************************************//
1001/** Randomize event data for all managed devices for mock runs. */
1002void QwBeamLine::RandomizeEventData(int helicity, double time)
1003{
1004 // Randomize all QwBPMStripline buffers
1005 for (size_t i = 0; i < fStripline.size(); i++)
1006 {
1007 fStripline[i].get()->RandomizeEventData(helicity, time);
1008 // fStripline[i].get()->PrintInfo();
1009 }
1010
1011 for (size_t i = 0; i < fCavity.size(); i++)
1012 fCavity[i].RandomizeEventData(helicity, time);
1013
1014 // Randomize all QwBCM buffers
1015 for (size_t i = 0; i < fBCM.size(); i++)
1016 {
1017 fBCM[i].get()->RandomizeEventData(helicity, time);
1018 // fBCM[i].get()->PrintInfo();
1019 }
1020
1021 // Randomize all QwHaloMonitor buffers
1022 //for (size_t i = 0; i < fHaloMonitor.size(); i++)
1023 //fHaloMonitor[i].RandomizeEventData(helicity, time);
1024
1025//-------------------------------------------------------------------------------------------
1026 for(size_t i=0;i<fBCMCombo.size();i++){
1027 fBCMCombo[i].get()->RandomizeEventData(helicity, time);
1028 for (size_t j=0; j<fBCMCombo[i].get()->GetNumberOfElements(); j++){
1029 VQwBCM * bcm = GetBCM(fBCMCombo[i].get()->GetSubElementName(j));
1030 if (bcm){
1031 fBCMCombo[i].get()->GetProjectedCharge(bcm);
1032 }
1033 }
1034 }
1035//-------------------------------------------------------------------------------------------
1036 for (size_t i=0; i<fBPMCombo.size(); i++){
1037 fBPMCombo[i].get()->RandomizeEventData(helicity, time);
1038 //fBPMCombo[i].get()->PrintValue();
1039 for (size_t j=0; j<fBPMCombo[i].get()->GetNumberOfElements(); j++){
1040 VQwBPM * bpm = GetBPMStripline(fBPMCombo[i].get()->GetSubElementName(j));
1041 if (bpm){
1042 fBPMCombo[i].get()->GetProjectedPosition(bpm);
1043// print the bpm device name, and get the x and y and z? values and print them
1044// std::cout << "bpm " << bpm->GetElementName() << std::endl;
1045// std::cout << "xpos= " << bpm->GetPosition(VQwBPM::kXAxis) << std::endl;
1046// std::cout << "ypos= " << bpm->GetPosition(VQwBPM::kYAxis) << std::endl;
1047// std::cout << "zpos= " << bpm->GetPosition(VQwBPM::kZAxsi) << std::endl;
1048// bpm->PrintInfo();
1049 // Call the new function in stripline class to fill all internal variables from the fAbsPos for the bpm object
1050 }
1051 }
1052 }
1053//-------------------------------------------------------------------------------------------
1054 for (size_t i=0;i<fECalculator.size();i++)
1055 {
1056 fECalculator[i].RandomizeEventData(helicity, time);
1057 //fECalculator[i].PrintValue();
1058 for (size_t j=0; j<fECalculator[i].GetNumberOfElements(); j++)
1059 {
1060 // std::cout << "In loop over ec subelements; device name = " << fECalculator[i].GetSubElementName(j) << std::endl;
1061 VQwBPM * bpm = GetBPMStripline(fECalculator[i].GetSubElementName(j));
1062 if (bpm)
1063 {
1064 fECalculator[i].GetProjectedPosition(bpm);
1065 }
1066 }
1067 }
1068}
1069
1070
1071//*****************************************************************//
1072/**
1073 * Serialize active element buffers into a CODA-style bank/subbank layout and
1074 * append to the provided buffer.
1075 */
1076void QwBeamLine::EncodeEventData(std::vector<UInt_t> &buffer)
1077{
1078 std::vector<UInt_t> elements;
1079 elements.clear();
1080
1081 // Get all buffers in the order they are defined in the map file
1082 for (size_t i = 0; i < fBeamDetectorID.size(); i++) {
1083 // This is a QwBCM
1084 if (fBeamDetectorID.at(i).fTypeID == kQwBCM){
1085 fBCM[fBeamDetectorID.at(i).fIndex].get()->EncodeEventData(elements);
1086 //std::cout << "" << fBCM[fBeamDetectorID.at(i).fIndex].get()->GetElementName() << std::endl;
1087 }
1088 // This is a QwBPMStripline (which has 4 entries, only process the first one)
1089 if (fBeamDetectorID.at(i).fTypeID == kQwBPMStripline
1090 && fBeamDetectorID.at(i).fSubelement == 0){
1091 fStripline[fBeamDetectorID.at(i).fIndex].get()->EncodeEventData(elements);
1092 // Print the HWsum absolute position values for the BPM
1093 //fStripline[fBeamDetectorID.at(i).fIndex].get()->PrintValue();
1094 }
1095
1096 // If this is a combined BPM, let's try to print the position and angle HWsum values
1097 }
1098
1099 // If there is element data, generate the subbank header
1100 std::vector<UInt_t> subbankheader;
1101 std::vector<UInt_t> rocheader;
1102 if (elements.size() > 0) {
1103
1104 // Form CODA subbank header
1105 subbankheader.clear();
1106 subbankheader.push_back(elements.size() + 1); // subbank size
1107 subbankheader.push_back((fCurrentBank_ID << 16) | (0x01 << 8) | (1 & 0xff));
1108 // subbank tag | subbank type | event number
1109
1110 // Form CODA bank/roc header
1111 rocheader.clear();
1112 rocheader.push_back(subbankheader.size() + elements.size() + 1); // bank/roc size
1113 rocheader.push_back((fCurrentROC_ID << 16) | (0x10 << 8) | (1 & 0xff));
1114 // bank tag == ROC | bank type | event number
1115
1116 // Add bank header, subbank header and element data to output buffer
1117 buffer.insert(buffer.end(), rocheader.begin(), rocheader.end());
1118 buffer.insert(buffer.end(), subbankheader.begin(), subbankheader.end());
1119 buffer.insert(buffer.end(), elements.begin(), elements.end());
1120 }
1121}
1122
1123//*****************************************************************//
1124/**
1125 * Route a raw ROC/bank buffer to the correct devices and subelements.
1126 *
1127 * @return 0 on success.
1128 */
1129/*!
1130 * \brief Route raw ROC/bank buffer data to the correct devices and subelements.
1131 * \param roc_id ReadOut Controller identifier.
1132 * \param bank_id Data bank identifier within the ROC.
1133 * \param buffer Pointer to raw data buffer from DAQ.
1134 * \param num_words Number of 32-bit words in the buffer.
1135 * \return 0 on success.
1136 *
1137 * This is a critical event processing function (~130 lines) that routes raw data
1138 * from the data acquisition system to the appropriate beam line devices. It:
1139 *
1140 * - Maps ROC/bank combinations to internal subbank indices using GetSubbankIndex()
1141 * - Handles data alignment by skipping padding words (0xf0f0f0f0) at buffer start
1142 * - Iterates through all registered beam detector IDs to find matching devices
1143 * - Routes data to device-specific ProcessEvBuffer() methods based on device type:
1144 * - kQwBPMStripline: 4-channel stripline beam position monitors
1145 * - kQwQPD: Quad photodiode detectors
1146 * - kQwLinearArray: Linear diode arrays
1147 * - kQwBPMCavity: Cavity-type beam position monitors
1148 * - kQwBCM: Beam current monitors (various ADC/scaler types)
1149 * - kQwClock: Timing reference channels
1150 *
1151 * Each device receives a pointer to its specific data section within the buffer,
1152 * calculated using the device's fWordInSubbank offset. The remaining word count
1153 * is passed to prevent buffer overruns during device-specific decoding.
1154 *
1155 * Buffer Layout Handling:
1156 * - Accounts for variable-length device data (e.g., 6 words for VQWK, 1 for scalers)
1157 * - Manages subelement indexing for multi-channel devices
1158 * - Handles both integrating ADCs and scaler-based measurements
1159 *
1160 * Error Conditions:
1161 * - Invalid ROC/bank combinations are silently ignored (index < 0)
1162 * - Empty buffers (num_words == 0) are skipped
1163 * - Buffer alignment issues are detected and corrected automatically
1164 *
1165 * \warning This function must be called after LoadChannelMap() to ensure
1166 * proper device registration and buffer offset calculations.
1167 */
1168Int_t QwBeamLine::ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words)
1169{
1170 Bool_t lkDEBUG=kFALSE;
1171
1172 Int_t index = GetSubbankIndex(roc_id,bank_id);
1173 if (index>=0 && num_words>0){
1174 // We want to process this ROC. Begin looping through the data.
1175 if (lkDEBUG)
1176 std::cout << "QwBeamLine::ProcessEvBuffer: "
1177 << "Begin processing ROC" << roc_id
1178 << " and subbank "<<bank_id
1179 << " number of words="<<num_words<<std::endl;
1180 if (buffer[0]==0xf0f0f0f0 && num_words%2==1){
1181 buffer++;
1182 if (lkDEBUG)
1183 std::cout << "QwBeamLine::ProcessEvBuffer: "
1184 << "Skipped padding word 0xf0f0f0f0 at beginning of buffer."
1185 << std::endl;
1186 }
1187
1188 for(size_t i=0;i<fBeamDetectorID.size();i++)
1189 {
1190 if(fBeamDetectorID[i].fSubbankIndex==index)
1191 {
1192
1193 if(fBeamDetectorID[i].fTypeID==kQwBPMStripline)
1194 {
1195 if (lkDEBUG)
1196 {
1197 std::cout<<"found stripline data for "<<fBeamDetectorID[i].fdetectorname<<std::endl;
1198 std::cout<<"word left to read in this buffer:"<<num_words-fBeamDetectorID[i].fWordInSubbank<<std::endl;
1199 }
1200 fStripline[fBeamDetectorID[i].fIndex].get()->
1201 ProcessEvBuffer(&(buffer[fBeamDetectorID[i].fWordInSubbank]),
1202 num_words-fBeamDetectorID[i].fWordInSubbank,
1203 fBeamDetectorID[i].fSubelement);
1204 }
1205
1206 if(fBeamDetectorID[i].fTypeID==kQwQPD)
1207 {
1208 if (lkDEBUG)
1209 {
1210 std::cout<<"found qpd data for "<<fBeamDetectorID[i].fdetectorname<<std::endl;
1211 std::cout<<"word left to read in this buffer:"<<num_words-fBeamDetectorID[i].fWordInSubbank<<std::endl;
1212 }
1213 fQPD[fBeamDetectorID[i].fIndex].
1214 ProcessEvBuffer(&(buffer[fBeamDetectorID[i].fWordInSubbank]),
1215 num_words-fBeamDetectorID[i].fWordInSubbank,
1216 fBeamDetectorID[i].fSubelement);
1217 }
1218
1219 if(fBeamDetectorID[i].fTypeID==kQwLinearArray)
1220 {
1221 if (lkDEBUG)
1222 {
1223 std::cout<<"found linear array data for "<<fBeamDetectorID[i].fdetectorname<<fBeamDetectorID[i].fIndex<<std::endl;
1224 std::cout<<"word left to read in this buffer:"<<num_words-fBeamDetectorID[i].fWordInSubbank<<std::endl;
1225 }
1226 fLinearArray[fBeamDetectorID[i].fIndex].
1227 ProcessEvBuffer(&(buffer[fBeamDetectorID[i].fWordInSubbank]),
1228 num_words-fBeamDetectorID[i].fWordInSubbank,
1229 fBeamDetectorID[i].fSubelement);
1230
1231 }
1232
1233 if(fBeamDetectorID[i].fTypeID==kQwBPMCavity)
1234 {
1235 if (lkDEBUG)
1236 {
1237 std::cout<<"found stripline data for "<<fBeamDetectorID[i].fdetectorname<<std::endl;
1238 std::cout<<"word left to read in this buffer:"<<num_words-fBeamDetectorID[i].fWordInSubbank<<std::endl;
1239 }
1240 fCavity[fBeamDetectorID[i].fIndex].
1241 ProcessEvBuffer(&(buffer[fBeamDetectorID[i].fWordInSubbank]),
1242 num_words-fBeamDetectorID[i].fWordInSubbank,
1243 fBeamDetectorID[i].fSubelement);
1244 }
1245
1246 if(fBeamDetectorID[i].fTypeID==kQwBCM)
1247 {
1248 if (lkDEBUG)
1249 {
1250 std::cout<<"found bcm data for "<<fBeamDetectorID[i].fdetectorname<<std::endl;
1251 std::cout<<"word left to read in this buffer:"<<num_words-fBeamDetectorID[i].fWordInSubbank<<std::endl;
1252 }
1253 fBCM[fBeamDetectorID[i].fIndex].get()->
1254 ProcessEvBuffer(&(buffer[fBeamDetectorID[i].fWordInSubbank]),
1255 num_words-fBeamDetectorID[i].fWordInSubbank);
1256 }
1257
1258 if(fBeamDetectorID[i].fTypeID==kQwClock)
1259 {
1260 if (lkDEBUG)
1261 {
1262 std::cout<<"found clock data for "<<fBeamDetectorID[i].fdetectorname<<std::endl;
1263 std::cout<<"word left to read in this buffer:"<<num_words-fBeamDetectorID[i].fWordInSubbank<<std::endl;
1264 }
1265 fClock[fBeamDetectorID[i].fIndex].get()->
1266 ProcessEvBuffer(&(buffer[fBeamDetectorID[i].fWordInSubbank]),
1267 num_words-fBeamDetectorID[i].fWordInSubbank);
1268 }
1269
1270 if(fBeamDetectorID[i].fTypeID==kQwHaloMonitor)
1271 {
1272 if (lkDEBUG)
1273 {
1274 std::cout<<"found halo monitor data for "<<fBeamDetectorID[i].fdetectorname<<std::endl;
1275 std::cout<<"word left to read in this buffer:"<<num_words-fBeamDetectorID[i].fWordInSubbank<<std::endl;
1276 }
1277 fHaloMonitor[fBeamDetectorID[i].fIndex].
1278 ProcessEvBuffer(&(buffer[fBeamDetectorID[i].fWordInSubbank]),
1279 num_words-fBeamDetectorID[i].fWordInSubbank);
1280 }
1281
1282 }
1283 }
1284 }
1285
1286 return 0;
1287}
1288
1289
1290
1291//*****************************************************************//
1292/** Apply single-event cuts to all devices and count failures. */
1294
1295 Bool_t status=kTRUE;
1296
1297 for(size_t i=0;i<fBCM.size();i++){
1298 status &= fBCM[i].get()->ApplySingleEventCuts();
1299 if(!status && bDEBUG) std::cout<<"******* QwBeamLine::SingleEventCuts()->BCM[ "<<i
1300 <<" , "<<fBCM[i].get()->GetElementName()<<" ] ******\n";
1301 }
1302
1303 for(size_t i=0;i<fClock.size();i++){
1304 status &= fClock[i].get()->ApplySingleEventCuts();
1305 if(!status && bDEBUG) std::cout<<"******* QwBeamLine::SingleEventCuts()->Clock[ "<<i
1306 <<" , "<<fClock[i].get()->GetElementName()<<" ] ******\n";
1307 }
1308
1309 for(size_t i=0;i<fHaloMonitor.size();i++){
1310 status &= fHaloMonitor[i].ApplySingleEventCuts();
1311 if(!status && bDEBUG) std::cout<<"******* QwBeamLine::SingleEventCuts()->HaloMonitor[ "<<i
1312 <<" , "<<fHaloMonitor[i].GetElementName()<<" ] ******\n";
1313 }
1314
1315 for(size_t i=0;i<fStripline.size();i++){
1316 status &= fStripline[i].get()->ApplySingleEventCuts();
1317 if(!status && bDEBUG) std::cout<<"******** QwBeamLine::SingleEventCuts()->BPMStripline[ "<<i
1318 <<" , "<<fStripline[i].get()->GetElementName()<<" ] *****\n";
1319
1320 }
1321
1322 for(size_t i=0;i<fQPD.size();i++){
1323 status &= fQPD[i].ApplySingleEventCuts();
1324 if(!status && bDEBUG) std::cout<<"******** QwBeamLine::SingleEventCuts()->QPD[ "<<i
1325 <<" , "<<fQPD[i].GetElementName()<<" ] *****\n";
1326 }
1327 for(size_t i=0;i<fLinearArray.size();i++){
1328 status &= fLinearArray[i].ApplySingleEventCuts();
1329 if(!status && bDEBUG) std::cout<<"******** QwBeamLine::SingleEventCuts()->LinearArray[ "<<i
1330 <<" , "<<fLinearArray[i].GetElementName()<<" ] *****\n";
1331 }
1332
1333 for(size_t i=0;i<fCavity.size();i++){
1334 status &= fCavity[i].ApplySingleEventCuts();
1335 if(!status && bDEBUG) std::cout<<"******** QwBeamLine::SingleEventCuts()->BPMCavity[ "<<i
1336 <<" , "<<fCavity[i].GetElementName()<<" ] *****\n";
1337 }
1338
1339 for(size_t i=0;i<fBCMCombo.size();i++){
1340 status &= fBCMCombo[i].get()->ApplySingleEventCuts();
1341 if(!status && bDEBUG) std::cout<<"******* QwBeamLine::SingleEventCuts()->CombinedBCM[ "<<i
1342 <<" , "<<fBCMCombo[i].get()->GetElementName()<<" ] ******\n";
1343 }
1344
1345 for(size_t i=0;i<fBPMCombo.size();i++){
1346 status &= fBPMCombo[i].get()->ApplySingleEventCuts();
1347 if(!status && bDEBUG) std::cout<<"******* QwBeamLine::SingleEventCuts()->CombinedBPM[ "<<i
1348 <<" , "<<fBPMCombo[i].get()->GetElementName()<<" ] ******\n";
1349
1350 }
1351 for(size_t i=0;i<fECalculator.size();i++){
1352 status &= fECalculator[i].ApplySingleEventCuts();
1353 if(!status && bDEBUG) std::cout<<"******* QwBeamLine::SingleEventCuts()->EnergyCalculator[ "<<i
1354 <<" , "<<fECalculator[i].GetElementName()<<" ] ******\n";
1355
1356 }
1357
1358
1359 //If at least one of the devices failed event cuts, increment error counter for QwBeamLine
1360 if (!status)
1362
1363
1364 return status;
1365
1366}
1367
1368/** Polymorphic per-device burp/burst check vs. a reference subsystem. */
1370 Bool_t burpstatus = kFALSE;
1371 VQwSubsystem* tmp = const_cast<VQwSubsystem *>(subsys);
1372 if(Compare(tmp)) {
1373 const QwBeamLine* input = dynamic_cast<const QwBeamLine*>(subsys);
1374 for(size_t i=0;i<input->fClock.size();i++){
1375 //QwError << "************* test Clock *****************" << QwLog::endl;
1376 burpstatus |= (this->fClock[i].get())->CheckForBurpFail(input->fClock[i].get());
1377 }
1378 for(size_t i=0;i<input->fStripline.size();i++){
1379 //QwError << "************* test stripline *****************" << QwLog::endl;
1380 burpstatus |= (this->fStripline[i].get())->CheckForBurpFail(input->fStripline[i].get());
1381 }
1382 for(size_t i=0;i<input->fQPD.size();i++){
1383 //QwError << "************* test QPD *****************" << QwLog::endl;
1384 burpstatus |= (this->fQPD[i]).CheckForBurpFail(&(input->fQPD[i]));
1385 }
1386 for(size_t i=0;i<input->fLinearArray.size();i++){
1387 //QwError << "************* test Lin *****************" << QwLog::endl;
1388 burpstatus |= (this->fLinearArray[i]).CheckForBurpFail(&(input->fLinearArray[i]));
1389 }
1390 for(size_t i=0;i<input->fCavity.size();i++){
1391 //QwError << "************* test Cavity *****************" << QwLog::endl;
1392 burpstatus |= (this->fCavity[i]).CheckForBurpFail(&(input->fCavity[i]));
1393 }
1394 for(size_t i=0;i<input->fBCM.size();i++){
1395 //QwError << "************* test BCM *****************" << QwLog::endl;
1396 burpstatus |= (this->fBCM[i].get())->CheckForBurpFail(input->fBCM[i].get());
1397 }
1398 for(size_t i=0;i<input->fBCMCombo.size();i++){
1399 //QwError << "************* test BCMC *****************" << QwLog::endl;
1400 burpstatus |= (this->fBCMCombo[i].get())->CheckForBurpFail(input->fBCMCombo[i].get());
1401 }
1402 for(size_t i=0;i<input->fBPMCombo.size();i++){
1403 //QwError << "************* test BPMC *****************" << QwLog::endl;
1404 burpstatus |= (this->fBPMCombo[i].get())->CheckForBurpFail(input->fBPMCombo[i].get());
1405 }
1406 for(size_t i=0;i<input->fECalculator.size();i++){
1407 //QwError << "************* test ECalc *****************" << QwLog::endl;
1408 burpstatus |= (this->fECalculator[i]).CheckForBurpFail(&(input->fECalculator[i]));
1409 }
1410 for(size_t i=0;i<input->fHaloMonitor.size();i++){
1411 //QwError << "************* test Halo *****************" << QwLog::endl;
1412 burpstatus |= (this->fHaloMonitor[i]).CheckForBurpFail(&(input->fHaloMonitor[i]));
1413 }
1414 }
1415 return burpstatus;
1416}
1417
1418
1419
1420//*****************************************************************//
1421/** Print a beamline-wide summary of persistent error counters. */
1422void QwBeamLine::PrintErrorCounters() const{//inherited from the VQwSubsystemParity; this will display the error summary
1423
1424 QwMessage<<"*********QwBeamLine Error Summary****************"<<QwLog::endl;
1426
1427 for(size_t i=0;i<fClock.size();i++){
1428 fClock[i].get()->PrintErrorCounters();
1429 }
1430 printf("\n");
1431 for(size_t i=0;i<fBCM.size();i++){
1432 fBCM[i].get()->PrintErrorCounters();
1433 }
1434 printf("\n");
1435 for(size_t i=0;i<fHaloMonitor.size();i++){
1436 fHaloMonitor[i].PrintErrorCounters();
1437 }
1438 printf("\n");
1439 for(size_t i=0;i<fStripline.size();i++){
1440 fStripline[i].get()->PrintErrorCounters();
1441 printf("\n");
1442 }
1443 for(size_t i=0;i<fQPD.size();i++){
1444 fQPD[i].PrintErrorCounters();
1445 }
1446 printf("\n");
1447 for(size_t i=0;i<fLinearArray.size();i++){
1448 fLinearArray[i].PrintErrorCounters();
1449 }
1450 printf("\n");
1451 for(size_t i=0;i<fCavity.size();i++){
1452 fCavity[i].PrintErrorCounters();
1453 }
1454 printf("\n");
1455 for(size_t i=0;i<fBCMCombo.size();i++){
1456 fBCMCombo[i].get()->PrintErrorCounters();
1457 }
1458 printf("\n");
1459 for(size_t i=0;i<fBPMCombo.size();i++){
1460 fBPMCombo[i].get()->PrintErrorCounters();
1461 }
1462 printf("\n");
1463 for(size_t i=0;i<fECalculator.size();i++){
1464 fECalculator[i].PrintErrorCounters();
1465 }
1467}
1468
1469//*****************************************************************//
1470/** Increment error counters across all managed devices. */
1472{
1473 for(size_t i=0;i<fClock.size();i++){
1474 fClock[i].get()->IncrementErrorCounters();
1475 }
1476 for(size_t i=0;i<fBCM.size();i++){
1477 fBCM[i].get()->IncrementErrorCounters();
1478 }
1479 for(size_t i=0;i<fHaloMonitor.size();i++){
1480 fHaloMonitor[i].IncrementErrorCounters();
1481 }
1482 for(size_t i=0;i<fStripline.size();i++){
1483 fStripline[i].get()->IncrementErrorCounters();
1484 }
1485 for(size_t i=0;i<fQPD.size();i++){
1486 fQPD[i].IncrementErrorCounters();
1487 }
1488 for(size_t i=0;i<fLinearArray.size();i++){
1489 fLinearArray[i].IncrementErrorCounters();
1490 }
1491 for(size_t i=0;i<fCavity.size();i++){
1492 fCavity[i].IncrementErrorCounters();
1493 }
1494 for(size_t i=0;i<fBCMCombo.size();i++){
1495 fBCMCombo[i].get()->IncrementErrorCounters();
1496 }
1497 for(size_t i=0;i<fBPMCombo.size();i++){
1498 fBPMCombo[i].get()->IncrementErrorCounters();
1499 }
1500 for(size_t i=0;i<fECalculator.size();i++){
1501 fECalculator[i].IncrementErrorCounters();
1502 }
1503}
1504
1505//*****************************************************************//
1506/** Return the OR of per-device event-cut error flags. */
1507UInt_t QwBeamLine::GetEventcutErrorFlag(){//return the error flag
1508 UInt_t ErrorFlag;
1509 UInt_t ErrorFlagtmp;
1510 ErrorFlag=0;
1511 for(size_t i=0;i<fBCM.size();i++){
1512 ErrorFlagtmp = fBCM[i].get()->GetEventcutErrorFlag();
1513 ErrorFlag |=ErrorFlagtmp;
1514 }
1515 for(size_t i=0;i<fStripline.size();i++){
1516 ErrorFlag |= fStripline[i].get()->GetEventcutErrorFlag();
1517 }
1518 for(size_t i=0;i<fQPD.size();i++){
1519 ErrorFlag |= fQPD[i].GetEventcutErrorFlag();
1520 }
1521 for(size_t i=0;i<fLinearArray.size();i++){
1522 ErrorFlag |= fLinearArray[i].GetEventcutErrorFlag();
1523 }
1524 for(size_t i=0;i<fCavity.size();i++){
1525 ErrorFlag |= fCavity[i].GetEventcutErrorFlag();
1526 }
1527 for(size_t i=0;i<fBCMCombo.size();i++){
1528 ErrorFlag |= fBCMCombo[i].get()->GetEventcutErrorFlag();
1529 }
1530 for(size_t i=0;i<fBPMCombo.size();i++){
1531 ErrorFlag |= fBPMCombo[i].get()->GetEventcutErrorFlag();
1532 }
1533 for(size_t i=0;i<fECalculator.size();i++){
1534 ErrorFlag |= fECalculator[i].GetEventcutErrorFlag();
1535 }
1536
1537 return ErrorFlag;
1538
1539}
1540
1541//*****************************************************************//
1542/** Update and return the OR of per-device event-cut error flags. */
1543UInt_t QwBeamLine::UpdateErrorFlag(){//return the error flag
1544 UInt_t ErrorFlag;
1545 UInt_t ErrorFlagtmp;
1546 ErrorFlag=0;
1547 for(size_t i=0;i<fBCM.size();i++){
1548 ErrorFlagtmp = fBCM[i].get()->UpdateErrorFlag();
1549 ErrorFlag |=ErrorFlagtmp;
1550 }
1551 for(size_t i=0;i<fStripline.size();i++){
1552 ErrorFlag |= fStripline[i].get()->UpdateErrorFlag();
1553 }
1554 for(size_t i=0;i<fQPD.size();i++){
1555 ErrorFlag |= fQPD[i].UpdateErrorFlag();
1556 }
1557 for(size_t i=0;i<fLinearArray.size();i++){
1558 ErrorFlag |= fLinearArray[i].UpdateErrorFlag();
1559 }
1560 for(size_t i=0;i<fCavity.size();i++){
1561 ErrorFlag |= fCavity[i].UpdateErrorFlag();
1562 }
1563 for(size_t i=0;i<fBCMCombo.size();i++){
1564 ErrorFlag |= fBCMCombo[i].get()->UpdateErrorFlag();
1565 }
1566 for(size_t i=0;i<fBPMCombo.size();i++){
1567 ErrorFlag |= fBPMCombo[i].get()->UpdateErrorFlag();
1568 }
1569 for(size_t i=0;i<fECalculator.size();i++){
1570 ErrorFlag |= fECalculator[i].UpdateErrorFlag();
1571 }
1572
1573 return ErrorFlag;
1574
1575}
1576
1577//*****************************************************************//
1578/** Copy error flags from a reference beamline into this instance. */
1580 VQwSubsystem* tmp = const_cast<VQwSubsystem*>(ev_error);
1581 if(Compare(tmp))
1582 {
1583
1584 const QwBeamLine* input = dynamic_cast<const QwBeamLine*>(ev_error);
1585
1586 /*
1587 for(size_t i=0;i<input->fClock.size();i++)
1588 *(this->fClock[i].get())=*(input->fClock[i].get());
1589 */
1590 for(size_t i=0;i<input->fStripline.size();i++)
1591 (this->fStripline[i].get())->UpdateErrorFlag(input->fStripline[i].get());
1592 for(size_t i=0;i<input->fQPD.size();i++)
1593 (this->fQPD[i]).UpdateErrorFlag(&(input->fQPD[i]));
1594 for(size_t i=0;i<input->fLinearArray.size();i++)
1595 (this->fLinearArray[i]).UpdateErrorFlag(&(input->fLinearArray[i]));
1596 for(size_t i=0;i<input->fCavity.size();i++)
1597 (this->fCavity[i]).UpdateErrorFlag(&(input->fCavity[i]));
1598 for(size_t i=0;i<input->fBCM.size();i++){
1599 (this->fBCM[i].get())->UpdateErrorFlag(input->fBCM[i].get());
1600 }
1601 for(size_t i=0;i<input->fBCMCombo.size();i++)
1602 (this->fBCMCombo[i].get())->UpdateErrorFlag(input->fBCMCombo[i].get()); //*(this->fBCMCombo[i].get())=*(input->fBCMCombo[i].get());
1603 for(size_t i=0;i<input->fBPMCombo.size();i++)
1604 (this->fBPMCombo[i].get())->UpdateErrorFlag(input->fBPMCombo[i].get()); //=*(input->fBPMCombo[i].get());
1605 for(size_t i=0;i<input->fECalculator.size();i++)
1606 (this->fECalculator[i]).UpdateErrorFlag(&(input->fECalculator[i]));
1607 for(size_t i=0;i<input->fHaloMonitor.size();i++)
1608 (this->fHaloMonitor[i]).UpdateErrorFlag(&(input->fHaloMonitor[i]));
1609
1610
1611
1612 }
1613}
1614
1615
1616//*****************************************************************//
1617/** Process one physics event: clocks first, then all devices. */
1619{
1620 // Make sure this one comes first! The clocks are needed by
1621 // other elements.
1622 for(size_t i=0;i<fClock.size();i++)
1623 fClock[i].get()->ProcessEvent();
1624
1625 for(size_t i=0;i<fStripline.size();i++){
1626 fStripline[i].get()->ProcessEvent();
1627 // fStripline[i].get()->PrintInfo();
1628 }
1629 for(size_t i=0;i<fCavity.size();i++)
1630 fCavity[i].ProcessEvent();
1631
1632 for(size_t i=0;i<fBCM.size();i++){
1633 fBCM[i].get()->ProcessEvent();
1634 // fBCM[i].get()->PrintInfo();
1635 }
1636 for(size_t i=0;i<fQPD.size();i++)
1637 fQPD[i].ProcessEvent();
1638
1639 for(size_t i=0;i<fLinearArray.size();i++)
1641
1642 for(size_t i=0;i<fHaloMonitor.size();i++){
1643 fHaloMonitor[i].ProcessEvent();
1644 }
1645
1646 for(size_t i=0;i<fBCMCombo.size();i++){
1647 fBCMCombo[i].get()->ProcessEvent();
1648 // fBCMCombo[i].get()->PrintInfo();
1649 }
1650 for(size_t i=0;i<fBPMCombo.size();i++){
1651 fBPMCombo[i].get()->ProcessEvent();
1652 // fBPMCombo[i].get()->PrintInfo();
1653 }
1654 for(size_t i=0;i<fECalculator.size();i++){
1655 fECalculator[i].ProcessEvent();
1656 }
1657 return;
1658}
1659
1660
1661//*****************************************************************//
1662/**
1663 * Handle configuration banks if present. Placeholder for future use.
1664 */
1665Int_t QwBeamLine::ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words)
1666{
1667
1668 return 0;
1669}
1670
1671//*****************************************************************//
1672/** Publish selected device channels according to the map file. */
1674{
1675 // Publish variables
1676 Bool_t status = kTRUE;
1677
1678 // Publish variables through map file
1679 // This should work with bcm, bpmstripline, bpmcavity, combo bpm and combo bcm
1680 for (size_t pp = 0; pp < fPublishList.size(); pp++) {
1681 TString publish_name = fPublishList.at(pp).at(0);
1682 TString device_type = fPublishList.at(pp).at(1);
1683 TString device_name = fPublishList.at(pp).at(2);
1684 TString device_prop = fPublishList.at(pp).at(3);
1685 device_type.ToLower();
1686 device_prop.ToLower();
1687
1688 const VQwHardwareChannel* tmp_channel = 0;
1689
1690 EQwBeamInstrumentType type_id;
1691 if (device_type == "combobpm")
1692 type_id = kQwCombinedBPM;
1693 else if (device_type == "combobcm")
1694 type_id = kQwCombinedBCM;
1695 else if (device_type == "comboenergy")
1696 type_id = kQwEnergyCalculator;
1697 else if (device_type == "scaler")
1698 type_id = kQwHaloMonitor;
1699 else
1700 type_id = GetQwBeamInstrumentType(device_type);
1701
1702 Int_t index = GetDetectorIndex(type_id,device_name);
1703
1704 if (type_id != kQwUnknownDeviceType
1705 && index != -1){
1706 tmp_channel = GetChannel(type_id,index,device_prop);
1707 } else
1708 QwError << "QwBeamLine::PublishInternalValues() error "<< QwLog::endl;
1709
1710 if (tmp_channel == NULL) {
1711 QwError << "QwBeamLine::PublishInternalValues(): " << publish_name << " not found" << QwLog::endl;
1712 status = kFALSE;
1713 } else {
1714 QwDebug << "QwBeamLine::PublishInternalValues(): " << publish_name << " found" << QwLog::endl;
1715
1716 status = PublishInternalValue(publish_name, "published-value", tmp_channel);
1717 }
1718 }
1719
1720 return status;
1721}
1722
1723//*****************************************************************//
1724/** Publish a device channel on-demand by inferred property suffix. */
1725Bool_t QwBeamLine::PublishByRequest(TString device_name)
1726{
1727 Bool_t status = kFALSE;
1728 const VQwHardwareChannel* tmp_channel = 0;
1729
1730 std::vector<TString> publishinfo(4,TString(""));
1731 publishinfo.at(0) = device_name;
1732
1733 EQwBeamInstrumentType type_id;
1734 Int_t index=-1;
1735
1736 TString name = device_name;
1737 TString device_prop = "value";
1738 if (device_name.EndsWith("WS")){
1739 name = device_name(0,device_name.Length()-2);
1740 device_prop = "ef";
1741 } else if (device_name.EndsWith("Q")){
1742 name = device_name(0,device_name.Length()-1);
1743 device_prop = "ef";
1744 } else if (device_name.EndsWith("XSlope")){
1745 name = device_name(0,device_name.Length()-6);
1746 device_prop = "xp";
1747 } else if (device_name.EndsWith("YSlope")){
1748 name = device_name(0,device_name.Length()-6);
1749 device_prop = "yp";
1750 } else if (device_name.EndsWith("X")){
1751 name = device_name(0,device_name.Length()-1);
1752 device_prop = "x";
1753 } else if (device_name.EndsWith("Y")){
1754 name = device_name(0,device_name.Length()-1);
1755 device_prop = "y";
1756 }
1757
1758 for(size_t i=0;i<fBeamDetectorID.size();i++) {
1759 if(fBeamDetectorID[i].fdetectorname==name
1760 || fBeamDetectorID[i].fdetectorname==device_name){
1761 index = fBeamDetectorID[i].fIndex;
1762 type_id = fBeamDetectorID[i].fTypeID;
1763
1764 publishinfo.at(1) = GetQwBeamInstrumentTypeName(type_id);
1765 publishinfo.at(2) = fBeamDetectorID[i].fdetectorname;
1766 publishinfo.at(3) = device_prop;
1767 break;
1768 }
1769 }
1770
1771 if (index != -1){
1772 tmp_channel = GetChannel(type_id,index,publishinfo.at(3));
1773 fPublishList.push_back(publishinfo);
1774 status = PublishInternalValue(publishinfo.at(0), "published-by-request",
1775 tmp_channel);
1776 }
1777
1778 return status;
1779}
1780
1781
1782//*****************************************************************//
1783/** Clear current-event state for all managed devices. */
1785{
1786 for(size_t i=0;i<fClock.size();i++)
1787 fClock[i].get()->ClearEventData();
1788 for(size_t i=0;i<fStripline.size();i++)
1789 fStripline[i].get()->ClearEventData();
1790 for(size_t i=0;i<fCavity.size();i++)
1792 for(size_t i=0;i<fBCM.size();i++)
1793 fBCM[i]->ClearEventData();
1794 for(size_t i=0;i<fQPD.size();i++)
1795 fQPD[i].ClearEventData();
1796 for(size_t i=0;i<fLinearArray.size();i++)
1798 for(size_t i=0;i<fHaloMonitor.size();i++)
1800
1801 for(size_t i=0;i<fBCMCombo.size();i++)
1802 fBCMCombo[i].get()->ClearEventData();
1803 for(size_t i=0;i<fBPMCombo.size();i++)
1804 fBPMCombo[i].get()->ClearEventData();
1805 for(size_t i=0;i<fECalculator.size();i++)
1807 return;
1808}
1809
1810//*****************************************************************//
1811/** Lookup the element index for a given device type and name. */
1812Int_t QwBeamLine::GetDetectorIndex( EQwBeamInstrumentType type_id, TString name) const
1813{
1814 Bool_t ldebug=kFALSE;
1815 Int_t result=-1;
1816 if(ldebug) {
1817 std::cout<<"QwBeamLine::GetDetectorIndex\n";
1818 std::cout<<"type_id=="<<type_id<<" name="<<name<<"\n";
1819 std::cout<<fBeamDetectorID.size()<<" already registered detector\n";
1820 }
1821 for(size_t i=0;i<fBeamDetectorID.size();i++) {
1822 if(ldebug){
1823 std::cout<<"testing against ("<<fBeamDetectorID[i].fTypeID
1824 <<","<<fBeamDetectorID[i].fdetectorname<<")=>"<<result<<"\n";
1825 }
1826 if(fBeamDetectorID[i].fTypeID==type_id
1827 && fBeamDetectorID[i].fdetectorname==name){
1828 result=fBeamDetectorID[i].fIndex;
1829 break;
1830 }
1831 }
1832 return result;
1833}
1834
1835/** Overload: retrieve a data element by detector ID. */
1837{
1838 return GetElement(det_id.fTypeID, det_id.fIndex);
1839};
1840
1841/** Overload: retrieve a data element by type and name. */
1843{
1844 Int_t index = GetDetectorIndex(TypeID,name);
1845 return GetElement(TypeID,index);
1846};
1847
1848/** Retrieve a data element pointer by type and index with dispatch. */
1850{
1851 VQwDataElement* tmp_ptr;
1852 switch (TypeID){
1853 case kQwBPMStripline:
1854 tmp_ptr = fStripline.at(index).get();
1855 break;
1856 case kQwQPD:
1857 tmp_ptr = &(fQPD.at(index));
1858 break;
1859 case kQwLinearArray:
1860 tmp_ptr = &(fLinearArray.at(index));
1861 break;
1862 case kQwBCM:
1863 tmp_ptr = fBCM.at(index).get();
1864 break;
1865 case kQwCombinedBCM:
1866 tmp_ptr = fBCMCombo.at(index).get();
1867 break;
1868 case kQwCombinedBPM:
1869 tmp_ptr = fBPMCombo.at(index).get();
1870 break;
1872 tmp_ptr = &(fECalculator.at(index));
1873 break;
1874 case kQwHaloMonitor:
1875 tmp_ptr = &(fHaloMonitor.at(index));
1876 break;
1877 case kQwBPMCavity:
1878 tmp_ptr = &(fCavity.at(index));
1879 break;
1880 case kQwClock:
1881 tmp_ptr = fClock.at(index).get();
1882 break;
1883 default:
1884 TString loc="QwBeamLine::GetElement called by "
1885 +this->GetName()+" with invalid arguments: "
1886 +GetQwBeamInstrumentTypeName(TypeID)+" "
1887 +Form("%d",index);
1888 throw std::invalid_argument(loc.Data());
1889 }
1890 return tmp_ptr;
1891};
1892
1893/** Const overload: retrieve a data element by type and index. */
1895{
1896 return const_cast<QwBeamLine*>(this)->GetElement(TypeID,index);
1897}
1898
1899/**
1900 * Retrieve a hardware channel (value/x/y/ef/xp/yp) from a specific device.
1901 */
1902const VQwHardwareChannel* QwBeamLine::GetChannel(EQwBeamInstrumentType TypeID, Int_t index, TString device_prop) const
1903{
1904 const VQwHardwareChannel* tmp_channel = 0;
1905
1906 if (TypeID==kQwBPMStripline || TypeID==kQwBPMCavity || TypeID==kQwQPD){
1907 const VQwBPM* tmp_ptr = dynamic_cast<const VQwBPM*>(GetElement(TypeID, index));
1908 if (device_prop == "x")
1909 tmp_channel = tmp_ptr->GetPosition(VQwBPM::kXAxis);
1910 else if (device_prop == "y")
1911 tmp_channel = tmp_ptr->GetPosition(VQwBPM::kYAxis);
1912 else if (device_prop == "ef")
1913 tmp_channel = tmp_ptr->GetEffectiveCharge();
1914 } else if (TypeID==kQwCombinedBPM){
1915 const VQwBPM* tmp_ptr = dynamic_cast<const VQwBPM*>(GetElement(TypeID, index));
1916 if (device_prop == "x")
1917 tmp_channel = tmp_ptr->GetPosition(VQwBPM::kXAxis);
1918 else if (device_prop == "y")
1919 tmp_channel = tmp_ptr->GetPosition(VQwBPM::kYAxis);
1920 else if (device_prop == "ef")
1921 tmp_channel = fBPMCombo.at(index)->GetEffectiveCharge();
1922 else if (device_prop == "xp")
1923 tmp_channel = fBPMCombo.at(index)->GetAngleX();
1924 else if (device_prop == "yp")
1925 tmp_channel = fBPMCombo.at(index)->GetAngleY();
1926 } else if (TypeID==kQwLinearArray){
1927 /// TODO: QwBeamLine::GetChannel
1928 /// How do we access linear array channel outputs?
1929 } else if (TypeID==kQwBCM || TypeID==kQwCombinedBCM){
1930 tmp_channel = dynamic_cast<const VQwBCM*>(GetElement(TypeID,index))->GetCharge();
1931 } else if (TypeID==kQwEnergyCalculator){
1932 tmp_channel = fECalculator.at(index).GetEnergy();
1933 } else if (TypeID==kQwHaloMonitor){
1934 tmp_channel = fHaloMonitor.at(index).GetScaler();
1935 } else if (TypeID==kQwClock){
1936 tmp_channel = fClock.at(index)->GetTime();
1937 } else {
1938 TString loc="QwBeamLine::GetChannel called by "
1939 +this->GetName()+" with invalid arguments: "
1940 +GetQwBeamInstrumentTypeName(TypeID)+" "
1941 +Form("%d",index);
1942 throw std::invalid_argument(loc.Data());
1943 }
1944 return tmp_channel;
1945}
1946
1947//*****************************************************************//
1948/** Find a BPMStripline by name. */
1950{
1951 if (! fStripline.empty()) {
1952 for (std::vector<VQwBPM_ptr >::iterator stripline = fStripline.begin(); stripline != fStripline.end(); ++stripline) {
1953 if ((*stripline).get()->GetElementName() == name) {
1954 return (*stripline).get();
1955 }
1956 }
1957 }
1958 return 0;
1959}
1960
1961//*****************************************************************//
1962
1963/** Find a BPM Cavity by name. */
1965{
1966 if (! fCavity.empty()) {
1967 for (std::vector<QwBPMCavity>::iterator cavity = fCavity.begin(); cavity != fCavity.end(); ++cavity) {
1968 if (cavity->GetElementName() == name) {
1969 return &(*cavity);
1970 }
1971 }
1972 }
1973 return 0;
1974}
1975
1976
1977//*****************************************************************//
1978/** Find a BCM by name. */
1979VQwBCM* QwBeamLine::GetBCM(const TString name)
1980{
1981 //QwWarning << "QwBeamLine::GetBCM" << QwLog::endl;
1982 if (! fBCM.empty()) {
1983 for (std::vector<VQwBCM_ptr >::iterator bcm = fBCM.begin(); bcm != fBCM.end(); ++bcm) {
1984 if ((*bcm).get()->GetElementName() == name) {
1985 return (*bcm).get();
1986 }
1987 }
1988
1989 //QwWarning << "BCM Found" << QwLog::endl;
1990 return 0;
1991 }
1992 return 0;
1993}
1994
1995
1996//*****************************************************************//
1997/** Find a Clock by name. */
1998VQwClock* QwBeamLine::GetClock(const TString name)
1999{
2000 //QwWarning << "QwBeamLine::GetClock" << QwLog::endl;
2001 if (! fClock.empty()) {
2002 for (std::vector<VQwClock_ptr >::iterator clock = fClock.begin(); clock != fClock.end(); ++clock) {
2003 if ((*clock).get()->GetElementName() == name) {
2004 return (*clock).get();
2005 }
2006 }
2007
2008 //QwWarning << "Clock Found" << QwLog::endl;
2009 return 0;
2010 }
2011 return 0;
2012}
2013
2014//*****************************************************************//
2015/** Find a CombinedBCM by name. */
2017{
2018 //QwWarning << "QwBeamLine::GetCombinedBCM" << QwLog::endl;
2019 if (! fBCMCombo.empty()) {
2020
2021 for (std::vector<VQwBCM_ptr>::iterator cbcm = fBCMCombo.begin(); cbcm != fBCMCombo.end(); ++cbcm) {
2022 if ((*cbcm).get()->GetElementName() == name) {
2023 return (*cbcm).get();
2024 }
2025 }
2026
2027
2028 }
2029 return 0;
2030}
2031
2032//*****************************************************************//
2033/** Find a CombinedBPM by name. */
2035{
2036 //QwWarning << "QwBeamLine::GetCombinedBPM" << QwLog::endl;
2037 if (! fBPMCombo.empty()) {
2038
2039 for (std::vector<VQwBPM_ptr>::iterator cbpm = fBPMCombo.begin(); cbpm != fBPMCombo.end(); ++cbpm) {
2040 if ((*cbpm).get()->GetElementName() == name) {
2041 return (*cbpm).get();
2042 }
2043 }
2044
2045
2046 }
2047 return 0;
2048}
2049
2050//*****************************************************************//
2051/** Find an EnergyCalculator by name. */
2053 if (! fECalculator.empty()) {
2054
2055 for (std::vector<QwEnergyCalculator>::iterator ecal = fECalculator.begin(); ecal != fECalculator.end(); ++ecal) {
2056 if (ecal->GetElementName() == name) {
2057 return &(*ecal);
2058 }
2059 }
2060
2061
2062 }
2063 return 0;
2064}
2065
2066//*****************************************************************//
2067/** Const overload: find a BPMStripline by name. */
2068const VQwBPM* QwBeamLine::GetBPMStripline(const TString name) const
2069{
2070 return const_cast<QwBeamLine*>(this)->GetBPMStripline(name);
2071}
2072
2074 if (! fHaloMonitor.empty()) {
2075
2076 for (std::vector<QwHaloMonitor>::iterator halo = fHaloMonitor.begin(); halo != fHaloMonitor.end(); ++halo) {
2077 if (halo->GetElementName() == name) {
2078 return &(*halo);
2079 }
2080 }
2081
2082
2083 }
2084 return 0;
2085};
2086
2087//*****************************************************************//
2088const QwBPMCavity* QwBeamLine::GetBPMCavity(const TString name) const
2089{
2090 return const_cast<QwBeamLine*>(this)->GetBPMCavity(name);
2091}
2092
2093//*****************************************************************//
2094const VQwBCM* QwBeamLine::GetBCM(const TString name) const
2095{
2096 return const_cast<QwBeamLine*>(this)->GetBCM(name);
2097}
2098
2099//*****************************************************************//
2100const VQwClock* QwBeamLine::GetClock(const TString name) const
2101{
2102 return const_cast<QwBeamLine*>(this)->GetClock(name);
2103}
2104
2105//*****************************************************************//
2106const VQwBCM* QwBeamLine::GetCombinedBCM(const TString name) const{
2107 return const_cast<QwBeamLine*>(this)->GetCombinedBCM(name);
2108}
2109
2110//*****************************************************************//
2111const VQwBPM* QwBeamLine::GetCombinedBPM(const TString name) const{
2112 return const_cast<QwBeamLine*>(this)->GetCombinedBPM(name);
2113}
2114
2115//*****************************************************************//
2117 return const_cast<QwBeamLine*>(this)->GetEnergyCalculator(name);
2118}
2119
2120 //*****************************************************************//
2121const QwHaloMonitor* QwBeamLine::GetScalerChannel(const TString name)const {
2122 return const_cast<QwBeamLine*>(this)->GetScalerChannel(name);
2123};
2124
2125
2126//*****************************************************************//
2128{
2129 // std::cout<<" here in QwBeamLine::operator= \n";
2130 if(Compare(value))
2131 {
2132
2133 QwBeamLine* input = dynamic_cast<QwBeamLine*>(value);
2134
2135 for(size_t i=0;i<input->fClock.size();i++)
2136 *(this->fClock[i].get())=*(input->fClock[i].get());
2137 for(size_t i=0;i<input->fStripline.size();i++)
2138 *(this->fStripline[i].get())=*(input->fStripline[i].get());
2139 for(size_t i=0;i<input->fQPD.size();i++)
2140 this->fQPD[i]=input->fQPD[i];
2141 for(size_t i=0;i<input->fLinearArray.size();i++)
2142 this->fLinearArray[i]=input->fLinearArray[i];
2143 for(size_t i=0;i<input->fCavity.size();i++)
2144 this->fCavity[i]=input->fCavity[i];
2145 for(size_t i=0;i<input->fBCM.size();i++)
2146 *(this->fBCM[i].get())=*(input->fBCM[i].get());
2147 for(size_t i=0;i<input->fHaloMonitor.size();i++)
2148 this->fHaloMonitor[i]=input->fHaloMonitor[i];
2149 for(size_t i=0;i<input->fBCMCombo.size();i++)
2150 *(this->fBCMCombo[i].get())=*(input->fBCMCombo[i].get());
2151 for(size_t i=0;i<input->fBPMCombo.size();i++)
2152 *(this->fBPMCombo[i].get())=*(input->fBPMCombo[i].get());
2153 for(size_t i=0;i<input->fECalculator.size();i++)
2154 this->fECalculator[i]=input->fECalculator[i];
2155
2156 if (input->fPublishList.size()>0){
2157 this->fPublishList.resize(input->fPublishList.size());
2158 for(size_t i=0;i<input->fPublishList.size();i++){
2159 this->fPublishList.at(i).resize(input->fPublishList.at(i).size());
2160 for(size_t j=0;j<input->fPublishList.at(i).size();j++){
2161 this->fPublishList.at(i).at(j)=input->fPublishList.at(i).at(j);
2162 }
2163 }
2164 }
2165
2166 }
2167 return *this;
2168}
2169
2170
2171//*****************************************************************//
2173{
2174 if(Compare(value))
2175 {
2176 //QwBeamLine* input= (QwBeamLine*)value ;
2177 QwBeamLine* input = dynamic_cast<QwBeamLine*>(value);
2178
2179 for(size_t i=0;i<input->fClock.size();i++)
2180 *(this->fClock[i].get())+=*(input->fClock[i].get());
2181 for(size_t i=0;i<input->fStripline.size();i++)
2182 *(this->fStripline[i].get())+=*(input->fStripline[i].get());
2183 for(size_t i=0;i<input->fCavity.size();i++)
2184 this->fCavity[i]+=input->fCavity[i];
2185 for(size_t i=0;i<input->fQPD.size();i++)
2186 this->fQPD[i]+=input->fQPD[i];
2187 for(size_t i=0;i<input->fLinearArray.size();i++)
2188 this->fLinearArray[i]+=input->fLinearArray[i];
2189 for(size_t i=0;i<input->fBCM.size();i++)
2190 *(this->fBCM[i].get())+=*(input->fBCM[i].get());
2191 for(size_t i=0;i<input->fHaloMonitor.size();i++)
2192 this->fHaloMonitor[i]+=input->fHaloMonitor[i];
2193 for(size_t i=0;i<input->fBCMCombo.size();i++)
2194 *(this->fBCMCombo[i].get())+=*(input->fBCMCombo[i].get());
2195 for(size_t i=0;i<input->fBPMCombo.size();i++)
2196 *(this->fBPMCombo[i].get())+=*(input->fBPMCombo[i].get());
2197 for(size_t i=0;i<input->fECalculator.size();i++)
2198 this->fECalculator[i]+=input->fECalculator[i];
2199
2200 if (input->fPublishList.size()>0){
2201 this->fPublishList.resize(input->fPublishList.size());
2202 for(size_t i=0;i<input->fPublishList.size();i++){
2203 this->fPublishList.at(i).resize(input->fPublishList.at(i).size());
2204 for(size_t j=0;j<input->fPublishList.at(i).size();j++){
2205 this->fPublishList.at(i).at(j)=input->fPublishList.at(i).at(j);
2206 }
2207 }
2208 }
2209
2210 }
2211 return *this;
2212}
2213
2214//*****************************************************************//
2216{
2217
2218 if(Compare(value))
2219 {
2220 QwBeamLine* input = dynamic_cast<QwBeamLine*>(value);
2221
2222 for(size_t i=0;i<input->fClock.size();i++)
2223 *(this->fClock[i].get())-=*(input->fClock[i].get());
2224 for(size_t i=0;i<input->fStripline.size();i++)
2225 *(this->fStripline[i].get())-=*(input->fStripline[i].get());
2226 for(size_t i=0;i<input->fCavity.size();i++)
2227 this->fCavity[i]-=input->fCavity[i];
2228 for(size_t i=0;i<input->fQPD.size();i++)
2229 this->fQPD[i]-=input->fQPD[i];
2230 for(size_t i=0;i<input->fLinearArray.size();i++)
2231 this->fLinearArray[i]-=input->fLinearArray[i];
2232 for(size_t i=0;i<input->fBCM.size();i++)
2233 *(this->fBCM[i].get())-=*(input->fBCM[i].get());
2234 for(size_t i=0;i<input->fHaloMonitor.size();i++)
2235 this->fHaloMonitor[i]-=input->fHaloMonitor[i];
2236 for(size_t i=0;i<input->fBCMCombo.size();i++)
2237 *(this->fBCMCombo[i].get())-=*(input->fBCMCombo[i].get());
2238 for(size_t i=0;i<input->fBPMCombo.size();i++)
2239 *(this->fBPMCombo[i].get())-=*(input->fBPMCombo[i].get());
2240 for(size_t i=0;i<input->fECalculator.size();i++)
2241 this->fECalculator[i]-=input->fECalculator[i];
2242
2243 if (input->fPublishList.size()>0){
2244 this->fPublishList.resize(input->fPublishList.size());
2245 for(size_t i=0;i<input->fPublishList.size();i++){
2246 this->fPublishList.at(i).resize(input->fPublishList.at(i).size());
2247 for(size_t j=0;j<input->fPublishList.at(i).size();j++){
2248 this->fPublishList.at(i).at(j)=input->fPublishList.at(i).at(j);
2249 }
2250 }
2251 }
2252
2253 }
2254 return *this;
2255}
2256
2257//*****************************************************************//
2259{
2260 if(Compare(numer)&&Compare(denom))
2261 {
2262 QwBeamLine* innumer = dynamic_cast<QwBeamLine*>(numer);
2263 QwBeamLine* indenom = dynamic_cast<QwBeamLine*>(denom);
2264
2265 for(size_t i=0;i<innumer->fClock.size();i++)
2266 this->fClock[i].get()->Ratio(*(innumer->fClock[i].get()),
2267 *(indenom->fClock[i].get()));
2268 for(size_t i=0;i<innumer->fStripline.size();i++)
2269 this->fStripline[i].get()->Ratio(*(innumer->fStripline[i].get()),
2270 *(indenom->fStripline[i].get()));
2271 for(size_t i=0;i<innumer->fCavity.size();i++)
2272 this->fCavity[i].Ratio(innumer->fCavity[i],indenom->fCavity[i]);
2273 for(size_t i=0;i<innumer->fQPD.size();i++)
2274 this->fQPD[i].Ratio(innumer->fQPD[i],indenom->fQPD[i]);
2275 for(size_t i=0;i<innumer->fLinearArray.size();i++)
2276 this->fLinearArray[i].Ratio(innumer->fLinearArray[i],indenom->fLinearArray[i]);
2277 for(size_t i=0;i<innumer->fBCM.size();i++)
2278 this->fBCM[i].get()->Ratio(*(innumer->fBCM[i].get()),
2279 *(indenom->fBCM[i].get()));
2280 for(size_t i=0;i<innumer->fHaloMonitor.size();i++)
2281 this->fHaloMonitor[i].Ratio(innumer->fHaloMonitor[i],indenom->fHaloMonitor[i]);
2282 for(size_t i=0;i<innumer->fBCMCombo.size();i++)
2283 this->fBCMCombo[i].get()->Ratio(*(innumer->fBCMCombo[i].get()),
2284 *(indenom->fBCMCombo[i]));
2285 for(size_t i=0;i<innumer->fBPMCombo.size();i++)
2286 this->fBPMCombo[i].get()->Ratio(*(innumer->fBPMCombo[i].get()),
2287 *(indenom->fBPMCombo[i].get()));
2288 for(size_t i=0;i<innumer->fECalculator.size();i++)
2289 this->fECalculator[i].Ratio(innumer->fECalculator[i],indenom->fECalculator[i]);
2290
2291 // For the combined bcm, maybe we might want to think about getting
2292 // the asymmetry using the asymmetries of the individual bcms with a
2293 // weight. But right now it is unclear if really need to have that
2294 // option.
2295 }
2296 return;
2297}
2298
2299//*****************************************************************//
2300void QwBeamLine::Scale(Double_t factor)
2301{
2302 for(size_t i=0;i<fClock.size();i++) fClock[i].get()->Scale(factor);
2303 for(size_t i=0;i<fStripline.size();i++) fStripline[i].get()->Scale(factor);
2304 for(size_t i=0;i<fCavity.size();i++) fCavity[i].Scale(factor);
2305 for(size_t i=0;i<fQPD.size();i++) fQPD[i].Scale(factor);
2306 for(size_t i=0;i<fLinearArray.size();i++) fLinearArray[i].Scale(factor);
2307 for(size_t i=0;i<fBCM.size();i++) fBCM[i].get()->Scale(factor);
2308 for(size_t i=0;i<fHaloMonitor.size();i++) fHaloMonitor[i].Scale(factor);
2309 for(size_t i=0;i<fBCMCombo.size();i++) fBCMCombo[i].get()->Scale(factor);
2310 for(size_t i=0;i<fBPMCombo.size();i++) fBPMCombo[i].get()->Scale(factor);
2311 for(size_t i=0;i<fECalculator.size();i++) fECalculator[i].Scale(factor);
2312 return;
2313}
2314
2315//*****************************************************************//
2317{
2318 for (size_t i = 0; i < fClock.size(); i++) fClock[i].get()->CalculateRunningAverage();
2319 for (size_t i = 0; i < fStripline.size(); i++) fStripline[i].get()->CalculateRunningAverage();
2320 for (size_t i = 0; i < fCavity.size(); i++) fCavity[i].CalculateRunningAverage();
2321 for (size_t i = 0; i < fQPD.size(); i++) fQPD[i].CalculateRunningAverage();
2322 for (size_t i = 0; i < fLinearArray.size(); i++) fLinearArray[i].CalculateRunningAverage();
2323 for (size_t i = 0; i < fBCM.size(); i++) fBCM[i].get()->CalculateRunningAverage();
2324 for (size_t i = 0; i < fHaloMonitor.size(); i++) fHaloMonitor[i].CalculateRunningAverage();
2325 for (size_t i = 0; i < fBCMCombo.size(); i++) fBCMCombo[i].get()->CalculateRunningAverage();
2326 for (size_t i = 0; i < fBPMCombo.size(); i++) fBPMCombo[i].get()->CalculateRunningAverage();
2327 for (size_t i = 0; i < fECalculator.size(); i++) fECalculator[i].CalculateRunningAverage();
2328}
2329
2330//*****************************************************************//
2332{
2333 QwMessage << "=== QwBeamLine: " << GetName() << " ===" << QwLog::endl;
2334 QwMessage << "Clock" << QwLog::endl;
2335 for (size_t i = 0; i < fClock.size(); i++) fClock[i].get()->PrintValue();
2336 QwMessage << "BPM stripline" << QwLog::endl;
2337 for (size_t i = 0; i < fStripline.size(); i++) fStripline[i].get()->PrintValue();
2338 QwMessage << "QPD" << QwLog::endl;
2339 for (size_t i = 0; i < fQPD.size(); i++) fQPD[i].PrintValue();
2340 QwMessage << "LinearArray" << QwLog::endl;
2341 for (size_t i = 0; i < fLinearArray.size(); i++) fLinearArray[i].PrintValue();
2342 QwMessage << "BPM cavity" << QwLog::endl;
2343 for (size_t i = 0; i < fCavity.size(); i++) fCavity[i].PrintValue();
2344 QwMessage << "BCM" << QwLog::endl;
2345 for (size_t i = 0; i < fBCM.size(); i++) fBCM[i].get()->PrintValue();
2346 QwMessage << "HaloMonitor" << QwLog::endl;
2347 for (size_t i = 0; i < fHaloMonitor.size(); i++) fHaloMonitor[i].PrintValue();
2348 QwMessage << "BCM combo" << QwLog::endl;
2349 for (size_t i = 0; i < fBCMCombo.size(); i++) fBCMCombo[i].get()->PrintValue();
2350 QwMessage << "BPM combo" << QwLog::endl;
2351 for (size_t i = 0; i < fBPMCombo.size(); i++) fBPMCombo[i].get()->PrintValue();
2352 QwMessage << "Energy " << QwLog::endl;
2353 for (size_t i = 0; i < fECalculator.size(); i++) fECalculator[i].PrintValue();
2354
2355}
2356
2357//*****************************************************************//
2358void QwBeamLine::AccumulateRunningSum(VQwSubsystem* value1, Int_t count, Int_t ErrorMask)
2359{
2360 if (Compare(value1)) {
2361 QwBeamLine* value = dynamic_cast<QwBeamLine*>(value1);
2362
2363 for (size_t i = 0; i < fClock.size(); i++)
2364 fClock[i].get()->AccumulateRunningSum(*(value->fClock[i].get()), count, ErrorMask);
2365 for (size_t i = 0; i < fStripline.size(); i++)
2366 fStripline[i].get()->AccumulateRunningSum(*(value->fStripline[i].get()), count, ErrorMask);
2367 for (size_t i = 0; i < fCavity.size(); i++)
2368 fCavity[i].AccumulateRunningSum(value->fCavity[i], count, ErrorMask);
2369 for (size_t i = 0; i < fBCM.size(); i++)
2370 fBCM[i].get()->AccumulateRunningSum(*(value->fBCM[i].get()), count, ErrorMask);
2371 for (size_t i = 0; i < fBCMCombo.size(); i++)
2372 fBCMCombo[i].get()->AccumulateRunningSum(*(value->fBCMCombo[i].get()), count, ErrorMask);
2373 for (size_t i = 0; i < fBPMCombo.size(); i++)
2374 fBPMCombo[i].get()->AccumulateRunningSum(*(value->fBPMCombo[i].get()), count, ErrorMask);
2375 for (size_t i = 0; i < fECalculator.size(); i++)
2376 fECalculator[i].AccumulateRunningSum(value->fECalculator[i], count, ErrorMask);
2377 for (size_t i = 0; i < fQPD.size(); i++)
2378 fQPD[i].AccumulateRunningSum(value->fQPD[i], count, ErrorMask);
2379 for (size_t i = 0; i < fLinearArray.size(); i++)
2380 fLinearArray[i].AccumulateRunningSum(value->fLinearArray[i], count, ErrorMask);
2381 for (size_t i = 0; i <fHaloMonitor.size(); i++)
2382 fHaloMonitor[i].AccumulateRunningSum(value->fHaloMonitor[i], count, ErrorMask);
2383
2384 }
2385}
2386
2387//*****************************************************************//
2389 if (Compare(value1)) {
2390 QwBeamLine* value = dynamic_cast<QwBeamLine*>(value1);
2391 for (size_t i = 0; i < fClock.size(); i++)
2392 fClock[i].get()->DeaccumulateRunningSum(*(value->fClock[i].get()), ErrorMask);
2393 for (size_t i = 0; i < fStripline.size(); i++)
2394 fStripline[i].get()->DeaccumulateRunningSum(*(value->fStripline[i].get()), ErrorMask);
2395 for (size_t i = 0; i < fCavity.size(); i++)
2396 fCavity[i].DeaccumulateRunningSum(value->fCavity[i], ErrorMask);
2397 for (size_t i = 0; i < fBCM.size(); i++)
2398 fBCM[i].get()->DeaccumulateRunningSum(*(value->fBCM[i].get()), ErrorMask);
2399 for (size_t i = 0; i < fBCMCombo.size(); i++)
2400 fBCMCombo[i].get()->DeaccumulateRunningSum(*(value->fBCMCombo[i].get()), ErrorMask);
2401 for (size_t i = 0; i < fBPMCombo.size(); i++)
2402 fBPMCombo[i].get()->DeaccumulateRunningSum(*(value->fBPMCombo[i].get()), ErrorMask);
2403 for (size_t i = 0; i < fQPD.size(); i++)
2404 fQPD[i].DeaccumulateRunningSum(value->fQPD[i], ErrorMask);
2405 for (size_t i = 0; i < fLinearArray.size(); i++)
2406 fLinearArray[i].DeaccumulateRunningSum(value->fLinearArray[i], ErrorMask);
2407 for (size_t i = 0; i < fECalculator.size(); i++)
2408 fECalculator[i].DeaccumulateRunningSum(value->fECalculator[i], ErrorMask);
2409 for (size_t i = 0; i <fHaloMonitor.size(); i++)
2410 fHaloMonitor[i].DeaccumulateRunningSum(value->fHaloMonitor[i], ErrorMask);
2411
2412 }
2413};
2414
2415//*****************************************************************//
2417{
2418 // std::cout<<" Here in QwBeamLine::Compare \n";
2419
2420 Bool_t res=kTRUE;
2421 if(typeid(*value)!=typeid(*this))
2422 {
2423 res=kFALSE;
2424 // std::cout<<" types are not ok \n";
2425 // std::cout<<" this is bypassed just for now but should be fixed eventually \n";
2426 }
2427 else
2428 {
2429 QwBeamLine* input = dynamic_cast<QwBeamLine*>(value);
2430 if(input->fStripline.size()!=fStripline.size())
2431 {
2432 // std::cout<<" not the same number of striplines \n";
2433 res=kFALSE;
2434 }
2435 else if(input->fBCM.size()!=fBCM.size())
2436 {
2437 res=kFALSE;
2438 // std::cout<<" not the same number of bcms \n";
2439 }
2440 else if(input->fHaloMonitor.size()!=fHaloMonitor.size())
2441 {
2442 res=kFALSE;
2443 // std::cout<<" not the same number of halomonitors \n";
2444 }
2445 else if(input->fClock.size()!=fClock.size()){
2446 res=kFALSE;
2447 // std::cout<<" not the same number of halomonitors \n";
2448 }else if(input->fBCMCombo.size()!=fBCMCombo.size()){
2449 res=kFALSE;
2450 }else if(input->fBPMCombo.size()!=fBPMCombo.size()){
2451 res=kFALSE;
2452 }else if(input->fLinearArray.size()!=fLinearArray.size()){
2453 res=kFALSE;
2454 }else if(input->fECalculator.size()!=fECalculator.size()){
2455 res=kFALSE;
2456 }else if(input->fCavity.size()!=fCavity.size()){
2457 res=kFALSE;
2458 }else if(input->fQPD.size()!=fQPD.size()){
2459 res=kFALSE;
2460 }
2461
2462 }
2463 return res;
2464}
2465
2466
2467//*****************************************************************//
2468void QwBeamLine::ConstructHistograms(TDirectory *folder, TString &prefix)
2469{
2470
2471 // std::cout<<" here is QwBeamLine::ConstructHistogram with prefix ="<<prefix<<"\n";
2472 for(size_t i=0;i<fClock.size();i++)
2473 fClock[i].get()->ConstructHistograms(folder,prefix);
2474
2475 for(size_t i=0;i<fStripline.size();i++)
2476 fStripline[i].get()->ConstructHistograms(folder,prefix);
2477
2478 for(size_t i=0;i<fQPD.size();i++)
2479 fQPD[i].ConstructHistograms(folder,prefix);
2480
2481 for(size_t i=0;i<fLinearArray.size();i++)
2482 fLinearArray[i].ConstructHistograms(folder,prefix);
2483
2484 for(size_t i=0;i<fCavity.size();i++)
2485 fCavity[i].ConstructHistograms(folder,prefix);
2486
2487 for(size_t i=0;i<fBCM.size();i++)
2488 fBCM[i].get()->ConstructHistograms(folder,prefix);
2489
2490 for(size_t i=0;i<fHaloMonitor.size();i++)
2491 fHaloMonitor[i].ConstructHistograms(folder,prefix);
2492
2493 for(size_t i=0;i<fBCMCombo.size();i++)
2494 fBCMCombo[i].get()->ConstructHistograms(folder,prefix);
2495
2496 for(size_t i=0;i<fBPMCombo.size();i++)
2497 fBPMCombo[i].get()->ConstructHistograms(folder,prefix);
2498
2499 for(size_t i=0;i<fECalculator.size();i++)
2500 fECalculator[i].ConstructHistograms(folder,prefix);
2501 return;
2502}
2503
2504//*****************************************************************//
2506{
2507 for(size_t i=0;i<fClock.size();i++)
2508 fClock[i].get()->FillHistograms();
2509 for(size_t i=0;i<fStripline.size();i++)
2510 fStripline[i].get()->FillHistograms();
2511 for(size_t i=0;i<fQPD.size();i++)
2512 fQPD[i].FillHistograms();
2513 for(size_t i=0;i<fLinearArray.size();i++)
2515 for(size_t i=0;i<fCavity.size();i++)
2517 for(size_t i=0;i<fBCM.size();i++)
2518 fBCM[i].get()->FillHistograms();
2519 for(size_t i=0;i<fHaloMonitor.size();i++)
2521 for(size_t i=0;i<fBCMCombo.size();i++)
2522 fBCMCombo[i].get()->FillHistograms();
2523 for(size_t i=0;i<fBPMCombo.size();i++)
2524 fBPMCombo[i].get()->FillHistograms();
2525 for(size_t i=0;i<fECalculator.size();i++)
2527
2528 return;
2529}
2530
2531
2532//*****************************************************************//
2533void QwBeamLine::ConstructBranchAndVector(TTree *tree, TString & prefix, QwRootTreeBranchVector &values)
2534{
2535
2536 for(size_t i = 0; i < fClock.size(); i++)
2537 fClock[i].get()->ConstructBranchAndVector(tree, prefix, values);
2538 for(size_t i = 0; i < fStripline.size(); i++)
2539 fStripline[i].get()->ConstructBranchAndVector(tree, prefix, values);
2540 for(size_t i = 0; i < fQPD.size(); i++)
2541 fQPD[i].ConstructBranchAndVector(tree, prefix, values);
2542 for(size_t i = 0; i < fLinearArray.size(); i++)
2543 fLinearArray[i].ConstructBranchAndVector(tree, prefix, values);
2544 for(size_t i = 0; i < fCavity.size(); i++)
2545 fCavity[i].ConstructBranchAndVector(tree, prefix, values);
2546 for(size_t i = 0; i < fBCM.size(); i++)
2547 fBCM[i].get()->ConstructBranchAndVector(tree, prefix, values);
2548 for(size_t i = 0; i < fHaloMonitor.size(); i++)
2549 fHaloMonitor[i].ConstructBranchAndVector(tree, prefix, values);
2550 for(size_t i = 0; i <fBCMCombo.size();i++)
2551 fBCMCombo[i].get()->ConstructBranchAndVector(tree, prefix, values);
2552 for(size_t i = 0; i <fBPMCombo.size();i++)
2553 fBPMCombo[i].get()->ConstructBranchAndVector(tree, prefix, values);
2554 for(size_t i = 0; i <fECalculator.size();i++)
2555 fECalculator[i].ConstructBranchAndVector(tree, prefix, values);
2556
2557 return;
2558}
2559
2560//*****************************************************************//
2561void QwBeamLine::ConstructBranch(TTree *tree, TString & prefix)
2562{
2563 for(size_t i = 0; i < fClock.size(); i++)
2564 fClock[i].get()->ConstructBranch(tree, prefix);
2565 for(size_t i = 0; i < fStripline.size(); i++)
2566 fStripline[i].get()->ConstructBranch(tree, prefix);
2567 for(size_t i = 0; i < fQPD.size(); i++)
2568 fQPD[i].ConstructBranch(tree, prefix);
2569 for(size_t i = 0; i < fLinearArray.size(); i++)
2570 fLinearArray[i].ConstructBranch(tree, prefix);
2571 for(size_t i = 0; i < fBCM.size(); i++)
2572 fBCM[i].get()->ConstructBranch(tree, prefix);
2573 for(size_t i = 0; i <fCavity.size(); i++)
2574 fStripline[i].get()->ConstructBranch(tree, prefix);
2575 for(size_t i = 0; i < fHaloMonitor.size(); i++)
2576 fHaloMonitor[i].ConstructBranch(tree, prefix);
2577 for(size_t i = 0; i <fBCMCombo.size();i++)
2578 fBCMCombo[i].get()->ConstructBranch(tree, prefix);
2579 for(size_t i = 0; i <fBPMCombo.size();i++)
2580 fBPMCombo[i].get()->ConstructBranch(tree, prefix);
2581 for(size_t i = 0; i <fECalculator.size();i++)
2582 fECalculator[i].ConstructBranch(tree, prefix);
2583
2584
2585 return;
2586}
2587
2588//*****************************************************************//
2589void QwBeamLine::ConstructBranch(TTree *tree, TString & prefix, QwParameterFile& trim_file)
2590{
2591 TString tmp,varname,varvalue;
2592 tmp="QwBCM";
2593 std::unique_ptr<QwParameterFile> nextmodule;
2594 trim_file.RewindToFileStart();
2595
2596
2597 tmp="QwBPMStripline";
2598 trim_file.RewindToFileStart();
2599 if (trim_file.FileHasModuleHeader(tmp)){
2600 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2601 for(size_t i = 0; i < fStripline.size(); i++)
2602 fStripline[i].get()->ConstructBranch(tree, prefix,*nextmodule);
2603
2604 }
2605
2606 tmp="QwQPD";
2607 trim_file.RewindToFileStart();
2608 if (trim_file.FileHasModuleHeader(tmp)){
2609 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2610 for(size_t i = 0; i < fQPD.size(); i++)
2611 fQPD[i].ConstructBranch(tree, prefix,*nextmodule);
2612 }
2613
2614 tmp="QwLinearDiodeArray";
2615 trim_file.RewindToFileStart();
2616 if (trim_file.FileHasModuleHeader(tmp)){
2617 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2618 for(size_t i = 0; i < fLinearArray.size(); i++)
2619 fLinearArray[i].ConstructBranch(tree, prefix,*nextmodule);
2620 }
2621
2622 tmp="QwBPMCavity";
2623 trim_file.RewindToFileStart();
2624 if (trim_file.FileHasModuleHeader(tmp)){
2625 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2626 for(size_t i = 0; i < fCavity.size(); i++)
2627 fCavity[i].ConstructBranch(tree, prefix,*nextmodule);
2628
2629 }
2630
2631 tmp="QwBCM";
2632 trim_file.RewindToFileStart();
2633 if (trim_file.FileHasModuleHeader(tmp)){
2634 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2635 for(size_t i = 0; i < fBCM.size(); i++)
2636 fBCM[i].get()->ConstructBranch(tree, prefix,*nextmodule);
2637 }
2638
2639 tmp="QwClock";
2640 trim_file.RewindToFileStart();
2641 if (trim_file.FileHasModuleHeader(tmp)){
2642 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2643 for(size_t i = 0; i < fClock.size(); i++)
2644 fClock[i].get()->ConstructBranch(tree, prefix,*nextmodule);
2645 }
2646
2647 tmp="QwHaloMonitor";
2648 trim_file.RewindToFileStart();
2649 if (trim_file.FileHasModuleHeader(tmp)){
2650 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2651 for(size_t i = 0; i < fHaloMonitor.size(); i++)
2652 fHaloMonitor[i].ConstructBranch(tree, prefix,*nextmodule);
2653 }
2654
2655
2656 tmp="QwCombinedBCM";
2657 trim_file.RewindToFileStart();
2658 if (trim_file.FileHasModuleHeader(tmp)){
2659 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2660 for(size_t i = 0; i <fBCMCombo.size();i++)
2661 fBCMCombo[i].get()->ConstructBranch(tree, prefix,*nextmodule);
2662 }
2663
2664
2665 tmp="QwCombinedBPM";
2666 trim_file.RewindToFileStart();
2667 if (trim_file.FileHasModuleHeader(tmp)){
2668 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2669 for(size_t i = 0; i <fBPMCombo.size();i++)
2670 fBPMCombo[i].get()->ConstructBranch(tree, prefix,*nextmodule);
2671 }
2672
2673 tmp="QwEnergyCalculator";
2674 trim_file.RewindToFileStart();
2675 if (trim_file.FileHasModuleHeader(tmp)){
2676 nextmodule=trim_file.ReadUntilNextModule();//This section contains sub modules and or channels to be included in the tree
2677 for(size_t i = 0; i <fECalculator.size();i++)
2678 fECalculator[i].ConstructBranch(tree, prefix,*nextmodule);
2679 }
2680
2681 return;
2682}
2683
2684//*****************************************************************//
2686{
2687 for(size_t i = 0; i < fClock.size(); i++)
2688 fClock[i].get()->FillTreeVector(values);
2689 for(size_t i = 0; i < fStripline.size(); i++)
2690 fStripline[i].get()->FillTreeVector(values);
2691 for(size_t i = 0; i < fQPD.size(); i++)
2692 fQPD[i].FillTreeVector(values);
2693 for(size_t i = 0; i < fLinearArray.size(); i++)
2694 fLinearArray[i].FillTreeVector(values);
2695 for(size_t i = 0; i < fCavity.size(); i++)
2696 fCavity[i].FillTreeVector(values);
2697 for(size_t i = 0; i < fBCM.size(); i++)
2698 fBCM[i].get()->FillTreeVector(values);
2699 for(size_t i = 0; i < fHaloMonitor.size(); i++)
2700 fHaloMonitor[i].FillTreeVector(values);
2701 for(size_t i = 0; i < fBCMCombo.size(); i++)
2702 fBCMCombo[i].get()->FillTreeVector(values);
2703 for(size_t i = 0; i < fBPMCombo.size(); i++)
2704 fBPMCombo[i].get()->FillTreeVector(values);
2705 for(size_t i = 0; i < fECalculator.size(); i++){
2706 fECalculator[i].FillTreeVector(values);}
2707 return;
2708}
2709
2710#ifdef HAS_RNTUPLE_SUPPORT
2711//*****************************************************************//
2712void QwBeamLine::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
2713{
2714 for(size_t i = 0; i < fClock.size(); i++)
2715 fClock[i].get()->ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2716 for(size_t i = 0; i < fStripline.size(); i++)
2717 fStripline[i].get()->ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2718 for(size_t i = 0; i < fQPD.size(); i++)
2719 fQPD[i].ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2720 for(size_t i = 0; i < fLinearArray.size(); i++)
2721 fLinearArray[i].ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2722 for(size_t i = 0; i < fCavity.size(); i++)
2723 fCavity[i].ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2724 for(size_t i = 0; i < fBCM.size(); i++)
2725 fBCM[i].get()->ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2726 for(size_t i = 0; i < fHaloMonitor.size(); i++)
2727 fHaloMonitor[i].ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2728 for(size_t i = 0; i <fBCMCombo.size();i++)
2729 fBCMCombo[i].get()->ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2730 for(size_t i = 0; i <fBPMCombo.size();i++)
2731 fBPMCombo[i].get()->ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2732 for(size_t i = 0; i <fECalculator.size();i++)
2733 fECalculator[i].ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
2734
2735 return;
2736}
2737
2738//*****************************************************************//
2739void QwBeamLine::FillNTupleVector(std::vector<Double_t>& values) const
2740{
2741 for(size_t i = 0; i < fClock.size(); i++)
2742 fClock[i].get()->FillNTupleVector(values);
2743 for(size_t i = 0; i < fStripline.size(); i++)
2744 fStripline[i].get()->FillNTupleVector(values);
2745 for(size_t i = 0; i < fQPD.size(); i++)
2746 fQPD[i].FillNTupleVector(values);
2747 for(size_t i = 0; i < fLinearArray.size(); i++)
2748 fLinearArray[i].FillNTupleVector(values);
2749 for(size_t i = 0; i < fCavity.size(); i++)
2750 fCavity[i].FillNTupleVector(values);
2751 for(size_t i = 0; i < fBCM.size(); i++)
2752 fBCM[i].get()->FillNTupleVector(values);
2753 for(size_t i = 0; i < fHaloMonitor.size(); i++)
2754 fHaloMonitor[i].FillNTupleVector(values);
2755 for(size_t i = 0; i < fBCMCombo.size(); i++)
2756 fBCMCombo[i].get()->FillNTupleVector(values);
2757 for(size_t i = 0; i < fBPMCombo.size(); i++)
2758 fBPMCombo[i].get()->FillNTupleVector(values);
2759 for(size_t i = 0; i < fECalculator.size(); i++){
2760 fECalculator[i].FillNTupleVector(values);}
2761 return;
2762}
2763#endif
2764
2765
2766//*****************************************************************//
2768{
2769 std::cout<<"Name of the subsystem ="<<fSystemName<<"\n";
2770 std::cout<<"there are "<<fClock.size()<<" clock \n";
2771 std::cout<<"there are "<<fStripline.size()<<" striplines \n";
2772 std::cout<<"there are "<<fQPD.size()<<" QPDs \n";
2773 std::cout<<"there are "<<fLinearArray.size()<<" LinearArrays \n";
2774 std::cout<<"there are "<<fCavity.size()<<" cavities \n";
2775 std::cout<<"there are "<<fBCM.size()<<" bcm \n";
2776 std::cout<<"there are "<<fHaloMonitor.size()<<" halomonitors \n";
2777 std::cout<<"there are "<<fBCMCombo.size()<<" combined bcms \n";
2778 std::cout<<"there are "<<fBPMCombo.size()<<" combined bpms \n";
2779 std::cout<<"there are "<<fECalculator.size()<<" energy calculators \n";
2780 std::cout<<" Printing Running AVG and other channel info for BCMs"<<std::endl;
2781 for(size_t i=0;i<fBCM.size();i++)
2782 fBCM[i].get()->PrintInfo();
2783 for(size_t i=0;i<fHaloMonitor.size();i++)
2785 return;
2786}
2787
2788
2789//*****************************************************************//
2791{
2792 for (size_t i=0;i<fBeamDetectorID.size();i++)
2793 {
2794 std::cout<<"============================="<<std::endl;
2795 std::cout<<" Detector ID="<<i<<std::endl;
2796 fBeamDetectorID[i].Print();
2797 }
2798 return;
2799}
2800
2801
2802
2803//*****************************************************************//
2805{
2806 const QwBeamLine* input = dynamic_cast<const QwBeamLine*>(source);
2807
2808 this->fClock.reserve(input->fClock.size());
2809 for(size_t i=0;i<input->fClock.size();i++) {
2810 this->fClock.push_back(VQwClock_ptr(VQwClock::Create(*(input->fClock[i].get()))));
2811 }
2812
2813 this->fStripline.reserve(input->fStripline.size());
2814 for(size_t i=0;i<input->fStripline.size();i++) {
2815 this->fStripline.push_back(VQwBPM_ptr(
2816 VQwBPM::CreateStripline(*(input->fStripline[i].get()))));
2817 }
2818
2819 this->fBCM.reserve(input->fBCM.size());
2820 for(size_t i=0;i<input->fBCM.size();i++) {
2821 this->fBCM.push_back(VQwBCM_ptr(
2822 VQwBCM::Create(*(input->fBCM[i].get()))));
2823 }
2824
2825 this->fBCMCombo.reserve(input->fBCMCombo.size());
2826 for(size_t i=0;i<input->fBCMCombo.size();i++) {
2827 this->fBCMCombo.push_back(VQwBCM_ptr(
2829 input->fBCMCombo[i].get()))));
2830 }
2831
2832 this->fBPMCombo.reserve(input->fBPMCombo.size());
2833 for(size_t i=0;i<input->fBPMCombo.size();i++){
2834 this->fBPMCombo.push_back(VQwBPM_ptr(
2835 VQwBPM::CreateCombo(*(input->fBPMCombo[i].get()))));
2836 }
2837}
2838
2839//*****************************************************************//
2840#ifdef __USE_DATABASE__
2841void QwBeamLine::FillDB(QwParityDB *db, TString datatype)
2842{
2843
2844 Bool_t local_print_flag = false;
2845
2846 if(local_print_flag) {
2847 QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
2848 QwMessage << " QwBeamLine::FillDB " << QwLog::endl;
2849 QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
2850 }
2851
2852 std::vector<QwDBInterface> interface;
2853 std::vector<QwParitySchema::beam_row> entrylist;
2854
2855 UInt_t analysis_id = db->GetAnalysisID();
2856
2857 TString measurement_type_bcm;
2858 TString measurement_type_bpm;
2859 TString measurement_type_halo;
2860
2861 measurement_type_bcm =
2863 measurement_type_bpm =
2865 measurement_type_halo =
2867
2868 UInt_t i,j;
2869 i = j = 0;
2870 // try to access BCM mean and its error
2871 // there are 2 different types BCM data we have at the moment
2872 // Yield and Asymmetry
2873 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Beam Current Monitors" <<QwLog::endl;
2874
2875 for(i=0; i< fBCM.size(); i++) {
2876 interface.clear();
2877 interface = fBCM[i].get()->GetDBEntry();
2878 for (j=0; j<interface.size(); j++){
2879 interface.at(j).SetAnalysisID( analysis_id );
2880 interface.at(j).SetMonitorID( db );
2881 interface.at(j).SetMeasurementTypeID( measurement_type_bcm );
2882 interface.at(j).PrintStatus( local_print_flag );
2883 interface.at(j).AddThisEntryToList( entrylist );
2884 }
2885 }
2886
2887 /// try to access BPM mean and its error
2888 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Beam Position Monitors" <<QwLog::endl;
2889 for(i=0; i< fStripline.size(); i++) {
2890 // fStripline[i].MakeBPMList();
2891 interface.clear();
2892 interface = fStripline[i].get()->GetDBEntry();
2893 for (j=0; j<interface.size()-5; j++){
2894 interface.at(j).SetAnalysisID( analysis_id ) ;
2895 interface.at(j).SetMonitorID( db );
2896 interface.at(j).SetMeasurementTypeID( measurement_type_bpm );
2897 interface.at(j).PrintStatus( local_print_flag);
2898 interface.at(j).AddThisEntryToList( entrylist );
2899 }
2900 // effective charge (last 4 elements) need to be saved as measurement_type_bcm
2901 for (j=interface.size()-5; j<interface.size(); j++){
2902 interface.at(j).SetAnalysisID( analysis_id ) ;
2903 interface.at(j).SetMonitorID( db );
2904 interface.at(j).SetMeasurementTypeID( measurement_type_bcm );
2905 interface.at(j).PrintStatus( local_print_flag);
2906 interface.at(j).AddThisEntryToList( entrylist );
2907 }
2908 }
2909
2910
2911 /// try to access CombinedBPM means and errors
2912 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Combined Beam Position Monitors" <<QwLog::endl;
2913 for(i=0; i< fBPMCombo.size(); i++) {
2914 // fBPMCombo[i].MakeBPMComboList();
2915 interface.clear();
2916 interface = fBPMCombo[i].get()->GetDBEntry();
2917 for (j=0; j<interface.size()-5; j++){
2918 interface.at(j).SetAnalysisID( analysis_id ) ;
2919 interface.at(j).SetMonitorID( db );
2920 interface.at(j).SetMeasurementTypeID( measurement_type_bpm );
2921 interface.at(j).PrintStatus( local_print_flag);
2922 interface.at(j).AddThisEntryToList( entrylist );
2923 }
2924 // effective charge (last element) need to be saved as measurement_type_bcm
2925 for (j=interface.size()-5; j<interface.size(); j++){
2926 interface.at(j).SetAnalysisID( analysis_id ) ;
2927 interface.at(j).SetMonitorID( db );
2928 interface.at(j).SetMeasurementTypeID( measurement_type_bcm );
2929 interface.at(j).PrintStatus( local_print_flag);
2930 interface.at(j).AddThisEntryToList( entrylist );
2931 }
2932 }
2933
2934 /// try to access CombinedBCM means and errors
2935 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Combined Beam Current Monitors" <<QwLog::endl;
2936
2937 for(i=0; i< fBCMCombo.size(); i++) {
2938 interface.clear();
2939 interface = fBCMCombo[i].get()->GetDBEntry();
2940 for (j=0; j<interface.size(); j++){
2941 interface.at(j).SetAnalysisID( analysis_id );
2942 interface.at(j).SetMonitorID( db );
2943 interface.at(j).SetMeasurementTypeID( measurement_type_bcm );
2944 interface.at(j).PrintStatus( local_print_flag );
2945 interface.at(j).AddThisEntryToList( entrylist );
2946 }
2947 }
2948
2949 /// try to access Energy Calculator mean and its error
2950 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Energy Calculator" <<QwLog::endl;
2951
2952 for(i=0; i< fECalculator.size(); i++) {
2953 interface.clear();
2954 interface = fECalculator[i].GetDBEntry();
2955 for (j=0; j<interface.size(); j++){
2956 interface.at(j).SetAnalysisID( analysis_id );
2957 interface.at(j).SetMonitorID( db );
2958 interface.at(j).SetMeasurementTypeID( measurement_type_bpm );
2959 interface.at(j).PrintStatus( local_print_flag );
2960 interface.at(j).AddThisEntryToList( entrylist );
2961 }
2962 }
2963
2964
2965 /// try to access QPD mean and its error
2966 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Quadrant PhotoDiodes" <<QwLog::endl;
2967 for(i=0; i< fQPD.size(); i++) {
2968 // fQPD[i].MakeQPDList();
2969 interface.clear();
2970 interface = fQPD[i].GetDBEntry();
2971 for (j=0; j<interface.size()-5; j++){
2972 interface.at(j).SetAnalysisID( analysis_id ) ;
2973 interface.at(j).SetMonitorID( db );
2974 interface.at(j).SetMeasurementTypeID( measurement_type_bpm );
2975 interface.at(j).PrintStatus( local_print_flag);
2976 interface.at(j).AddThisEntryToList( entrylist );
2977 }
2978 // effective charge need (last element) to be saved as measurement_type_bcm
2979 for (j=interface.size()-5; j<interface.size(); j++){
2980 interface.at(j).SetAnalysisID( analysis_id ) ;
2981 interface.at(j).SetMonitorID( db );
2982 interface.at(j).SetMeasurementTypeID( measurement_type_bcm );
2983 interface.at(j).PrintStatus( local_print_flag);
2984 interface.at(j).AddThisEntryToList( entrylist );
2985 }
2986 }
2987
2988 /// try to access LinearArray mean and its error
2989 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Linear PhotoDiode Array" <<QwLog::endl;
2990 for(i=0; i< fLinearArray.size(); i++) {
2991 // fLinearArray[i].MakeLinearArrayList();
2992 interface.clear();
2993 interface = fLinearArray[i].GetDBEntry();
2994 for (j=0; j<interface.size()-5; j++){
2995 interface.at(j).SetAnalysisID( analysis_id ) ;
2996 interface.at(j).SetMonitorID( db );
2997 interface.at(j).SetMeasurementTypeID( measurement_type_bpm );
2998 interface.at(j).PrintStatus( local_print_flag);
2999 interface.at(j).AddThisEntryToList( entrylist );
3000 }
3001 for (j=interface.size()-5; j<interface.size(); j++){
3002 interface.at(j).SetAnalysisID( analysis_id ) ;
3003 interface.at(j).SetMonitorID( db );
3004 interface.at(j).SetMeasurementTypeID( measurement_type_bcm );
3005 interface.at(j).PrintStatus( local_print_flag);
3006 interface.at(j).AddThisEntryToList( entrylist );
3007 }
3008 }
3009
3010 /// try to access cavity bpm mean and its error
3011 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Cavity Monitors" <<QwLog::endl;
3012 for(i=0; i< fCavity.size(); i++) {
3013 // fCavity[i].MakeBPMCavityList();
3014 interface.clear();
3015 interface = fCavity[i].GetDBEntry();
3016 for (j=0; j<interface.size()-5; j++){
3017 interface.at(j).SetAnalysisID( analysis_id ) ;
3018 interface.at(j).SetMonitorID( db );
3019 interface.at(j).SetMeasurementTypeID( measurement_type_bpm );
3020 interface.at(j).PrintStatus( local_print_flag);
3021 interface.at(j).AddThisEntryToList( entrylist );
3022 }
3023 for (j=interface.size()-5; j<interface.size(); j++){
3024 interface.at(j).SetAnalysisID( analysis_id ) ;
3025 interface.at(j).SetMonitorID( db );
3026 interface.at(j).SetMeasurementTypeID( measurement_type_bcm );
3027 interface.at(j).PrintStatus( local_print_flag);
3028 interface.at(j).AddThisEntryToList( entrylist );
3029 }
3030 }
3031
3032 // try to access halo mean and its error
3033 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Halo Monitors" <<QwLog::endl;
3034
3035 for(i=0; i< fHaloMonitor.size(); i++) {
3036 interface.clear();
3037 interface = fHaloMonitor[i].GetDBEntry();
3038 for (j=0; j<interface.size(); j++){
3039 interface.at(j).SetAnalysisID( analysis_id );
3040 interface.at(j).SetMonitorID( db );
3041 interface.at(j).SetMeasurementTypeID( measurement_type_halo );
3042 interface.at(j).PrintStatus( local_print_flag );
3043 interface.at(j).AddThisEntryToList( entrylist );
3044 }
3045 }
3046
3047 if(local_print_flag){
3048 QwMessage << QwColor(Qw::kGreen) << "Starting database insertion"
3049 << QwColor(Qw::kNormal) << QwLog::endl;
3050 }
3051
3052 // Check the entrylist size, if it isn't zero, start to query..
3053 if( entrylist.size() ) {
3054 auto c = db->GetScopedConnection();
3055 for (const auto& entry: entrylist) {
3056 c->QueryExecute(entry.insert_into());
3057 }
3058 } else {
3059 QwMessage << "QwBeamLine::FillDB :: This is the case when the entrlylist contains nothing in "<< datatype.Data() << QwLog::endl;
3060 }
3061}
3062
3063
3064void QwBeamLine::FillErrDB(QwParityDB *db, TString datatype)
3065{
3066
3067 Bool_t local_print_flag = false;
3068
3069 if(local_print_flag) {
3070 QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
3071 QwMessage << " QwBeamLine::FillErrDB " << QwLog::endl;
3072 QwMessage << " --------------------------------------------------------------- " << QwLog::endl;
3073 }
3074
3075 std::vector<QwErrDBInterface> interface;
3076 std::vector<QwParitySchema::beam_errors_row> entrylist;
3077
3078 UInt_t analysis_id = db->GetAnalysisID();
3079
3080 UInt_t i,j;
3081 i = j = 0;
3082
3083 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Beam Current Monitors" <<QwLog::endl;
3084 for(i=0; i< fBCM.size(); i++) {
3085 interface.clear();
3086 interface = fBCM[i].get()->GetErrDBEntry();
3087 for (j=0; j<interface.size(); j++){
3088 interface.at(j).SetAnalysisID( analysis_id );
3089 interface.at(j).SetMonitorID( db );
3090 interface.at(j).PrintStatus( local_print_flag );
3091 interface.at(j).AddThisEntryToList( entrylist );
3092 }
3093 if(local_print_flag) printf("\n");
3094 }
3095
3096 /// try to access BPM mean and its error
3097 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Beam Position Monitors" <<QwLog::endl;
3098 for(i=0; i< fStripline.size(); i++) {
3099 interface.clear();
3100 interface = fStripline[i].get()->GetErrDBEntry();
3101 for (j=0; j<interface.size(); j++){
3102 interface.at(j).SetAnalysisID( analysis_id ) ;
3103 interface.at(j).SetMonitorID( db );
3104 interface.at(j).PrintStatus( local_print_flag );
3105 interface.at(j).AddThisEntryToList( entrylist );
3106 }
3107 if(local_print_flag) printf("\n");
3108 }
3109
3110 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Combined Beam Position Monitors" <<QwLog::endl;
3111 for(i=0; i< fBPMCombo.size(); i++) {
3112 interface.clear();
3113 interface = fBPMCombo[i].get()->GetErrDBEntry();
3114 for (j=0; j<interface.size(); j++){
3115 interface.at(j).SetAnalysisID( analysis_id ) ;
3116 interface.at(j).SetMonitorID( db );
3117 interface.at(j).PrintStatus( local_print_flag );
3118 interface.at(j).AddThisEntryToList( entrylist );
3119 }
3120 if(local_print_flag) printf("\n");
3121 }
3122
3123 /// try to access CombinedBCM means and errors
3124 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Combined Beam Current Monitors" <<QwLog::endl;
3125 for(i=0; i< fBCMCombo.size(); i++) {
3126 interface.clear();
3127 interface = fBCMCombo[i].get()->GetErrDBEntry();
3128 for (j=0; j<interface.size(); j++){
3129 interface.at(j).SetAnalysisID( analysis_id ) ;
3130 interface.at(j).SetMonitorID( db );
3131 interface.at(j).PrintStatus( local_print_flag );
3132 interface.at(j).AddThisEntryToList( entrylist );
3133 }
3134 if(local_print_flag) printf("\n");
3135 }
3136
3137 /// try to access Energy Calculator mean and its error
3138 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Energy Calculator" <<QwLog::endl;
3139 for(i=0; i< fECalculator.size(); i++) {
3140 interface.clear();
3141 interface = fECalculator[i].GetErrDBEntry();
3142 for (j=0; j<interface.size(); j++){
3143 interface.at(j).SetAnalysisID( analysis_id ) ;
3144 interface.at(j).SetMonitorID( db );
3145 interface.at(j).PrintStatus( local_print_flag );
3146 interface.at(j).AddThisEntryToList( entrylist );
3147 }
3148 if(local_print_flag) printf("\n");
3149 }
3150
3151 /// try to access QPD mean and its error
3152 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Quadrant PhotoDiodes" <<QwLog::endl;
3153 for(i=0; i< fQPD.size(); i++) {
3154 interface.clear();
3155 interface = fQPD[i].GetErrDBEntry();
3156 for (j=0; j<interface.size(); j++){
3157 interface.at(j).SetAnalysisID( analysis_id ) ;
3158 interface.at(j).SetMonitorID( db );
3159 interface.at(j).PrintStatus( local_print_flag );
3160 interface.at(j).AddThisEntryToList( entrylist );
3161 }
3162 if(local_print_flag) printf("\n");
3163 }
3164
3165 /// try to access LinearArray mean and its error
3166 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Linear PhotoDiode Array" <<QwLog::endl;
3167 for(i=0; i< fLinearArray.size(); i++) {
3168 interface.clear();
3169 interface = fLinearArray[i].GetErrDBEntry();
3170 for (j=0; j<interface.size(); j++){
3171 interface.at(j).SetAnalysisID( analysis_id ) ;
3172 interface.at(j).SetMonitorID( db );
3173 interface.at(j).PrintStatus( local_print_flag );
3174 interface.at(j).AddThisEntryToList( entrylist );
3175 }
3176 if(local_print_flag) printf("\n");
3177 }
3178
3179 /// try to access cavity bpm mean and its error
3180 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Cavity Monitors" <<QwLog::endl;
3181 for(i=0; i< fCavity.size(); i++) {
3182 interface.clear();
3183 interface = fCavity[i].GetErrDBEntry();
3184 for (j=0; j<interface.size(); j++){
3185 interface.at(j).SetAnalysisID( analysis_id ) ;
3186 interface.at(j).SetMonitorID( db );
3187 interface.at(j).PrintStatus( local_print_flag );
3188 interface.at(j).AddThisEntryToList( entrylist );
3189 }
3190 if(local_print_flag) printf("\n");
3191 }
3192
3193 // try to access halo mean and its error
3194 if(local_print_flag) QwMessage << QwColor(Qw::kGreen) << "Halo Monitors" <<QwLog::endl;
3195 for(i=0; i< fHaloMonitor.size(); i++) {
3196 interface.clear();
3197 interface = fHaloMonitor[i].GetErrDBEntry();
3198 for (j=0; j<interface.size(); j++){
3199 interface.at(j).SetAnalysisID( analysis_id ) ;
3200 interface.at(j).SetMonitorID( db );
3201 interface.at(j).PrintStatus( local_print_flag );
3202 interface.at(j).AddThisEntryToList( entrylist );
3203 }
3204 if(local_print_flag) printf("\n");
3205 }
3206
3207
3208 if(local_print_flag){
3209 QwMessage << QwColor(Qw::kGreen) << "Starting error database insertion"
3210 << QwColor(Qw::kNormal) << QwLog::endl;
3211 }
3212
3213 // Check the entrylist size, if it isn't zero, start to query..
3214 if (entrylist.size()) {
3215 auto c = db->GetScopedConnection();
3216 for (const auto& entry: entrylist) {
3217 c->QueryExecute(entry.insert_into());
3218 }
3219 } else {
3220 QwMessage << "QwBeamLine::FillErrDB :: This is the case when the entrlylist contains nothing in "<< datatype.Data() << QwLog::endl;
3221 }
3222}
3223#endif //__USE_DATABASE__
3224
3226{
3227 Bool_t local_print_flag = false;
3228 Bool_t local_add_element= type.Contains("yield");
3229
3230
3231
3232 if(local_print_flag) {
3233 printf("---------------------------------------------------------------\n");
3234 printf("QwBeamLine::WritePromptSummary() Type : %12s\n", type.Data());
3235 printf("---------------------------------------------------------------\n");
3236 }
3237
3238 const VQwHardwareChannel* tmp_channel = 0;
3239 TString element_name = "";
3240 Double_t element_value = 0.0;
3241 Double_t element_value_err = 0.0;
3242 Double_t element_value_width = 0.0;
3243
3244 PromptSummaryElement *local_ps_element = NULL;
3245 Bool_t local_add_these_elements= false;
3246
3247 // Add BCMs
3248 for (size_t i = 0; i < fBCM.size(); i++)
3249 {
3250 tmp_channel=GetChannel(kQwBCM, i,"");
3251 element_name = tmp_channel->GetElementName();
3252 element_value = 0.0;
3253 element_value_err = 0.0;
3254 element_value_width = 0.0;
3255
3256 local_add_these_elements = element_name.EqualTo("bcm_an_us")||element_name.EqualTo("bcm_an_ds")||element_name.EqualTo("bcm_an_ds3")|| (element_name.Contains("cav4") ); // Need to change this to add other BCMs in summary
3257
3258 if(local_add_these_elements && local_add_element){
3259 ps->AddElement(new PromptSummaryElement(element_name));
3260 }
3261
3262
3263 local_ps_element=ps->GetElementByName(element_name);
3264
3265
3266 if(local_ps_element) {
3267 element_value = tmp_channel->GetValue();
3268 element_value_err = tmp_channel->GetValueError();
3269 element_value_width = tmp_channel->GetValueWidth();
3270
3271 local_ps_element->Set(type, element_value, element_value_err, element_value_width);
3272 }
3273
3274 if( local_print_flag && local_ps_element) {
3275 printf("Type %12s, Element %32s, value %12.4e error %8.4e width %12.4e\n",
3276 type.Data(), element_name.Data(), element_value, element_value_err, element_value_width);
3277 }
3278 }
3279
3280 // Add combined BCMs
3281 for (size_t i = 0; i < fBCMCombo.size(); i++) {
3282 tmp_channel = GetChannel(kQwCombinedBCM, i,"");
3283 // Need to change this to add other BCMs in summary
3284 static const TString kTargetBCMName = "bcm_target";
3285 local_add_these_elements = element_name.EqualTo(kTargetBCMName);
3286 element_value_err = 0.0;
3287 element_value_width = 0.0;
3288
3289 // Need to change this to add other BCMs in summary
3290 local_add_these_elements = element_name.EqualTo("bcm_target");
3291
3292 if(local_add_these_elements && local_add_element){
3293 ps->AddElement(new PromptSummaryElement(element_name));
3294 }
3295
3296
3297 local_ps_element=ps->GetElementByName(element_name);
3298
3299
3300 if(local_ps_element) {
3301 element_value = tmp_channel->GetValue();
3302 element_value_err = tmp_channel->GetValueError();
3303 element_value_width = tmp_channel->GetValueWidth();
3304
3305 local_ps_element->Set(type, element_value, element_value_err, element_value_width);
3306 }
3307
3308 if( local_print_flag && local_ps_element) {
3309 printf("Type %12s, Element %32s, value %12.4e error %8.4e width %12.4e\n",
3310 type.Data(), element_name.Data(), element_value, element_value_err, element_value_width);
3311 }
3312 }
3313
3314 // Add BPM Cavity
3315 for (size_t i = 0; i < fCavity.size(); i++)
3316 {
3317 tmp_channel=GetChannel(kQwBPMCavity, i,"ef");
3318 element_name = tmp_channel->GetElementName();
3319 element_value = 0.0;
3320 element_value_err = 0.0;
3321 element_value_width = 0.0;
3322
3323 local_add_these_elements = (element_name.EqualTo("cav4bQ")||element_name.EqualTo("cav4cQ")|| element_name.EqualTo("cav4dQ") ); // Need to change this to add other cavities in summary
3324
3325 if(local_add_these_elements && local_add_element){
3326 ps->AddElement(new PromptSummaryElement(element_name));
3327 }
3328
3329
3330 local_ps_element=ps->GetElementByName(element_name);
3331
3332
3333 if(local_ps_element) {
3334 element_value = tmp_channel->GetValue();
3335 element_value_err = tmp_channel->GetValueError();
3336 element_value_width = tmp_channel->GetValueWidth();
3337
3338 local_ps_element->Set(type, element_value, element_value_err, element_value_width);
3339 }
3340
3341 if( local_print_flag && local_ps_element) {
3342 printf("Type %12s, Element %32s, value %12.4e error %8.4e width %12.4e\n",
3343 type.Data(), element_name.Data(), element_value, element_value_err, element_value_width);
3344 }
3345 }
3346
3347//////
3348
3349
3350
3351 char property[2][6]={"x","y"};
3352
3353 local_ps_element=NULL;
3354 local_add_these_elements=false;
3355
3356 // Add BPM striplines
3357 for(size_t i=0; i< fStripline.size(); i++)
3358 {
3359 for (Int_t j=0;j<2;j++){
3360 tmp_channel= GetChannel(kQwBPMStripline, i,property[j]);
3361 element_name= tmp_channel->GetElementName();
3362 element_value = 0.0;
3363 element_value_err = 0.0;
3364 element_value_width = 0.0;
3365
3366 // List of BPM names to include in the summary (move to config if needed)
3367 static const std::vector<TString> kSummaryBPMNames = {
3368 "bpm4", "bpm18", "bpm14", "bpm12"
3369 };
3370 local_add_these_elements = false;
3371 for (const auto& bpm_name : kSummaryBPMNames) {
3372 if (element_name.Contains(bpm_name)) {
3373 local_add_these_elements = true;
3374 break;
3375 }
3376 }
3377
3378 if( local_add_these_elements && local_add_element){
3379 ps->AddElement(new PromptSummaryElement(element_name));
3380 }
3381
3382 local_ps_element=ps->GetElementByName(element_name);
3383
3384
3385
3386 if(local_ps_element) {
3387 element_value = tmp_channel->GetValue();
3388 element_value_err = tmp_channel->GetValueError();
3389 element_value_width = tmp_channel->GetValueWidth();
3390 local_ps_element->Set(type, element_value, element_value_err, element_value_width);
3391 }
3392
3393 if( local_print_flag && local_ps_element) {
3394 printf("Type %12s, Element %32s, value %12.4e error %8.4e width %12.4e\n",
3395 type.Data(), element_name.Data(), element_value, element_value_err, element_value_width);
3396 }
3397
3398 }
3399 }
3400
3401 // Add combined BPM striplines
3402 for(size_t i=0; i< fBPMCombo.size(); i++)
3403 {
3404 for (Int_t j=0;j<2;j++){
3405 tmp_channel= GetChannel(kQwCombinedBPM, i, property[j]);
3406 element_name= tmp_channel->GetElementName();
3407 element_value = 0.0;
3408 element_value_err = 0.0;
3409 element_value_width = 0.0;
3410
3411 local_add_these_elements=element_name.Contains("bpm4")||element_name.Contains("bpm18")||element_name.Contains("bpm14")||element_name.Contains("bpm12"); //Need to change this to add other stripline BPMs in summary
3412
3413 if( local_add_these_elements && local_add_element){
3414 ps->AddElement(new PromptSummaryElement(element_name));
3415 }
3416
3417 local_ps_element=ps->GetElementByName(element_name);
3418
3419
3420
3421 if(local_ps_element) {
3422 element_value = tmp_channel->GetValue();
3423 element_value_err = tmp_channel->GetValueError();
3424 element_value_width = tmp_channel->GetValueWidth();
3425 local_ps_element->Set(type, element_value, element_value_err, element_value_width);
3426 }
3427
3428 if( local_print_flag && local_ps_element) {
3429 printf("Type %12s, Element %32s, value %12.4e error %8.4e width %12.4e\n",
3430 type.Data(), element_name.Data(), element_value, element_value_err, element_value_width);
3431 }
3432
3433 }
3434 }
3435
3436};
A logfile class, based on an identical class in the Hermes analyzer.
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
#define QwDebug
Predefined log drain for debugging output.
Definition QwLog.h:59
Prompt summary data management.
#define REGISTER_SUBSYSTEM_FACTORY(A)
Definition QwFactory.h:270
ULong64_t BankID_t
Definition QwTypes.h:21
UInt_t GetGlobalErrorFlag(TString evtype, Int_t evMode, Double_t stabilitycut)
Definition QwTypes.cc:132
EQwBeamInstrumentType GetQwBeamInstrumentType(TString name)
Definition QwTypes.cc:34
UInt_t ROCID_t
Definition QwTypes.h:20
EQwBeamInstrumentType
Definition QwTypes.h:143
@ kQwEnergyCalculator
Definition QwTypes.h:151
@ kQwHaloMonitor
Definition QwTypes.h:152
@ kQwCombinedBPM
Definition QwTypes.h:150
@ kQwBPMStripline
Definition QwTypes.h:145
@ kQwClock
Definition QwTypes.h:154
@ kQwLinearArray
Definition QwTypes.h:147
@ kQwCombinedBCM
Definition QwTypes.h:149
@ kQwQPD
Definition QwTypes.h:146
@ kQwBCM
Definition QwTypes.h:148
@ kQwUnknownDeviceType
Definition QwTypes.h:144
@ kQwBPMCavity
Definition QwTypes.h:153
TString GetQwBeamInstrumentTypeName(EQwBeamInstrumentType type)
Definition QwTypes.cc:100
std::shared_ptr< VQwClock > VQwClock_ptr
Definition VQwClock.h:121
std::shared_ptr< VQwBCM > VQwBCM_ptr
Definition VQwBCM.h:184
std::shared_ptr< VQwBPM > VQwBPM_ptr
Definition VQwBPM.h:354
Beamline subsystem containing BPMs, BCMs, and other beam monitoring devices.
@ kGreen
Definition QwColor.h:77
@ kNormal
Definition QwColor.h:81
Bool_t PublishInternalValue(const TString name, const TString desc, const VQwHardwareChannel *element) const
static TString DetermineMeasurementTypeID(TString type, TString suffix="", Bool_t forcediffs=kFALSE)
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Command-line and configuration file options processor.
Definition QwOptions.h:141
Configuration file parser with flexible tokenization and search capabilities.
T GetTypedNextToken()
Get next token into specific type.
std::unique_ptr< QwParameterFile > ReadUntilNextModule(const bool add_current_line=false)
Bool_t PopValue(const std::string keyname, T &retvalue)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
void SetCommentChars(const std::string value)
Set various sets of special characters.
Bool_t SkipSection(std::string secname)
Skips from the beginning of the section 'secname' until the first section that does not have that nam...
void AddBreakpointKeyword(std::string keyname)
void TrimComment(const char commentchar)
const std::pair< TString, TString > GetParamFileNameContents()
Bool_t FileHasModuleHeader(const std::string &secname)
Bool_t ReturnValue(const std::string keyname, T &retvalue)
std::unique_ptr< QwParameterFile > ReadNextSection(std::string &secname, const bool keep_header=false)
void Set(TString type, const Double_t a, const Double_t a_err, const Double_t a_width)
void AddElement(PromptSummaryElement *in)
PromptSummaryElement * GetElementByName(TString name)
A helper class to manage a vector of branch entries for ROOT trees.
Definition QwRootFile.h:53
static void PrintErrorCounterTail()
static void PrintErrorCounterHead()
The pure virtual base class of all data elements.
virtual void SetExternalClockPtr(const VQwHardwareChannel *)
virtual void LoadChannelParameters(QwParameterFile &)
virtual void LoadMockDataParameters(QwParameterFile &)
virtual const TString & GetElementName() const
Get the name of this element.
virtual Bool_t NeedsExternalClock()
virtual std::string GetExternalClockName()
Abstract base for concrete hardware channels implementing dual-operator pattern.
Double_t GetValueError() const
Double_t GetValueWidth() const
Double_t GetValue() const
std::vector< std::vector< TString > > fPublishList
BankID_t fCurrentBank_ID
Bank ID (and Marker word) that is currently being processed;.
TString fSystemName
Name of this subsystem.
Int_t GetSubbankIndex() const
void RegisterRocBankMarker(QwParameterFile &mapstr)
TString GetName() const
std::map< TString, TString > fDetectorMaps
Map of file name to full path or content.
VQwSubsystem(const TString &name)
Constructor with name.
ROCID_t fCurrentROC_ID
ROC ID that is currently being processed.
Beam detector mapping/ID decoded from map files.
EQwBeamInstrumentType fTypeID
Bool_t ReportInitErrors() const
Subsystem aggregating beamline instruments (BPMs, BCMs, clocks, etc.)
Definition QwBeamLine.h:43
void IncrementErrorCounters() override
std::vector< VQwBCM_ptr > fBCM
Definition QwBeamLine.h:192
void Scale(Double_t factor) override
void ProcessOptions(QwOptions &options) override
Definition QwBeamLine.cc:43
VQwSubsystem & operator=(VQwSubsystem *value) override
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
void CopyTemplatedDataElements(const VQwSubsystem *source)
size_t GetNumberOfElements()
Int_t AddToElementList(std::vector< TT > &elementlist, QwBeamDetectorID &detector_id)
Adds a new element to a vector of data elements, and returns the index of that element within the arr...
Definition QwBeamLine.cc:95
std::vector< QwLinearDiodeArray > fLinearArray
Definition QwBeamLine.h:198
VQwSubsystem & operator+=(VQwSubsystem *value) override
VQwDataElement * GetElement(QwBeamDetectorID det_id)
void LoadMockDataParameters(TString mapfile) override
Bool_t Compare(VQwSubsystem *source)
std::vector< QwEnergyCalculator > fECalculator
Definition QwBeamLine.h:203
void Ratio(VQwSubsystem *numer, VQwSubsystem *denom) override
std::vector< QwBeamDetectorID > fBeamDetectorID
Definition QwBeamLine.h:204
std::vector< VQwBPM_ptr > fStripline
Definition QwBeamLine.h:189
Int_t GetDetectorIndex(EQwBeamInstrumentType TypeID, TString name) const
void FillHistograms() override
Fill the histograms for this subsystem.
const VQwHardwareChannel * GetChannel(EQwBeamInstrumentType TypeID, Int_t index, TString device_prop) const
Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
Route raw ROC/bank buffer data to the correct devices and subelements.
Bool_t PublishInternalValues() const override
std::vector< QwBPMCavity > fCavity
Definition QwBeamLine.h:199
UInt_t UpdateErrorFlag() override
void AssignGeometry(QwParameterFile *mapstr, VQwBPM *bpm)
void WritePromptSummary(QwPromptSummary *ps, TString type) override
QwBeamLine()
Private default constructor (not implemented, will throw linker error on use)
VQwBPM * GetBPMStripline(const TString name)
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Bool_t CheckForBurpFail(const VQwSubsystem *subsys) override
void CalculateRunningAverage() override
Calculate the average for all good events.
Int_t LoadGeometryDefinition(TString mapfile) override
void FillTreeVector(QwRootTreeBranchVector &values) const override
Fill the tree vector.
std::vector< QwQPD > fQPD
Definition QwBeamLine.h:197
Bool_t PublishByRequest(TString device_name) override
std::vector< VQwBPM_ptr > fBPMCombo
Definition QwBeamLine.h:190
void LoadEventCuts_Fin(Int_t &eventcut_flag) override
Int_t LoadChannelMap(TString mapfile) override
Bool_t ApplySingleEventCuts() override
QwHaloMonitor * GetScalerChannel(const TString name)
VQwBCM * GetBCM(const TString name)
void PrintInfo() const override
Print some information about the subsystem.
VQwClock * GetClock(const TString name)
QwEnergyCalculator * GetEnergyCalculator(const TString name)
Int_t fQwBeamLineErrorCount
Definition QwBeamLine.h:211
void PrintValue() const override
Print values of all channels.
void LoadEventCuts_Line(QwParameterFile &mapstr, TString &varvalue, Int_t &eventcut_flag) override
std::vector< QwHaloMonitor > fHaloMonitor
Definition QwBeamLine.h:200
void PrintErrorCounters() const override
std::vector< VQwBCM_ptr > fBCMCombo
Definition QwBeamLine.h:193
void AccumulateRunningSum(VQwSubsystem *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Update the running sums for devices.
UInt_t GetEventcutErrorFlag() override
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Construct the branch and tree vector.
static const Bool_t bDEBUG
Definition QwBeamLine.h:214
VQwSubsystem & operator-=(VQwSubsystem *value) override
void ProcessEvent() override
void RandomizeEventData(int helicity=0, double time=0.0) override
void EncodeEventData(std::vector< UInt_t > &buffer) override
VQwBCM * GetCombinedBCM(const TString name)
std::vector< VQwClock_ptr > fClock
Definition QwBeamLine.h:195
void ConstructBranch(TTree *tree, TString &prefix) override
Construct the branch and tree vector.
VQwBPM * GetCombinedBPM(const TString name)
void PrintDetectorID() const
QwBPMCavity * GetBPMCavity(const TString name)
void ClearEventData() override
void DeaccumulateRunningSum(VQwSubsystem *value, Int_t ErrorMask=0xFFFFFFF) override
remove one entry from the running sums for devices
Int_t LoadInputParameters(TString pedestalfile) override
Cavity-style BPM using VQWK channels.
Definition QwBPMCavity.h:38
Computes beam energy change from BPM information.
Wrapper around a scaler channel to monitor beam halo rates.
Abstract base for beam current monitors (BCMs)
Definition VQwBCM.h:52
static VQwBCM * CreateCombo(TString subsystemname, TString type, TString name)
Factory method to create a concrete Combined BCM for the requested module type.
Definition VQwBCM.cc:101
static VQwBCM * Create(TString subsystemname, TString type, TString name, TString clock="")
Factory method to create a concrete BCM instance for the requested module type.
Definition VQwBCM.cc:41
Abstract base for beam position monitors (BPMs)
Definition VQwBPM.h:52
@ kXAxis
Definition VQwBPM.h:72
@ kYAxis
Definition VQwBPM.h:72
void GetSurveyOffsets(Double_t Xoffset, Double_t Yoffset, Double_t Zoffset)
Store geometry/survey offsets for absolute position calibration.
Definition VQwBPM.cc:56
void SetRotation(Double_t)
Set detector rotation angle and update cached trigonometric values.
Definition VQwBPM.cc:108
static VQwBPM * CreateCombo(TString subsystemname, TString type, TString name)
A fast way of creating a BPM stripline of specified type.
Definition VQwBPM.cc:314
void SetRotationOff()
Definition VQwBPM.cc:126
void GetElectronicFactors(Double_t BSENfactor, Double_t AlphaX, Double_t AlphaY)
Apply per-detector electronic calibration and relative gains.
Definition VQwBPM.cc:77
void SetGains(TString pos, Double_t value)
Definition VQwBPM.cc:134
static VQwBPM * CreateStripline(TString subsystemname, TString type, TString name)
A fast way of creating a BPM stripline of specified type.
Definition VQwBPM.cc:267
virtual const VQwHardwareChannel * GetEffectiveCharge() const =0
virtual const VQwHardwareChannel * GetPosition(EBeamPositionMonitorAxis axis) const
Definition VQwBPM.h:140
Abstract base for beam clocks used to normalize rates and yields.
Definition VQwClock.h:47
static VQwClock * Create(TString subsystemname, TString type, TString name)
Definition VQwClock.cc:30
virtual void FillDB(QwParityDB *, TString)
Fill the database.
virtual void FillErrDB(QwParityDB *, TString)