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