JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwEventRing Class Reference

Ring buffer of subsystem snapshots for burp/stability handling. More...

#include <QwEventRing.h>

+ Collaboration diagram for QwEventRing:

Public Member Functions

 QwEventRing (QwOptions &options, QwSubsystemArrayParity &event)
 
virtual ~QwEventRing ()
 
void ProcessOptions (QwOptions &options)
 Process options.
 
void push (QwSubsystemArrayParity &event)
 Add the subsystem to the ring.
 
QwSubsystemArrayParitypop ()
 Return the last subsystem in the ring.
 
void PrintRollingAverage ()
 Print value of rolling average.
 
Bool_t IsReady ()
 Return the read status of the ring.
 
void CheckBurpCut (Int_t thisevent)
 
Int_t GetNumberOfEvents () const
 Return the number of events in the ring.
 
void Unwind ()
 Unwind the ring until empty.
 

Static Public Member Functions

static void DefineOptions (QwOptions &options)
 Define options.
 

Private Member Functions

 QwEventRing ()
 

Private Attributes

Int_t fRING_SIZE
 
Int_t fNumberOfEvents
 
Int_t fNextToBeFilled
 
Int_t fNextToBeRead
 
Bool_t fPrintAfterUnwind
 
Bool_t bEVENT_READY
 
Bool_t bRING_READY
 
std::vector< QwSubsystemArrayParityfEvent_Ring
 
QwSubsystemArrayParity fRollingAvg
 
FILE * out_file
 
Bool_t bStability
 
int holdoff
 
int countdown
 
Int_t fBurpExtent
 
Int_t fBurpPrecut
 
QwSubsystemArrayParity fBurpAvg
 

Static Private Attributes

static const Bool_t bDEBUG =kFALSE
 
static const Bool_t bDEBUG_Write =kFALSE
 

Detailed Description

Ring buffer of subsystem snapshots for burp/stability handling.

Maintains a sliding window of events to compute running averages, handle beam trips with holdoff, and apply burp cuts over extents.

Definition at line 28 of file QwEventRing.h.

Constructor & Destructor Documentation

◆ QwEventRing() [1/2]

QwEventRing::QwEventRing ( )
private

◆ QwEventRing() [2/2]

QwEventRing::QwEventRing ( QwOptions & options,
QwSubsystemArrayParity & event )

QwEventRing.cc

Event ring buffer for burp detection and stability monitoring. Maintains a circular buffer of recent events, applies rolling averages for stability cuts, and implements burp detection with configurable extent and precut parameters. Documentation-only edits; runtime behavior unchanged. Constructor: initialize ring buffer with specified size and options.

Definition at line 14 of file QwEventRing.cc.

15 : fRollingAvg(event), fBurpAvg(event)
16{
17 ProcessOptions(options);
18
19 fEvent_Ring.resize(fRING_SIZE,event);
20
21 bRING_READY = kFALSE;
22 bEVENT_READY = kTRUE;
23
26 fNextToBeRead = 0;
27 countdown = 0;
28
29 //open the log file
30 if (bDEBUG_Write)
31 out_file = fopen("Ring_log.txt", "wt");
32}
Int_t fNextToBeFilled
Definition QwEventRing.h:81
FILE * out_file
Definition QwEventRing.h:96
QwSubsystemArrayParity fRollingAvg
Definition QwEventRing.h:93
QwSubsystemArrayParity fBurpAvg
Bool_t bEVENT_READY
Definition QwEventRing.h:86
std::vector< QwSubsystemArrayParity > fEvent_Ring
Definition QwEventRing.h:91
Bool_t bRING_READY
Definition QwEventRing.h:89
void ProcessOptions(QwOptions &options)
Process options.
Int_t fNumberOfEvents
Definition QwEventRing.h:79
static const Bool_t bDEBUG_Write
Definition QwEventRing.h:98
Int_t fNextToBeRead
Definition QwEventRing.h:82
Int_t fRING_SIZE
Definition QwEventRing.h:77

References bDEBUG_Write, bEVENT_READY, bRING_READY, countdown, fBurpAvg, fEvent_Ring, fNextToBeFilled, fNextToBeRead, fNumberOfEvents, fRING_SIZE, fRollingAvg, out_file, and ProcessOptions().

