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

Event buffer management for reading and processing CODA data. More...

#include <QwEventBuffer.h>

+ Collaboration diagram for QwEventBuffer:

Public Member Functions

 QwEventBuffer ()
 Default constructor.
 
virtual ~QwEventBuffer ()
 
void ProcessOptions (QwOptions &options)
 Sets internal flags based on the QwOptions.
 
void PrintRunTimes ()
 
TString GetRunLabel () const
 Returns a string like <run#> or <run#>.<file#>
 
Bool_t AreRunletsSplit () const
 Return true if file segments are being separated for.
 
Int_t GetRunNumber () const
 Return CODA file run number.
 
Int_t GetSegmentNumber () const
 Return CODA file segment number.
 
std::pair< UInt_t, UInt_t > GetEventRange () const
 
Int_t OpenNextStream ()
 Opens the event stream (file or ET) based on the internal flags.
 
Int_t CloseStream ()
 Closes a currently open event stream.
 
void SetDataDirectory (const TString datadir)
 
const TString & GetDataFile () const
 
const TString & GetDataDirectory () const
 
Int_t ReOpenStream ()
 
Int_t OpenDataFile (UInt_t current_run, Short_t seg)
 
Int_t OpenDataFile (UInt_t current_run, const TString rw="R")
 
Int_t OpenDataFile (const TString filename, const TString rw="R")
 
Int_t CloseDataFile ()
 
Int_t OpenETStream (TString computer, TString session, int mode, const TString stationname="")
 
Int_t CloseETStream ()
 
Bool_t IsPhysicsEvent ()
 
Int_t GetPhysicsEventNumber ()
 
Int_t GetEventNumber ()
 
Bool_t GetNextEventRange ()
 Read the next requested event range, return true if success.
 
Bool_t GetNextRunRange ()
 Read the next requested run range, return true if success.
 
Bool_t GetNextRunNumber ()
 Get the next run in the active run range, proceed to next range if needed.
 
void VerifyCodaVersion (const UInt_t *buffer)
 
Int_t GetNextEvent ()
 
Int_t GetEvent ()
 
Int_t WriteEvent (int *buffer)
 
Bool_t IsOnline ()
 
Bool_t IsROCConfigurationEvent ()
 
Bool_t IsEPICSEvent ()
 
Bool_t FillSubsystemConfigurationData (QwSubsystemArray &subsystems)
 
Bool_t FillSubsystemData (QwSubsystemArray &subsystems)
 
Bool_t FillEPICSData (QwEPICSEvent &epics)
 
template<class T>
Bool_t FillObjectWithEventData (T &t)
 
void ResetControlParameters ()
 
void ReportRunSummary ()
 
Int_t EncodeSubsystemData (QwSubsystemArray &subsystems)
 
Int_t EncodePrestartEvent (int runnumber, int runtype=0)
 
Int_t EncodeGoEvent ()
 
Int_t EncodePauseEvent ()
 
Int_t EncodeEndEvent ()
 
TString GetStartSQLTime ()
 
TString GetEndSQLTime ()
 
time_t GetStartUnixTime ()
 
time_t GetEndUnixTime ()
 
void ResetFlags ()
 

Static Public Member Functions

static void DefineOptions (QwOptions &options)
 
static void SetDefaultDataDirectory (const std::string &dir)
 
static void SetDefaultDataFileStem (const std::string &stem)
 
static void SetDefaultDataFileExtension (const std::string &extension)
 

Static Public Attributes

static const Int_t kRunNotSegmented = -20
 
static const Int_t kNoNextDataFile = -30
 
static const Int_t kFileHandleNotConfigured = -40
 
static const UInt_t kNullDataWord = 0x4e554c4c
 

Protected Types

enum  CodaStreamMode { fEvStreamNull , fEvStreamFile , fEvStreamET }
 
typedef ULong64_t RocBankLabel_t
 Methods and data members needed to find marker words.
 

Protected Member Functions

Int_t GetFileEvent ()
 
Int_t GetEtEvent ()
 
Int_t WriteFileEvent (int *buffer)
 
Int_t WriteEtEvent (int *buffer)
 
Bool_t DataFileIsSegmented ()
 
Int_t CloseThisSegment ()
 
Int_t OpenNextSegment ()
 
const TString & DataFile (const UInt_t run, const Short_t seg)
 
std::size_t CheckForMarkerWords (QwSubsystemArray &subsystems)
 
UInt_t FindMarkerWord (UInt_t markerID, UInt_t *buffer, UInt_t num_words)
 
UInt_t GetMarkerWord (UInt_t markerID)
 

Protected Attributes

Bool_t fOnline
 
TString fETHostname
 
TString fETSession
 
TString fETStationName
 
Int_t fETWaitMode
 
Bool_t fExitOnEnd
 
Bool_t fEventRateLimitEnabled {false}
 
Double_t fMaxEventRate {0.0}
 
std::chrono::duration< double > fMinEventInterval
 
std::chrono::duration< double > fAccumulatedDelay {0.0}
 
std::chrono::steady_clock::time_point fLastEventTime
 
Bool_t fChainDataFiles
 
std::pair< Int_t, Int_t > fRunRange
 
std::string fRunListFileName
 
std::unique_ptr< QwParameterFilefRunListFile
 
std::vector< Int_t > fRunRangeMinList
 
std::vector< Int_t > fRunRangeMaxList
 
std::pair< UInt_t, UInt_t > fEventRange
 
std::string fEventListFileName
 
std::unique_ptr< QwParameterFilefEventListFile
 
std::vector< UInt_t > fEventList
 
std::pair< Int_t, Int_t > fSegmentRange
 
TString fDataFileStem
 
TString fDataFileExtension
 
TString fDataDirectory
 
TString fDataFile
 
enum QwEventBuffer::CodaStreamMode fEvStreamMode
 
THaCodaData * fEvStream
 
Int_t fCurrentRun
 
Bool_t fRunIsSegmented
 
std::vector< Int_t > fRunSegments
 
std::vector< Int_t >::iterator fRunSegmentIterator
 
Double_t fCleanParameter [3]
 Scan data/clean data from the green monster.
 
TStopwatch fRunTimer
 Timer used for runlet processing loop.
 
TStopwatch fStopwatch
 Timer used for internal timing.
 
std::unordered_map< RocBankLabel_t, std::vector< UInt_t > > fMarkerList
 
std::unordered_map< RocBankLabel_t, std::vector< UInt_t > > fOffsetList
 
RocBankLabel_t fThisRocBankLabel
 
UInt_t fNumPhysicsEvents
 
UInt_t fStartingPhysicsEvent
 
Bool_t fSingleFile
 
VEventDecoderdecoder
 

Static Protected Attributes

static std::string fDefaultDataDirectory = "/adaq1/data1/apar"
 
static std::string fDefaultDataFileStem = "QwRun_"
 
static std::string fDefaultDataFileExtension = "log"
 

Private Member Functions

void ClearEventData (std::vector< VQwSubsystem * > &subsystems)
 
Bool_t FillSubsystemConfigurationData (std::vector< VQwSubsystem * > &subsystems)
 
Bool_t FillSubsystemData (std::vector< VQwSubsystem * > &subsystems)
 

Private Attributes

Int_t fDataVersionVerify = 0
 
Int_t fDataVersion
 

Detailed Description

Event buffer management for reading and processing CODA data.

Manages the reading of CODA event data files, including support for segmented files, run lists, and event stream processing. Handles event decoding via pluggable decoder classes and provides iteration over events and runs.

Definition at line 47 of file QwEventBuffer.h.

Member Typedef Documentation

◆ RocBankLabel_t

Methods and data members needed to find marker words.

Definition at line 276 of file QwEventBuffer.h.

Member Enumeration Documentation

◆ CodaStreamMode

Enumerator
fEvStreamNull 
fEvStreamFile 
fEvStreamET 

Definition at line 255 of file QwEventBuffer.h.

Constructor & Destructor Documentation

◆ QwEventBuffer()

QwEventBuffer::QwEventBuffer ( )

Default constructor.

Definition at line 56 of file QwEventBuffer.cc.

57 : fRunListFile(nullptr),
58 fEventListFile(nullptr),
63 fEvStream(NULL),
64 fCurrentRun(-1),
66 fSingleFile(kFALSE),
67 decoder(NULL)
68{
69 // Set up the signal handler.
70 globalEXIT=0;
71 signal(SIGINT, sigint_handler);// ctrl+c
72 signal(SIGTERM, sigint_handler);// kill in shell // 15
73 // signal(SIGTSTP, sigint_handler);// ctrl+z // 20
75 signal(SIGUSR1, sigusr_handler);
76
77 fCleanParameter[0] = 0.0;
78 fCleanParameter[1] = 0.0;
79 fCleanParameter[2] = 0.0;
80}
void sigint_handler(int sig)
Bool_t onlineRestart
void sigusr_handler(int sig)
Bool_t globalEXIT
TString fDataDirectory
static std::string fDefaultDataDirectory
VEventDecoder * decoder
std::unique_ptr< QwParameterFile > fEventListFile
Double_t fCleanParameter[3]
Scan data/clean data from the green monster.
TString fDataFileExtension
static std::string fDefaultDataFileExtension
UInt_t fNumPhysicsEvents
static std::string fDefaultDataFileStem
THaCodaData * fEvStream
std::unique_ptr< QwParameterFile > fRunListFile
TString fDataFileStem

References decoder, fCleanParameter, fCurrentRun, fDataDirectory, fDataFileExtension, fDataFileStem, fDefaultDataDirectory, fDefaultDataFileExtension, fDefaultDataFileStem, fEventListFile, fEvStream, fEvStreamMode, fEvStreamNull, fNumPhysicsEvents, fRunListFile, fSingleFile, globalEXIT, onlineRestart, sigint_handler(), and sigusr_handler().

+ Here is the call graph for this function:

◆ ~QwEventBuffer()

virtual QwEventBuffer::~QwEventBuffer ( )
inlinevirtual

Definition at line 71 of file QwEventBuffer.h.

71 {
72 // Delete event stream
73 if (fEvStream != NULL) {
74 delete fEvStream;
75 fEvStream = NULL;
76 }
77 // Delete Decoder
78 if(decoder != NULL) {
79 delete decoder;
80 decoder = NULL;
81 }
82 };

References decoder, and fEvStream.

Member Function Documentation

◆ AreRunletsSplit()

Bool_t QwEventBuffer::AreRunletsSplit ( ) const
inline

Return true if file segments are being separated for.

Definition at line 93 of file QwEventBuffer.h.

93 {
95 };
Bool_t fChainDataFiles
Bool_t fRunIsSegmented

References fChainDataFiles, and fRunIsSegmented.

◆ CheckForMarkerWords()

std::size_t QwEventBuffer::CheckForMarkerWords ( QwSubsystemArray & subsystems)
protected

Definition at line 1313 of file QwEventBuffer.cc.

1314{
1315 QwDebug << "QwEventBuffer::GetMarkerWordList: start function" <<QwLog::endl;
1316 fThisRocBankLabel = decoder->GetROC();
1318 fThisRocBankLabel += decoder->GetSubbankTag();
1319 if (fMarkerList.count(fThisRocBankLabel)==0){
1320 std::vector<UInt_t> tmpvec;
1321 subsystems.GetMarkerWordList(decoder->GetROC(), decoder->GetSubbankTag(), tmpvec);
1322 fMarkerList.emplace(fThisRocBankLabel, tmpvec);
1323 fOffsetList.emplace(fThisRocBankLabel, std::vector<UInt_t>(tmpvec.size(),0));
1324 }
1325 QwDebug << "QwEventBuffer::GetMarkerWordList: fMarkerList.count(fThisRocBankLabel)=="
1327 << " fMarkerList.at(fThisRocBankLabel).size()=="
1328 << fMarkerList.at(fThisRocBankLabel).size()
1329 << QwLog::endl;
1330 return fMarkerList.at(fThisRocBankLabel).size();
1331}
#define QwDebug
Predefined log drain for debugging output.
Definition QwLog.h:59
std::unordered_map< RocBankLabel_t, std::vector< UInt_t > > fMarkerList
std::unordered_map< RocBankLabel_t, std::vector< UInt_t > > fOffsetList
RocBankLabel_t fThisRocBankLabel
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
void GetMarkerWordList(const ROCID_t roc_id, const BankID_t bank_id, std::vector< UInt_t > &marker) const

