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