GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TYYYAnalysis.cxx
Go to the documentation of this file.
1 // $Id: TYYYAnalysis.cxx 930 2013-01-24 16:10:10Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum f�r Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TYYYAnalysis.h"
15 
16 #include <stdlib.h>
17 
18 #include "TCanvas.h"
19 #include "TH1.h"
20 #include "TFile.h"
21 
22 #include "Go4EventServer.h"
23 #include "TGo4AnalysisStep.h"
24 #include "TGo4Version.h"
25 
26 #include "TYYYUnpackEvent.h"
27 #include "TYYYParameter.h"
28 #include "TYYYRawEvent.h"
29 #include "TGo4StepFactory.h"
30 
31 //***********************************************************
33  TGo4Analysis(),
34  fRawEvent(0),
35  fUnpackEvent(0),
36  fSize(0),
37  fPar(0),
38  fEvents(0)
39 {
40  TGo4Log::Error("Wrong constructor TYYYAnalysis()!");
41 }
42 //***********************************************************
43 // this constructor is used
44 TYYYAnalysis::TYYYAnalysis(int argc, char** argv) :
45  TGo4Analysis(argc, argv),
46  fRawEvent(0),
47  fUnpackEvent(0),
48  fSize(0),
49  fPar(0),
50  fEvents(0)
51 {
53  TGo4Log::Error("Go4 version mismatch");
54  exit(-1);
55  }
56 
57  TGo4Log::Info("Create TYYYAnalysis %s", GetName());
58 
59  // the step definitions can be changed in the GUI
60  // first step definitions:
61  // the name of the step can be used later to get event objects
62  TGo4StepFactory* factory1 = new TGo4StepFactory("Unpack-factory");
63 
64  factory1->DefUserEventSource("TYYYEventSource"); // class name of user event source
65  factory1->DefInputEvent("RawEvent","TYYYRawEvent"); // object name, class name
66  factory1->DefEventProcessor("UnpackProc", "TYYYUnpackProc");// object name, class name
67  factory1->DefOutputEvent("UnpackEvent", "TYYYUnpackEvent"); // object name, class name
68 
69  TGo4UserSourceParameter* source1 = new TGo4UserSourceParameter("befoil50.scf");
70  TGo4FileStoreParameter* store1 = new TGo4FileStoreParameter(Form("%sOutput", argv[0]));
71  store1->SetOverwriteMode(kTRUE);
72  TGo4AnalysisStep* step1 = new TGo4AnalysisStep("Unpack",factory1,source1,store1,0);
73 
74  step1->SetSourceEnabled(kTRUE);
75  step1->SetStoreEnabled(kFALSE); // disable output
76  step1->SetProcessEnabled(kTRUE);
77  step1->SetErrorStopEnabled(kTRUE);
78  AddAnalysisStep(step1);
79 
80  // uncomment following line to define custom passwords for analysis server
81  // DefineServerPasswords("YYYadmin", "YYYctrl", "YYYview");
82 
84  // At this point, autosave file has not yet been read!
85  // Therefore parameter values set here will be overwritten
86  // if an autosave file is there.
87  fPar = new TYYYParameter("YYYPar1");
88  fPar->frP1 = 100;
89  fPar->frP2 = 200;
91 
92  if (GetCanvas("TestCanvas")==0) {
93  TCanvas* mycan = new TCanvas("TestCanvas","Does this work?");
94  mycan->Divide(2,2);
95  AddCanvas(mycan);
96  }
97 }
98 
99 //***********************************************************
101 {
102  TGo4Log::Info("TYYYAnalysis: Delete");
103 }
104 //***********************************************************
105 
106 //-----------------------------------------------------------
108 {
109  TGo4Log::Info("TYYYAnalysis: PreLoop");
110  // we update the pointers to the current event structures here:
111  fRawEvent = dynamic_cast<TYYYRawEvent*> (GetInputEvent("Unpack")); // of step "Unpack"
112  fUnpackEvent = dynamic_cast<TYYYUnpackEvent*> (GetOutputEvent("Unpack"));
113  fEvents=0;
114 
115  // create histogram for UserEventFunc
116  // At this point, the histogram has been restored from autosave file if any.
117  fSize=(TH1D*)GetHistogram("Eventsize");
118  if(fSize==0) {
119  // no autosave read, create new and register
120  fSize = new TH1D ("Eventsize", "Read columns",160,1,160);
122  }
123  ClearObjects("Histograms"); // reset all histograms to 0 before run
124  // name specifies folder to clear
125  return 0;
126 }
127 //-----------------------------------------------------------
129 {
130  TGo4Log::Info("TYYYAnalysis: PostLoop");
131  TGo4Log::Info("Total events: %d", fEvents);
132  TCanvas* can = GetCanvas("TestCanvas");
133  if(can) {
134  TH1* hx = GetHistogram("Xfinal");
135  TH1* hy = GetHistogram("Yfinal");
136  TH1* hvx = GetHistogram("Vxfinal");
137  TH1* hvy = GetHistogram("Vyfinal");
138  can->cd(1);
139  if(hx) hx->Draw();
140  can->cd(2);
141  if(hy) hy->Draw();
142  can->cd(3);
143  if(hvx) hvx->Draw();
144  can->cd(4);
145  if(hvy) hvy->Draw();
146  }
147 
148  fUnpackEvent = 0; // reset to avoid invalid pointer if analysis is changed in between
149  fRawEvent = 0;
150  fEvents=0;
151  return 0;
152 }
153 
154 //-----------------------------------------------------------
156 {
158  Int_t value=0;
159  if(fRawEvent) value = fRawEvent->GetColumns();
160  fSize->Fill(value); // fill histogram
161  fEvents++;
162  return 0;
163 }
Bool_t AddCanvas(TCanvas *can, const char *subfolder=0)
Bool_t AddParameter(TGo4Parameter *par, const char *subfolder=0)
Int_t GetColumns() const
Definition: TYYYRawEvent.h:44
static Bool_t CheckVersion(Int_t version)
Definition: TGo4Version.cxx:42
void DefUserEventSource(const char *Sclass)
void DefEventProcessor(const char *Pname, const char *Pclass)
virtual Int_t UserPostLoop()
friend class TGo4AnalysisStep
TYYYRawEvent * fRawEvent
Definition: TYYYAnalysis.h:33
TGo4EventElement * GetOutputEvent()
Bool_t AddHistogram(TH1 *his, const char *subfolder=0, Bool_t replace=kTRUE)
void SetSourceEnabled(Bool_t on=kTRUE)
virtual ~TYYYAnalysis()
void SetOverwriteMode(Bool_t over=kTRUE)
TH1 * GetHistogram(const char *name)
TGo4EventElement * GetInputEvent(const char *stepname)
TCanvas * GetCanvas(const char *name)
TH1D * fSize
Definition: TYYYAnalysis.h:35
virtual Int_t UserPreLoop()
void DefOutputEvent(const char *Oname, const char *Oclass)
Bool_t ClearObjects(const char *name)
#define __GO4BUILDVERSION__
Definition: TGo4Version.h:24
virtual const char * GetName() const
void SetStoreEnabled(Bool_t on=kTRUE)
virtual Int_t UserEventFunc()
void SetProcessEnabled(Bool_t on=kTRUE)
Bool_t AddAnalysisStep(TGo4AnalysisStep *next)
void SetErrorStopEnabled(Bool_t on)
TYYYUnpackEvent * fUnpackEvent
Definition: TYYYAnalysis.h:34
void DefInputEvent(const char *Iname, const char *Iclass)
static void Error(const char *text,...)
Definition: TGo4Log.cxx:309
static void Info(const char *text,...)
Definition: TGo4Log.cxx:283
TYYYParameter * fPar
Definition: TYYYAnalysis.h:36