References decoder, QwLog::endl(), fMarkerList, fOffsetList, fThisRocBankLabel, QwSubsystemArray::GetMarkerWordList(), and QwDebug.

Referenced by FillSubsystemData().

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

◆ ClearEventData()

void QwEventBuffer::ClearEventData ( std::vector< VQwSubsystem * > & subsystems)
private

◆ CloseDataFile()

Int_t QwEventBuffer::CloseDataFile ( )

Definition at line 1275 of file QwEventBuffer.cc.

1276{
1277 Int_t status = kFileHandleNotConfigured;
1279 status = fEvStream->codaClose();
1280 }
1281 return status;
1282}
static const Int_t kFileHandleNotConfigured

References fEvStream, fEvStreamFile, fEvStreamMode, and kFileHandleNotConfigured.

Referenced by CloseStream(), CloseThisSegment(), and main().

+ Here is the caller graph for this function:

◆ CloseETStream()

Int_t QwEventBuffer::CloseETStream ( )

Definition at line 1303 of file QwEventBuffer.cc.

1304{
1305 Int_t status = kFileHandleNotConfigured;
1307 status = fEvStream->codaClose();
1308 }
1309 return status;
1310}

References fEvStream, fEvStreamET, fEvStreamMode, and kFileHandleNotConfigured.

Referenced by CloseStream().

+ Here is the caller graph for this function:

◆ CloseStream()

Int_t QwEventBuffer::CloseStream ( )

Closes a currently open event stream.

Definition at line 428 of file QwEventBuffer.cc.

429{
430 // Stop the timers.
431 fRunTimer.Stop();
432 fStopwatch.Stop();
433 QwWarning << "Starting CloseStream."
434 << QwLog::endl;
435 Int_t status = kFileHandleNotConfigured;
438 // The run is segmented and we are not chaining the
439 // segments together in the event loop, so close
440 // the current segment.
441 status = CloseThisSegment();
442 } else if (fEvStreamMode==fEvStreamFile) {
443 status = CloseDataFile();
444 } else if (fEvStreamMode==fEvStreamFile){
445 status = CloseETStream();
446 }
447 return status;
448}
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
Int_t CloseThisSegment()
TStopwatch fStopwatch
Timer used for internal timing.
TStopwatch fRunTimer
Timer used for runlet processing loop.

References CloseDataFile(), CloseETStream(), CloseThisSegment(), QwLog::endl(), fChainDataFiles, fEvStreamFile, fEvStreamMode, fRunIsSegmented, fRunTimer, fStopwatch, kFileHandleNotConfigured, and QwWarning.

Referenced by main().

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

◆ CloseThisSegment()

Int_t QwEventBuffer::CloseThisSegment ( )
protected

Definition at line 1135 of file QwEventBuffer.cc.

1136{
1137 Int_t status = kFileHandleNotConfigured;
1138 Int_t last_runsegment;
1139 if (fRunIsSegmented){
1140 last_runsegment = *fRunSegmentIterator;
1142 if (fRunSegmentIterator <= fRunSegments.end()){
1143 QwMessage << "Closing run segment " << last_runsegment <<"."
1144 << QwLog::endl;
1145 status = CloseDataFile();
1146 }
1147 } else {
1148 // Don't try to close a nonsegmented file; we will explicitly
1149 // use CloseDataFile() later.
1150 }
1151 return status;
1152}
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
std::vector< Int_t >::iterator fRunSegmentIterator
std::vector< Int_t > fRunSegments

References CloseDataFile(), QwLog::endl(), fRunIsSegmented, fRunSegmentIterator, fRunSegments, kFileHandleNotConfigured, and QwMessage.

Referenced by CloseStream(), and GetFileEvent().

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

◆ DataFile()

const TString & QwEventBuffer::DataFile ( const UInt_t run,
const Short_t seg = -1 )
protected

Definition at line 1016 of file QwEventBuffer.cc.

1017{
1018 if(!fSingleFile){
1019 TString basename = fDataFileStem + Form("%u.",run) + fDataFileExtension;
1020 if(seg == -1){
1021 fDataFile = fDataDirectory + basename;
1022 } else {
1023 fDataFile = fDataDirectory + basename + Form(".%d",seg);
1024 }
1025 }
1026 return fDataFile;
1027}

References fDataDirectory, fDataFile, fDataFileExtension, fDataFileStem, and fSingleFile.

Referenced by OpenDataFile(), and OpenNextSegment().

+ Here is the caller graph for this function:

◆ DataFileIsSegmented()

Bool_t QwEventBuffer::DataFileIsSegmented ( )
protected

Definition at line 1030 of file QwEventBuffer.cc.

1031{
1032 glob_t globbuf;
1033
1034 TString searchpath;
1035 TString scanvalue;
1036 Int_t local_segment;
1037
1038 std::vector<Int_t> tmp_segments;
1039 std::vector<Int_t> local_index;
1040
1041 /* Clear and set up the fRunSegments vector. */
1042 tmp_segments.clear();
1043 fRunSegments.clear();
1044 fRunSegments.resize(0);
1045 fRunIsSegmented = kFALSE;
1046
1047 searchpath = fDataFile;
1048 glob(searchpath.Data(), GLOB_ERR, NULL, &globbuf);
1049
1050 if(fSingleFile){
1051
1052 fRunIsSegmented = kFALSE;
1053
1054 } else if (globbuf.gl_pathc == 1){
1055 /* The base file name exists. *
1056 * Do not look for file segments. */
1057 fRunIsSegmented = kFALSE;
1058
1059 } else {
1060 /* The base file name does not exist. *
1061 * Look for file segments. */
1062 QwWarning << "File " << fDataFile << " does not exist!\n"
1063 << " Trying to find run segments for run "
1064 << fCurrentRun << "... ";
1065
1066 searchpath.Append(".[0-9]*");
1067 glob(searchpath.Data(), GLOB_ERR, NULL, &globbuf);
1068
1069 if (globbuf.gl_pathc == 0){
1070 /* There are no file segments and no base file *
1071 * Produce and error message and exit. */
1072 QwError << "\n There are no file segments either!!" << QwLog::endl;
1073
1074 // This could mean a single gzipped file!
1075 fRunIsSegmented = kFALSE;
1076
1077 } else {
1078 /* There are file segments. *
1079 * Determine the segment numbers and fill fRunSegments *
1080 * to indicate the existing file segments. */
1081
1082 QwMessage << "OK" << QwLog::endl;
1083 scanvalue = fDataFile + ".%d";
1084
1085 /* Get the list of segment numbers in file listing *
1086 * order. */
1087 for (size_t iloop=0;iloop<globbuf.gl_pathc;++iloop){
1088 /* Extract the segment numbers from the file name. */
1089 sscanf(globbuf.gl_pathv[iloop], scanvalue.Data(), &local_segment);
1090 tmp_segments.push_back(local_segment);
1091 }
1092 local_index.resize(tmp_segments.size(),0);
1093 /* Get the list of segments sorted numerically in *
1094 * increasing order. */
1095 TMath::Sort(static_cast<int>(tmp_segments.size()),&(tmp_segments[0]),&(local_index[0]),
1096 kFALSE);
1097 /* Put the segments into numerical order in fRunSegments. Add *
1098 * only those segments requested (though always add segment 0). */
1099 QwMessage << " Found the segment(s): ";
1100 size_t printed = 0;
1101 for (size_t iloop=0; iloop<tmp_segments.size(); ++iloop){
1102 local_segment = tmp_segments[local_index[iloop]];
1103 if (printed++) QwMessage << ", ";
1104 QwMessage << local_segment ;
1105 if (local_segment == 0 ||
1106 ( fSegmentRange.first <= local_segment &&
1107 local_segment <= fSegmentRange.second ) ) {
1108 fRunSegments.push_back(local_segment);
1109 } else {
1110 QwMessage << " (skipped)" ;
1111 }
1112 }
1113 QwMessage << "." << QwLog::endl;
1115
1116 fRunIsSegmented = kTRUE;
1117
1118 /* If the first requested segment hasn't been found,
1119 forget everything. */
1120 if ( local_segment < fSegmentRange.first ) {
1121 QwError << "First requested run segment "
1122 << fSegmentRange.first << " not found.\n";
1123 fRunSegments.pop_back();
1125 fRunIsSegmented = kTRUE; // well, it is true.
1126 }
1127 }
1128 }
1129 globfree(&globbuf);
1130 return fRunIsSegmented;
1131}
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
std::pair< Int_t, Int_t > fSegmentRange

References QwLog::endl(), fCurrentRun, fDataFile, fRunIsSegmented, fRunSegmentIterator, fRunSegments, fSegmentRange, fSingleFile, QwError, QwMessage, and QwWarning.

Referenced by OpenDataFile().

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

◆ DefineOptions()

void QwEventBuffer::DefineOptions ( QwOptions & options)
static

Defines configuration options for QwEventBuffer class using QwOptions functionality.

Parameters
optionsOptions object

Definition at line 88 of file QwEventBuffer.cc.

89{
90 // Define the execution options
91 options.AddDefaultOptions()
92 ("online", po::value<bool>()->default_bool_value(false),
93 "use online data stream");
94 options.AddDefaultOptions()
95 ("online.RunNumber", po::value<int>()->default_bool_value(0),
96 "Effective run number to be used by online system to find the parameter files");
97 options.AddDefaultOptions()
98 ("run,r", po::value<string>()->default_value("0:0"),
99 "run range in format #[:#]");
100 options.AddDefaultOptions()
101 ("data,d", po::value<string>()->default_value(fDefaultDataDirectory),
102 "data directory, also $QW_DATA");
103 options.AddDefaultOptions()
104 ("runlist", po::value<string>()->default_value(""),
105 "run list file name");
106 options.AddDefaultOptions()
107 ("event,e", po::value<string>()->default_value("0:"),
108 "event range in format #[:#]");
109 options.AddDefaultOptions()
110 ("segment,s", po::value<string>()->default_value("0:"),
111 "run segment range in format #[:#]");
112 options.AddDefaultOptions()
113 ("chainfiles", po::value<bool>()->default_bool_value(false),
114 "chain file segments together, do not analyze them separately");
115 options.AddDefaultOptions()
116 ("codafile-stem", po::value<string>()->default_value(fDefaultDataFileStem),
117 "stem of the input CODA filename");
118 options.AddDefaultOptions()
119 ("codafile-ext", po::value<string>()->default_value(fDefaultDataFileExtension),
120 "extension of the input CODA filename");
121 options.AddOptions()
122 ("directfile", po::value<string>(),
123 "Run over single event file");
124 // Special flag to allow sub-bank IDs less than 31
125 options.AddDefaultOptions()
126 ("allow-low-subbank-ids", po::value<bool>()->default_bool_value(false),
127 "allow the sub-bank ids to be 31 or less, when using this flag, all ROCs must be sub-banked");
128 // Options specific to the ET clients
129 options.AddOptions("ET system options")
130 ("ET.hostname", po::value<string>(),
131 "Name of the ET session's host machine --- Only used in online mode\nDefaults to the environment variable $HOSTNAME");
132 options.AddOptions("ET system options")
133 ("ET.session", po::value<string>(),
134 "ET session name --- Only used in online mode\nDefaults to the environment variable $SESSION");
135 options.AddOptions("ET system options")
136 ("ET.station", po::value<string>(),
137 "ET station name --- Only used in online mode");
138 options.AddOptions("ET system options")
139 ("ET.waitmode", po::value<int>()->default_value(0),
140 "ET system wait mode: 0 is wait-forever, 1 is timeout \"quickly\" --- Only used in online mode");
141 options.AddOptions("ET system options")
142 ("ET.exit-on-end", po::value<bool>()->default_value(false),
143 "Exit the event loop if the end event is found. JAPAN remains open and waits for the next run. --- Only used in online mode");
144 options.AddOptions("CodaVersion")
145 ("coda-version", po::value<int>()->default_value(3),
146 "Sets the Coda Version. Allowed values = {2,3}. \nThis is needed for writing and reading mock data. Mock data needs to be written and read with the same Coda Version.");
147 options.AddOptions("Event rate limiting")
148 ("max-event-rate", po::value<double>()->default_value(0.0),
149 "Maximum event write rate in Hz (0 = disabled, no rate limiting)");
150}
po::options_description_easy_init AddDefaultOptions()
Add a default option.
Definition QwOptions.h:165
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::AddDefaultOptions(), QwOptions::AddOptions(), fDefaultDataDirectory, fDefaultDataFileExtension, and fDefaultDataFileStem.

