Hall C ROOT/C++ Analyzer (hcana)
Loading...
Searching...
No Matches
THcAnalyzer.cxx
Go to the documentation of this file.
1
15#include "THcAnalyzer.h"
16#include "THaRunBase.h"
17#include "THaBenchmark.h"
18#include "TList.h"
19#include "THcParmList.h"
20#include "THcFormula.h"
21#include "THcGlobals.h"
22#include "TMath.h"
23
24#include <fstream>
25#include <algorithm>
26#include <iomanip>
27#include <cstring>
28#include <iostream>
29
30using namespace std;
31
32
33// Pointer to single instance of this object
34//THcAnalyzer* THcAnalyzer::fgAnalyzer = 0;
35
36//FIXME:
37// do we need to "close" scalers/EPICS analysis if we reach the event limit?
38
39//_____________________________________________________________________________
44
45//_____________________________________________________________________________
47{
48 // Destructor.
49
50}
51
52//_____________________________________________________________________________
53void THcAnalyzer::PrintReport(const char* templatefile, const char* ofile)
54{
59 ifstream ifile;
60 ifile.open(templatefile);
61
62 if(!ifile.is_open()) {
63 cout << "Error opening template file " << templatefile << endl;
64 return;
65 }
66
67 ofstream ostr(ofile);
68
69 if(!ostr.is_open()) {
70 cout << "Error opening report output file " << ofile << endl;
71 return;
72 }
73
74 LoadInfo(); // Load some run information into gHcParms
75
76 // In principle, we should allow braces to be escaped. But for
77 // now we won't. Existing template files don't seem to output
78 // any braces
79 for(string line; getline(ifile, line);) {
80 // cout << line << endl;
81 string::size_type start;
82 while((start = line.find('{',0)) != string::npos) {
83 // cout << start << endl;
84 string::size_type end = line.find('}',start);
85 if(end==string::npos) break; // No more expressions on the line
86 string expression=line.substr(start+1,end-start-1);
87 string::size_type formatpos = expression.find(':',0);
88 string format;
89 if(formatpos != string::npos) {
90 format=expression.substr(formatpos+1);
91 expression=expression.substr(0,formatpos);
92 // cout << "|" << expression << "|" << format << "|" << endl;
93 }
94 // Should we first check if the expression can be simply a variable
95 // or index into variable?
96 // For now, first check if it is a string.
97 // If not, then evaluate as an expression.
98 string replacement;
99 if(const char *textstring=gHcParms->GetString(expression)) {
100 // cout << expression << " is a string with value " << textstring << endl;
101 if(format.empty()) format = "%s";
102 replacement=Form(format.c_str(),textstring);
103 } else {
104 THcFormula* formula = new THcFormula("temp",expression.c_str(),gHcParms,gHaVars,gHaCuts);
105 Double_t value=formula->Eval();
106 delete formula; formula = 0;
107 // If the value is close to integer and no format is defined
108 // use "%.0f" to print out integer
109 if(format.empty()) {
110 if(TMath::Abs(value-TMath::Nint(value)) < 0.0000001) {
111 format = "%.0f";
112 } else {
113 format = "%f";
114 }
115 }
116 if(format[format.length()-1] == 'd') {
117 replacement=Form(format.c_str(),TMath::Nint(value));
118 } else {
119 replacement=Form(format.c_str(),value);
120 }
121 }
122 // cout << "Replacement:" << replacement << endl;
123 line.replace(start,end-start+1,replacement);
124 }
125 ostr << line << endl;
126 }
127 ostr.close();
128 ifile.close();
129
130 return;
131}
132
133//_____________________________________________________________________________
135{
138 // run number, first event analyzed, number of events, etc.
142 Int_t* runnum;
143 Int_t* firstevent;
144 Int_t* lastevent;
145
146 THaVar* varptr;
147 varptr = gHcParms->Find("gen_run_number");
148 if(varptr) {
149 runnum = (Int_t*) varptr->GetValuePointer(); // Assume correct type
150 } else {
151 runnum = new Int_t[1];
152 gHcParms->Define("gen_run_number","Run Number", *runnum);
153 }
154 *runnum = fRun->GetNumber();
155
156 varptr = gHcParms->Find("gen_run_starting_event");
157 if(varptr) {
158 firstevent = (Int_t*) varptr->GetValuePointer(); // Assume correct type
159 } else {
160 firstevent = new Int_t[1];
161 gHcParms->Define("gen_run_starting_event","First event analyzed", *firstevent);
162 }
163 // May not agree with engine event definintions
164 *firstevent = fRun->GetFirstEvent();
165
166 varptr = gHcParms->Find("gen_event_id_number");
167 if(varptr) {
168 lastevent = (Int_t*)varptr->GetValuePointer(); // Assume correct type
169 } else {
170 lastevent = new Int_t[1];
171 gHcParms->Define("gen_event_id_number","Last event analyzed", *lastevent);
172 }
173 // Not accurate
174 *lastevent = fRun->GetFirstEvent()+fRun->GetNumAnalyzed();
175}
176
177//_____________________________________________________________________________
178
180
int Int_t
double Double_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
R__EXTERN class THaVarList * gHaVars
R__EXTERN class THaCutList * gHaCuts
ClassImp(VDC::AnalyticTTDConv) using namespace std
R__EXTERN class THcParmList * gHcParms
Definition THcGlobals.h:11
char * Form(const char *fmt,...)
THaRunBase * fRun
virtual Double_t Eval()
UInt_t GetFirstEvent() const
UInt_t GetNumAnalyzed() const
UInt_t GetNumber() const
THaVar * Define(const char *name, const Byte_t &var, const Int_t *count=nullptr)
virtual THaVar * Find(const char *name) const
const void * GetValuePointer() const
Hall C analyzer class.
Definition THcAnalyzer.h:12
void PrintReport(const char *templatefile, const char *ofile)
virtual ~THcAnalyzer()
Enhanced THaFormula for use in report files.
Definition THcFormula.h:15
const char * GetString(const std::string &name) const
Definition THcParmList.h:38
TLine * line
start
end
Int_t Nint(T x)
Double_t Abs(Double_t d)
STL namespace.