Skip to content

Commit

Permalink
Updating to EVIOv5.3 (JeffersonLab#20)
Browse files Browse the repository at this point in the history
Removes the bundled EVIO from japan-MOLLER and places it as a standalone dependency that must be compiled independently. Target library version: EVIOv5.3 (internal EVIO data format 4)

__Warning__:
EVIOv5.3 (https://github.com/JeffersonLab/evio/tree/evio-5.3) does not properly support the bundled EVIO version currently in japan-MOLLER. Any previous mock data generated cannot be analyzed with the EVIOv5.3, and would need to be regenerated.

=============================
* Adds cmake modules FindEVIO.cmake and FetchBuildEVIO.cmake from the Hall A analyzer
* Modifies CMakeTextList(s) and adds evio/CMakeLists.txt.in to support building against a seperate EVIO lib.
* Replaces THaCodaData.[h,C] and replaces THaCodaFile.[h,C] with the Hall A analyzer's version
* Adds additional header files needed for wrapper compilation

Moves QwEventBuffer decoding logic into an abstract class VEventDecoder. Two concrete decoding classes are derived from the abstract decoder class: Coda2Decoder and Coda3Decoder. QwEventbuffer instantiates the appropriate class at runtime. 
* Original japan-MOLLER event decoding logic is moved into Coda2Decoder.[h,cc].
* Ports Hall A analyzer CODA 3 decoding into the Coda3Decoder class. 
* Adds CODA 3 style mock data generation

Adds QwEventBuffer Command Line Args to select which CODA version data is being decoded.
* --coda-version flag can be used to select the CODA version. Only supports versions 2 or 3
* Adds verification in QwEventBuffer. Exits if mismatch occurs (ie analyzing CODA 2 data with CODA 3 logic). 

Misc. Changes:
* Adds version number the TList* condition output in root files
* Adjusts formatting of the TList* condition naming scheme



Note: Hall A analyzer version: commit 9616c77e8e061ef1b69dfe1882e2254a5113683b
Files ported:
* analyzer/cmake/Modules/FindEVIO.cmake
* analyzer/cmake/Modules/FetchBuildEVIO.cmake
* analyzer/cmake/scripts/mk_rootdict.sh 
* analyzer/Database/Helper.h
* analyzer/hana_decode/CustomAlloc.h 
* analyzer/hana_decode/THaCodaFile.h
analyzer/hana_decode/THaCodaData.h
* analyzer/hana_decode/Decoder.h 
* analyzer/hana_decode/CodaDecoder.h

* Fixes errors found in the clang-build workflow
	* fEvtLength is protected in context error
	* Typo in include guard
Note: Comments out function QwEventBuffer::FillObjectWithEventData to check if it is used anywhere

* Undoes the commenting out of  QwEventBuffer::FillObjectWithEventData
so that it is included in compilation

* Fixes typo where a was duplicated

* Cleans up misc. TODO comments and modifies the warning for undetermined CODA3 events

* Adds simple Doxygen-Style comments to Decoder Functions
  • Loading branch information
Mrc1104 authored Aug 29, 2024
1 parent e44dd2a commit b2776e5
Show file tree
Hide file tree
Showing 39 changed files with 2,292 additions and 3,557 deletions.
35 changes: 35 additions & 0 deletions Analysis/include/Coda2EventDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef CODA2EVENTDECODER_H
#define CODA2EVENTDECODER_H

#include "VEventDecoder.h"
#include "Rtypes.h"

#include <vector>

class Coda2EventDecoder : public VEventDecoder
{
public:
Coda2EventDecoder() :
fEvtClass(0),
fStatSum(0),
fIDBankNum(0) { }
~Coda2EventDecoder() { }
public:
// Encoding Functions
virtual std::vector<UInt_t> EncodePHYSEventHeader(std::vector<ROCID_t> &ROCList);
virtual void EncodePrestartEventHeader(int* buffer, int runnumber, int runtype, int localtime);
virtual void EncodeGoEventHeader(int* buffer, int eventcount, int localtime);
virtual void EncodePauseEventHeader(int* buffer, int eventcount, int localtime);
virtual void EncodeEndEventHeader(int* buffer, int eventcount, int localtime);
public:
// Decoding Functions
virtual Int_t DecodeEventIDBank(UInt_t *buffer);
virtual void PrintDecoderInfo(QwLog& out);

private:
// Event Information (CODA 2 Specific)
UInt_t fEvtClass;
UInt_t fStatSum;
UInt_t fIDBankNum;
};
#endif
105 changes: 105 additions & 0 deletions Analysis/include/Coda3EventDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#ifndef CODA3EVENTDECODER_H
#define CODA3EVENTDECODER_H

#include "VEventDecoder.h"
#include "Rtypes.h"

#include <vector>

class Coda3EventDecoder : public VEventDecoder
{
public:
Coda3EventDecoder() :
tsEvType(0),
block_size(0),
evt_time(0),
trigger_bits(0),
TSROCNumber(0) { }
~Coda3EventDecoder() { }
public:
// Encoding Functions
virtual std::vector<UInt_t> EncodePHYSEventHeader(std::vector<ROCID_t> &ROCList);
virtual void EncodePrestartEventHeader(int* buffer, int runnumber, int runtype, int localtime);
virtual void EncodeGoEventHeader(int* buffer, int eventcount, int localtime);
virtual void EncodePauseEventHeader(int* buffer, int eventcount, int localtime);
virtual void EncodeEndEventHeader(int* buffer, int eventcount, int localtime);

public:
// Decoding Functions
virtual Int_t DecodeEventIDBank(UInt_t *buffer);
private:
// Debugging Functions
void printUserEvent(const UInt_t *buffer);
virtual void PrintDecoderInfo(QwLog& out);
protected:
// TI Decoding Functions
UInt_t InterpretBankTag(UInt_t tag);
Int_t trigBankDecode(UInt_t* buffer);
void trigBankErrorHandler( Int_t flag );

ULong64_t GetEvTime() const { return evt_time; }
void SetEvTime(ULong64_t evtime) { evt_time = evtime; }
UInt_t tsEvType, block_size;
ULong64_t evt_time; // Event time (for CODA 3.* this is a 250 Mhz clock)
UInt_t trigger_bits; // (Not completely sure) The TS# trigger for the TS
public:
// Ti Specific Functions
enum { HED_OK = 0, HED_WARN = -63, HED_ERR = -127, HED_FATAL = -255 };
class coda_format_error : public std::runtime_error {
public:
explicit coda_format_error( const std::string& what_arg ) : std::runtime_error(what_arg) {}
explicit coda_format_error( const char* what_arg ) : std::runtime_error(what_arg) {}
};

// Trigger Bank OBJect
class TBOBJ {
public:
TBOBJ() : blksize(0), tag(0), nrocs(0), len(0), tsrocLen(0), evtNum(0),
runInfo(0), start(nullptr), evTS(nullptr), evType(nullptr),
TSROC(nullptr) {}
void Clear() { memset(this, 0, sizeof(*this)); }
uint32_t Fill( const uint32_t* evbuffer, uint32_t blkSize, uint32_t tsroc );
bool withTimeStamp() const { return (tag & 1) != 0; }
bool withRunInfo() const { return (tag & 2) != 0; }
bool withTriggerBits() const { return (tsrocLen > 2*blksize);}

uint32_t blksize; /* total number of triggers in the Bank */
uint16_t tag; /* Trigger Bank Tag ID = 0xff2x */
uint16_t nrocs; /* Number of ROC Banks in the Event Block (val = 1-256) */
uint32_t len; /* Total Length of the Trigger Bank - including Bank header */
uint32_t tsrocLen; /* Number of words in TSROC array */
uint64_t evtNum; /* Starting Event # of the Block */
uint64_t runInfo; /* Run Info Data (optional) */
const uint32_t *start; /* Pointer to start of the Trigger Bank */
const uint64_t *evTS; /* Pointer to the array of Time Stamps (optional) */
const uint16_t *evType; /* Pointer to the array of Event Types */
const uint32_t *TSROC; /* Pointer to Trigger Supervisor ROC segment data */
};

protected:
Int_t LoadTrigBankInfo( UInt_t index_buffer );
TBOBJ tbank;

public:
// Hall A analyzer keywords (analyzer/Decoder.h)
// Keywords that collide with JAPAN have been removed (deferring to JAPAN's definitions)
static const UInt_t MAX_PHYS_EVTYPE = 14; // Types up to this are physics
static const UInt_t TS_PRESCALE_EVTYPE = 120;
// TODO:
// Do we need any of these keywords?
static const UInt_t PRESCALE_EVTYPE = 133;
static const UInt_t DETMAP_FILE = 135; // Most likely do not need this one
static const UInt_t DAQCONFIG_FILE1 = 137;
static const UInt_t DAQCONFIG_FILE2 = 138;
static const UInt_t TRIGGER_FILE = 136;
static const UInt_t SCALER_EVTYPE = 140;
static const UInt_t SBSSCALER_EVTYPE = 141;
static const UInt_t HV_DATA_EVTYPE = 150;

protected:
// TODO:
// How does JAPAN want to handle a TS?
// Currently implemented as 0
uint32_t TSROCNumber;
};
#endif
89 changes: 39 additions & 50 deletions Analysis/include/QwEventBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#include <unordered_map>

#include "VEventDecoder.h"
#include "Coda3EventDecoder.h"
#include "Coda2EventDecoder.h"

class QwOptions;
class QwEPICSEvent;
class VQwSubsystem;
Expand Down Expand Up @@ -67,6 +71,11 @@ class QwEventBuffer: public MQwCodaControlEvent{
delete fRunListFile;
fRunListFile = NULL;
}
// Delete Decoder
if(decoder != NULL) {
delete decoder;
decoder = NULL;
}
};

/// \brief Sets internal flags based on the QwOptions
Expand Down Expand Up @@ -114,16 +123,16 @@ class QwEventBuffer: public MQwCodaControlEvent{
Int_t CloseETStream();

Bool_t IsPhysicsEvent() {
// fEvtType is an unsigned integer, hence always positive
return ((fIDBankNum == 0xCC) && ( /* fEvtType >= 0 && */ fEvtType <= 15));
return ( decoder->IsPhysicsEvent() );
};

Int_t GetPhysicsEventNumber() {return fNumPhysicsEvents;};
Int_t GetEventNumber() { return fEvtNumber; };
Int_t GetEventNumber() { return decoder->GetEvtNumber(); };

Bool_t GetNextEventRange();
Bool_t GetNextRunRange();
Bool_t GetNextRunNumber();
void VerifyCodaVersion( const UInt_t *buffer);

Int_t GetNextEvent();

Expand All @@ -133,15 +142,12 @@ class QwEventBuffer: public MQwCodaControlEvent{
Bool_t IsOnline(){return fOnline;};

Bool_t IsROCConfigurationEvent(){
return (fEvtType>=0x90 && fEvtType<=0xaf);
return ( decoder->IsROCConfigurationEvent() );
};

Bool_t IsEPICSEvent(){
// What are the correct codes for our EPICS events?
//return (fEvtType>=160 && fEvtType<=170);// epics event type is only with tag="160"
// return (fEvtType>=160 && fEvtType<=190);// epics event type is only with tag="180" from July 2010 running
return (fEvtType==131);// epics event type is for 2019 summer PREX-II
};
return ( decoder->IsEPICSEvent() ); // Defined in CodaDecoder.h
}

Bool_t FillSubsystemConfigurationData(QwSubsystemArray &subsystems);
Bool_t FillSubsystemData(QwSubsystemArray &subsystems);
Expand All @@ -165,6 +171,11 @@ class QwEventBuffer: public MQwCodaControlEvent{

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

// Coda Version that is set by void VerifyCodaVersion( )
// Compared against the user-input coda version
Int_t fDataVersionVerify = 0;
Int_t fDataVersion; // User-input Coda Version

protected:
///
Expand All @@ -175,7 +186,6 @@ class QwEventBuffer: public MQwCodaControlEvent{
Int_t fETWaitMode;
Bool_t fExitOnEnd;

Bool_t fAllowLowSubbankIDs;

Bool_t fChainDataFiles;
std::pair<Int_t, Int_t> fRunRange;
Expand Down Expand Up @@ -216,9 +226,6 @@ class QwEventBuffer: public MQwCodaControlEvent{
Int_t CloseThisSegment();
Int_t OpenNextSegment();

void DecodeEventIDBank(UInt_t *buffer);
Bool_t DecodeSubbankHeader(UInt_t *buffer);

const TString& DataFile(const UInt_t run, const Short_t seg);

// void SetEventLength(const ULong_t tmplength) {fEvtLength = tmplength;};
Expand All @@ -241,28 +248,8 @@ class QwEventBuffer: public MQwCodaControlEvent{


protected:
Bool_t fPhysicsEventFlag;

UInt_t fEvtLength;
UInt_t fWordsSoFar;

UInt_t fEvtType;

UInt_t fEvtTag;
UInt_t fBankDataType;
UInt_t fIDBankNum;

UInt_t fEvtNumber; ///< CODA event number; only defined for physics events
UInt_t fEvtClass;
UInt_t fStatSum;

Double_t fCleanParameter[3]; ///< Scan data/clean data from the green monster

UInt_t fFragLength;
BankID_t fSubbankTag;
UInt_t fSubbankType;
UInt_t fSubbankNum;
ROCID_t fROC;

TStopwatch fRunTimer; ///< Timer used for runlet processing loop
TStopwatch fStopwatch; ///< Timer used for internal timing
Expand All @@ -282,8 +269,10 @@ class QwEventBuffer: public MQwCodaControlEvent{
UInt_t fNumPhysicsEvents;
UInt_t fStartingPhysicsEvent;

Bool_t fSingleFile;
Bool_t fSingleFile;

protected:
VEventDecoder* decoder;
};

template < class T > Bool_t QwEventBuffer::FillObjectWithEventData(T &object){
Expand All @@ -301,33 +290,33 @@ template < class T > Bool_t QwEventBuffer::FillObjectWithEventData(T &object){
Bool_t okay = kFALSE;
UInt_t *localbuff = (UInt_t*)(fEvStream->getEvBuffer());

if (fFragLength==1 && localbuff[fWordsSoFar]==kNullDataWord){
fWordsSoFar += fFragLength;
} else if (object.CanUseThisEventType(fEvtType)){
if (decoder->GetFragLength()==1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord){
decoder->AddWordsSoFarAndFragLength();
} else if (object.CanUseThisEventType(decoder->GetEvtType())){
// Clear the old event information from the object
object.ClearEventData(fEvtType);
object.ClearEventData(decoder->GetEvtType());
// Loop through the data buffer in this event.
if (fBankDataType == 0x10){
if (decoder->GetBankDataType() == 0x10){
// This bank is subbanked; loop through subbanks
while ((okay = DecodeSubbankHeader(&localbuff[fWordsSoFar]))){
while ((okay = decoder->DecodeSubbankHeader(&localbuff[decoder->GetWordsSoFar()]))){
// If this bank has further subbanks, restart the loop.
if (fSubbankType == 0x10) continue;
if (decoder->GetSubbankType() == 0x10) continue;
// If this bank only contains the word 'NULL' then skip
// this bank.
if (fFragLength==1 && localbuff[fWordsSoFar]==kNullDataWord){
fWordsSoFar += fFragLength;
if (decoder->GetFragLength()==1 && localbuff[decoder->GetWordsSoFar()]==kNullDataWord){
decoder->AddWordsSoFarAndFragLength();
continue;
}
object.ProcessBuffer(fEvtType, fROC, fSubbankTag, fSubbankType,
&localbuff[fWordsSoFar],
fFragLength);
fWordsSoFar += fFragLength;
object.ProcessBuffer(decoder->GetEvtType(), decoder->GetROC(), decoder->GetSubbankTag(), decoder->GetSubbankType(),
&localbuff[decoder->GetWordsSoFar()],
decoder->GetFragLength());
decoder->AddWordsSoFarAndFragLength();
}
} else {
// This is a single bank of some type
object.ProcessBuffer(fEvtType, 0, fBankDataType,
&localbuff[fWordsSoFar],
fEvtLength);
object.ProcessBuffer(decoder->GetEvtType(), 0, decoder->GetBankDataType(),
&localbuff[decoder->GetWordsSoFar()],
decoder->GetEvtLength());
}
}
return okay;
Expand Down
3 changes: 3 additions & 0 deletions Analysis/include/QwSubsystemArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class QwSubsystemArray:
/// \brief Encode the data in this event
void EncodeEventData(std::vector<UInt_t> &buffer);

/// \brief Get the ROCID list
void GetROCIDList(std::vector<ROCID_t> &list);

/// \brief Process the decoded data in this event
void ProcessEvent();

Expand Down
Loading

0 comments on commit b2776e5

Please sign in to comment.