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 "THaGlobals.h"
23#include "TMath.h"
24
25#include <fstream>
26#include <algorithm>
27#include <iomanip>
28#include <cstring>
29#include <iostream>
30
31using namespace std;
32
33
34// Pointer to single instance of this object
35//THcAnalyzer* THcAnalyzer::fgAnalyzer = 0;
36
37//FIXME:
38// do we need to "close" scalers/EPICS analysis if we reach the event limit?
39
40//_____________________________________________________________________________
45
46//_____________________________________________________________________________
48{
49 // Destructor.
50
51}
52
53//_____________________________________________________________________________
54void THcAnalyzer::PrintReport(const char* templatefile, const char* ofile)
55{
60 ifstream ifile;
61 ifile.open(templatefile);
62
63 if(!ifile.is_open()) {
64 cout << "Error opening template file " << templatefile << endl;
65 return;
66 }
67
68 ofstream ostr(ofile);
69
70 if(!ostr.is_open()) {
71 cout << "Error opening report output file " << ofile << endl;
72 return;
73 }
74
75 LoadInfo(); // Load some run information into gHcParms
76
77 // In principle, we should allow braces to be escaped. But for
78 // now we won't. Existing template files don't seem to output
79 // any braces
80 for(string line; getline(ifile, line);) {
81 // cout << line << endl;
82 string::size_type start;
83 while((start = line.find('{',0)) != string::npos) {
84 // cout << start << endl;
85 string::size_type end = line.find('}',start);
86 if(end==string::npos) break; // No more expressions on the line
87 string expression=line.substr(start+1,end-start-1);
88 string::size_type formatpos = expression.find(':',0);
89 string format;
90 if(formatpos != string::npos) {
91 format=expression.substr(formatpos+1);
92 expression=expression.substr(0,formatpos);
93 // cout << "|" << expression << "|" << format << "|" << endl;
94 }
95 // Should we first check if the expression can be simply a variable
96 // or index into variable?
97 // For now, first check if it is a string.
98 // If not, then evaluate as an expression.
99 string replacement;
100 if(const char *textstring=gHcParms->GetString(expression)) {
101 // cout << expression << " is a string with value " << textstring << endl;
102 if(format.empty()) format = "%s";
103 replacement=Form(format.c_str(),textstring);
104 } else {
105 THcFormula* formula = new THcFormula("temp",expression.c_str(),gHcParms,gHaVars,gHaCuts);
106 Double_t value=formula->Eval();
107 delete formula; formula = 0;
108 // If the value is close to integer and no format is defined
109 // use "%.0f" to print out integer
110 if(format.empty()) {
111 if(TMath::Abs(value-TMath::Nint(value)) < 0.0000001) {
112 format = "%.0f";
113 } else {
114 format = "%f";
115 }
116 }
117 if(format[format.length()-1] == 'd') {
118 replacement=Form(format.c_str(),TMath::Nint(value));
119 } else {
120 replacement=Form(format.c_str(),value);
121 }
122 }
123 // cout << "Replacement:" << replacement << endl;
124 line.replace(start,end-start+1,replacement);
125 }
126 ostr << line << endl;
127 }
128 ostr.close();
129 ifile.close();
130
131 return;
132}
133
134//_____________________________________________________________________________
136{
139 // run number, first event analyzed, number of events, etc.
143 Int_t* runnum;
144 Int_t* firstevent;
145 Int_t* lastevent;
146
147 THaVar* varptr;
148 varptr = gHcParms->Find("gen_run_number");
149 if(varptr) {
150 runnum = (Int_t*) varptr->GetValuePointer(); // Assume correct type
151 } else {
152 runnum = new Int_t[1];
153 gHcParms->Define("gen_run_number","Run Number", *runnum);
154 }
155 *runnum = fRun->GetNumber();
156
157 varptr = gHcParms->Find("gen_run_starting_event");
158 if(varptr) {
159 firstevent = (Int_t*) varptr->GetValuePointer(); // Assume correct type
160 } else {
161 firstevent = new Int_t[1];
162 gHcParms->Define("gen_run_starting_event","First event analyzed", *firstevent);
163 }
164 // May not agree with engine event definintions
165 *firstevent = fRun->GetFirstEvent();
166
167 varptr = gHcParms->Find("gen_event_id_number");
168 if(varptr) {
169 lastevent = (Int_t*)varptr->GetValuePointer(); // Assume correct type
170 } else {
171 lastevent = new Int_t[1];
172 gHcParms->Define("gen_event_id_number","Last event analyzed", *lastevent);
173 }
174 // Not accurate
175 *lastevent = fRun->GetFirstEvent()+fRun->GetNumAnalyzed();
176}
177
178//_____________________________________________________________________________
179
181
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.