Referenced by QwOptions::DefineOptions().

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

◆ EncodeEndEvent()

Int_t QwEventBuffer::EncodeEndEvent ( )

Definition at line 774 of file QwEventBuffer.cc.

775{
776 int buffer[5];
777 int localtime = (int)time(0);
778 int eventcount = 0;
779 decoder->EncodeEndEventHeader(buffer, eventcount, localtime);
780 return WriteEvent(buffer);
781}
Int_t WriteEvent(int *buffer)

References decoder, and WriteEvent().

Referenced by main().

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

◆ EncodeGoEvent()

Int_t QwEventBuffer::EncodeGoEvent ( )

Definition at line 758 of file QwEventBuffer.cc.

759{
760 int buffer[5];
761 int localtime = (int)time(0);
762 int eventcount = 0;
763 decoder->EncodeGoEventHeader(buffer, eventcount, localtime);
764 return WriteEvent(buffer);
765}

References decoder, and WriteEvent().

Referenced by main().

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

◆ EncodePauseEvent()

Int_t QwEventBuffer::EncodePauseEvent ( )

Definition at line 766 of file QwEventBuffer.cc.

767{
768 int buffer[5];
769 int localtime = (int)time(0);
770 int eventcount = 0;
771 decoder->EncodePauseEventHeader(buffer, eventcount, localtime);
772 return WriteEvent(buffer);
773}

References decoder, and WriteEvent().

+ Here is the call graph for this function:

◆ EncodePrestartEvent()

Int_t QwEventBuffer::EncodePrestartEvent ( int runnumber,
int runtype = 0 )

Definition at line 751 of file QwEventBuffer.cc.

752{
753 int buffer[5];
754 int localtime = (int)time(0);
755 decoder->EncodePrestartEventHeader(buffer, runnumber, runtype, localtime);
756 return WriteEvent(buffer);
757}

References decoder, and WriteEvent().

Referenced by main().

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

◆ EncodeSubsystemData()

Int_t QwEventBuffer::EncodeSubsystemData ( QwSubsystemArray & subsystems)

Definition at line 691 of file QwEventBuffer.cc.

692{
693 // Encode the data in the elements of the subsystem array
694 std::vector<UInt_t> buffer;
695 std::vector<ROCID_t> ROCList;
696 subsystems.EncodeEventData(buffer);
697 subsystems.GetROCIDList(ROCList);
698 // Add CODA event header
699 std::vector<UInt_t> header = decoder->EncodePHYSEventHeader(ROCList);
700
701 // Copy the encoded event buffer into an array of integers,
702 // as expected by the CODA routines.
703 // Size of the event buffer in long words
704 int* codabuffer = new int[header.size() + buffer.size() + 1];
705 // First entry contains the buffer size
706 int k = 0;
707 codabuffer[k++] = header.size() + buffer.size();
708 for (size_t i = 0; i < header.size(); i++)
709 codabuffer[k++] = header.at(i);
710 for (size_t i = 0; i < buffer.size(); i++)
711 codabuffer[k++] = buffer.at(i);
712
713 // Now write the buffer to the stream
714 Int_t status = WriteEvent(codabuffer);
715 // delete the buffer
716 delete[] codabuffer;
717 // and report success or fail
718 return status;
719}
void EncodeEventData(std::vector< UInt_t > &buffer)
Encode the data in this event.
void GetROCIDList(std::vector< ROCID_t > &list)
Get the ROCID list.

References decoder, QwSubsystemArray::EncodeEventData(), QwSubsystemArray::GetROCIDList(), and WriteEvent().

Referenced by main().

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

◆ FillEPICSData()

Bool_t QwEventBuffer::FillEPICSData ( QwEPICSEvent & epics)

Definition at line 942 of file QwEventBuffer.cc.

943{
944 // QwVerbose << "QwEventBuffer::FillEPICSData: "
945// << Form("Length: %d; Tag: 0x%x; Bank ID num: 0x%x; ",
946// fEvtLength, fEvtTag, fIDBankNum)
947// << Form("Evt type: 0x%x; Evt number %d; Evt Class 0x%.8x; ",
948// fEvtType(), fEvtNumber, fEvtClass)
949// << Form("Status Summary: 0x%.8x; Words so far %d",
950// fStatSum, fWordsSoFar)
951// << QwLog::endl;
952
953
954 ///
955 Bool_t okay = kTRUE;
956 if (! IsEPICSEvent()){
957 okay = kFALSE;
958 return okay;
959 }
960 QwVerbose << "QwEventBuffer::FillEPICSData: "
961 << QwLog::endl;
962 // Loop through the data buffer in this event.
963 UInt_t *localbuff = (UInt_t*)(fEvStream->getEvBuffer());
964 if (decoder->GetBankDataType()==0x10){
965 while ((okay = decoder->DecodeSubbankHeader(&localbuff[decoder->GetWordsSoFar()]))){
966 // If this bank has further subbanks, restart the loop.
967 if (decoder->GetSubbankType() == 0x10) continue;
968 // If this bank only contains the word 'NULL' then skip
969 // this bank.
970 if (decoder->GetFragLength()==1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord){
971 decoder->AddWordsSoFarAndFragLength();
972 continue;
973 }
974
975 if (decoder->GetSubbankType() == 0x3){
976 // This is an ASCII string bank. Try to decode it and
977 // pass it to the EPICS class.
978 char* tmpchar = (Char_t*)&localbuff[decoder->GetWordsSoFar()];
979
980 epics.ExtractEPICSValues(string(tmpchar), GetEventNumber());
981 QwVerbose << "test for GetEventNumber =" << GetEventNumber() << QwLog::endl;// always zero, wrong.
982
983 }
984
985
986 decoder->AddWordsSoFarAndFragLength();
987
988// QwDebug << "QwEventBuffer::FillEPICSData: "
989// << "Ending loop: fWordsSoFar=="<<GetWordsSoFar()
990// <<QwLog::endl;
991// QwMessage<<"\nQwEventBuffer::FillEPICSData: fWordsSoFar = "<<GetWordsSoFar()<<QwLog::endl;
992
993
994 }
995 } else {
996 // Single bank in the event, use event headers.
997 if (decoder->GetBankDataType() == 0x3){
998 // This is an ASCII string bank. Try to decode it and
999 // pass it to the EPICS class.
1000 Char_t* tmpchar = (Char_t*)&localbuff[decoder->GetWordsSoFar()];
1001
1002 QwError << tmpchar << QwLog::endl;
1003
1004 epics.ExtractEPICSValues(string(tmpchar), GetEventNumber());
1005
1006 }
1007
1008 }
1009
1010 //std::cout<<"\nEpics data coming!! "<<GetWordsSoFar()<<std::endl;
1011 QwVerbose << "QwEventBuffer::FillEPICSData: End of routine"
1012 << QwLog::endl;
1013 return okay;
1014}
#define QwVerbose
Predefined log drain for verbose messages.
Definition QwLog.h:54
void ExtractEPICSValues(const string &data, int event)
Int_t GetEventNumber()
Bool_t IsEPICSEvent()
static const UInt_t kNullDataWord

References decoder, QwLog::endl(), QwEPICSEvent::ExtractEPICSValues(), fEvStream, GetEventNumber(), IsEPICSEvent(), kNullDataWord, QwError, and QwVerbose.

Referenced by main().

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

◆ FillObjectWithEventData()

template<class T>
Bool_t QwEventBuffer::FillObjectWithEventData ( T & t)

Template to fill any object with data from a CODA event.

The classes for which this template can be specialized must have the following three methods defined:

  • Bool_t T::CanUseThisEventType(const UInt_t event_type);
  • Bool_t T::ClearEventData(const UInt_t event_type);
  • Int_t T::ProcessBuffer(const UInt_t event_type, const ROCID_t roc_id, const BankID_t bank_id, const UInt_t banktype, UInt_t* buffer, UInt_t num_words);

Definition at line 295 of file QwEventBuffer.h.

295 {
296 /// Template to fill any object with data from a CODA event.
297 ///
298 /// The classes for which this template can be specialized
299 /// must have the following three methods defined:
300 ///
301 /// - Bool_t T::CanUseThisEventType(const UInt_t event_type);
302 /// - Bool_t T::ClearEventData(const UInt_t event_type);
303 /// - Int_t T::ProcessBuffer(const UInt_t event_type,
304 /// const ROCID_t roc_id, const BankID_t bank_id,
305 /// const UInt_t banktype, UInt_t* buffer, UInt_t num_words);
306 ///
307 Bool_t okay = kFALSE;
308 UInt_t *localbuff = (UInt_t*)(fEvStream->getEvBuffer());
309
310 if (decoder->GetFragLength()==1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord){
311 decoder->AddWordsSoFarAndFragLength();
312 } else if (object.CanUseThisEventType(decoder->GetEvtType())){
313 // Clear the old event information from the object
314 object.ClearEventData(decoder->GetEvtType());
315 // Loop through the data buffer in this event.
316 if (decoder->GetBankDataType() == 0x10){
317 // This bank is subbanked; loop through subbanks
318 while ((okay = decoder->DecodeSubbankHeader(&localbuff[decoder->GetWordsSoFar()]))){
319 // If this bank has further subbanks, restart the loop.
320 if (decoder->GetSubbankType() == 0x10) continue;
321 // If this bank only contains the word 'NULL' then skip
322 // this bank.
323 if (decoder->GetFragLength()==1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord){
324 decoder->AddWordsSoFarAndFragLength();
325 continue;
326 }
327 object.ProcessBuffer(decoder->GetEvtType(), decoder->GetROC(), decoder->GetSubbankTag(), decoder->GetSubbankType(),
328 &localbuff[decoder->GetWordsSoFar()],
329 decoder->GetFragLength());
330 decoder->AddWordsSoFarAndFragLength();
331 }
332 } else {
333 // This is a single bank of some type
334 object.ProcessBuffer(decoder->GetEvtType(), 0, decoder->GetBankDataType(),
335 &localbuff[decoder->GetWordsSoFar()],
336 decoder->GetEvtLength());
337 }
338 }
339 return okay;
340}

References decoder, fEvStream, and kNullDataWord.

◆ FillSubsystemConfigurationData() [1/2]

Bool_t QwEventBuffer::FillSubsystemConfigurationData ( QwSubsystemArray & subsystems)

Passes the data for the configuration events into each subsystem object. Each object is responsible for recognizing the configuration data which it ought to decode. NOTE TO DAQ PROGRAMMERS: The configuration event for a ROC must have the same subbank structure as the physics events for that ROC.

Definition at line 787 of file QwEventBuffer.cc.