+ Here is the call graph for this function:

◆ ~QwEventRing()

virtual QwEventRing::~QwEventRing ( )
inlinevirtual

Definition at line 41 of file QwEventRing.h.

41{ };

Member Function Documentation

◆ CheckBurpCut()

void QwEventRing::CheckBurpCut ( Int_t thisevent)

Perform burp detection for the specified event, marking preceding events if a burp is detected and maintaining the burp average window.

Definition at line 224 of file QwEventRing.cc.

225{
226 if (bRING_READY || thisevent>fBurpExtent){
227 if (fBurpAvg.CheckForBurpFail(fEvent_Ring[thisevent])){
228 Int_t precut_start = (thisevent+fRING_SIZE-fBurpPrecut)%fRING_SIZE;
229 for(Int_t i=precut_start;i!=(thisevent+1)%fRING_SIZE;i=(i+1)%fRING_SIZE){
230 fEvent_Ring[i].UpdateErrorFlag(fBurpAvg);
231 fEvent_Ring[i].UpdateErrorFlag();
232 }
233 }
234 Int_t beforeburp = (thisevent+fRING_SIZE-fBurpExtent-1)%fRING_SIZE;
235 fBurpAvg.DeaccumulateRunningSum(fEvent_Ring[beforeburp], kPreserveError);
236 }
237 fBurpAvg.AccumulateAllRunningSum(fEvent_Ring[thisevent], 0, kPreserveError);
238
239}
static const UInt_t kPreserveError
Definition QwTypes.h:186
Int_t fBurpPrecut
Int_t fBurpExtent

References bRING_READY, fBurpAvg, fBurpExtent, fBurpPrecut, fEvent_Ring, fRING_SIZE, and kPreserveError.

Referenced by push().

+ Here is the caller graph for this function:

◆ DefineOptions()

void QwEventRing::DefineOptions ( QwOptions & options)
static

Define options.

Define command-line options for ring buffer and burp detection parameters.

Definition at line 36 of file QwEventRing.cc.

37{
38 // Define the execution options
39 options.AddOptions()("ring.size",
40 po::value<int>()->default_value(4800),
41 "QwEventRing: ring/buffer size");
42
43 options.AddOptions()("burp.extent",
44 po::value<int>()->default_value(10),
45 "QwEventRing: burp extent");
46
47 options.AddOptions()("burp.precut",
48 po::value<int>()->default_value(5),
49 "QwEventRing: burp precut");
50
51 options.AddOptions()("burp.holdoff",
52 po::value<int>()->default_value(10),
53 "QwEventRing: burp holdoff");
54
55 options.AddOptions()("ring.stability_cut",
56 po::value<double>()->default_value(1),
57 "QwEventRing: Stability ON/OFF");
58 options.AddOptions()("ring.print-after-unwind",
59 po::value<bool>()->default_bool_value(false),
60 "QwEventRing: print rolling avg after unwind");
61 options.AddOptions()("ring.holdoff",
62 po::value<int>()->default_value(200),
63 "QwEventRing: number of events ignored after the beam trips");
64}
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Definition QwOptions.h:170

References QwOptions::AddOptions().

Referenced by DefineOptionsParity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetNumberOfEvents()

Int_t QwEventRing::GetNumberOfEvents ( ) const
inline

Return the number of events in the ring.

Definition at line 65 of file QwEventRing.h.

65{ return fNumberOfEvents; }

References fNumberOfEvents.

Referenced by Unwind().

+ Here is the caller graph for this function:

◆ IsReady()

Bool_t QwEventRing::IsReady ( )

Return the read status of the ring.

Check if the ring buffer has events ready for retrieval.

Definition at line 216 of file QwEventRing.cc.

216 { //Check for readiness to read data from the ring using the pop() routine
217 return bRING_READY;
218}

References bRING_READY.

Referenced by main().

+ Here is the caller graph for this function:

◆ pop()

QwSubsystemArrayParity & QwEventRing::pop ( )

Return the last subsystem in the ring.

Retrieve the next event from the ring buffer and deaccumulate from rolling average if stability monitoring is enabled.

