GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4StepFactory.cxx
Go to the documentation of this file.
1 // $Id$
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 fuer 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 "TGo4StepFactory.h"
15 
16 #include "TClass.h"
17 #include "TROOT.h"
18 #include "TString.h"
19 
20 #include "TGo4Log.h"
21 #include "TGo4EventElement.h"
24 #include "TGo4UserStoreParameter.h"
25 
26 //***********************************************************
29 {
30  TGo4Log::Debug("Create factory");
31 }
32 
33 //***********************************************************
36 {
37  TGo4Log::Debug("Create factory %s", name);
38  fnewInputEvent = "";
39  fnewOutputEvent = "";
40  fnewProcessor = "";
41  fInputEventName = "for MBS";
42  fOutputEventName = "";
43  fProcessorName = "";
44 }
45 
46 //***********************************************************
48 {
49  TGo4Log::Debug("Delete factory %s", GetName());
50 }
51 
52 //-----------------------------------------------------------
53 void TGo4StepFactory::DefEventProcessor(const char *Pname, const char *Pclass)
54 {
55  fnewProcessor.Form("new %s(\"%s\")", Pclass, Pname);
56  fProcessorName = Pname;
57 }
58 
59 //-----------------------------------------------------------
61 {
62  TGo4EventProcessor *proc = nullptr;
63 
64  // par is the object specified as last argument creating the step in TAnalysis
65  // only info we can get is an ID
66  TGo4Log::Info("%s: Create event processor %s", GetName(), fProcessorName.Data());
67  if(fnewProcessor.IsNull())
68  TGo4Log::Error("No event processor was specified!");
69  else
70  // create event processor by macro
71  proc = (TGo4EventProcessor *) gROOT->ProcessLineFast(fnewProcessor.Data());
72  if(!proc)
73  TGo4Log::Error("Cannot create event processor: %s", fProcessorName.Data());
74  return proc;
75 }
76 
77 //-----------------------------------------------------------
78 void TGo4StepFactory::DefOutputEvent(const char *Oname, const char *Oclass)
79 {
80  // need not to register object, because it is done by Go4 framework
81  fnewOutputEvent.Form("new %s(\"%s\")",Oclass,Oname);
82  fOutputEventName = Oname;
83 }
84 
85 //-----------------------------------------------------------
87 {
88  TGo4EventElement *event = nullptr;
89 
90  TGo4Log::Info("%s: Create output event %s", GetName(), fOutputEventName.Data());
91 
92  if(fnewOutputEvent.IsNull())
93  TGo4Log::Error("No output event was specified!");
94  else
95  event = (TGo4EventElement *) gROOT->ProcessLineFast(fnewOutputEvent.Data());
96  if(!event)
97  TGo4Log::Error("Cannot create output event: %s", fOutputEventName.Data());
98  return event;
99 }
100 
101 //-----------------------------------------------------------
102 void TGo4StepFactory::DefInputEvent(const char *Iname, const char *Iclass)
103 {
104  fnewInputEvent.Form("new %s(\"%s\")", Iclass, Iname);
105  fInputEventName = Iname;
106 }
107 
108 //-----------------------------------------------------------
110 {
111  TGo4Log::Info("%s: Create input event %s", GetName(), fInputEventName.Data());
112 
113  if(fnewInputEvent.IsNull())
115 
116  TGo4EventElement *event = (TGo4EventElement *) gROOT->ProcessLineFast(fnewInputEvent.Data());
117  if(!event)
118  TGo4Log::Error("Cannot create input event: %s", fInputEventName.Data());
119  return event;
120 }
121 
122 //-----------------------------------------------------------
123 void TGo4StepFactory::DefUserEventSource(const char *Sclass)
124 {
125  #ifdef _MSC_VER
126  const char *ptr_arg = "0x%x";
127  #else
128  const char *ptr_arg = "%p";
129  #endif
130 
131  fnewEventSource.Form("new %s((%s*)%s)", Sclass, TGo4UserSourceParameter::Class()->GetName(), ptr_arg);
132 }
133 
134 //-----------------------------------------------------------
135 void TGo4StepFactory::DefUserEventStore(const char *Sclass)
136 {
137  #ifdef _MSC_VER
138  const char *ptr_arg = "0x%x";
139  #else
140  const char *ptr_arg = "%p";
141  #endif
142 
143  fnewEventStore.Form("new %s((%s*)%s)", Sclass, TGo4UserStoreParameter::Class()->GetName(), ptr_arg);
144 }
145 
146 
147 //-----------------------------------------------------------
149 {
150  if ((fnewEventSource.Length() > 0) && par->InheritsFrom(TGo4UserSourceParameter::Class())) {
151 
152  TGo4Log::Info("%s: Create input source %s", GetName(), fnewEventSource.Data());
153 
154  TString arg = TString::Format(fnewEventSource.Data(), par);
155 
156  TGo4EventSource *source = (TGo4EventSource *) gROOT->ProcessLineFast(arg.Data());
157 
158  if (source) return source;
159 
160  TGo4Log::Error("Cannot create event source with cmd: %s", fnewEventSource.Data());
161  }
162 
164 }
165 
166 //-----------------------------------------------------------
168 {
169  if ((fnewEventStore.Length() > 0) && par->InheritsFrom(TGo4UserStoreParameter::Class())) {
170 
171  TGo4Log::Info("%s: Create event store %s", GetName(), fnewEventStore.Data());
172 
173  TString arg = TString::Format(fnewEventStore.Data(), par);
174 
175  TGo4EventStore *store = (TGo4EventStore *) gROOT->ProcessLineFast(arg.Data());
176 
177  if (store) return store;
178 
179  TGo4Log::Error("Cannot create event store with cmd: %s", fnewEventStore.Data());
180  }
181 
183 }
TGo4EventSource * CreateEventSource(TGo4EventSourceParameter *par) override
static void Info(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:294
void DefUserEventSource(const char *Sclass)
TString fOutputEventName
void DefEventProcessor(const char *Pname, const char *Pclass)
TGo4EventSource * CreateEventSource(TGo4EventSourceParameter *par) override
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
void DefOutputEvent(const char *Oname, const char *Oclass)
TGo4EventStore * CreateEventStore(TGo4EventStoreParameter *par) override
TString fnewEventStore
TString fProcessorName
TGo4EventProcessor * CreateEventProcessor(TGo4EventProcessorParameter *par) override
TGo4EventStore * CreateEventStore(TGo4EventStoreParameter *par) override
static void Error(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:320
TString fnewEventSource
TString fnewOutputEvent
void DefUserEventStore(const char *Sclass)
TGo4EventElement * CreateOutputEvent() override
TString fInputEventName
TGo4EventElement * CreateInputEvent() override
virtual ~TGo4StepFactory()
void DefInputEvent(const char *Iname, const char *Iclass)
TString fnewInputEvent
TGo4EventElement * CreateInputEvent() override