788{
789 /// Passes the data for the configuration events into each subsystem
790 /// object. Each object is responsible for recognizing the configuration
791 /// data which it ought to decode.
792 /// NOTE TO DAQ PROGRAMMERS:
793 /// The configuration event for a ROC must have the same
794 /// subbank structure as the physics events for that ROC.
795 Bool_t okay = kTRUE;
796 UInt_t rocnum = decoder->GetEvtType() - 0x90;
797 QwMessage << "QwEventBuffer::FillSubsystemConfigurationData: "
798 << "Found configuration event for ROC"
799 << rocnum
800 << QwLog::endl;
801 decoder->PrintDecoderInfo(QwMessage);
802 // Loop through the data buffer in this event.
803 UInt_t *localbuff = (UInt_t*)(fEvStream->getEvBuffer());
804 decoder->DecodeEventIDBank(localbuff);
805 while ((okay = decoder->DecodeSubbankHeader(&localbuff[decoder->GetWordsSoFar()]))){
806 // If this bank has further subbanks, restart the loop.
807 if (decoder->GetSubbankType() == 0x10) {
808 QwMessage << "This bank has further subbanks, restart the loop" << QwLog::endl;
809 continue;
810 }
811 // If this bank only contains the word 'NULL' then skip
812 // this bank.
813 if (decoder->GetFragLength()==1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord){
814 decoder->AddWordsSoFarAndFragLength();
815 QwMessage << "Skip this bank" << QwLog::endl;
816 continue;
817 }
818
819 // Subsystems may be configured to accept data in formats
820 // other than 32 bit integer (banktype==1), but the
821 // bank type is not provided. Subsystems must be able
822 // to process their data knowing only the ROC and bank tags.
823 //
824 // After trying the data in each subsystem, bump the
825 // fWordsSoFar to move to the next bank.
826
827 subsystems.ProcessConfigurationBuffer(rocnum, decoder->GetSubbankTag(),
828 &localbuff[decoder->GetWordsSoFar()],
829 decoder->GetFragLength());
830 decoder->AddWordsSoFarAndFragLength();
831 QwDebug << "QwEventBuffer::FillSubsystemConfigurationData: "
832 << "Ending loop: fWordsSoFar=="<<decoder->GetWordsSoFar()
833 <<QwLog::endl;
834 }
835
836 return okay;
837}
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for configuration events.

References decoder, QwLog::endl(), fEvStream, kNullDataWord, QwSubsystemArray::ProcessConfigurationBuffer(), QwDebug, and QwMessage.

Referenced by main().

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

◆ FillSubsystemConfigurationData() [2/2]

Bool_t QwEventBuffer::FillSubsystemConfigurationData ( std::vector< VQwSubsystem * > & subsystems)
private

◆ FillSubsystemData() [1/2]

Bool_t QwEventBuffer::FillSubsystemData ( QwSubsystemArray & subsystems)

Definition at line 839 of file QwEventBuffer.cc.

840{
841 // Initialize local flag
842 Bool_t okay = kTRUE;
843
844 // Reload the data buffer and decode the header again, this allows
845 // multiple calls to this function for different subsystem arrays.
846 UInt_t *localbuff = (UInt_t*)(fEvStream->getEvBuffer());
847
848 decoder->DecodeEventIDBank(localbuff);
849
850 // Clear the old event information from the subsystems.
851 subsystems.ClearEventData();
852
853 // Pass CODA run, segment, event number and type to the subsystem array.
854 subsystems.SetCodaRunNumber(fCurrentRun);
856 subsystems.SetCodaEventNumber(decoder->GetEvtNumber());
857 subsystems.SetCodaEventType(decoder->GetEvtType());
858
859 // If this event type is masked for the subsystem array, return right away
860 if (((0x1 << (decoder->GetEvtType() - 1)) & subsystems.GetEventTypeMask()) == 0) {
861 return kTRUE;
862 }
863
864 UInt_t offset;
865
866 // Loop through the data buffer in this event.
867 while ((okay = decoder->DecodeSubbankHeader(&localbuff[decoder->GetWordsSoFar()]))){
868
869 // If this bank has further subbanks, restart the loop.
870 if (decoder->GetSubbankType() == 0x10) continue;
871
872 // If this bank only contains the word 'NULL' then skip
873 // this bank.
874 if (decoder->GetFragLength() == 1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord) {
875 decoder->AddWordsSoFarAndFragLength();
876 continue;
877 }
878
879 // if (GetSubbankType() == 0x85) {
880 // std::cout << "ProcessEventBuffer: , SubbankTag= "<< GetSubbankTag()<<" FragLength="<<GetFragLength() <<std::endl;
881 // }
882
883// QwDebug << "QwEventBuffer::FillSubsystemData: "
884// << "Beginning loop: fWordsSoFar=="<<GetWordsSoFar()
885// <<QwLog::endl;
886
887 // Loop through the subsystems and try to store the data
888 // from this bank in each subsystem.
889 //
890 // Subsystems may be configured to accept data in formats
891 // other than 32 bit integer (banktype==1), but the
892 // bank type is not provided. Subsystems must be able
893 // to process their data knowing only the ROC and bank tags.
894 //
895 // After trying the data in each subsystem, bump the
896 // fWordsSoFar to move to the next bank.
897
898 // TODO:
899 // What is special about this subbank?
900 if( decoder->GetROC() == 0 && decoder->GetSubbankTag()==0x6101) {
901 //std::cout << "ProcessEventBuffer: ROC="<<GetROC()<<", SubbankTag="<< GetSubbankTag()<<", FragLength="<<GetFragLength() <<std::endl;
902 fCleanParameter[0]=localbuff[decoder->GetWordsSoFar()+decoder->GetFragLength()-4];//clean data
903 fCleanParameter[1]=localbuff[decoder->GetWordsSoFar()+decoder->GetFragLength()-3];//scan data 1
904 fCleanParameter[2]=localbuff[decoder->GetWordsSoFar()+decoder->GetFragLength()-2];//scan data 2
905 //std::cout << "ProcessEventBuffer: ROC="<<GetROC()<<", SubbankTag="<< GetSubbankTag()
906 // <<", FragLength="<<GetFragLength() << " " <<fCleanParameter[0]<< " " <<fCleanParameter[1]<< " " <<fCleanParameter[2]<<std::endl;
907
908 }
909
911
912 std::size_t nmarkers = CheckForMarkerWords(subsystems);
913 if (nmarkers>0) {
914 // There are markerwords for this ROC/Bank
915 for (size_t i=0; i<nmarkers; i++){
916 offset = FindMarkerWord(i,&localbuff[decoder->GetWordsSoFar()],decoder->GetFragLength());
917 BankID_t tmpbank = GetMarkerWord(i);
918 tmpbank = ((tmpbank)<<32) + decoder->GetSubbankTag();
919 offset++; // Skip the marker word
920 subsystems.ProcessEvBuffer(decoder->GetEvtType(), decoder->GetROC(), tmpbank,
921 &localbuff[decoder->GetWordsSoFar()+offset],
922 decoder->GetFragLength()-offset);
923 }
924 } else {
925 QwDebug << "QwEventBuffer::FillSubsystemData: "
926 << "fROC=="<<decoder->GetROC() << ", GetSubbankTag()==" << decoder->GetSubbankTag()
927 << QwLog::endl;
928 subsystems.ProcessEvBuffer(decoder->GetEvtType(), decoder->GetROC(), decoder->GetSubbankTag(),
929 &localbuff[decoder->GetWordsSoFar()],
930 decoder->GetFragLength());
931 }
932 decoder->AddWordsSoFarAndFragLength();
933// QwDebug << "QwEventBuffer::FillSubsystemData: "
934// << "Ending loop: fWordsSoFar=="<<GetWordsSoFar()
935// <<QwLog::endl;
936 }
937 return okay;
938}
ULong64_t BankID_t
Definition QwTypes.h:21
UInt_t FindMarkerWord(UInt_t markerID, UInt_t *buffer, UInt_t num_words)
std::size_t CheckForMarkerWords(QwSubsystemArray &subsystems)
UInt_t GetMarkerWord(UInt_t markerID)
void SetCodaRunNumber(UInt_t runnum)
Set the internal record of the CODA run number.
void SetCleanParameters(Double_t cleanparameter[3])
Set the internal record of the CODA event number.
UInt_t GetEventTypeMask() const
Get event type mask.
void SetCodaSegmentNumber(UInt_t segnum)
Set the internal record of the CODA segment number.
Int_t ProcessEvBuffer(const UInt_t event_type, const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for events.
void SetCodaEventNumber(UInt_t evtnum)
Set the internal record of the CODA event number.
void SetCodaEventType(UInt_t evttype)
Set the internal record of the CODA event type.

References CheckForMarkerWords(), QwSubsystemArray::ClearEventData(), decoder, QwLog::endl(), fCleanParameter, fCurrentRun, fEvStream, FindMarkerWord(), fRunIsSegmented, fRunSegmentIterator, QwSubsystemArray::GetEventTypeMask(), GetMarkerWord(), kNullDataWord, QwSubsystemArray::ProcessEvBuffer(), QwDebug, QwSubsystemArray::SetCleanParameters(), QwSubsystemArray::SetCodaEventNumber(), QwSubsystemArray::SetCodaEventType(), QwSubsystemArray::SetCodaRunNumber(), and QwSubsystemArray::SetCodaSegmentNumber().

Referenced by main().

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

◆ FillSubsystemData() [2/2]

Bool_t QwEventBuffer::FillSubsystemData ( std::vector< VQwSubsystem * > & subsystems)
private

◆ FindMarkerWord()

UInt_t QwEventBuffer::FindMarkerWord ( UInt_t markerID,
UInt_t * buffer,
UInt_t num_words )
protected

Definition at line 1338 of file QwEventBuffer.cc.

1338 {
1339 UInt_t markerpos = fOffsetList.at(fThisRocBankLabel).at(markerindex);
1340 UInt_t markerval = fMarkerList.at(fThisRocBankLabel).at(markerindex);
1341 if (markerpos < num_words && buffer[markerpos] == markerval){
1342 // The marker word is where it was last time
1343 return markerpos;
1344 } else {
1345 for (size_t i=0; i<num_words; i++){
1346 if (buffer[i] == markerval){
1347 fOffsetList.at(fThisRocBankLabel).at(markerindex) = i;
1348 markerpos = i;
1349 break;
1350 }
1351 }
1352 }
1353 return markerpos;
1354}

References fMarkerList, fOffsetList, and fThisRocBankLabel.

Referenced by FillSubsystemData().

+ Here is the caller graph for this function:

◆ GetDataDirectory()

const TString & QwEventBuffer::GetDataDirectory ( ) const
inline

Definition at line 116 of file QwEventBuffer.h.

116{return fDataDirectory;};

References fDataDirectory.

Referenced by main().

+ Here is the caller graph for this function:

◆ GetDataFile()

const TString & QwEventBuffer::GetDataFile ( ) const
inline

Definition at line 115 of file QwEventBuffer.h.

115{return fDataFile;};

References fDataFile.

◆ GetEndSQLTime()

TString QwEventBuffer::GetEndSQLTime ( )

Definition at line 736 of file QwEventBuffer.cc.

737{
738 return decoder->GetEndSQLTime();
739}

References decoder.

Referenced by main().

+ Here is the caller graph for this function:

◆ GetEndUnixTime()

time_t QwEventBuffer::GetEndUnixTime ( )

Definition at line 746 of file QwEventBuffer.cc.

747{
748 return decoder->GetEndUnixTime();
749}

References decoder.

◆ GetEtEvent()

Int_t QwEventBuffer::GetEtEvent ( )
protected

Definition at line 591 of file QwEventBuffer.cc.

591 {
592 Int_t status = CODA_OK;
593 // Do we want to have any loop here to wait for a bad
594 // read to be cleared?
595 status = fEvStream->codaRead();
596 if (status != CODA_OK) {
597 globalEXIT = 1;
598 }
599 return status;
600}

References fEvStream, and globalEXIT.

Referenced by GetEvent().

+ Here is the caller graph for this function:

◆ GetEvent()

Int_t QwEventBuffer::GetEvent ( )

Definition at line 523 of file QwEventBuffer.cc.

524{
525 Int_t status = kFileHandleNotConfigured;
526 ResetFlags();
528 status = GetFileEvent();
529 } else if (fEvStreamMode==fEvStreamET){
530 status = GetEtEvent();
531 }
532 if (status == CODA_OK){
533 // Coda Data was loaded correctly
534 UInt_t* evBuffer = (UInt_t*)fEvStream->getEvBuffer();
535 if(fDataVersionVerify == 0){ // Default = 0 => Undetermined
536 VerifyCodaVersion(evBuffer);
537 }
538 decoder->DecodeEventIDBank(evBuffer);
539 }
540 return status;
541}
void VerifyCodaVersion(const UInt_t *buffer)
Int_t fDataVersionVerify