Returns
Reference to the retrieved event.

Definition at line 193 of file QwEventRing.cc.

193 {
194 Int_t tempIndex;
195 tempIndex=fNextToBeRead;
196 if (bDEBUG) QwMessage<<" Read at "<<fNextToBeRead<<QwLog::endl;
197 if (bDEBUG_Write) fprintf(out_file," Read at %d \n",fNextToBeRead);
198
199 if (fNextToBeRead==(fRING_SIZE-1)){
200 bRING_READY=kFALSE;//setting to false is an extra measure of security to prevent reading a NULL value.
201 }
202 if (bStability){
203 fRollingAvg.DeaccumulateRunningSum(fEvent_Ring[tempIndex]);
204 }
205
206 // Increment read index
209
210 // Return the event
211 return fEvent_Ring[tempIndex];
212}
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Bool_t bStability
static const Bool_t bDEBUG
Definition QwEventRing.h:97

References bDEBUG, bDEBUG_Write, bRING_READY, bStability, QwLog::endl(), fEvent_Ring, fNextToBeRead, fNumberOfEvents, fRING_SIZE, fRollingAvg, out_file, and QwMessage.

Referenced by main(), and Unwind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintRollingAverage()

void QwEventRing::PrintRollingAverage ( )
inline

Print value of rolling average.

Definition at line 54 of file QwEventRing.h.

54 {
55 fRollingAvg.CalculateRunningAverage();
56 fRollingAvg.PrintValue();
57 }

References fRollingAvg.

Referenced by Unwind().

+ Here is the caller graph for this function:

◆ ProcessOptions()

void QwEventRing::ProcessOptions ( QwOptions & options)

Process options.

Process options and validate ring/burp parameter consistency.

Definition at line 67 of file QwEventRing.cc.

68{
69 // Reads Event Ring parameters from cmd
70 Double_t stability = 0.0;
71 if (gQwOptions.HasValue("ring.size"))
72 fRING_SIZE=gQwOptions.GetValue<int>("ring.size");
73
74 if (gQwOptions.HasValue("burp.extent"))
75 fBurpExtent=gQwOptions.GetValue<int>("burp.extent");
76
77 if (gQwOptions.HasValue("burp.precut"))
78 fBurpPrecut=gQwOptions.GetValue<int>("burp.precut");
79
80 int tmpval = fBurpExtent;
82 QwWarning << "The burp precut ("<<fBurpPrecut
83 << ") is larger than the burp extent ("
85 << "; this may not be what you meant to do."
86 << QwLog::endl;
87 tmpval = fBurpPrecut;
88 }
89 tmpval += 2;
90 if (fRING_SIZE<tmpval){
91 QwWarning << "Forcing ring size to be " << tmpval
92 << " to accommodate a burp extent of " << fBurpExtent
93 << " and a burp precut of " << fBurpPrecut
94 << "; it had been " << fRING_SIZE << "." << QwLog::endl;
95 fRING_SIZE = tmpval;
96 }
97
98 if (gQwOptions.HasValue("burp.holdoff"))
99 VQwHardwareChannel::SetBurpHoldoff(gQwOptions.GetValue<int>("burp.holdoff"));
100
101 if (gQwOptions.HasValue("ring.stability_cut"))
102 stability=gQwOptions.GetValue<double>("ring.stability_cut");
103
104 if(gQwOptions.HasValue("ring.holdoff"))
105 holdoff=gQwOptions.GetValue<int>("ring.holdoff");
106
107 if (stability>0.0)
108 bStability=kTRUE;
109 else
110 bStability=kFALSE;
111
112 fPrintAfterUnwind = gQwOptions.GetValue<bool>("ring.print-after-unwind");
113}
#define gQwOptions
Definition QwOptions.h:31
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
static void SetBurpHoldoff(Int_t holdoff)
Bool_t fPrintAfterUnwind
Definition QwEventRing.h:84

References bStability, QwLog::endl(), fBurpExtent, fBurpPrecut, fPrintAfterUnwind, fRING_SIZE, gQwOptions, holdoff, QwWarning, and VQwHardwareChannel::SetBurpHoldoff().

