Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaFilter.cxx
Go to the documentation of this file.
1// a class to handle event filtering
2// Each filter has an associated global 'cut' variable
3// to test against
4
5#include "THaFilter.h"
6#include "THaCodaFile.h"
7#include "TError.h"
8#include "TString.h"
9#include "THaCutList.h"
10#include "THaCut.h"
11#include "THaRunBase.h"
12#include "THaEvData.h"
13// only for ERetVal, used by Process(). Should put ERetVal in a separate header
14#include "THaAnalyzer.h"
15
16using namespace std;
17using namespace Decoder;
18
19//_____________________________________________________________________________
20THaFilter::THaFilter( const char *cutexpr, const char* filename ) :
21 fCutExpr(cutexpr), fFileName(filename), fCodaOut(nullptr), fCut(nullptr)
22{
23 // Constructor
24
25 // This module returns compatible return codes
27}
28
29//_____________________________________________________________________________
31{
32 // Destructor. Calls virtual Close(). NB: any derived class
33 // that overrides Close() must implement its own destructor and call its
34 // own Close() from there.
35
36 Close();
37 delete fCut;
38 delete fCodaOut;
39}
40
41//_____________________________________________________________________________
43{
44 // Close this filter. Closes output file if open.
45
46 if( !fCodaOut ) return 0;
47 //cout << "Flushing and Closing " << fFileName << endl;
48 return fCodaOut->codaClose();
49}
50
51//_____________________________________________________________________________
53{
54 // Init the filter
55
56 const char* const here = "THaFilter::Init";
57
58 if (fIsInit)
59 return 0;
60
61 // Set up our cut
62 fCut = new THaCut( "Filter_Test", fCutExpr, "PostProcess" );
63 // Expression error?
64 if( !fCut || fCut->IsZombie()) {
65 delete fCut; fCut = nullptr;
66 Warning(here,"Illegal cut expression: %s.\nFilter is inactive.",
67 fCutExpr.Data());
68 } else {
70 if (!fCodaOut) {
71 Error(here,"Cannot create CODA output file object. "
72 "Something is very wrong." );
73 return -2;
74 }
75
76 if ( fCodaOut->codaOpen(fFileName, "w", 1) ) {
77 Error(here,"Cannot open CODA file %s for writing.",fFileName.Data());
78 delete fCodaOut;
79 return -3;
80 }
81 fIsInit = 1;
82 }
83 return 0;
84}
85
86//_____________________________________________________________________________
87Int_t THaFilter::Process( const THaEvData* evdata, const THaRunBase* run,
88 Int_t /* code */ )
89{
90 // Process event. Write the event to output CODA file if and only if
91 // the event passes the filter cut.
92
93 const char* const here = "THaFilter::Process";
94
95 if (!fIsInit || !fCut->EvalCut())
96 return THaAnalyzer::kOK;
97
98 // write out the event
99 Int_t ret = fCodaOut->codaWrite(run->GetEvBuffer());
100 if( ret == CODA_FATAL ) {
101 Error( here, "Fatal error writing to CODA output file %s. Check if you have "
102 "write permission", fFileName.Data() );
103 return THaAnalyzer::kFatal;
104 } else if( ret != CODA_OK ) {
105 Error( here, "Error writing to CODA output file %s. Event %d not written",
106 fFileName.Data(), (evdata != nullptr) ? evdata->GetEvNum() : -1 );
107 }
108 return THaAnalyzer::kOK;
109}
110
111//_____________________________________________________________________________
int Int_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
#define CODA_FATAL
Definition THaCodaData.h:31
#define CODA_OK
Definition THaCodaData.h:28
static const char *const here
Definition THaVar.cxx:64
virtual Int_t codaOpen(const char *filename, Int_t mode=1)
virtual Int_t codaClose()
Int_t codaWrite(const UInt_t *evbuffer)
Bool_t EvalCut()
Definition THaCut.h:31
UInt_t GetEvNum() const
Definition THaEvData.h:56
virtual Int_t Process(const THaEvData *, const THaRunBase *, Int_t code)
Definition THaFilter.cxx:87
virtual Int_t Init(const TDatime &)
Definition THaFilter.cxx:52
virtual Int_t Close()
Definition THaFilter.cxx:42
Decoder::THaCodaFile * fCodaOut
Definition THaFilter.h:27
THaFilter(const char *cutexpr, const char *filename)
Definition THaFilter.cxx:20
THaCut * fCut
Definition THaFilter.h:28
TString fCutExpr
Definition THaFilter.h:25
TString fFileName
Definition THaFilter.h:26
virtual ~THaFilter()
Definition THaFilter.cxx:30
virtual const UInt_t * GetEvBuffer() const =0
void SetBit(UInt_t f)
virtual void Warning(const char *method, const char *msgfmt,...) const
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual void Error(const char *method, const char *msgfmt,...) const
const char * Data() const
STL namespace.
ClassImp(TPyArg)