9 #include "KVDataAnalyser.h"
10 #include "KVDataAnalysisTask.h"
11 #include "KVDataSetManager.h"
16 #include "KVBatchSystemManager.h"
49 fWorkDirInit = fWorkDirEnd = 0;
52 fProofMode = EProofMode::None;
56 fUseBaseClassSubmitTask =
kFALSE;
64 KVDataAnalyser::~KVDataAnalyser()
69 if (gDataAnalyser ==
this)gDataAnalyser =
nullptr;
84 fUserClassOptions =
"";
86 fBatchSystem =
nullptr;
89 fProofMode = EProofMode::None;
109 if (CheckTaskVariables()) {
112 fBatchSystem->SubmitTask(
this);
114 if (
BatchMode() && fBatchSystem && !fParent) fBatchSystem->Print(
"log");
115 if (!RunningInLaunchDirectory() && fParent) {
119 ScanWorkingDirectory(&fWorkDirInit);
121 if (!PreSubmitCheck())
return;
131 if (fUseBaseClassSubmitTask)
136 if (!RunningInLaunchDirectory() && fParent) {
140 ScanWorkingDirectory(&fWorkDirEnd);
143 CopyAnalysisResultsToLaunchDirectory();
145 if (
BatchMode() && fBatchSystem && !fParent) {
179 if (NeedToChooseWhatToDo())
181 else if (NeedToChooseWhatToAnalyse())
182 ChooseWhatToAnalyse();
205 if (
BatchMode()) ReadBatchEnvFile(
Form(
".%s", GetBatchName()));
209 if (fTask->WithUserClass() && fUserClass !=
ClassName()) {
211 if (fUserClass ==
"") {
216 if (!CheckIfUserClassIsValid(fUserClassAlternativeBaseClass)) {
217 cout <<
"============> Warning <=============" << endl;
218 cout << GetUserClass() <<
" is not a valid " << fTask->GetUserBaseClass() << endl;
219 cout <<
"Analysis aborted." << endl;
220 cout <<
"====================================" << endl;
226 if (nbEventToRead < 0) {
227 ChooseNbEventToRead();
239 if (NeedToChooseWhatToDo()) {
243 if (NeedToChooseWhatToAnalyse()) {
296 fIncludes +=
id.
Data();
298 if (!curIncDir.
Contains(
id.Data())) {
299 cout <<
"Include path \"" <<
id.Data() <<
"\" added." << endl;
334 while (!slib.
End() && !loaded) {
337 Info(
"SetUserLibraries",
"%s already load",
id.Data());
343 Info(
"SetUserLibraries",
"Library \"%s\"added.",
id.Data());
346 fLibraries +=
id.Data();
362 SetNbEventToRead(-1);
363 while (nbEventToRead < 0) {
364 cout <<
"Give the number of events to read [<RET>=all]:" << endl;
375 Data() <<
"\" is not a number. Please retry." << endl;
412 while (!fUserClass.Length()) {
413 cout <<
"Give the name of the analysis class derived from " << fTask->GetUserBaseClass() <<
":" << endl;
414 fUserClass.ReadLine(cin);
472 TObject* o = GetInstanceOfUserClass(alternative_base_class);
520 fBatchSystem =
nullptr;
559 if (!fTask->CheckUserBaseClassIsLoaded())
return 0x0;
562 TPluginHandler* ph =
gROOT->GetPluginManager()->FindHandler(fTask->GetUserBaseClass(), fUserClass.Data());
570 if (DoUserClassFilesExist()) {
573 cmd.
Form(
".L %s%s", fUserClassImp.Data(), GetACliCMode());
576 cl =
gROOT->GetClass(fUserClass.Data());
579 Info(
"GetInstanceOfUserClass",
"Class %s is unknown and no source files available",
585 Info(
"GetInstanceOfUserClass",
"Compilation of class %s failed. Correct the mistakes and try again",
589 if (!cl->GetBaseClass(fTask->GetUserBaseClass())) {
591 if (alternative_base_class ==
"") {
592 Info(
"GetInstanceOfUserClass",
"Class %s does not inherit from correct base class (%s), or compilation of class %s failed. Correct the mistakes and try again",
593 fUserClass.Data(), fTask->GetUserBaseClass(), fUserClass.Data());
597 bool got_good_base =
false;
599 alternative_base_class.
Begin(
",");
600 while (!alternative_base_class.
End()) {
601 good_base = alternative_base_class.
Next(
kTRUE);
602 if (cl->GetBaseClass(good_base)) {
603 got_good_base =
true;
608 Info(
"GetInstanceOfUserClass",
"Class %s inherits from alternative base class %s: OK!",
609 fUserClass.Data(), good_base.
Data());
611 Info(
"GetInstanceOfUserClass",
"Class %s does not inherit from task-defined base class (%s) or any provided alternative base classes (%s), or compilation of class %s failed. Correct the mistakes and try again",
612 fUserClass.Data(), fTask->GetUserBaseClass(), alternative_base_class.
Data(), fUserClass.Data());
620 Info(
"GetInstanceOfUserClass",
"Found plugin handler for class %s",
625 Info(
"GetInstanceOfUserClass",
"KVBase::LoadPlugin failed for %s", fUserClass.Data());
631 if (obj->
InheritsFrom(fTask->GetUserBaseClass()))
return obj;
632 Info(
"GetInstanceOfUserClass",
"%s does not inherit from %s", fUserClass.Data(), fTask->GetUserBaseClass());
635 Info(
"GetInstanceOfUserClass",
"constructor not OK for %s", fUserClass.Data());
658 fUserClassIsOK = CheckIfUserClassIsValid();
660 fUserClassIsOK =
kTRUE;
680 OpenBatchInfoFile(
Form(
".%s", jobname.
Data()));
682 fBatchEnv->SetValue(
"BatchSystem", fBatchSystem->GetName());
683 fBatchSystem->WriteBatchEnvFile(GetBatchInfoFile());
685 fBatchEnv->SetValue(
"AnalysisTask", fTask->GetType());
687 if (fTask->WithUserClass()) {
688 fBatchEnv->SetValue(
"UserClass", GetUserClass());
689 if (fUserClassImp ==
"" || fUserClassDec ==
"") {
690 if (!DoUserClassFilesExist()) {
691 Warning(
"WriteBatchEnvFile",
"Source files for user class %s do not exist. Job will not work.",
695 fBatchEnv->SetValue(
"UserClassOptions", fUserClassOptions);
696 fBatchEnv->SetValue(
"UserClassImp", fUserClassImp);
697 fBatchEnv->SetValue(
"UserClassDec", fUserClassDec);
700 if (fUserClassOptions !=
"") fBatchEnv->SetValue(
"UserClassOptions", fUserClassOptions);
702 fBatchEnv->SetValue(
"NbToRead", (
Double_t)nbEventToRead);
704 if (fIncludes.Length()) {
705 fBatchEnv->SetValue(
"UserIncludes", fIncludes.Data());
707 if (fLibraries.Length()) {
708 fBatchEnv->SetValue(
"UserLibraries", fLibraries.Data());
711 if (save) fBatchEnv->SaveLevel(
kEnvUser);
732 if (!GetAnalysisTask()) {
736 KVString val = fBatchEnv->GetValue(
"AnalysisTask",
"");
737 SetAnalysisTask(
nullptr);
739 if (!gDataSetManager) {
741 gDataSetManager->
Init();
745 Error(
"ReadBatchEnvFile",
"Name of analysis task not given");
748 if (!GetAnalysisTask()) {
749 Error(
"ReadBatchEnvFile",
"Analysis task \"%s\"not found for dataset %s",
755 nbEventToRead = (
Long64_t)fBatchEnv->GetValue(
"NbToRead", -1);
756 SetUserIncludes(fBatchEnv->GetValue(
"UserIncludes",
""));
757 SetUserLibraries(fBatchEnv->GetValue(
"UserLibraries",
""));
760 if (strcmp(fBatchEnv->GetValue(
"BatchSystem",
""),
"")) {
761 fBatchSystem = gBatchSystemManager->
GetBatchSystem(fBatchEnv->GetValue(
"BatchSystem",
""));
764 fBatchSystem->SetAnalyser(
this);
768 if (fTask->WithUserClass()) {
769 fUserClass = fBatchEnv->GetValue(
"UserClass",
"");
770 if (fUserClass ==
"") {
771 Error(
"ReadBatchEnvFile",
"Name of user class not given");
775 fUserClassOptions = fBatchEnv->GetValue(
"UserClassOptions",
"");
776 fUserClassImp = fBatchEnv->GetValue(
"UserClassImp",
"");
777 if (fUserClassImp ==
"") {
778 Error(
"ReadBatchEnvFile",
"Name of user class implementation file not given");
781 fUserClassDec = fBatchEnv->GetValue(
"UserClassDec",
"");
782 if (fUserClass ==
"") {
783 Error(
"ReadBatchEnvFile",
"Name of user class header file not given");
786 fUserClassAlternativeBaseClass = fBatchEnv->GetValue(
"UserClassAlternativeBaseClass",
"");
790 if (!RunningInLaunchDirectory()) {
804 fUserClassOptions = fBatchEnv->GetValue(
"UserClassOptions",
"");
857 KVString task_data_analyser = fTask->GetDataAnalyser();
858 Info(
"SubmitTask",
"fTask->GetDataAnalyser()=%s", task_data_analyser.
Data());
859 unique_ptr<KVDataAnalyser> the_analyser;
860 if (task_data_analyser ==
"UserClass") {
864 the_analyser.reset(GetAnalyser(fTask->GetDataAnalyser()));
866 if (!the_analyser.get())
867 Fatal(
"SubmitTask",
"the_analyser is 0x0, go to crash");
869 set_up_analyser_for_task(the_analyser.get());
871 if (fTask->WithUserClass()) {
872 the_analyser->SetUserClass(GetUserClass(),
kFALSE);
873 the_analyser->SetUserClassOptions(fUserClassOptions);
874 }
else if (strcmp(fTask->GetUserBaseClass(),
"")) the_analyser->SetUserClass(fTask->GetUserBaseClass(),
kFALSE);
879 the_analyser->CheckTaskVariables();
880 if (!fChoseRunMode) ChooseRunningMode();
883 the_analyser->SetBatchName(GetBatchName());
884 the_analyser->SetBatchSystem(fBatchSystem);
885 the_analyser->SetProofMode(GetProofMode());
888 gDataAnalyser = the_analyser.get();
915 if (fUserClass.Length()) tmp.
ReplaceAll(
"$UserClass", fUserClass.Data());
916 else if (fTask) tmp.
ReplaceAll(
"$UserClass", fTask->GetDataAnalyser());
927 static TString keywords =
"Will be expanded: $Date, $User, $UserClass";
980 if (!
BatchMode() || !fBatchEnv)
return "";
986 TString launchDir = GetLaunchDirectory();
1002 TEnv stats(GetBatchStatusFileName());
1003 stats.
SetValue(
"TotalEvents", totev);
1004 stats.
SetValue(
"EventsRead", evread);
1022 TString stats = GetBatchStatusFileName();
1038 return (!(nevents % fTask->GetStatusUpdateInterval()) && nevents);
1050 cout <<
" +++ " << nevents <<
" events processed +++ " << endl;
1053 cout <<
" ------------- Process infos -------------" << endl;
1054 printf(
" CpuSys = %f s. CpuUser = %f s. ResMem = %f MB VirtMem = %f MB\n",
1074 fChoseRunMode =
kTRUE;
1077 cout << endl <<
"Run in Interactive or Batch mode (I or B) ? : ";
1079 }
while (tmp !=
"i" && tmp !=
"I" && tmp !=
"b" && tmp !=
"B");
1086 cout << endl <<
"Choose the batch system to use : " << endl;
1087 gBatchSystemManager->
Print();
1089 cout <<
"(enter a number) : " << endl;
1093 fBatchSystem->
Clear();
1107 if (*ls)
delete(*ls);
1126 if (!fWorkDirInit || !fWorkDirEnd)
return;
1128 TIter next_new_file(fWorkDirEnd);
1130 while ((
file = next_new_file())) {
1131 if (!fWorkDirInit->FindObject(
file->GetName())) {
1141 Info(
"CopyAnalysisResultsToLaunchDirectory",
"Copying analysis results file :\n%s ---> %s",
1145 Info(
"CopyAnalysisResultsToLaunchDirectory",
"File copied correctly");
1147 Info(
"CopyAnalysisResultsToLaunchDirectory",
" **** ERROR copying file !!! ");
1168 tt->GetUserInfo()->Add(
new TEnv());
1169 TEnv* kvenv = (
TEnv*)
tt->GetUserInfo()->FindObject(
"TEnv");
1185 #ifdef WITH_BZR_INFOS
1186 kvenv->
SetValue(
"KVBase::bzrRevisionId()", KVBase::bzrRevisionId(),
kEnvUser);
1187 kvenv->
SetValue(
"KVBase::bzrRevisionDate()", KVBase::bzrRevisionDate(),
kEnvUser);
1188 kvenv->
SetValue(
"KVBase::bzrBranchNick()", KVBase::bzrBranchNick(),
kEnvUser);
1189 kvenv->
SetValue(
"KVBase::bzrRevisionNumber()", KVBase::bzrRevisionNumber());
1190 kvenv->
SetValue(
"KVBase::bzrIsBranchClean()", KVBase::bzrIsBranchClean());
1192 #ifdef WITH_GIT_INFOS
1241 ::Warning(
"KVDataAnalyser::RunAnalyser",
"No plugin %s found for KVDataAnalyser",
1286 jdl->
SetValue(
"AnalysisTask", fTask->GetType());
1287 jdl->
SetValue(
"PROOFMode", GetProofMode());
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 filename
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 format
char * Form(const char *fmt,...)
void AssignAndDelete(TString &target, char *tobedeleted)
R__EXTERN TSystem * gSystem
static Bool_t FindClassSourceFiles(const Char_t *class_name, KVString &imp_file, KVString &dec_file, const Char_t *dir_name=".")
static const Char_t * GetKVBuildDate()
Returns KaliVeda build date.
static const Char_t * gitCommit()
Returns last git commit of sources.
static const Char_t * GetKVBuildUser()
Returns username of person who performed build.
static const Char_t * gitBranch()
Returns git branch of sources.
static const Char_t * GetKVSourceDir()
Returns top-level directory of source tree used for build.
static void PrintSplashScreen()
Prints welcome message and infos on version etc.
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
static const Char_t * GetKVVersion()
Returns KaliVeda version string.
Handles list of all available batch systems for processing non-interactive data analysis tasks.
void Print(Option_t *opt="") const
KVBatchSystem * GetBatchSystem(const Char_t *name)
Get batch system by name.
virtual const Char_t * GetJobName() const
virtual void ReadBatchEnvFile(TEnv *)
virtual void Clear(Option_t *opt="")
Manager class which sets up and runs data analysis tasks.
const Char_t * GetACliCMode()
void DoStatusUpdate(Long64_t nevents) const
Print infos on events treated, disk usage, memory usage.
virtual TString ExpandAutoBatchName(const Char_t *format) const
void SetParent(KVDataAnalyser *da)
virtual void PostRunReset()
virtual void Run()
Check all task variables, then run analyser.
virtual void AddJobDescriptionList(TList *)
virtual void WriteBatchEnvFile(const TString &, Bool_t sav=kTRUE)
void ChooseNbEventToRead()
Ask user to set number of events to read.
Bool_t RunningInLaunchDirectory()
void SetUserLibraries(const Char_t *libs=0)
void SetUserClass(const Char_t *kvs, Bool_t check=kTRUE)
virtual Bool_t CheckIfUserClassIsValid(const KVString &alternative_base_class="")
TString GetPathToFileInLaunchDirectory(const TString &) const
void WriteBatchInfo(TTree *)
virtual void RunMenus()
Run data analyser in menu-driven mode.
virtual Bool_t CheckTaskVariables()
Bool_t DoUserClassFilesExist()
const Char_t * GetLaunchDirectory() const
void SetAnalysisTask(KVDataAnalysisTask *at)
virtual const Char_t * GetRecognisedAutoBatchNameKeywords() const
virtual void set_up_analyser_for_task(KVDataAnalyser *the_analyser)
virtual Bool_t CheckStatusUpdateInterval(Long64_t nevents) const
virtual Bool_t CheckWhatToAnalyseAndHow()
virtual void SubmitTask()
const Char_t * GetBatchStatusFileName() const
Returns full path to file used to store status of running batch jobs.
virtual void ChooseWhatToAnalyse()
TO IMPLEMENT ?
KVDataAnalyser()
Default constructor.
static Bool_t fCleanAbort
flag to force abort of processing
static KVDataAnalyser * GetAnalyser(const Char_t *plugin)
static Bool_t IsRunningBatchAnalysis()
static void RunAnalyser(const Char_t *plugin="")
void ScanWorkingDirectory(TList **)
void ChooseUserClass()
Choose the user's analysis class.
void CopyAnalysisResultsToLaunchDirectory()
virtual Bool_t ReadBatchEnvFile(const TString &)
void DeleteBatchStatusFile() const
Delete batch status file (and backup - '.bak') for batch job.
void SetUserIncludes(const Char_t *incDirs=0)
virtual void ChooseWhatToDo()
TO IMPLEMENT ?
void UpdateBatchStatusFile(Int_t totev, Int_t evread, TString disk) const
Update infos in batch status file.
KVBatchSystem * fBatchSystem
batch system to use for submission of job
TObject * GetInstanceOfUserClass(const KVString &alternative_base_class="")
void SetNbEventToRead(Long64_t nb=0)
Define and manage data analysis tasks.
virtual const Char_t * GetPrereq() const
Manage all datasets contained in a given data repository.
virtual Bool_t Init(KVDataRepository *=0)
KVDataAnalysisTask * GetAnalysisTaskAny(const Char_t *keywords) const
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
void SetValue(const Char_t *name, value_type value)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const
virtual Int_t GetEntries() const
virtual void SetOwner(Bool_t enable=kTRUE)
const char * AsSQLString() const
THashList * GetTable() const
virtual const char * GetValue(const char *name, const char *dflt) const
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
virtual void SaveLevel(EEnvLevel level)
TObject * At(Int_t idx) const override
const char * GetName() const override
const TString & GetString() const
virtual const char * GetName() const
virtual Bool_t InheritsFrom(const char *classname) const
Longptr_t ExecPlugin(int nargs)
std::istream & ReadToDelim(std::istream &str, char delim='\n')
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
TObjArray * Tokenize(const TString &delim) const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Form(const char *fmt,...)
TString & Remove(EStripType s, char c)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
std::istream & ReadLine(std::istream &str, Bool_t skipWhite=kTRUE)
virtual TList * GetListOfFiles() const
virtual const char * GetBuildNode() const
virtual const char * GetBuildCompilerVersion() const
virtual const char * GetBuildDir() const
virtual void AddIncludePath(const char *includePath)
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
virtual const char * Getenv(const char *env)
virtual const char * GetIncludePath()
virtual char * ConcatFileName(const char *dir, const char *name)
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
virtual UserGroup_t * GetUserInfo(const char *user=nullptr)
virtual int GetProcInfo(ProcInfo_t *info) const
virtual const char * HostName()
virtual const char * WorkingDirectory()
virtual const char * GetBuildCompiler() const
virtual const char * GetLibraries(const char *regexp="", const char *option="", Bool_t isRegexp=kTRUE)
virtual const char * GetBuildArch() const
virtual int Unlink(const char *name)
RooCmdArg ClassName(const char *name)
RooCmdArg BatchMode(std::string const &batchMode)