Referenced by QwEventRing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ push()

void QwEventRing::push ( QwSubsystemArrayParity & event)

Add the subsystem to the ring.

Add an event to the ring buffer, applying stability cuts and burp detection. Updates rolling averages and marks events with beam trip or stability errors.

Definition at line 118 of file QwEventRing.cc.

119{
120 if (bDEBUG) QwMessage << "QwEventRing::push: BEGIN" <<QwLog::endl;
121
122
123
124 if (bEVENT_READY){
125 Int_t thisevent = fNextToBeFilled;
126 Int_t prevevent = (thisevent+fRING_SIZE-1)%fRING_SIZE;
127 fEvent_Ring[thisevent]=event;//copy the current good event to the ring
128 if (bStability){
129 fRollingAvg.AccumulateAllRunningSum(event);
130 }
131
132
133 if (bDEBUG) QwMessage<<" Filled at "<<thisevent;//<<"Ring count "<<fRing_Count<<QwLog::endl;
134 if (bDEBUG_Write) fprintf(out_file," Filled at %d ",thisevent);
135
136 // Increment fill index
138 fNextToBeFilled = (thisevent + 1) % fRING_SIZE;
139
140 if(fNextToBeFilled == 0){
141 //then we have RING_SIZE events to process
142 if (bDEBUG) QwMessage<<" RING FILLED "<<thisevent; //<<QwLog::endl;
143 if (bDEBUG_Write) fprintf(out_file," RING FILLED ");
144 bRING_READY=kTRUE;//ring is filled with good multiplets
145 fNextToBeFilled=0;//next event to be filled is the first element
146 }
147
148
149 //check for current ramps
150 if (bRING_READY && bStability){
151 fRollingAvg.CalculateRunningAverage();
152 /*
153 //The fRollingAvg dose not contain any regular errorcodes since it only accumulate rolling sum for errorflag==0 event.
154 //The only errorflag it generates is the stability cut failure error when the rolling avg is computed.
155 //Therefore when fRollingAvg.GetEventcutErrorFlag() is called it will return non-zero error code only if a global stability cut has failed
156 //When fRollingAvg.GetEventcutErrorFlag() is called the fErrorFlag of the subsystemarrayparity object will be updated with any global
157 //stability cut failures
158 */
159 fRollingAvg.UpdateErrorFlag(); //to update the global error code in the fRollingAvg
160 if ( fRollingAvg.GetEventcutErrorFlag() != 0 ) {
161 // This test really needs to determine in any of the subelements
162 // might have a local stability cut failure, instead of just this
163 // global stability cut failure.
164 for(Int_t i=0;i<fRING_SIZE;i++){
165 fEvent_Ring[i].UpdateErrorFlag(fRollingAvg);
166 fEvent_Ring[i].UpdateErrorFlag();
167 }
168 }
169 if ((fEvent_Ring[thisevent].GetEventcutErrorFlag() & kBCMErrorFlag)!=0 &&
170 (fEvent_Ring[prevevent].GetEventcutErrorFlag() & kBCMErrorFlag)!=0){
172 }
173 if (countdown > 0) {
174 --countdown;
175 for(Int_t i=0;i<fRING_SIZE;i++){
176 fEvent_Ring[i].UpdateErrorFlag(kBeamTripError);
177 }
178 }
179 }
180 //ring processing is done at a separate location
181
182 this->CheckBurpCut(thisevent);
183 }
184}
static const UInt_t kBCMErrorFlag
Definition QwTypes.h:168
static const UInt_t kBeamTripError
Definition QwTypes.h:181
void CheckBurpCut(Int_t thisevent)

References bDEBUG, bDEBUG_Write, bEVENT_READY, bRING_READY, bStability, CheckBurpCut(), countdown, QwLog::endl(), fEvent_Ring, fNextToBeFilled, fNumberOfEvents, fRING_SIZE, fRollingAvg, holdoff, kBCMErrorFlag, kBeamTripError, out_file, and QwMessage.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Unwind()

void QwEventRing::Unwind ( )
inline

Unwind the ring until empty.

Definition at line 68 of file QwEventRing.h.

