/**
- * @defgroup pwglf_forward_trains Trains
+ * @defgroup pwglf_forward_trains Trains.
*
- * Train specifications
- *
+ * Train specifications.
+ * See also @ref train_setup_doc
*/
/**
* @file TrainSetup.C
#ifndef TRAINSETUP_C
#define TRAINSETUP_C
#ifndef __CINT__
-# include "Helper.C"
+# include "Railway.C"
# include "Option.C"
# include <TDatime.h>
# include <TUrl.h>
# include <AliMCEventHandler.h>
# include <ctime>
#else
-struct Helper;
+struct Railway;
struct OptionList;
class TDatime;
class TUrl;
TrainSetup(const TString& name)
: fName(name),
fEscapedName(name),
+ fDatimeString(""),
fOptions(),
- fHelper(0)
+ fRailway(0),
+ fMonitored("")
{
fOptions.Add("help", "Show help", false);
fOptions.Add("date", "YYYY-MM-DD HH:MM", "Set date", "now");
fOptions.Add("type", "ESD|AOD|USER", "Input data stype", "");
fOptions.Add("setup", "Only do the setup", false);
fOptions.Add("branches", "Load only requested branches", false);
- fEscapedName = EscapeName(fName, "");
+ fDatimeString = "";
+ fEscapedName = EscapeName(fName, fDatimeString);
}
/**
* Copy constructor
TrainSetup(const TrainSetup& o)
: fName(o.fName),
fEscapedName(o.fEscapedName),
+ fDatimeString(o.fDatimeString),
fOptions(o.fOptions),
- fHelper(o.fHelper)
+ fRailway(o.fRailway),
+ fMonitored(o.fMonitored)
{}
/**
* Assignment operator
TrainSetup& operator=(const TrainSetup& o)
{
if (&o == this) return *this;
- fName = o.fName;
- fEscapedName = o.fEscapedName;
- fOptions = o.fOptions;
- fHelper = o.fHelper;
+ fName = o.fName;
+ fEscapedName = o.fEscapedName;
+ fDatimeString = o.fDatimeString;
+ fOptions = o.fOptions;
+ fRailway = o.fRailway;
+ fMonitored = o.fMonitored;
return *this;
}
TString url = fOptions.Get("url");
Int_t verbose = fOptions.AsInt("verbose");
- fHelper = Helper::Create(url.Data(), verbose);
- if (!fHelper) {
+ fRailway = Railway::Create(url.Data(), verbose);
+ if (!fRailway) {
Error("Init", "Failed to make the worker for URL %s", url.Data());
return false;
}
// --- Check the type, if possible -------------------------------
- UShort_t type = fHelper->InputType();
- Bool_t mc = fHelper->IsMC();
+ UShort_t type = fRailway->InputType();
+ Bool_t mc = fRailway->IsMC();
if (fOptions.Has("type")) {
const TString& it = fOptions.Get("type");
- if (it.EqualTo("ESD",TString::kIgnoreCase)) type = Helper::kESD;
- else if (it.EqualTo("AOD",TString::kIgnoreCase)) type = Helper::kAOD;
+ if (it.EqualTo("ESD",TString::kIgnoreCase)) type = Railway::kESD;
+ else if (it.EqualTo("AOD",TString::kIgnoreCase)) type = Railway::kAOD;
else if (it.EqualTo("user",TString::kIgnoreCase))
- type = Helper::kUser;
+ type = Railway::kUser;
}
// --- Rewrite the escpaed name ----------------------------------
if (fOptions.Has("date")) {
- TString date = fOptions.Get("date");
- fEscapedName = EscapeName(fName, date);
+ fDatimeString = fOptions.Get("date");
+ fEscapedName = EscapeName(fName, fDatimeString);
}
// --- Get current directory and set-up sub-directory ------------
if (!SetupWorkingDirectory()) return false;
// --- Do initial helper setup -----------------------------------
- if (!fHelper->PreSetup()) return false;
+ if (!fRailway->PreSetup()) return false;
// --- Load ROOT libraries ---------------------------------------
- if (!fHelper->LoadROOT()) return false;
+ if (!fRailway->LoadROOT()) return false;
// --- Load AliROOT libraries ------------------------------------
- if (!fHelper->LoadAliROOT()) return false;
+ if (!fRailway->LoadAliROOT()) return false;
// --- Create analysis manager -----------------------------------
AliAnalysisManager *mgr = CreateAnalysisManager(fEscapedName);
// if (oper == kTest) mgr->SetNSysInfo(1);
if (verbose > 0) mgr->SetDebugLevel(verbose);
mgr->SetAutoBranchLoading(!fOptions.Has("branches"));
- if (fHelper->Mode() == Helper::kLocal)
+ if (fRailway->Mode() == Railway::kLocal)
mgr->SetUseProgressBar(kTRUE, 100);
// --- ESD input handler ------------------------------------------
cwd.Data(), gROOT->GetMacroPath()));
// --- Physics selction - only for ESD ---------------------------
- if (type == Helper::kESD) CreatePhysicsSelection(mc, mgr);
+ if (type == Railway::kESD) CreatePhysicsSelection(mc, mgr);
// --- Create centrality task ------------------------------------
- CreateCentralitySelection(mc, mgr);
+ CreateCentralitySelection(mc);
// --- Create tasks ----------------------------------------------
CreateTasks(mgr);
+ // --- Create monitor objects ------------------------------------
+ CreateMonitors();
+
// --- Post set-up initialization of helper ----------------------
- if (!fHelper->PostSetup()) return false;
+ if (!fRailway->PostSetup()) return false;
// --- Set debug level on defined tasks --------------------------
if (verbose > 0) {
}
// --- Enable progress bar ---------------------------------------
- if (fHelper->Mode() != Helper::kGrid)
+ if (fRailway->Mode() != Railway::kGrid)
mgr->SetUseProgressBar(true, 100);
// --- Save setup to disk ----------------------------------------
// --- Some information ------------------------------------------
mgr->PrintStatus();
- if (fHelper->Mode() != Helper::kLocal) {
+ if (fRailway->Mode() != Railway::kLocal) {
TIter next(mgr->GetTasks());
AliAnalysisTask* sub = 0;
while ((sub = static_cast<AliAnalysisTask*>(next()))) {
// if (r) SaveSetup(*r, nEvents, asShell);
Long64_t nEvents = fOptions.AsLong("events", -1);
- Long64_t ret = fHelper->Run(nEvents);
+ Long64_t ret = fRailway->Run(nEvents);
PrintTimer(timer, "Processing");
timer.Continue();
else Error("Run", "%s", e.Data());
}
if (fOptions.Has("date")) {
- TString escaped = EscapeName(fName, "");
+ TString tmp = "";
+ TString escaped = EscapeName(fName, tmp);
gSystem->Exec(Form("rm -f last_%s", escaped.Data()));
gSystem->Exec(Form("ln -sf %s last_%s",
fEscapedName.Data(), escaped.Data()));
std::cout << "Train: " << fName << " (" << fEscapedName << ")"
<< std::endl;
fOptions.Show(std::cout);
- if (fHelper) fHelper->Print();
+ if (fRailway) fRailway->Print();
}
/**
* Show the help
fOptions.Help(o, asProg ? " --" : " ");
o << "\n";
- if (!fHelper && fOptions.Has("url")) {
+ if (!fRailway && fOptions.Has("url")) {
TString url = fOptions.Get("url");
- fHelper = Helper::Create(url.Data());
+ fRailway = Railway::Create(url.Data());
}
- if (fHelper) {
- o << fHelper->Desc() << " URL form:\n\n"
- << " " << fHelper->UrlHelp() << "\n\n"
+ if (fRailway) {
+ o << fRailway->Desc() << " URL form:\n\n"
+ << " " << fRailway->UrlHelp() << "\n\n"
<< "Options:\n";
- fHelper->Options().Help(o, " ");
+ fRailway->Options().Help(o, " ");
o << "\n";
}
else {
o << "Possible URL forms:\n\n";
- Helper::ShowUrlHelp("LocalHelper");
- Helper::ShowUrlHelp("ProofHelper");
- Helper::ShowUrlHelp("LiteHelper");
- Helper::ShowUrlHelp("AAFHelper");
- Helper::ShowUrlHelp("AAFPluginHelper");
- Helper::ShowUrlHelp("GridHelper");
+ Railway::ShowUrlHelp("LocalRailway");
+ Railway::ShowUrlHelp("ProofRailway");
+ Railway::ShowUrlHelp("LiteRailway");
+ Railway::ShowUrlHelp("AAFRailway");
+ Railway::ShowUrlHelp("AAFPluginRailway");
+ Railway::ShowUrlHelp("GridRailway");
o << "\n";
}
return false;
virtual AliVEventHandler* CreateInputHandler(UShort_t type)
{
switch (type) {
- case Helper::kESD: return new AliESDInputHandler();
- case Helper::kAOD: return new AliAODInputHandler();
- case Helper::kUser: return 0;
+ case Railway::kESD: return new AliESDInputHandler();
+ case Railway::kAOD: return new AliAODInputHandler();
+ case Railway::kUser: return 0;
}
return 0;
}
{
AliAODHandler* ret = new AliAODHandler();
switch (type) {
- case Helper::kESD:
+ case Railway::kESD:
ret->SetOutputFileName("AliAOD.root");
break;
- case Helper::kAOD:
+ case Railway::kAOD:
ret->SetOutputFileName("AliAOD.pass2.root");
break;
- case Helper::kUser:
+ case Railway::kUser:
break;
}
return;
}
- gROOT->Macro(Form("AddTaskPhysicsSelection.C(%d)", mc));
+ CoupleCar("AddTaskPhysicsSelection.C", Form("%d", mc));
mgr->RegisterExtraFile("event_stat.root");
mgr->AddStatisticsTask(AliVEvent::kAny);
}
* @param mc Whether this is for MC
* @param mgr Manager
*/
- virtual void CreateCentralitySelection(Bool_t mc, AliAnalysisManager* mgr)
+ virtual void CreateCentralitySelection(Bool_t mc)
{
- gROOT->Macro("AddTaskCentrality.C(true)");
- const char* name = "CentralitySelection";
+ AliAnalysisTask* task = CoupleCar("AddTaskCentrality.C","true");
AliCentralitySelectionTask* ctask =
- dynamic_cast<AliCentralitySelectionTask*>(mgr->GetTask(name));
+ dynamic_cast<AliCentralitySelectionTask*>(task);
if (!ctask) return;
if (mc) ctask->SetMCInput();
}
*
* @return Created task or null
*/
- virtual AliAnalysisTask* AddTask(const TString& macro,
- const TString& args)
+ virtual AliAnalysisTask* CoupleCar(const TString& macro,
+ const TString& args)
{
TString p = gSystem->Which(gROOT->GetMacroPath(), macro.Data());
if (p.IsNull()) {
- Error("AddTask", "Macro %s not found", macro.Data());
+ Error("CoupleCar", "Macro %s not found", macro.Data());
return 0;
}
TString cmd(p);
Int_t err;
Long_t ret = gROOT->Macro(cmd.Data(), &err, false);
if (!ret) {
- Error("AddTask", "Failed to execute %s", cmd.Data());
+ Error("CoupleCar", "Failed to execute %s (%ld)", cmd.Data(), ret);
return 0;
}
return reinterpret_cast<AliAnalysisTask*>(ret);
*
* @return The added task, if any
*/
- virtual AliAnalysisTask* AddTask(const TString& macro)
+ virtual AliAnalysisTask* CoupleCar(const TString& macro)
{
TString args;
- return AddTask(macro, args);
+ return CoupleCar(macro, args);
}
/**
* Add a single event analysis task to the train, passing the
*
* @return The added task, if any
*/
- virtual AliAnalysisTaskSE* AddSETask(const TString& macro,
+ virtual AliAnalysisTaskSE* CoupleSECar(const TString& macro,
const TString& args)
{
- return dynamic_cast<AliAnalysisTaskSE*>(AddTask(macro, args));
+ return dynamic_cast<AliAnalysisTaskSE*>(CoupleCar(macro, args));
}
/**
* Add a single event task to the train with no arguments passed to
*
* @return The added task, if any
*/
- virtual AliAnalysisTaskSE* AddSETask(const TString& macro)
+ virtual AliAnalysisTaskSE* CoupleSECar(const TString& macro)
{
TString args;
- return AddSETask(macro, args);
+ return CoupleSECar(macro, args);
+ }
+ /**
+ * Find an already added task
+ *
+ * @param name Name of the task
+ * @param verbose If true,
+ *
+ * @return
+ */
+ virtual AliAnalysisTask* FindCar(const TString& name,
+ Bool_t verbose=true) const
+ {
+ AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
+ if (!mgr) {
+ ::Warning("FindCar", "No manager defined");
+ return 0;
+ }
+ AliAnalysisTask* task = mgr->GetTask(name);
+ if (!task && verbose)
+ ::Warning("FindCar", "Task \"%s\" not found in train",
+ name.Data());
+ return task;
+ }
+ /**
+ * Check if we have an MC handler attached
+ *
+ * @return True if MC handler is found in a valid manager. False if
+ * manager is not defined, or has no MC handler.
+ */
+ virtual Bool_t HasMCHandler() const
+ {
+ AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
+ if (!mgr) return false;
+ return mgr->GetMCtruthEventHandler() != 0;
}
-
/**
* Set the name of the train - should be name of the class. Must be
* overloaded.
virtual const Char_t* ClassName() const = 0;
/* @} */
//__________________________________________________________________
+ virtual void AddMonitor(const TString& name)
+ {
+ if (!fMonitored.IsNull()) fMonitored.Append(":");
+ fMonitored.Append(name);
+ }
+ virtual void CreateMonitors()
+ {
+ if (fMonitored.IsNull()) return;
+ if (fRailway->Mode() != Railway::kProof) return;
+
+ TObjArray* tokens = fMonitored.Tokenize(":");
+ TObject* token = 0;
+ TIter next(tokens);
+ while ((token = next())) {
+ gROOT->ProcessLine(Form("gProof->AddFeedback(\"%s\");",
+ token->GetName()));
+
+ }
+ tokens->Delete();
+ }
+ //__________________________________________________________________
/**
* @{
* @name Utility functions
*
* @return escaped name
*/
- static TString EscapeName(const char* name, const TString& datimeStr)
+ static TString EscapeName(const char* name, TString& datimeStr)
{
TString escaped = name;
char c[] = { ' ', '/', '@', 0 };
escaped.ReplaceAll(tmp, "_");
p++;
}
- if (!datimeStr.IsNull()) {
+ if (!datimeStr.IsNull() &&
+ !datimeStr.EqualTo("none", TString::kIgnoreCase)) {
TDatime datime;
if (datimeStr.EqualTo("now", TString::kIgnoreCase))
datime.Set();
if (datime.GetYear() <= 1995 ||
datime.GetMonth() == 0 ||
datime.GetDay() == 0) return escaped;
- escaped.Append(Form("_%04d%02d%02d_%02d%02d",
- datime.GetYear(),
- datime.GetMonth(),
- datime.GetDay(),
- datime.GetHour(),
- datime.GetMinute()));
+ datimeStr = Form("%04d%02d%02d_%02d%02d",
+ datime.GetYear(),
+ datime.GetMonth(),
+ datime.GetDay(),
+ datime.GetHour(),
+ datime.GetMinute());
+ escaped.Append(Form("_%s", datimeStr.Data()));
}
return escaped;
}
// Check if the directory exists already
Bool_t exists = gSystem->AccessPathName(nam.Data()) == 0;
- if (fHelper->Operation() == Helper::kTerminate && !exists) {
+ if (fRailway->Operation() == Railway::kTerminate && !exists) {
Error("SetupWorkingDirectory", "File/directory %s does not exists",
nam.Data());
return false;
virtual void SaveSetup(Bool_t asShellScript)
{
OptionList tmp(fOptions);
- const OptionList* uopts = (fHelper ? &fHelper->Options() : 0);
+ const OptionList* uopts = (fRailway ? &fRailway->Options() : 0);
if (tmp.Find("overwrite")) tmp.Set("overwrite");
if (tmp.Find("date") && fEscapedName.Length() > fName.Length()+1) {
Int_t n = fName.Length()+1;
if (asShellScript)
SaveSetupShell("rerun", ClassName(), fName, tmp, uopts);
SaveSetupROOT("ReRun", ClassName(), fName, tmp, uopts);
- if (fHelper) fHelper->AuxSave(fEscapedName, asShellScript);
+ if (fRailway) fRailway->AuxSave(fEscapedName, asShellScript);
+ SavePostShellScript();
}
/**
* Save a setup as a shell script
<< "//" << std::endl;
o.close();
}
+ /**
+ * Write shell code to do post processing after terminate. This
+ * code should deal with a single run (or run range). The following
+ * shell variables are available to the code:
+ *
+ * - @c $prefix Relative path to job directory or empty
+ * - @c $dest Destination for output to be stored
+ *
+ * Note, the code is injected into a shell function, and should
+ * therefor not define new functions or the like.
+ *
+ * @param o The output stream.
+ */
+ virtual void PostShellCode(std::ostream& o)
+ {
+ o << " echo \"Nothing to do for " << ClassName()
+ << " train\"" << std::endl;
+ }
+ /**
+ * Save a script to do post processing after terminate on each run
+ * or run-range.
+ *
+ * The shell script will execute the train defined code (in
+ * PostShellCode) for each run or run-range. The train defined code
+ * and call drawing and summarizing macros or the like.
+ *
+ * In case of Grid analysis, this script will download and extract
+ * the appropriate ZIP files to separate directories, and then
+ * change directory to these directories and execute the train
+ * defined shell code there. In this case, the script defines the
+ * shell variable @c $prefix as the relative path to the job
+ * directory.
+ *
+ */
+ void SavePostShellScript()
+ {
+ std::ofstream f("post.sh");
+ if (!f) {
+ Error("SavePostAll", "Failed to open post.sh script");
+ return;
+ }
+ f << "#!/bin/bash\n"
+ << "# Generated by " << ClassName() << "\n"
+ << "set -e\n"
+ << "\n"
+ << "dest=$1\n"
+ << "prefix=\n"
+ << "\n"
+ << "doall() {"
+ << std::endl;
+ PostShellCode(f);
+ f << "}\n"
+ << "\n"
+ << "if test ! -f Download.C ;then\n"
+ << " doall\n"
+ << " exit\n"
+ << "fi\n"
+ << "\n"
+ << "if test ! -f .download ; then\n"
+ << " aliroot -l -b -q Download.C\\(1\\)\n"
+ << " touch .download\n"
+ << "fi\n"
+ << "prefix=../\n"
+ << "\n"
+ << "for i in root_archive_*.zip ; do\n"
+ << " d=`basename $i .zip` \n"
+ << " if test ! -d $d ; then\n"
+ << " echo \"Directory $d missing\"\n"
+ << " continue\n"
+ << " fi\n"
+ << " \n"
+ << " (cd $d && doall)\n"
+ << "done\n"
+ << "# EOF"
+ << std::endl;
+ f.close();
+ gSystem->Exec("chmod a+x post.sh");
+ }
+
/* @} */
TString fName;
TString fEscapedName;
+ TString fDatimeString;
OptionList fOptions;
- Helper* fHelper;
+ Railway* fRailway;
+ TString fMonitored;
};
#endif