KaliVeda
Toolkit for HIC analysis
KVDataAnalysisTask.cpp
1 /*
2 $Id: KVDataAnalysisTask.cpp,v 1.10 2009/01/14 16:01:38 franklan Exp $
3 $Revision: 1.10 $
4 $Date: 2009/01/14 16:01:38 $
5 $Author: franklan $
6 */
7 
8 #include "KVDataAnalysisTask.h"
9 #include "TSystem.h"
10 #include "Riostream.h"
11 #include "TObjString.h"
12 #include "TClass.h"
13 #include "TPluginManager.h"
14 
15 using namespace std;
16 
17 ClassImp(KVDataAnalysisTask)
18 
19 
20 
24 {
25  //Default ctor.
26  fUserClass = kFALSE;
27  fBaseIsPlugin = kFALSE;
28  fStatusUpdateInterval = 1000;
29 }
30 
31 
32 
35 
37 {
38  //Copy ctor
39 #if ROOT_VERSION_CODE >= ROOT_VERSION(3,4,0)
40  obj.Copy(*this);
41 #else
42  ((KVDataAnalysisTask&) obj).Copy(*this);
43 #endif
44 }
45 
46 
47 #if ROOT_VERSION_CODE >= ROOT_VERSION(3,4,0)
48 
52 
53 void KVDataAnalysisTask::Copy(TObject& obj) const
54 #else
55 void KVDataAnalysisTask::Copy(TObject& obj)
56 #endif
57 {
58  //Copy this to obj
59  //Redefinition of KVBase::Copy
60 
61  KVBase::Copy(obj);
62  ((KVDataAnalysisTask&) obj).fPrereq = fPrereq;
63  ((KVDataAnalysisTask&) obj).fAnalyser = fAnalyser;
64  ((KVDataAnalysisTask&) obj).fBaseClass = fBaseClass;
65  ((KVDataAnalysisTask&) obj).fUserClass = fUserClass;
66  ((KVDataAnalysisTask&) obj).fBaseIsPlugin = fBaseIsPlugin;
67  ((KVDataAnalysisTask&) obj).fPluginBase = fPluginBase;
68  ((KVDataAnalysisTask&) obj).fPluginURI = fPluginURI;
69  ((KVDataAnalysisTask&) obj).fExtraAClicIncludes = fExtraAClicIncludes;
70  ((KVDataAnalysisTask&) obj).fStatusUpdateInterval = fStatusUpdateInterval;
71 }
72 
73 
74 
76 
77 KVDataAnalysisTask::~KVDataAnalysisTask()
78 {
79 }
80 
81 
82 
85 
86 void KVDataAnalysisTask::ls(Option_t*) const
87 {
88  //Print analysis task information
89  cout << "KVDataAnalysisTask : ";
90  cout << GetName() << " : ";
91  cout << GetTitle();
92  cout << " (pre-req = " << GetPrereq();
93  cout << ", analyser = " << GetDataAnalyser();
94  if (fUserClass) cout << ", base class for user analysis = " << GetUserBaseClass();
95  else if (fBaseClass != "") cout << ", default class for analysis = " << GetUserBaseClass();
96  cout << ")" << endl;
97 }
98 
99 
100 
127 
128 void KVDataAnalysisTask::SetUserBaseClass(const Char_t* base_name)
129 {
130  // Set the class from which user's analysis class must derive.
131  // This is normally read in from the following environment variable:
132  //
133  // TaskName.DataAnalysisTask.UserClass.Base: [base_name]
134  //
135  // If base_name is not the name of a known (i.e. currently contained in the ROOT
136  // dictionary class table) class, it is assumed to be the uri of a plugin class.
137  // By default, we assume that the plugin extends the KVDataAnalyser class, but
138  // this can be changed using the following syntax:
139  //
140  // TaskName.DataAnalysisTask.UserClass.Base: [uri]/[base class]
141  //
142  // Example 1:
143  // The user analysis class for task "RawAnalysis" must derive from class
144  // KVIVRawDataAnalyser which is defined in library libVAMOS.so (not loaded by default):
145  //
146  // RawAnalysis.DataAnalysisTask.UserClass.Base: IVRawDataAnalyser
147  // +Plugin.KVDataAnalyser: IVRawDataAnalyser KVIVRawDataAnalyser VAMOS "KVIVRawDataAnalyser()"
148  //
149  // Example 2:
150  // The user analysis class for task "ReconIdent" must derive from class
151  // KVIVReconIdent (itself derived from TSelector) which is defined in library libVAMOS.so (not loaded by default):
152  //
153  // ReconIdent.DataAnalysisTask.UserClass.Base: IVReconIdent/TSelector
154  // +Plugin.TSelector: IVReconIdent KVIVReconIdent VAMOS "KVIVReconIdent()"
155 
156  fBaseClass = base_name;
157  if (fBaseClass != "" && !TClass::GetClass(base_name)) {
158  // Base class is not in dictionary. Assume that base_name is a plugin.
159  fBaseIsPlugin = kTRUE;
160  KVString _base(base_name);
161  TObjArray* toks = _base.Tokenize("/");
162  if (toks->GetEntries() > 1) {
163  // base_name = uri/base
164  fPluginURI = ((TObjString*)toks->At(0))->String();
165  fPluginBase = ((TObjString*)toks->At(1))->String();
166  }
167  else {
168  // base_name = uri. default plugin base class is KVDataAnalyser
169  fPluginURI = base_name;
170  fPluginBase = "KVDataAnalyser";
171  }
172  delete toks;
173  // check plugin exists
174  TPluginHandler* ph = gPluginMgr->FindHandler(fPluginBase.Data(), fPluginURI.Data());
175  if (!ph) {
176  Error("SetUserBaseClass", "Analysis task=%s :\nNo plugin found with URI=%s for base class %s",
177  GetName(), fPluginURI.Data(), fPluginBase.Data());
178  return;
179  }
180  // get name of plugin base class that user's analysis must derive from
181  fBaseClass = ph->GetClass();
182  if (gDebug > 1) Info("SetUserBaseClass", "Analysis task=%s :\nUser analysis class derives from %s, extension of %s in plugin %s",
183  GetName(), fBaseClass.Data(), fPluginBase.Data(), fPluginURI.Data());
184  }
185 }
186 
187 
188 
195 
197 {
198  // This method checks that the base class for the user's analysis class is loaded.
199  // If this base class requires a plugin library to be loaded, it will be loaded.
200  // First we add any required extra ACliC include paths (taken from DataAnalysisTask.UserClass.ExtraACliCIncludes)
201  // If all is OK, returns kTRUE.
202  // Returns kFALSE if plugin cannot be loaded or class is simply unknown
203 
204  if (fExtraAClicIncludes != "") {
205  gSystem->AddIncludePath(fExtraAClicIncludes.Data());
206  Info("CheckUserBaseClassIsLoaded", "Added ACliC include path: %s", fExtraAClicIncludes.Data());
207  }
208  TClass* cl = TClass::GetClass(fBaseClass.Data()); // class in dictionary already ?
209  if (cl) return kTRUE;
210  if (fBaseIsPlugin) {
211  // base class is in a plugin library. load it now.
212  TPluginHandler* ph = LoadPlugin(fPluginBase.Data(), fPluginURI.Data());
213  if (ph) return kTRUE;
214  Error("CheckUserBaseClassIsLoaded", "Analysis task=%s : Failed to load plugin class=%s base=%s uri=%s",
215  GetName(), fBaseClass.Data(), fPluginBase.Data(), fPluginURI.Data());
216  }
217  else {
218  Error("CheckUserBaseClassIsLoaded", "Analysis task=%s : User analysis base class %s is unknown",
219  GetName(), fBaseClass.Data());
220  }
221  return kFALSE;
222 }
223 
224 
Base class for KaliVeda framework.
Definition: KVBase.h:142
virtual void Copy(TObject &) const
Make a copy of this object.
Definition: KVBase.cpp:394
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:793
Define and manage data analysis tasks.
Bool_t fBaseIsPlugin
true if base class for user analysis is in a plugin library
KVString fPluginBase
known base class extended by plugin library
KVString fPluginURI
uri of the plugin library containing user base class
KVString fExtraAClicIncludes
to be added to AClic include paths before compilation
virtual Bool_t CheckUserBaseClassIsLoaded()
KVString fBaseClass
base class for user analysis
virtual void Copy(TObject &) const
KVDataAnalysisTask()
Default ctor.
virtual const Char_t * GetDataAnalyser() const
virtual const Char_t * GetUserBaseClass() const
virtual const Char_t * GetPrereq() const
virtual void ls(Option_t *opt="") const
Print analysis task information.
Bool_t fUserClass
true if analysis task requires user-supplied class (derived from fBaseClass)
virtual void SetUserBaseClass(const Char_t *d)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73