Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaInterface.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 12/05/2000
2
4//
5// THaInterface
6//
7// THaInterface is the interactive interface to the Hall A Analyzer.
8// It allows interactive access to all analyzer classes as well as
9// all of standard ROOT.
10//
12
13#include "TROOT.h"
14#include "TClass.h"
15#include "TError.h"
16#include "TSystem.h"
17#include "TString.h"
18#include "TRegexp.h"
19#include "TTree.h"
20#include "THaInterface.h"
21#include "TInterpreter.h"
22#include "THaVarList.h"
23#include "THaCutList.h"
24#include "CodaRawDecoder.h"
25#include "THaGlobals.h"
26#include "THaAnalyzer.h"
27//#include "THaFileDB.h"
28#include "Textvars.h" // for gHaTextvars
29#include "ha_compiledata.h"
30#include <cstring>
31#include <sstream>
32#include <iomanip>
33
34using namespace std;
35
36THaVarList* gHaVars = nullptr; // List of symbolic analyzer variables
37THaCutList* gHaCuts = nullptr; // List of global analyzer cuts/tests
38TList* gHaApps = nullptr; // List of Apparatuses
39TList* gHaPhysics = nullptr; // List of physics modules
40TList* gHaEvtHandlers = nullptr; // List of event handlers
41THaRunBase* gHaRun = nullptr; // The currently active run
42TClass* gHaDecoder = nullptr; // Class(!) of decoder to use
43THaDB* gHaDB = nullptr; // Database system to use
44
45THaInterface* THaInterface::fgAint = nullptr; // Pointer to this interface
46
48
49//_____________________________________________________________________________
50THaInterface::THaInterface( const char* appClassName, int* argc, char** argv,
51 void* options, int numOptions, Bool_t noLogo ) :
52 TRint( appClassName, argc, argv, options, numOptions, true )
53{
54 // Create the Hall A analyzer application environment. The THaInterface
55 // environment provides an interface to the the interactive ROOT system
56 // via inheritance of TRint as well as access to the Hall A analyzer classes.
57
58 if( fgAint ) {
59 Error("THaInterface", "only one instance of THaInterface allowed");
60 MakeZombie();
61 return;
62 }
63
64 if( !noLogo )
66
67 THaInterface::SetPrompt("analyzer [%d] ");
68 gHaVars = new THaVarList;
69 gHaCuts = new THaCutList( gHaVars );
70 gHaApps = new TList;
71 gHaPhysics = new TList;
73 // Use the standard CODA file decoder by default
75 // File-based database by default
76 // gHaDB = new THaFileDB();
77 gHaTextvars = new Podd::Textvars;
78
79 // Set the maximum size for a file written by Podd contained by the TTree
80 // putting it to 1.5 GB, down from the default 1.9 GB since something odd
81 // happens for larger files
82 //FIXME: investigate
83 TTree::SetMaxTreeSize(1500000000);
84
85 // Make the Podd header directory(s) available so scripts don't have to
86 // specify an explicit path.
87 // If $ANALYZER defined, we take our includes from there, otherwise we fall
88 // back to the compile-time directories (which may have moved!)
89 TString s = gSystem->Getenv("ANALYZER");
90 if( s.IsNull() ) {
91 s = HA_INCLUDEPATH "";
92 } else {
93 // Give preference to $ANALYZER/include
94 TString p = s+"/include";
95 void* dp = gSystem->OpenDirectory(p);
96 if( dp ) {
98 s = p;
99 } else
100 s = s+"/src " + s+"/hana_decode ";
101 }
102 // Directories names separated by blanks.
103 // FIXME: allow blanks
104 TRegexp re("[^ ]+");
105 TString ss = s(re);
106 while( !ss.IsNull() ) {
107 // Only add dirs that exist
108 void* dp = gSystem->OpenDirectory(ss);
109 if( dp ) {
110 gInterpreter->AddIncludePath(ss);
112 }
113 s.Remove(0,s.Index(re)+ss.Length());
114 ss = s(re);
115 }
116
117 // Because of lack of foresight, the analyzer uses TDatime objects,
118 // which are kept in localtime() and hence are not portable, and also
119 // uses localtime() directly in several places. As a result, database
120 // lookups depend on the timezone of the machine that the replay is done on!
121 // If this timezone is different from the one in which the data were taken,
122 // mismatches may occur. This is bad.
123 // FIXME: Use TTimeStamp to keep time in UTC internally.
124 // To be done in version 1.6
125 //
126 // As a temporary workaround, we assume that all data were taken in
127 // US/Eastern time, and that the database has US/Eastern timestamps.
128 // This is certainly true for all JLab production data..
129 fgTZ = gSystem->Getenv("TZ");
130 gSystem->Setenv("TZ","US/Eastern");
131
132
133 fgAint = this;
134}
135
136//_____________________________________________________________________________
138{
139 // Destructor
140
141 if( fgAint == this ) {
142 // Restore the user's original TZ
143 gSystem->Setenv("TZ",fgTZ.Data());
144 // Clean up the analyzer object if defined
146 // Delete all global lists and objects contained in them
147 delete gHaTextvars; gHaTextvars=nullptr;
148 // delete gHaDB; gHaDB = nullptr;
149 delete gHaPhysics; gHaPhysics=nullptr;
150 delete gHaEvtHandlers; gHaEvtHandlers=nullptr;
151 delete gHaApps; gHaApps=nullptr;
152 delete gHaVars; gHaVars=nullptr;
153 delete gHaCuts; gHaCuts=nullptr;
154 fgAint = nullptr;
155 }
156}
157
158//_____________________________________________________________________________
160{
161 // Print the Hall A analyzer logo on standard output.
162
163 static const char* months[] = {"???","Jan","Feb","Mar","Apr","May",
164 "Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
165 const char* root_version = gROOT->GetVersion();
166 Int_t idatqq = gROOT->GetVersionDate();
167 Int_t iday = idatqq%100;
168 Int_t imonth = (idatqq/100)%100;
169 if( imonth < 1 || imonth > 12 ) // should never happen, but to be safe,
170 imonth = 0; // print "???"
171 Int_t iyear = (idatqq/10000);
172 Int_t mille = iyear;
173 if ( iyear < 90 )
174 mille = 2000 + iyear;
175 else if ( iyear < 1900 )
176 mille = 1900 + iyear;
177 ostringstream ostr;
178 ostr << setw(2) << setfill('0') << iday << setfill(' ');
179 ostr << " " << months[imonth] << " " << mille;
180 TString tmp(ostr.str().c_str());
181 const char* root_date = tmp.Data();
182
183 if( !lite ) {
184 Printf(" ************************************************");
185 Printf(" * *");
186 Printf(" * W E L C O M E to the *");
187 Printf(" * H A L L A C++ A N A L Y Z E R *");
188 Printf(" * *");
189 Printf(" * Release %16s %18s *", HA_VERSION "", GetHaDate());
190 Printf(" * Based on ROOT %10s %18s *", root_version, root_date);
191 if( strstr(HA_VERSION "", "-dev") || strstr(HA_VERSION "", "alpha") ||
192 strstr(HA_VERSION "", "beta") || strstr(HA_VERSION "", "rc") )
193 Printf(" * Development version *");
194 Printf(" * *");
195 Printf(" * For information visit *");
196 Printf(" * https://redmine.jlab.org/projects/podd/wiki/ *");
197 Printf(" * *");
198 Printf(" ************************************************");
199 }
200
201 gInterpreter->PrintIntro();
202}
203
204//_____________________________________________________________________________
206{
207 // Get class of the current decoder
208 return gHaDecoder;
209}
210
211//_____________________________________________________________________________
213{
214 // Get software version
215 return HA_VERSION "";
216}
217
218//_____________________________________________________________________________
220{
221 // Extract date from git format=%cD long date string. For example,
222 // "Tue, 29 Mar 2022 22:29:10 -0400" -> "29 Mar 2022"
223 TString d{long_date};
224 Ssiz_t pos = 0, i = 0, start = 0;
225 while( (pos = d.Index(" ", pos)) != kNPOS ) {
226 ++i;
227 if( i == 4 )
228 return d(start, pos-start);
229 while( d[++pos] == ' ' ); // d[d.Length()] is always '\0', so this is safe
230 if( i == 1 )
231 start = pos;
232 }
233 return d;
234}
235
236//_____________________________________________________________________________
238{
239 static TString ha_date;
240
241 if( ha_date.IsNull() ) {
242 bool use_buildtime = true;
243 size_t len = strlen(HA_GITREV "");
244 if( len > 0 ) {
245 const char* gitrev = HA_GITREV "";
246 use_buildtime = (len > 6 && strcmp(gitrev + len - 6, "-dirty") == 0);
247 }
248 if( use_buildtime )
249 ha_date = extract_short_date(HA_BUILDTIME "");
250 else
251 ha_date = extract_short_date(HA_SOURCETIME "");
252 }
253 return ha_date.Data();
254}
255
256//_____________________________________________________________________________
258{
259 // Get software version string (printed by analyzer -v)
260
261 static TString version_string;
262
263 if( version_string.IsNull() ) {
264 ostringstream ostr;
265 ostr << "Podd " << HA_VERSION "";
266 if( strlen(HA_GITREV "") > 0 )
267 ostr << " git@" << HA_GITREV "";
268 ostr << " " << GetHaDate() << endl;
269 ostr << "Built for " << HA_OSVERS "";
270 ostr << " using " << HA_CXXSHORTVERS "";
271 if( strlen(HA_ROOTVERS "") )
272 ostr << ", ROOT " << HA_ROOTVERS "";
273 version_string = ostr.str().c_str();
274 }
275 return version_string.Data();
276}
277
278//_____________________________________________________________________________
280{
281 // Set the type of decoder to be used. Make sure the specified class
282 // actually inherits from the standard THaEvData decoder.
283 // Returns the decoder class (i.e. its argument) or nullptr if error.
284
285 const char* const here = "THaInterface::SetDecoder";
286
287 if( !c ) {
288 ::Error(here, "argument is nullptr");
289 return nullptr;
290 }
291 if( !c->InheritsFrom("THaEvData")) {
292 ::Error(here, "decoder class must inherit from THaEvData");
293 return nullptr;
294 }
295
296 return gHaDecoder = c;
297}
298
299//_____________________________________________________________________________
300const char* THaInterface::SetPrompt( const char* newPrompt )
301{
302 // Make sure the prompt is and stays "analyzer [%d]". ROOT 6 resets the
303 // interpreter prompt for every line without respect to any user-set
304 // default prompt.
305
306 TString s;
307 if( newPrompt ) {
308 s = newPrompt;
309 if( s.Index("root") == 0 )
310 s.Replace(0,4,"analyzer");
311 }
312 return TRint::SetPrompt(s.Data());
313}
314
315//_____________________________________________________________________________
int Int_t
#define d(i)
#define c(i)
bool Bool_t
const Ssiz_t kNPOS
int Ssiz_t
winID h TVirtualViewer3D TVirtualGLPainter p
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 UChar_t len
R__EXTERN class TList * gHaEvtHandlers
Definition THaGlobals.h:15
R__EXTERN class TList * gHaApps
Definition THaGlobals.h:13
R__EXTERN class THaVarList * gHaVars
Definition THaGlobals.h:11
R__EXTERN class TList * gHaPhysics
Definition THaGlobals.h:14
R__EXTERN class TClass * gHaDecoder
Definition THaGlobals.h:17
R__EXTERN class THaCutList * gHaCuts
Definition THaGlobals.h:12
TClass * gHaDecoder
THaCutList * gHaCuts
static TString fgTZ
TList * gHaEvtHandlers
TList * gHaPhysics
THaDB * gHaDB
TList * gHaApps
THaRunBase * gHaRun
THaVarList * gHaVars
static const char *const here
Definition THaVar.cxx:64
#define gInterpreter
#define gROOT
void Printf(const char *fmt,...)
R__EXTERN TSystem * gSystem
static THaAnalyzer * GetInstance()
Definition THaAnalyzer.h:97
THaInterface(const char *appClassName, int *argc, char **argv, void *options=nullptr, int numOptions=0, Bool_t noLogo=false)
static const char * GetVersion()
virtual void PrintLogo(Bool_t lite=false)
static const char * GetVersionString()
static TClass * GetDecoder()
static TString extract_short_date(const char *long_date)
virtual ~THaInterface()
static TClass * SetDecoder(TClass *c)
static const char * GetHaDate()
virtual const char * SetPrompt(const char *newPrompt)
static THaInterface * fgAint
static TClass * Class()
virtual void Error(const char *method, const char *msgfmt,...) const
void MakeZombie()
virtual const char * SetPrompt(const char *newPrompt)
Ssiz_t Length() const
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
const char * Data() const
Bool_t IsNull() const
TString & Remove(EStripType s, char c)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual void FreeDirectory(void *dirp)
virtual void * OpenDirectory(const char *name)
virtual const char * Getenv(const char *env)
virtual void Setenv(const char *name, const char *value)
start
STL namespace.
ClassImp(TPyArg)