References decoder, fDataVersionVerify, fEvStream, fEvStreamET, fEvStreamFile, fEvStreamMode, GetEtEvent(), GetFileEvent(), kFileHandleNotConfigured, ResetFlags(), and VerifyCodaVersion().

Referenced by GetNextEvent().

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

◆ GetEventNumber()

Int_t QwEventBuffer::GetEventNumber ( )
inline

Definition at line 133 of file QwEventBuffer.h.

133{ return decoder->GetEvtNumber(); };

References decoder.

Referenced by FillEPICSData(), and main().

+ Here is the caller graph for this function:

◆ GetEventRange()

std::pair< UInt_t, UInt_t > QwEventBuffer::GetEventRange ( ) const
inline

Definition at line 103 of file QwEventBuffer.h.

103 {
104 return fEventRange;
105 };
std::pair< UInt_t, UInt_t > fEventRange

References fEventRange.

◆ GetFileEvent()

Int_t QwEventBuffer::GetFileEvent ( )
protected

Definition at line 573 of file QwEventBuffer.cc.

573 {
574 Int_t status = CODA_OK;
575 // Try to get a new event. If the EOF occurs,
576 // and the run is segmented, try to open the
577 // next segment and read a new event; repeat
578 // if needed.
579 do {
580 status = fEvStream->codaRead();
581 if (fChainDataFiles && status == EOF){
583 // Crash out of the loop if we can't open the
584 // next segment!
585 if (OpenNextSegment()!=CODA_OK) break;
586 }
587 } while (fChainDataFiles && status == EOF);
588 return status;
589}
Int_t OpenNextSegment()

References CloseThisSegment(), fChainDataFiles, fEvStream, and OpenNextSegment().

Referenced by GetEvent().

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

◆ GetMarkerWord()

UInt_t QwEventBuffer::GetMarkerWord ( UInt_t markerID)
protected

Definition at line 1333 of file QwEventBuffer.cc.

1333 {
1334 return fMarkerList.at(fThisRocBankLabel).at(markerID);
1335};

References fMarkerList, and fThisRocBankLabel.

Referenced by FillSubsystemData().

+ Here is the caller graph for this function:

◆ GetNextEvent()

Int_t QwEventBuffer::GetNextEvent ( )

Definition at line 452 of file QwEventBuffer.cc.

453{
454 // This will return for read errors,
455 // non-physics events, and for physics
456 // events that are within the event range.
457 Int_t status = CODA_OK;
458 do {
459 status = GetEvent();
460 if (globalEXIT == 1) {
461 // QUESTION: Should we continue to loop once we've
462 // reached the maximum event, to allow access to
463 // non-physics events?
464 // For now, mock up EOF if we've reached the maximum event.
465 status = EOF;
466 }
467 if (decoder->GetEvtNumber() > fEventRange.second) {
468 do {
469 if (GetNextEventRange()) status = CODA_OK;
470 else status = EOF;
471 } while (decoder->GetEvtNumber() < fEventRange.first);
472 }
473 // While we're in a run segment which was not requested (which
474 // should happen only when reading the zeroth segment for startup
475 // information), pretend that there's an event cut causing us to
476 // ignore events. Read configuration events only from the first
477 // part of the file.
479 fEventRange.first = decoder->GetEvtNumber() + 1;
480 if (decoder->GetEvtNumber() > 1000) status = EOF;
481 }
482 if (fOnline && fExitOnEnd && decoder->GetEndTime()>0){
483 // fExitOnEnd exits the event loop only and does not exit JAPAN.
484 // The root file gets processed and JAPAN immediately waits for the next run.
485 // We considered adding a exit-JAPAN-on-end flag that quits JAPAN but decided
486 // we didn't have a use case for it. If quitting JAPAN is desired, just set:
487 // globalEXIT = 1
488 // -- mrc (01/21/25)
489 QwMessage << "Caught End Event (end time=="<< decoder->GetEndTime()
490 << "). Exit event loop." << QwLog::endl;
491 status = EOF;
492 }
493 if (fOnline && onlineRestart){
495 status = EOF;
496 }
497 } while (status == CODA_OK &&
498 IsPhysicsEvent() &&
499 (decoder->GetEvtNumber() < fEventRange.first
500 || decoder->GetEvtNumber() > fEventRange.second)
501 );
502 if (status == CODA_OK && IsPhysicsEvent()) fNumPhysicsEvents++;
503
504 // Progress meter (this should probably produce less output in production)
505 int nevents = 10000;
506 if (IsPhysicsEvent() && decoder->GetEvtNumber() > 0 && decoder->GetEvtNumber() % nevents == 0) {
507 QwMessage << "Processing event " << decoder->GetEvtNumber() << " ";
508 fStopwatch.Stop();
509 double efficiency = 100.0 * fStopwatch.CpuTime() / fStopwatch.RealTime();
510 QwMessage << "(" << fStopwatch.CpuTime()*1e3/nevents << " ms per event with ";
511 QwMessage << efficiency << "% efficiency)";
512 fStopwatch.Reset();
513 fStopwatch.Start();
515 } else if (decoder->GetEvtNumber() > 0 && decoder->GetEvtNumber() % 100 == 0) {
516 QwVerbose << "Processing event " << decoder->GetEvtNumber() << QwLog::endl;
517 }
518
519 return status;
520}
Int_t GetSegmentNumber() const
Return CODA file segment number.
Bool_t GetNextEventRange()
Read the next requested event range, return true if success.
Bool_t IsPhysicsEvent()

References decoder, QwLog::endl(), fEventRange, fExitOnEnd, fNumPhysicsEvents, fOnline, fRunIsSegmented, fSegmentRange, fStopwatch, GetEvent(), GetNextEventRange(), GetSegmentNumber(), globalEXIT, IsPhysicsEvent(), onlineRestart, QwMessage, and QwVerbose.

Referenced by main().

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

◆ GetNextEventRange()

Bool_t QwEventBuffer::GetNextEventRange ( )

Read the next requested event range, return true if success.

Definition at line 293 of file QwEventBuffer.cc.

293 {
294 // If there is an event list, open the next section
295 if (fEventListFile && !fEventListFile->IsEOF()) {
296 std::string eventrange;
297 // Find next non-whitespace, non-comment, non-empty line, before EOF
298 do {
299 fEventListFile->ReadNextLine(eventrange);
300 fEventListFile->TrimWhitespace();
301 fEventListFile->TrimComment('#');
302 } while (fEventListFile->LineIsEmpty() && !fEventListFile->IsEOF());
303 // If EOF return false; no next event range
304 if (fEventListFile->IsEOF()) return kFALSE;
305 // Parse the event range
307 QwMessage << "Next event range is " << eventrange << QwLog::endl;
308 return kTRUE;
309 }
310 return kFALSE;
311}
static std::pair< int, int > ParseIntRange(const std::string &separatorchars, const std::string &range)
Parse a range of integers as #:# where either can be missing.

References QwLog::endl(), fEventListFile, fEventRange, QwParameterFile::ParseIntRange(), and QwMessage.

Referenced by GetNextEvent(), and GetNextRunRange().

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

◆ GetNextRunNumber()

Bool_t QwEventBuffer::GetNextRunNumber ( )

Get the next run in the active run range, proceed to next range if needed.

Definition at line 335 of file QwEventBuffer.cc.

335 {
336 // First run
337 if (fCurrentRun == -1) {
338 fCurrentRun = fRunRange.first;
339 return kTRUE;
340 // Run is in range
341 } else if (fCurrentRun < fRunRange.second) {
342 fCurrentRun++;
343 return kTRUE;
344 // Run is not in range, get new range
345 } else if (GetNextRunRange()) {
346 fCurrentRun = fRunRange.first;
347 return kTRUE;
348 }
349 return kFALSE;
350}
Bool_t GetNextRunRange()
Read the next requested run range, return true if success.
std::pair< Int_t, Int_t > fRunRange

References fCurrentRun, fRunRange, and GetNextRunRange().

Referenced by OpenNextStream().

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

◆ GetNextRunRange()

Bool_t QwEventBuffer::GetNextRunRange ( )

Read the next requested run range, return true if success.

Definition at line 314 of file QwEventBuffer.cc.

314 {
315 // If there is a run list, open the next section
316 std::string runrange;
317 if (fRunListFile && !fRunListFile->IsEOF() &&
318 (fEventListFile = fRunListFile->ReadNextSection(runrange))) {
319 // Parse the run range
321 QwMessage << "Next run range is " << runrange << QwLog::endl;
322 // If there is no event range for this run range, set to default of 0:MAXINT
323 if (! GetNextEventRange()) {
324 QwWarning << "No valid event range in run list file: "
325 << fEventListFile->GetLine() << ". "
326 << "Assuming the full event range." << QwLog::endl;
328 }
329 return kTRUE;
330 }
331 return kFALSE;
332}

References QwLog::endl(), fEventListFile, fEventRange, fRunListFile, fRunRange, GetNextEventRange(), QwParameterFile::ParseIntRange(), QwMessage, and QwWarning.

Referenced by GetNextRunNumber(), and ProcessOptions().

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

◆ GetPhysicsEventNumber()

Int_t QwEventBuffer::GetPhysicsEventNumber ( )
inline

Definition at line 132 of file QwEventBuffer.h.

132{return fNumPhysicsEvents;};

References fNumPhysicsEvents.

Referenced by main().

+ Here is the caller graph for this function:

◆ GetRunLabel()

TString QwEventBuffer::GetRunLabel ( ) const

Returns a string like <run#> or <run#>.<file#>

Definition at line 352 of file QwEventBuffer.cc.

353{
354 TString runlabel = Form("%d",fCurrentRun);
356 runlabel += Form(".%03d",*fRunSegmentIterator);
357 }
358 return runlabel;
359}

References fChainDataFiles, fCurrentRun, fRunIsSegmented, and fRunSegmentIterator.

Referenced by main().

+ Here is the caller graph for this function:

◆ GetRunNumber()

Int_t QwEventBuffer::GetRunNumber ( ) const
inline

Return CODA file run number.

Definition at line 97 of file QwEventBuffer.h.

97{return fCurrentRun;};

References fCurrentRun.

Referenced by main(), and PrintRunTimes().

+ Here is the caller graph for this function:

◆ GetSegmentNumber()

Int_t QwEventBuffer::GetSegmentNumber ( ) const
inline

Return CODA file segment number.

Definition at line 99 of file QwEventBuffer.h.

99 {
100 return fRunSegments.size() ? *fRunSegmentIterator : 0;
101 };

References fRunSegmentIterator, and fRunSegments.

Referenced by GetNextEvent(), and main().

+ Here is the caller graph for this function:

◆ GetStartSQLTime()

TString QwEventBuffer::GetStartSQLTime ( )

Definition at line 731 of file QwEventBuffer.cc.

732{
733 return decoder->GetStartSQLTime();
734}

References decoder.

Referenced by main().

+ Here is the caller graph for this function:

◆ GetStartUnixTime()

time_t QwEventBuffer::GetStartUnixTime ( )

Definition at line 741 of file QwEventBuffer.cc.

742{
743 return decoder->GetStartUnixTime();
744}

References decoder.

◆ IsEPICSEvent()

Bool_t QwEventBuffer::IsEPICSEvent ( )
inline

Definition at line 151 of file QwEventBuffer.h.

151 {
152 return ( decoder->IsEPICSEvent() ); // Defined in CodaDecoder.h
153 }

References decoder.

Referenced by FillEPICSData(), and main().

+ Here is the caller graph for this function:

◆ IsOnline()

Bool_t QwEventBuffer::IsOnline ( )
inline

Definition at line 145 of file QwEventBuffer.h.

145{return fOnline;};

References fOnline.

Referenced by main(), and main().

+ Here is the caller graph for this function:

◆ IsPhysicsEvent()

Bool_t QwEventBuffer::IsPhysicsEvent ( )
inline

Definition at line 128 of file QwEventBuffer.h.

128 {
129 return ( decoder->IsPhysicsEvent() );
130 };

References decoder.

Referenced by GetNextEvent(), and main().

+ Here is the caller graph for this function:

◆ IsROCConfigurationEvent()

Bool_t QwEventBuffer::IsROCConfigurationEvent ( )
inline

Definition at line 147 of file QwEventBuffer.h.

147 {
148 return ( decoder->IsROCConfigurationEvent() );
149 };

References decoder.

Referenced by main().

+ Here is the caller graph for this function:

◆ OpenDataFile() [1/3]

Int_t QwEventBuffer::OpenDataFile ( const TString filename,
const TString rw = "R" )

Definition at line 1221 of file QwEventBuffer.cc.

1222{
1224 QwDebug << "QwEventBuffer::OpenDataFile: File handle doesn't exist.\n"
1225 << " Try to open a new file handle!"
1226 << QwLog::endl;
1227 fEvStream = new THaCodaFile();
1229 } else if (fEvStreamMode!=fEvStreamFile){
1230 QwError << "QwEventBuffer::OpenDataFile: The stream is not configured as an input\n"
1231 << " file stream! Can't deal with this!\n"
1232 << QwLog::endl;
1233 exit(1);
1234 }
1235 fDataFile = filename;
1236
1237 if (rw.Contains("w",TString::kIgnoreCase)) {
1238 // If we open a file for write access, let's suppose
1239 // we've given the path we want to use.
1240 QwMessage << "Opening data file: " << fDataFile << QwLog::endl;
1241 } else {
1242 // Let's try to find the data file for read access.
1243 glob_t globbuf;
1244 glob(fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1245 if (globbuf.gl_pathc == 0){
1246 // Can't find the file; try in the "fDataDirectory".
1247 fDataFile = fDataDirectory + filename;
1248 glob(fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1249 }
1250 if (globbuf.gl_pathc == 0){
1251 // Can't find the file; try gzipped.
1252 fDataFile = filename + ".gz";
1253 glob(fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1254 }
1255 if (globbuf.gl_pathc == 0){
1256 // Can't find the file; try gzipped in the "fDataDirectory".
1257 fDataFile = fDataDirectory + filename + ".gz";
1258 glob(fDataFile.Data(), GLOB_ERR, NULL, &globbuf);
1259 }
1260 if (globbuf.gl_pathc == 1){
1261 QwMessage << "Opening data file: " << fDataFile << QwLog::endl;
1262 } else {
1263 fDataFile = filename;
1264 QwError << "Unable to find "
1265 << filename.Data() << " or "
1266 << (fDataDirectory + filename).Data() << QwLog::endl;
1267 }
1268 globfree(&globbuf);
1269 }
1270 return fEvStream->codaOpen(fDataFile, rw);
1271}

References QwLog::endl(), fDataDirectory, fDataFile, fEvStream, fEvStreamFile, fEvStreamMode, fEvStreamNull, QwDebug, QwError, and QwMessage.

+ Here is the call graph for this function:

◆ OpenDataFile() [2/3]

Int_t QwEventBuffer::OpenDataFile ( UInt_t current_run,
const TString rw = "R" )

Definition at line 1205 of file QwEventBuffer.cc.

1206{
1207 Int_t status;
1208 fCurrentRun = current_run;
1210 if (DataFileIsSegmented()){
1211 status = OpenNextSegment();
1212 } else {
1213 status = OpenDataFile(DataFile(fCurrentRun),rw);
1214 }
1215 return status;
1216}
const TString & DataFile(const UInt_t run, const Short_t seg)
Bool_t DataFileIsSegmented()
Int_t OpenDataFile(UInt_t current_run, Short_t seg)

References DataFile(), DataFileIsSegmented(), fCurrentRun, OpenDataFile(), and OpenNextSegment().

+ Here is the call graph for this function:

◆ OpenDataFile() [3/3]

Int_t QwEventBuffer::OpenDataFile ( UInt_t current_run,
Short_t seg )

Definition at line 1191 of file QwEventBuffer.cc.

1192{
1193 fCurrentRun = current_run;
1194
1195 fRunSegments.clear();
1196 fRunIsSegmented = kTRUE;
1197
1198 fRunSegments.push_back(seg);
1200 return OpenNextSegment();
1201}

References fCurrentRun, fRunIsSegmented, fRunSegmentIterator, fRunSegments, and OpenNextSegment().

Referenced by main(), OpenDataFile(), OpenNextSegment(), OpenNextStream(), and ReOpenStream().

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

◆ OpenETStream()

Int_t QwEventBuffer::OpenETStream ( TString computer,
TString session,
int mode,
const TString stationname = "" )

Definition at line 1285 of file QwEventBuffer.cc.

1287{
1288 Int_t status = CODA_OK;
1290#ifdef __CODA_ET
1291 if (stationname != ""){
1292 fEvStream = new THaEtClient(computer, session, mode, stationname.Data());
1293 } else {
1294 fEvStream = new THaEtClient(computer, session, mode);
1295 }
1297#endif
1298 }
1299 return status;
1300}

References fEvStream, fEvStreamET, fEvStreamMode, and fEvStreamNull.

Referenced by OpenNextStream(), and ReOpenStream().

+ Here is the caller graph for this function:

◆ OpenNextSegment()

Int_t QwEventBuffer::OpenNextSegment ( )
protected

Definition at line 1156 of file QwEventBuffer.cc.

1157{
1158 Int_t status;
1159 if (! fRunIsSegmented){
1160 /* We are processing a non-segmented run. *
1161 * We should not have entered this routine, but *
1162 * since we are here, don't do anything. */
1163 status = kRunNotSegmented;
1164
1165 } else if (fRunSegments.size()==0){
1166 /* There are actually no file segments located. *
1167 * Return "kNoNextDataFile", but don't print an *
1168 * error message. */
1169 status = kNoNextDataFile;
1170
1171 } else if (fRunSegmentIterator >= fRunSegments.begin() &&
1173 QwMessage << "Trying to open run segment " << *fRunSegmentIterator << QwLog::endl;
1175
1176 } else if (fRunSegmentIterator == fRunSegments.end() ) {
1177 /* We have reached the last run segment. */
1178 QwMessage << "There are no run segments remaining." << QwLog::endl;
1179 status = kNoNextDataFile;
1180
1181 } else {
1182 QwError << "QwEventBuffer::OpenNextSegment(): Unrecognized error" << QwLog::endl;
1183 status = CODA_ERROR;
1184 }
1185 return status;
1186}
static const Int_t kRunNotSegmented
static const Int_t kNoNextDataFile

References DataFile(), QwLog::endl(), fCurrentRun, fRunIsSegmented, fRunSegmentIterator, fRunSegments, kNoNextDataFile, kRunNotSegmented, OpenDataFile(), QwError, and QwMessage.

Referenced by GetFileEvent(), OpenDataFile(), OpenDataFile(), OpenNextStream(), and ReOpenStream().

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

◆ OpenNextStream()

Int_t QwEventBuffer::OpenNextStream ( )

Opens the event stream (file or ET) based on the internal flags.

Definition at line 382 of file QwEventBuffer.cc.

383{
384 Int_t status = CODA_ERROR;
385 if (globalEXIT==1) {
386 // We want to exit, so don't open the next stream.
387 status = CODA_ERROR;
388 } else if (fOnline) {
389 /* Modify the call below for your ET system, if needed.
390 OpenETStream( ET host name , $SESSION , mode)
391 mode=0: wait forever
392 mode=1: timeout quickly
393 */
394 QwMessage << "Try to open the ET station with HOSTNAME=="
395 << fETHostname
396 << ", SESSION==" << fETSession << "."
397 << QwLog::endl;
399
400 } else {
401 // Try to open the next data file for the current run,
402 // but only if we haven't hit the event limit.
403 if (fCurrentRun != -1 && !fChainDataFiles
404 && decoder->GetEvtNumber() <= fEventRange.second) {
405 status = OpenNextSegment();
406 }
407 while (status != CODA_OK && GetNextRunNumber()) {
408 status = OpenDataFile(fCurrentRun);
409 if (status == CODA_ERROR){
410 // The data file can't be opened.
411 // Get ready to process the next run.
412 QwError << "ERROR: Unable to find data files for run "
413 << fCurrentRun << ". Moving to the next run.\n"
414 << QwLog::endl;
415 }
416 }
417
418 }
419 // Grab the starting event counter
421 // Start the timers.
422 fRunTimer.Reset();
423 fRunTimer.Start();
424 fStopwatch.Start();
425 return status;
426}
TString fETHostname
UInt_t fStartingPhysicsEvent
Int_t OpenETStream(TString computer, TString session, int mode, const TString stationname="")
TString fETStationName
Bool_t GetNextRunNumber()
Get the next run in the active run range, proceed to next range if needed.

References decoder, QwLog::endl(), fChainDataFiles, fCurrentRun, fETHostname, fETSession, fETStationName, fETWaitMode, fEventRange, fNumPhysicsEvents, fOnline, fRunTimer, fStartingPhysicsEvent, fStopwatch, GetNextRunNumber(), globalEXIT, OpenDataFile(), OpenETStream(), OpenNextSegment(), QwError, and QwMessage.

Referenced by main().

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

◆ PrintRunTimes()

void QwEventBuffer::PrintRunTimes ( )

Definition at line 276 of file QwEventBuffer.cc.

277{
278 UInt_t nevents = fNumPhysicsEvents - fStartingPhysicsEvent;
279 if (nevents==0) nevents=1;
281 << "Analysis of run " << GetRunNumber() << QwLog::endl
282 << fNumPhysicsEvents << " physics events were processed"<< QwLog::endl
283 << "CPU time used: " << fRunTimer.CpuTime() << " s "
284 << "(" << 1000.0 * fRunTimer.CpuTime() / nevents << " ms per event)" << QwLog::endl
285 << "Real time used: " << fRunTimer.RealTime() << " s "
286 << "(" << 1000.0 * fRunTimer.RealTime() / nevents << " ms per event)" << QwLog::endl
287 << QwLog::endl;
288}
Int_t GetRunNumber() const
Return CODA file run number.

References QwLog::endl(), fNumPhysicsEvents, fRunTimer, fStartingPhysicsEvent, GetRunNumber(), and QwMessage.

Referenced by main().

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

◆ ProcessOptions()

void QwEventBuffer::ProcessOptions ( QwOptions & options)

Sets internal flags based on the QwOptions.

Definition at line 152 of file QwEventBuffer.cc.

153{
154 fOnline = options.GetValue<bool>("online");
155 if (fOnline){
156 fETWaitMode = options.GetValue<int>("ET.waitmode");
157 fExitOnEnd = options.GetValue<bool>("ET.exit-on-end");
158#ifndef __CODA_ET
159 QwError << "Online mode will not work without the CODA libraries!"
160 << QwLog::endl;
161 exit(EXIT_FAILURE);
162#else
163 if (options.HasValue("online.RunNumber")) {
164 fCurrentRun = options.GetValue<int>("online.RunNumber");
165 }
166 if (options.HasValue("ET.station")) {
167 fETStationName = options.GetValue<string>("ET.station");
168 } else {
169 fETStationName = "";
170 }
171 if (options.HasValue("ET.hostname")) {
172 fETHostname = options.GetValue<string>("ET.hostname");
173 } else {
174 fETHostname = getenv("HOSTNAME");
175 }
176 if (options.HasValue("ET.session")) {
177 fETSession = options.GetValue<string>("ET.session");
178 } else {
179 fETSession = getenv("SESSION");
180 }
181 if (fETHostname.Length() == 0 || fETSession.Length() == 0) {
182 TString tmp = "";
183 if (fETHostname == NULL || fETHostname.Length() == 0)
184 tmp += " \"HOSTNAME\"";
185 if (fETSession == NULL || fETSession.Length() == 0){
186 if (tmp.Length() > 0)
187 tmp += " and";
188 tmp += " ET \"SESSION\"";
189 }
190 QwError << "The" << tmp
191 << " variable(s) is(are) not defined in your environment.\n"
192 << " This is needed to run the online analysis."
193 << QwLog::endl;
194 exit(EXIT_FAILURE);
195 }
196#endif
197 }
198 if(options.HasValue("directfile")){
199 fSingleFile = kTRUE;
200 fDataFile = options.GetValue<string>("directfile");
201 } else {
202 fSingleFile = kFALSE;
203 }
204 fDataDirectory = options.GetValue<string>("data");
205 if (fDataDirectory.Length() == 0){
206 QwError << "ERROR: Can't get the data directory in the QwEventBuffer creator."
207 << QwLog::endl;
208 } else if (! fDataDirectory.EndsWith("/")) {
209 fDataDirectory.Append("/");
210 }
211
212 fRunRange = options.GetIntValuePair("run");
213 fEventRange = options.GetIntValuePair("event");
214 fSegmentRange = options.GetIntValuePair("segment");
215 fRunListFileName = options.GetValue<string>("runlist");
216 fChainDataFiles = options.GetValue<bool>("chainfiles");
217 fDataFileStem = options.GetValue<string>("codafile-stem");
218 fDataFileExtension = options.GetValue<string>("codafile-ext");
219 fDataVersion = options.GetValue<int>("coda-version");
220
221 if(fDataVersion == 2){
222 decoder = new Coda2EventDecoder();
223 } else if(fDataVersion == 3) {
224 decoder = new Coda3EventDecoder();
225 } else{
226 QwError << "Invalid Coda Version. Only versions 2 and 3 are supported. "
227 << "Please set using --coda-version 2(3)" << QwLog::endl;
228 exit(EXIT_FAILURE);
229 }
230
231 decoder->SetAllowLowSubbankIDs( options.GetValue<bool>("allow-low-subbank-ids") );
232
233 // Process event rate limiting option
234 fMaxEventRate = options.GetValue<double>("max-event-rate");
235 if (fMaxEventRate > 0.0) {
237 fMinEventInterval = std::chrono::duration<double>(1.0 / fMaxEventRate);
238 QwMessage << "Event rate limiting enabled: " << fMaxEventRate << " Hz "
239 << "(minimum interval: " << (1000.0 / fMaxEventRate) << " ms)"
240 << QwLog::endl;
241 } else {
243 }
244 fLastEventTime = std::chrono::steady_clock::now();
245
246 // Open run list file
247 /* runlist file format example:
248 [5253]
249 234
250 246
251 256
252 345:456
253 567:789
254 [5259]
255 [5260]
256 0:10000
257 [5261:5270]
258 9000:10000
259 - for run 5253 it will analyze three individual events, and two event ranges
260 - for run 5259 it will analyze the entire run (all segments)
261 - for run 5260 it will analyze the first 10000 events
262 - for runs 5261 through 5270 it will analyze the events 9000 through 10000)
263 */
264 if (fRunListFileName.size() > 0) {
265 fRunListFile = std::make_unique<QwParameterFile>(fRunListFileName);
266 fEventListFile = nullptr;
267 if (! GetNextRunRange()) {
268 QwWarning << "No run range found in run list file: " << fRunListFile->GetLine() << QwLog::endl;
269 }
270 } else {
271 fRunListFile = nullptr;
272 fEventListFile = nullptr;
273 }
274}
Bool_t fEventRateLimitEnabled
Double_t fMaxEventRate
std::string fRunListFileName
std::chrono::duration< double > fMinEventInterval
std::chrono::steady_clock::time_point fLastEventTime
std::pair< int, int > GetIntValuePair(const std::string &key)
Get a pair of integer values.
Definition QwOptions.cc:357
T GetValue(const std::string &key)
Get a templated value.
Definition QwOptions.h:236
bool HasValue(const std::string &key)
Has this key been defined.
Definition QwOptions.h:229

References decoder, QwLog::endl(), fChainDataFiles, fCurrentRun, fDataDirectory, fDataFile, fDataFileExtension, fDataFileStem, fDataVersion, fETHostname, fETSession, fETStationName, fETWaitMode, fEventListFile, fEventRange, fEventRateLimitEnabled, fExitOnEnd, fLastEventTime, fMaxEventRate, fMinEventInterval, fOnline, fRunListFile, fRunListFileName, fRunRange, fSegmentRange, fSingleFile, QwOptions::GetIntValuePair(), GetNextRunRange(), QwOptions::GetValue(), QwOptions::HasValue(), QwError, QwMessage, and QwWarning.

Referenced by main(), and main().

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

◆ ReOpenStream()

Int_t QwEventBuffer::ReOpenStream ( )

Definition at line 361 of file QwEventBuffer.cc.

362{
363 Int_t status = CODA_ERROR;
364 // Reset the physics event counter
366
367 if (fOnline) {
368 // Online stream
370 } else {
371 // Offline data file
372 if (fRunIsSegmented)
373 // Segmented
374 status = OpenNextSegment();
375 else
376 // Not segmented
377 status = OpenDataFile(fCurrentRun);
378 }
379 return status;
380}

References fCurrentRun, fETHostname, fETSession, fETStationName, fETWaitMode, fNumPhysicsEvents, fOnline, fRunIsSegmented, fStartingPhysicsEvent, OpenDataFile(), OpenETStream(), and OpenNextSegment().

Referenced by main(), and main().

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

◆ ReportRunSummary()

void QwEventBuffer::ReportRunSummary ( )

Definition at line 726 of file QwEventBuffer.cc.

727{
728 decoder->ReportRunSummary();
729}

References decoder.

Referenced by main(), and main().

+ Here is the caller graph for this function:

◆ ResetControlParameters()

void QwEventBuffer::ResetControlParameters ( )

Definition at line 722 of file QwEventBuffer.cc.

723{
724 decoder->ResetControlParameters();
725}

References decoder.

Referenced by main().

+ Here is the caller graph for this function:

◆ ResetFlags()

void QwEventBuffer::ResetFlags ( )

Definition at line 784 of file QwEventBuffer.cc.

784 {
785}

Referenced by GetEvent(), and WriteEvent().

+ Here is the caller graph for this function:

◆ SetDataDirectory()

void QwEventBuffer::SetDataDirectory ( const TString datadir)
inline

Definition at line 112 of file QwEventBuffer.h.

112{fDataDirectory = datadir;}

References fDataDirectory.

◆ SetDefaultDataDirectory()

static void QwEventBuffer::SetDefaultDataDirectory ( const std::string & dir)
inlinestatic

Definition at line 50 of file QwEventBuffer.h.

50 {
52 }

References fDefaultDataDirectory.

◆ SetDefaultDataFileExtension()

static void QwEventBuffer::SetDefaultDataFileExtension ( const std::string & extension)
inlinestatic

Definition at line 56 of file QwEventBuffer.h.

56 {
57 fDefaultDataFileExtension = extension;
58 }

References fDefaultDataFileExtension.

◆ SetDefaultDataFileStem()

static void QwEventBuffer::SetDefaultDataFileStem ( const std::string & stem)
inlinestatic

Definition at line 53 of file QwEventBuffer.h.

53 {
55 }

References fDefaultDataFileStem.

◆ VerifyCodaVersion()

void QwEventBuffer::VerifyCodaVersion ( const UInt_t * buffer)

Definition at line 548 of file QwEventBuffer.cc.

549{
550 if(buffer[0] == 0) return;
551 UInt_t header = buffer[1];
552 int top = (header & 0xff000000) >> 24;
553 int bot = (header & 0xff );
554 fDataVersionVerify = 0; // Default
555 if( (top == 0xff) && (bot != 0xcc) ){
556 fDataVersionVerify = 3; // Coda 3
557 } else if( (top != 0xff) && (bot == 0xcc) ){
558 fDataVersionVerify = 2; // Coda 2
559 }
560 // Validate
562 QwError << "QwEventBuffer::GetEvent: Coda Version is not recognized" << QwLog::endl;
563 QwError << "fDataVersion == " << fDataVersion
564 << ", but it looks like the data is from Coda Version "
566 << "\nTry running with --coda-version " << fDataVersionVerify
567 << "\nExiting ... " << QwLog::endl;
568 globalEXIT = 1;
569 }
570 return;
571}