68 {
69 while (GetNumberOfEvents() > 0) pop();
71 QwMessage << "Residual rolling average (should be zero)" << QwLog::endl;
73 }
74 }
QwSubsystemArrayParity & pop()
Return the last subsystem in the ring.
void PrintRollingAverage()
Print value of rolling average.
Definition QwEventRing.h:54
Int_t GetNumberOfEvents() const
Return the number of events in the ring.
Definition QwEventRing.h:65

References QwLog::endl(), fPrintAfterUnwind, GetNumberOfEvents(), pop(), PrintRollingAverage(), and QwMessage.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ bDEBUG

const Bool_t QwEventRing::bDEBUG =kFALSE
staticprivate

Definition at line 97 of file QwEventRing.h.

Referenced by pop(), and push().

◆ bDEBUG_Write

const Bool_t QwEventRing::bDEBUG_Write =kFALSE
staticprivate

Definition at line 98 of file QwEventRing.h.

Referenced by pop(), push(), and QwEventRing().

◆ bEVENT_READY

Bool_t QwEventRing::bEVENT_READY
private

Definition at line 86 of file QwEventRing.h.

Referenced by push(), and QwEventRing().

◆ bRING_READY

Bool_t QwEventRing::bRING_READY
private

Definition at line 89 of file QwEventRing.h.

Referenced by CheckBurpCut(), IsReady(), pop(), push(), and QwEventRing().

◆ bStability

Bool_t QwEventRing::bStability
private

Definition at line 101 of file QwEventRing.h.

Referenced by pop(), ProcessOptions(), and push().

◆ countdown

int QwEventRing::countdown
private

Definition at line 105 of file QwEventRing.h.

Referenced by push(), and QwEventRing().

◆ fBurpAvg

QwSubsystemArrayParity QwEventRing::fBurpAvg
private

Definition at line 110 of file QwEventRing.h.

Referenced by CheckBurpCut(), and QwEventRing().

◆ fBurpExtent

Int_t QwEventRing::fBurpExtent
private

Definition at line 108 of file QwEventRing.h.

Referenced by CheckBurpCut(), and ProcessOptions().

◆ fBurpPrecut

Int_t QwEventRing::fBurpPrecut
private

Definition at line 109 of file QwEventRing.h.

Referenced by CheckBurpCut(), and ProcessOptions().

◆ fEvent_Ring

std::vector<QwSubsystemArrayParity> QwEventRing::fEvent_Ring
private

Definition at line 91 of file QwEventRing.h.

Referenced by CheckBurpCut(), pop(), push(), and QwEventRing().

◆ fNextToBeFilled

Int_t QwEventRing::fNextToBeFilled
private

Definition at line 81 of file QwEventRing.h.

Referenced by push(), and QwEventRing().

◆ fNextToBeRead

Int_t QwEventRing::fNextToBeRead
private

Definition at line 82 of file QwEventRing.h.

Referenced by pop(), and QwEventRing().

◆ fNumberOfEvents

Int_t QwEventRing::fNumberOfEvents
private

Definition at line 79 of file QwEventRing.h.

Referenced by GetNumberOfEvents(), pop(), push(), and QwEventRing().

◆ fPrintAfterUnwind

Bool_t QwEventRing::fPrintAfterUnwind
private

Definition at line 84 of file QwEventRing.h.

Referenced by ProcessOptions(), and Unwind().

◆ fRING_SIZE

Int_t QwEventRing::fRING_SIZE
private

Definition at line 77 of file QwEventRing.h.

Referenced by CheckBurpCut(), pop(), ProcessOptions(), push(), and QwEventRing().

◆ fRollingAvg

QwSubsystemArrayParity QwEventRing::fRollingAvg
private

Definition at line 93 of file QwEventRing.h.

Referenced by pop(), PrintRollingAverage(), push(), and QwEventRing().

◆ holdoff

int QwEventRing::holdoff
private

Definition at line 104 of file QwEventRing.h.

Referenced by ProcessOptions(), and push().

◆ out_file

FILE* QwEventRing::out_file
private

Definition at line 96 of file QwEventRing.h.

Referenced by pop(), push(), and QwEventRing().


The documentation for this class was generated from the following files: