JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwEventBuffer.h
Go to the documentation of this file.
1
2/*!
3 * \file QwEventBuffer.h
4 * \brief Event buffer management for reading and processing CODA data
5 * \author P. M. King
6 * \date 2008-07-22
7 */
8
9#pragma once
10
11#include <string>
12#include <vector>
13#include "Rtypes.h"
14#include "TString.h"
15#include "TStopwatch.h"
16
17#include "THaCodaData.h"
18
19#include "MQwCodaControlEvent.h"
20#include "QwParameterFile.h"
21
22#include <unordered_map>
23
24#include "VEventDecoder.h"
25#include "Coda3EventDecoder.h"
26#include "Coda2EventDecoder.h"
27
28class QwOptions;
29class QwEPICSEvent;
30class VQwSubsystem;
32
33//////////////////////////////////////////////////////////////////////
34
35
36/**
37 * \class QwEventBuffer
38 * \ingroup QwAnalysis
39 * \brief Event buffer management for reading and processing CODA data
40 *
41 * Manages the reading of CODA event data files, including support for
42 * segmented files, run lists, and event stream processing. Handles
43 * event decoding via pluggable decoder classes and provides iteration
44 * over events and runs.
45 */
47 public:
48 static void DefineOptions(QwOptions &options);
49 static void SetDefaultDataDirectory(const std::string& dir) {
51 }
52 static void SetDefaultDataFileStem(const std::string& stem) {
54 }
55 static void SetDefaultDataFileExtension(const std::string& extension) {
56 fDefaultDataFileExtension = extension;
57 }
58
59 public:
60 static const Int_t kRunNotSegmented;
61 static const Int_t kNoNextDataFile;
62 static const Int_t kFileHandleNotConfigured;
63
64 static const UInt_t kNullDataWord;
65
66
67
68 public:
70 virtual ~QwEventBuffer() {
71 // Delete event stream
72 if (fEvStream != NULL) {
73 delete fEvStream;
74 fEvStream = NULL;
75 }
76 // Delete Decoder
77 if(decoder != NULL) {
78 delete decoder;
79 decoder = NULL;
80 }
81 };
82
83 /// \brief Sets internal flags based on the QwOptions
84 void ProcessOptions(QwOptions &options);
85
86 void PrintRunTimes();
87
88 /// \brief Returns a string like <run#> or <run#>.<file#>
89 TString GetRunLabel() const;
90 /// \brief Return true if file segments are being separated for
91 //analysis
92 Bool_t AreRunletsSplit() const {
94 };
95 /// \brief Return CODA file run number
96 Int_t GetRunNumber() const {return fCurrentRun;};
97 /// \brief Return CODA file segment number
98 Int_t GetSegmentNumber() const {
99 return fRunSegments.size() ? *fRunSegmentIterator : 0;
100 };
101
102 std::pair<UInt_t, UInt_t> GetEventRange() const {
103 return fEventRange;
104 };
105
106 /// \brief Opens the event stream (file or ET) based on the internal flags
107 Int_t OpenNextStream();
108 /// \brief Closes a currently open event stream.
109 Int_t CloseStream();
110
111 void SetDataDirectory(const TString datadir){fDataDirectory = datadir;}
112
113
114 const TString& GetDataFile() const {return fDataFile;};
115 const TString& GetDataDirectory() const {return fDataDirectory;};
116
117 Int_t ReOpenStream();
118
119 Int_t OpenDataFile(UInt_t current_run, Short_t seg);
120 Int_t OpenDataFile(UInt_t current_run, const TString rw = "R");
121 Int_t OpenDataFile(const TString filename, const TString rw = "R");
122 Int_t CloseDataFile();
123
124 Int_t OpenETStream(TString computer, TString session, int mode, const TString stationname="");
125 Int_t CloseETStream();
126
127 Bool_t IsPhysicsEvent() {
128 return ( decoder->IsPhysicsEvent() );
129 };
130
132 Int_t GetEventNumber() { return decoder->GetEvtNumber(); };
133
134 Bool_t GetNextEventRange();
135 Bool_t GetNextRunRange();
136 Bool_t GetNextRunNumber();
137 void VerifyCodaVersion( const UInt_t *buffer);
138
139 Int_t GetNextEvent();
140
141 Int_t GetEvent();
142 Int_t WriteEvent(int* buffer);
143
144 Bool_t IsOnline(){return fOnline;};
145
147 return ( decoder->IsROCConfigurationEvent() );
148 };
149
150 Bool_t IsEPICSEvent(){
151 return ( decoder->IsEPICSEvent() ); // Defined in CodaDecoder.h
152 }
153
155 Bool_t FillSubsystemData(QwSubsystemArray &subsystems);
156
157 Bool_t FillEPICSData(QwEPICSEvent &epics);
158
159 template < class T > Bool_t FillObjectWithEventData(T &t);
160
161
163 void ReportRunSummary();
164 Int_t EncodeSubsystemData(QwSubsystemArray &subsystems);
165 Int_t EncodePrestartEvent(int runnumber, int runtype = 0);
166 Int_t EncodeGoEvent();
167 Int_t EncodePauseEvent();
168 Int_t EncodeEndEvent();
169
170 TString GetStartSQLTime();
171 TString GetEndSQLTime();
172 time_t GetStartUnixTime();
173 time_t GetEndUnixTime();
174
175 void ResetFlags();
176
177 private:
178 // These methods will be removed from a future version
179 void ClearEventData(std::vector<VQwSubsystem*> &subsystems);
180
181 Bool_t FillSubsystemConfigurationData(std::vector<VQwSubsystem*> &subsystems);
182 Bool_t FillSubsystemData(std::vector<VQwSubsystem*> &subsystems);
183
184 // Coda Version that is set by void VerifyCodaVersion( )
185 // Compared against the user-input coda version
187 Int_t fDataVersion; // User-input Coda Version
188
189 protected:
190 ///
191 Bool_t fOnline;
192 TString fETHostname;
193 TString fETSession;
197
198
200 std::pair<Int_t, Int_t> fRunRange;
201 std::string fRunListFileName;
202 std::unique_ptr<QwParameterFile> fRunListFile;
204
205 std::pair<UInt_t, UInt_t> fEventRange;
207 std::unique_ptr<QwParameterFile> fEventListFile;
208 std::vector<UInt_t> fEventList;
209
210 std::pair<Int_t, Int_t> fSegmentRange;
211
212 protected:
213
214 static std::string fDefaultDataDirectory;
215 static std::string fDefaultDataFileStem;
216 static std::string fDefaultDataFileExtension;
217
220
222 TString fDataFile;
223
224 // UInt_t fRunNumber;
225
226
227 protected:
228 Int_t GetFileEvent();
229 Int_t GetEtEvent();
230
231 Int_t WriteFileEvent(int* buffer);
232
233 Bool_t DataFileIsSegmented();
234
235 Int_t CloseThisSegment();
236 Int_t OpenNextSegment();
237
238 const TString& DataFile(const UInt_t run, const Short_t seg);
239
240 // void SetEventLength(const ULong_t tmplength) {fEvtLength = tmplength;};
241 // void SetEventType(const UInt_t tmptype) {fEvtType = tmptype;};
242 // void SetWordsSoFar(const ULong_t tmpwords) {fWordsSoFar = tmpwords;};
243
244
245
246 protected:
248 THaCodaData *fEvStream; // Pointer to a THaCodaFile or THaEtClient
249
251
253
254
255 std::vector<Int_t> fRunSegments;
256 std::vector<Int_t>::iterator fRunSegmentIterator;
257
258
259 protected:
260 Double_t fCleanParameter[3]; ///< Scan data/clean data from the green monster
261
262
263 TStopwatch fRunTimer; ///< Timer used for runlet processing loop
264 TStopwatch fStopwatch; ///< Timer used for internal timing
265
266 protected:
267 /// Methods and data members needed to find marker words
269 std::unordered_map<RocBankLabel_t, std::vector<UInt_t> > fMarkerList;
270 std::unordered_map<RocBankLabel_t, std::vector<UInt_t> > fOffsetList;
271
272 std::size_t CheckForMarkerWords(QwSubsystemArray &subsystems);
274 UInt_t FindMarkerWord(UInt_t markerID, UInt_t* buffer, UInt_t num_words);
275 UInt_t GetMarkerWord(UInt_t markerID);
276
277 protected:
280
282
283 protected:
285};
286
287template < class T > Bool_t QwEventBuffer::FillObjectWithEventData(T &object){
288 /// Template to fill any object with data from a CODA event.
289 ///
290 /// The classes for which this template can be specialized
291 /// must have the following three methods defined:
292 ///
293 /// - Bool_t T::CanUseThisEventType(const UInt_t event_type);
294 /// - Bool_t T::ClearEventData(const UInt_t event_type);
295 /// - Int_t T::ProcessBuffer(const UInt_t event_type,
296 /// const ROCID_t roc_id, const BankID_t bank_id,
297 /// const UInt_t banktype, UInt_t* buffer, UInt_t num_words);
298 ///
299 Bool_t okay = kFALSE;
300 UInt_t *localbuff = (UInt_t*)(fEvStream->getEvBuffer());
301
302 if (decoder->GetFragLength()==1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord){
303 decoder->AddWordsSoFarAndFragLength();
304 } else if (object.CanUseThisEventType(decoder->GetEvtType())){
305 // Clear the old event information from the object
306 object.ClearEventData(decoder->GetEvtType());
307 // Loop through the data buffer in this event.
308 if (decoder->GetBankDataType() == 0x10){
309 // This bank is subbanked; loop through subbanks
310 while ((okay = decoder->DecodeSubbankHeader(&localbuff[decoder->GetWordsSoFar()]))){
311 // If this bank has further subbanks, restart the loop.
312 if (decoder->GetSubbankType() == 0x10) continue;
313 // If this bank only contains the word 'NULL' then skip
314 // this bank.
315 if (decoder->GetFragLength()==1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord){
316 decoder->AddWordsSoFarAndFragLength();
317 continue;
318 }
319 object.ProcessBuffer(decoder->GetEvtType(), decoder->GetROC(), decoder->GetSubbankTag(), decoder->GetSubbankType(),
320 &localbuff[decoder->GetWordsSoFar()],
321 decoder->GetFragLength());
322 decoder->AddWordsSoFarAndFragLength();
323 }
324 } else {
325 // This is a single bank of some type
326 object.ProcessBuffer(decoder->GetEvtType(), 0, decoder->GetBankDataType(),
327 &localbuff[decoder->GetWordsSoFar()],
328 decoder->GetEvtLength());
329 }
330 }
331 return okay;
332}
CODA control event data structure and management.
Parameter file parsing and management.
Virtual base class for event decoders to encode and decode CODA data.
CODA version 3 event decoder implementation.
CODA version 2 event decoder implementation.
unsigned long long ULong64_t
Definition QwBlinder.h:41
EPICS slow controls data management.
TString GetRunLabel() const
Returns a string like <run#> or <run#>.<file#>
static void SetDefaultDataFileExtension(const std::string &extension)
Int_t EncodeSubsystemData(QwSubsystemArray &subsystems)
TString fETHostname
static const Int_t kRunNotSegmented
Int_t EncodeGoEvent()
TString GetEndSQLTime()
time_t GetStartUnixTime()
TString fDataDirectory
ULong64_t RocBankLabel_t
Methods and data members needed to find marker words.
const TString & GetDataDirectory() const
Int_t EncodePauseEvent()
UInt_t fStartingPhysicsEvent
std::pair< UInt_t, UInt_t > GetEventRange() const
Int_t GetEventNumber()
Int_t CloseThisSegment()
void ReportRunSummary()
static std::string fDefaultDataDirectory
Bool_t IsOnline()
Int_t EncodeEndEvent()
Bool_t fChainDataFiles
std::unordered_map< RocBankLabel_t, std::vector< UInt_t > > fMarkerList
enum QwEventBuffer::CodaStreamMode fEvStreamMode
Int_t CloseStream()
Closes a currently open event stream.
Bool_t IsEPICSEvent()
Int_t OpenETStream(TString computer, TString session, int mode, const TString stationname="")
Bool_t fRunIsSegmented
Bool_t GetNextRunRange()
Read the next requested run range, return true if success.
Int_t EncodePrestartEvent(int runnumber, int runtype=0)
QwEventBuffer()
Default constructor.
void VerifyCodaVersion(const UInt_t *buffer)
Int_t WriteFileEvent(int *buffer)
Int_t OpenNextStream()
Opens the event stream (file or ET) based on the internal flags.
static const Int_t kFileHandleNotConfigured
std::vector< Int_t >::iterator fRunSegmentIterator
static void SetDefaultDataDirectory(const std::string &dir)
void ProcessOptions(QwOptions &options)
Sets internal flags based on the QwOptions.
Bool_t FillSubsystemData(QwSubsystemArray &subsystems)
VEventDecoder * decoder
TStopwatch fStopwatch
Timer used for internal timing.
Int_t WriteEvent(int *buffer)
Int_t GetSegmentNumber() const
Return CODA file segment number.
std::unique_ptr< QwParameterFile > fEventListFile
void ResetControlParameters()
const TString & DataFile(const UInt_t run, const Short_t seg)
virtual ~QwEventBuffer()
TString GetStartSQLTime()
void SetDataDirectory(const TString datadir)
TString fETStationName
static void DefineOptions(QwOptions &options)
std::unordered_map< RocBankLabel_t, std::vector< UInt_t > > fOffsetList
const TString & GetDataFile() const
static void SetDefaultDataFileStem(const std::string &stem)
Double_t fCleanParameter[3]
Scan data/clean data from the green monster.
UInt_t FindMarkerWord(UInt_t markerID, UInt_t *buffer, UInt_t num_words)
TString fDataFileExtension
Int_t GetRunNumber() const
Return CODA file run number.
std::vector< Int_t > fRunRangeMinList
std::vector< Int_t > fRunRangeMaxList
static const UInt_t kNullDataWord
static const Int_t kNoNextDataFile
Bool_t IsROCConfigurationEvent()
RocBankLabel_t fThisRocBankLabel
Int_t GetPhysicsEventNumber()
Bool_t GetNextEventRange()
Read the next requested event range, return true if success.
Bool_t DataFileIsSegmented()
std::pair< Int_t, Int_t > fRunRange
std::pair< UInt_t, UInt_t > fEventRange
Int_t OpenDataFile(UInt_t current_run, Short_t seg)
static std::string fDefaultDataFileExtension
void ClearEventData(std::vector< VQwSubsystem * > &subsystems)
std::string fRunListFileName
Int_t OpenNextSegment()
UInt_t fNumPhysicsEvents
Bool_t FillObjectWithEventData(T &t)
Bool_t FillSubsystemData(std::vector< VQwSubsystem * > &subsystems)
TStopwatch fRunTimer
Timer used for runlet processing loop.
time_t GetEndUnixTime()
static std::string fDefaultDataFileStem
Bool_t GetNextRunNumber()
Get the next run in the active run range, proceed to next range if needed.
Bool_t IsPhysicsEvent()
Bool_t FillEPICSData(QwEPICSEvent &epics)
THaCodaData * fEvStream
Bool_t FillSubsystemConfigurationData(std::vector< VQwSubsystem * > &subsystems)
Bool_t AreRunletsSplit() const
Return true if file segments are being separated for.
std::pair< Int_t, Int_t > fSegmentRange
std::unique_ptr< QwParameterFile > fRunListFile
std::vector< UInt_t > fEventList
std::string fEventListFileName
std::size_t CheckForMarkerWords(QwSubsystemArray &subsystems)
std::vector< Int_t > fRunSegments
Bool_t FillSubsystemConfigurationData(QwSubsystemArray &subsystems)
TString fDataFileStem
Int_t fDataVersionVerify
UInt_t GetMarkerWord(UInt_t markerID)
Command-line and configuration file options processor.
Definition QwOptions.h:141
Container for managing multiple subsystems with common operations.
Abstract base for CODA event encoding and decoding.
Base class for subsystems implementing container-delegation pattern.