References QwLog::endl(), fDataVersion, fDataVersionVerify, globalEXIT, and QwError.

Referenced by GetEvent().

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

◆ WriteEtEvent()

Int_t QwEventBuffer::WriteEtEvent ( int * buffer)
protected

Definition at line 664 of file QwEventBuffer.cc.

665{
666 Int_t status = CODA_OK;
667 // fEvStream is of inherited type THaCodaData,
668 // but codaWrite for ET is defined in THaEtClient.
669#ifdef __CODA_ET
670 // Get the buffer length from the first word (CODA event header)
671 UInt_t* ubuffer = (UInt_t*)buffer;
672 UInt_t event_length = ubuffer[0]; // First word is event length in words
673
674 if( event_length == 0 || event_length > MAXEVLEN ) {
675 QwError << "WriteEtEvent: Invalid event length: " << event_length << QwLog::endl;
676 return CODA_ERROR;
677 }
678
679 status = ((THaEtClient*)fEvStream)->codaWrite(ubuffer, event_length);
680 if( status != CODA_OK ) {
681 QwError << "WriteEtEvent: codaWrite failed with status " << status << QwLog::endl;
682 }
683#else
684 QwError << "WriteEtEvent: ET support not compiled in" << QwLog::endl;
685 status = CODA_ERROR;
686#endif
687 return status;
688}

References QwLog::endl(), fEvStream, and QwError.

Referenced by WriteEvent().

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

◆ WriteEvent()

Int_t QwEventBuffer::WriteEvent ( int * buffer)

Definition at line 603 of file QwEventBuffer.cc.

604{
605 Int_t status = kFileHandleNotConfigured;
606 ResetFlags();
607
608 // Rate limiting: sleep until minimum interval has elapsed, accounting for accumulated delays
610 auto now = std::chrono::steady_clock::now();
611 auto elapsed = now - fLastEventTime;
612
613 if (elapsed < fMinEventInterval) {
614 // We're ahead of schedule - need to wait
615 auto target_sleep = fMinEventInterval - elapsed;
616
617 // Reduce sleep time by accumulated delay (time we're behind)
618 auto actual_sleep = target_sleep - fAccumulatedDelay;
619
620 if (actual_sleep > std::chrono::duration<double>(0)) {
621 // Still need to sleep after compensation
622 auto sleep_until_time = now + actual_sleep;
623 std::this_thread::sleep_until(sleep_until_time);
624
625 // We've compensated for some or all of the accumulated delay
626 fAccumulatedDelay -= (target_sleep - actual_sleep);
627 if (fAccumulatedDelay < std::chrono::duration<double>(0)) {
628 fAccumulatedDelay = std::chrono::duration<double>(0);
629 }
630 } else {
631 // Accumulated delay is larger than needed sleep - don't sleep at all
632 fAccumulatedDelay -= target_sleep;
633 }
634 } else {
635 // We're behind schedule - accumulate the delay
636 auto delay = elapsed - fMinEventInterval;
637 fAccumulatedDelay += delay;
638 }
639 fLastEventTime = std::chrono::steady_clock::now();
640 }
641
643 status = WriteFileEvent(buffer);
644 } else if (fEvStreamMode==fEvStreamET) {
645 status = WriteEtEvent(buffer);
646 }
647
648 if (globalEXIT == 1) {
649 status = CODA_ERROR;
650 }
651
652 return status;
653}
Int_t WriteEtEvent(int *buffer)
Int_t WriteFileEvent(int *buffer)
std::chrono::duration< double > fAccumulatedDelay

References fAccumulatedDelay, fEventRateLimitEnabled, fEvStreamET, fEvStreamFile, fEvStreamMode, fLastEventTime, fMinEventInterval, globalEXIT, kFileHandleNotConfigured, ResetFlags(), WriteEtEvent(), and WriteFileEvent().

Referenced by EncodeEndEvent(), EncodeGoEvent(), EncodePauseEvent(), EncodePrestartEvent(), and EncodeSubsystemData().

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

◆ WriteFileEvent()

Int_t QwEventBuffer::WriteFileEvent ( int * buffer)
protected

Definition at line 655 of file QwEventBuffer.cc.

656{
657 Int_t status = CODA_OK;
658 // fEvStream is of inherited type THaCodaData,
659 // but codaWrite is only defined for THaCodaFile.
660 status = ((THaCodaFile*)fEvStream)->codaWrite((UInt_t*) buffer);
661 return status;
662}

References fEvStream.

Referenced by WriteEvent().

+ Here is the caller graph for this function:

Field Documentation

◆ decoder

◆ fAccumulatedDelay

std::chrono::duration<double> QwEventBuffer::fAccumulatedDelay {0.0}
protected

Definition at line 203 of file QwEventBuffer.h.

203{0.0};

Referenced by WriteEvent().

◆ fChainDataFiles

Bool_t QwEventBuffer::fChainDataFiles
protected

◆ fCleanParameter

Double_t QwEventBuffer::fCleanParameter[3]
protected

Scan data/clean data from the green monster.

Definition at line 268 of file QwEventBuffer.h.

Referenced by FillSubsystemData(), and QwEventBuffer().

◆ fCurrentRun

◆ fDataDirectory

TString QwEventBuffer::fDataDirectory
protected

◆ fDataFile

TString QwEventBuffer::fDataFile
protected

◆ fDataFileExtension

TString QwEventBuffer::fDataFileExtension
protected

Definition at line 226 of file QwEventBuffer.h.

Referenced by DataFile(), ProcessOptions(), and QwEventBuffer().

◆ fDataFileStem

TString QwEventBuffer::fDataFileStem
protected

Definition at line 225 of file QwEventBuffer.h.

Referenced by DataFile(), ProcessOptions(), and QwEventBuffer().

◆ fDataVersion

Int_t QwEventBuffer::fDataVersion
private

Definition at line 188 of file QwEventBuffer.h.

Referenced by ProcessOptions(), and VerifyCodaVersion().

◆ fDataVersionVerify

Int_t QwEventBuffer::fDataVersionVerify = 0
private

Definition at line 187 of file QwEventBuffer.h.

Referenced by GetEvent(), and VerifyCodaVersion().

◆ fDefaultDataDirectory

std::string QwEventBuffer::fDefaultDataDirectory = "/adaq1/data1/apar"
staticprotected

Definition at line 221 of file QwEventBuffer.h.

Referenced by DefineOptions(), QwEventBuffer(), and SetDefaultDataDirectory().

◆ fDefaultDataFileExtension

std::string QwEventBuffer::fDefaultDataFileExtension = "log"
staticprotected

Definition at line 223 of file QwEventBuffer.h.

Referenced by DefineOptions(), QwEventBuffer(), and SetDefaultDataFileExtension().

◆ fDefaultDataFileStem

std::string QwEventBuffer::fDefaultDataFileStem = "QwRun_"
staticprotected

Definition at line 222 of file QwEventBuffer.h.

Referenced by DefineOptions(), QwEventBuffer(), and SetDefaultDataFileStem().

◆ fETHostname

TString QwEventBuffer::fETHostname
protected

Definition at line 193 of file QwEventBuffer.h.

Referenced by OpenNextStream(), ProcessOptions(), and ReOpenStream().

◆ fETSession

TString QwEventBuffer::fETSession
protected

Definition at line 194 of file QwEventBuffer.h.

Referenced by OpenNextStream(), ProcessOptions(), and ReOpenStream().

◆ fETStationName

TString QwEventBuffer::fETStationName
protected

Definition at line 195 of file QwEventBuffer.h.

Referenced by OpenNextStream(), ProcessOptions(), and ReOpenStream().

◆ fETWaitMode

Int_t QwEventBuffer::fETWaitMode
protected

Definition at line 196 of file QwEventBuffer.h.

Referenced by OpenNextStream(), ProcessOptions(), and ReOpenStream().

◆ fEventList

std::vector<UInt_t> QwEventBuffer::fEventList
protected

Definition at line 215 of file QwEventBuffer.h.

◆ fEventListFile

std::unique_ptr<QwParameterFile> QwEventBuffer::fEventListFile
protected

Definition at line 214 of file QwEventBuffer.h.

Referenced by GetNextEventRange(), GetNextRunRange(), ProcessOptions(), and QwEventBuffer().

◆ fEventListFileName

std::string QwEventBuffer::fEventListFileName
protected

Definition at line 213 of file QwEventBuffer.h.

◆ fEventRange

std::pair<UInt_t, UInt_t> QwEventBuffer::fEventRange
protected

◆ fEventRateLimitEnabled

Bool_t QwEventBuffer::fEventRateLimitEnabled {false}
protected

Definition at line 200 of file QwEventBuffer.h.

200{false};

Referenced by ProcessOptions(), and WriteEvent().

◆ fEvStream

◆ fEvStreamMode

◆ fExitOnEnd

Bool_t QwEventBuffer::fExitOnEnd
protected

Definition at line 197 of file QwEventBuffer.h.

Referenced by GetNextEvent(), and ProcessOptions().

◆ fLastEventTime

std::chrono::steady_clock::time_point QwEventBuffer::fLastEventTime
protected

Definition at line 204 of file QwEventBuffer.h.

Referenced by ProcessOptions(), and WriteEvent().

◆ fMarkerList

std::unordered_map<RocBankLabel_t, std::vector<UInt_t> > QwEventBuffer::fMarkerList
protected

Definition at line 277 of file QwEventBuffer.h.

Referenced by CheckForMarkerWords(), FindMarkerWord(), and GetMarkerWord().

◆ fMaxEventRate

Double_t QwEventBuffer::fMaxEventRate {0.0}
protected

Definition at line 201 of file QwEventBuffer.h.

201{0.0};

Referenced by ProcessOptions().

◆ fMinEventInterval

std::chrono::duration<double> QwEventBuffer::fMinEventInterval
protected

Definition at line 202 of file QwEventBuffer.h.

Referenced by ProcessOptions(), and WriteEvent().

◆ fNumPhysicsEvents

UInt_t QwEventBuffer::fNumPhysicsEvents
protected

◆ fOffsetList

std::unordered_map<RocBankLabel_t, std::vector<UInt_t> > QwEventBuffer::fOffsetList
protected

Definition at line 278 of file QwEventBuffer.h.

Referenced by CheckForMarkerWords(), and FindMarkerWord().

◆ fOnline

Bool_t QwEventBuffer::fOnline
protected

Definition at line 192 of file QwEventBuffer.h.

Referenced by GetNextEvent(), IsOnline(), OpenNextStream(), ProcessOptions(), and ReOpenStream().

◆ fRunIsSegmented

◆ fRunListFile

std::unique_ptr<QwParameterFile> QwEventBuffer::fRunListFile
protected

Definition at line 209 of file QwEventBuffer.h.

Referenced by GetNextRunRange(), ProcessOptions(), and QwEventBuffer().

◆ fRunListFileName

std::string QwEventBuffer::fRunListFileName
protected

Definition at line 208 of file QwEventBuffer.h.

Referenced by ProcessOptions().

◆ fRunRange

std::pair<Int_t, Int_t> QwEventBuffer::fRunRange
protected

Definition at line 207 of file QwEventBuffer.h.

Referenced by GetNextRunNumber(), GetNextRunRange(), and ProcessOptions().

◆ fRunRangeMaxList

std::vector<Int_t> QwEventBuffer::fRunRangeMaxList
protected

Definition at line 210 of file QwEventBuffer.h.

◆ fRunRangeMinList

std::vector<Int_t> QwEventBuffer::fRunRangeMinList
protected

Definition at line 210 of file QwEventBuffer.h.

◆ fRunSegmentIterator

std::vector<Int_t>::iterator QwEventBuffer::fRunSegmentIterator
protected

◆ fRunSegments

std::vector<Int_t> QwEventBuffer::fRunSegments
protected

◆ fRunTimer

TStopwatch QwEventBuffer::fRunTimer
protected

Timer used for runlet processing loop.

Definition at line 271 of file QwEventBuffer.h.

Referenced by CloseStream(), OpenNextStream(), and PrintRunTimes().

◆ fSegmentRange

std::pair<Int_t, Int_t> QwEventBuffer::fSegmentRange
protected

Definition at line 217 of file QwEventBuffer.h.

Referenced by DataFileIsSegmented(), GetNextEvent(), and ProcessOptions().

◆ fSingleFile

Bool_t QwEventBuffer::fSingleFile
protected

Definition at line 289 of file QwEventBuffer.h.

Referenced by DataFile(), DataFileIsSegmented(), ProcessOptions(), and QwEventBuffer().

◆ fStartingPhysicsEvent

UInt_t QwEventBuffer::fStartingPhysicsEvent
protected

Definition at line 287 of file QwEventBuffer.h.

Referenced by OpenNextStream(), PrintRunTimes(), and ReOpenStream().

◆ fStopwatch

TStopwatch QwEventBuffer::fStopwatch
protected

Timer used for internal timing.

Definition at line 272 of file QwEventBuffer.h.

Referenced by CloseStream(), GetNextEvent(), and OpenNextStream().

◆ fThisRocBankLabel

RocBankLabel_t QwEventBuffer::fThisRocBankLabel
protected

Definition at line 281 of file QwEventBuffer.h.

Referenced by CheckForMarkerWords(), FindMarkerWord(), and GetMarkerWord().

◆ kFileHandleNotConfigured

const Int_t QwEventBuffer::kFileHandleNotConfigured = -40
static

◆ kNoNextDataFile

const Int_t QwEventBuffer::kNoNextDataFile = -30
static

Definition at line 62 of file QwEventBuffer.h.

Referenced by OpenNextSegment().

◆ kNullDataWord

const UInt_t QwEventBuffer::kNullDataWord = 0x4e554c4c
static

This is the ASCII character array 'NULL', and is used by the DAQ to indicate a known empty buffer.

Definition at line 65 of file QwEventBuffer.h.

Referenced by FillEPICSData(), FillObjectWithEventData(), FillSubsystemConfigurationData(), and FillSubsystemData().

◆ kRunNotSegmented

const Int_t QwEventBuffer::kRunNotSegmented = -20
static

Definition at line 61 of file QwEventBuffer.h.

Referenced by OpenNextSegment().


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