Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4StepFactory.h"
00015
00016 #include "TClass.h"
00017 #include "TROOT.h"
00018 #include "TString.h"
00019
00020 #include "TGo4Log.h"
00021 #include "TGo4EventProcessor.h"
00022 #include "TGo4EventElement.h"
00023 #include "TGo4EventSourceParameter.h"
00024 #include "TGo4UserSourceParameter.h"
00025
00026
00027 TGo4StepFactory::TGo4StepFactory() :
00028 TGo4EventServerFactory(),
00029 fnewProcessor(),
00030 fProcessorName(),
00031 fnewOutputEvent(),
00032 fOutputEventName(),
00033 fnewInputEvent(),
00034 fInputEventName(),
00035 fnewEventSource()
00036 {
00037 TGo4Log::Debug("Create factory");
00038 }
00039
00040
00041 TGo4StepFactory::TGo4StepFactory(const char* name) :
00042 TGo4EventServerFactory(name),
00043 fnewProcessor(),
00044 fProcessorName(),
00045 fnewOutputEvent(),
00046 fOutputEventName(),
00047 fnewInputEvent(),
00048 fInputEventName()
00049 {
00050 TGo4Log::Debug("Create factory %s", name);
00051 fnewInputEvent = "";
00052 fnewOutputEvent = "";
00053 fnewProcessor = "";
00054 fInputEventName = "for MBS";
00055 fOutputEventName = "";
00056 fProcessorName = "";
00057 }
00058
00059
00060 TGo4StepFactory::~TGo4StepFactory()
00061 {
00062 TGo4Log::Debug("Delete factory %s", GetName());
00063 }
00064
00065
00066 void TGo4StepFactory::DefEventProcessor(const char* Pname, const char* Pclass)
00067 {
00068 fnewProcessor.Form("new %s(\"%s\")", Pclass, Pname);
00069 fProcessorName = Pname;
00070 }
00071
00072
00073 TGo4EventProcessor * TGo4StepFactory::CreateEventProcessor(TGo4EventProcessorParameter* par)
00074 {
00075 TGo4EventProcessor * proc = 0;
00076
00077
00078
00079 TGo4Log::Info("%s: Create event processor %s", GetName(), fProcessorName.Data());
00080 if(fnewProcessor.Length() == 0)
00081 TGo4Log::Error("No event processor was specified!");
00082 else
00083
00084 proc = (TGo4EventProcessor*) gROOT->ProcessLineFast(fnewProcessor.Data());
00085 if(proc == 0)
00086 TGo4Log::Error("Cannot create event processor: %s", fProcessorName.Data());
00087 return proc;
00088 }
00089
00090
00091 void TGo4StepFactory::DefOutputEvent(const char* Oname, const char* Oclass)
00092 {
00093
00094 fnewOutputEvent.Form("new %s(\"%s\")",Oclass,Oname);
00095 fOutputEventName = Oname;
00096 }
00097
00098
00099 TGo4EventElement * TGo4StepFactory::CreateOutputEvent()
00100 {
00101 TGo4EventElement * Oevent = 0;
00102
00103 TGo4Log::Info("%s: Create output event %s", GetName(), fOutputEventName.Data());
00104
00105 if(fnewOutputEvent.Length() == 0)
00106 TGo4Log::Error("No output event was specified!");
00107 else
00108 Oevent = (TGo4EventElement*) gROOT->ProcessLineFast(fnewOutputEvent.Data());
00109 if(Oevent == 0)
00110 TGo4Log::Error("Cannot create output event: %s", fOutputEventName.Data());
00111 return Oevent;
00112 }
00113
00114
00115 void TGo4StepFactory::DefInputEvent(const char* Iname, const char* Iclass)
00116 {
00117 fnewInputEvent.Form("new %s(\"%s\")", Iclass, Iname);
00118 fInputEventName = Iname;
00119 }
00120
00121
00122 TGo4EventElement* TGo4StepFactory::CreateInputEvent()
00123 {
00124 TGo4Log::Info("%s: Create input event %s", GetName(), fInputEventName.Data());
00125
00126 if(fnewInputEvent.Length() == 0)
00127 return TGo4EventServerFactory::CreateInputEvent();
00128
00129 TGo4EventElement* Ievent = (TGo4EventElement*) gROOT->ProcessLineFast(fnewInputEvent.Data());
00130 if(Ievent == 0)
00131 TGo4Log::Error("Cannot create input event: %s", fInputEventName.Data());
00132 return Ievent;
00133 }
00134
00135
00136 void TGo4StepFactory::DefUserEventSource(const char* Sclass)
00137 {
00138 #ifdef WIN32
00139 const char* ptr_arg = "0x%x";
00140 #else
00141 const char* ptr_arg = "%p";
00142 #endif
00143
00144 fnewEventSource.Form("new %s((%s*)%s)", Sclass, TGo4UserSourceParameter::Class()->GetName(), ptr_arg);
00145 }
00146
00147
00148 TGo4EventSource* TGo4StepFactory::CreateEventSource(TGo4EventSourceParameter* par)
00149 {
00150 if ((fnewEventSource.Length()>0) && par->InheritsFrom(TGo4UserSourceParameter::Class())) {
00151
00152 TGo4Log::Info("%s: Create input source %s", GetName(), fnewEventSource.Data());
00153
00154 TString arg = TString::Format(fnewEventSource.Data(), par);
00155
00156 TGo4EventSource* source = (TGo4EventSource*) gROOT->ProcessLineFast(arg.Data());
00157
00158 if (source) return source;
00159
00160 TGo4Log::Error("Cannot create event source with cmd: %s", fnewEventSource.Data());
00161 }
00162
00163 return TGo4EventServerFactory::CreateEventSource(par);
00164 }