///
/// Helper macro to run a single task either locally or on Grid
/// Usage:
-/// aliroot -b -q -l run-single-task.C'("mode", "run", "task", "name", useMC, events, "path", "pattern", "friendPattern", "outputDir", "user")'
+/// aliroot -b -q -l run-single-task.C'("mode", "run", "tasks", "name", useMC, events, "path", "pattern", "friendPattern", "outputDir", "user")'
/// arguments
/// mode: local, full, test
/// run: list of run numbers. Or if using AODs with predefined list/AODs in same folder, specifiy as "AOD"
-/// task: class name of task
+/// tasks: list of class names/source or header files of task
///
/// optional arguments
/// name: analysis name (default 'myanalysis')
+/// useMC: MC analysis enabled if true (default false')
/// events: number of events to be processed (default -1 -> all)
/// path: data search path for grid analysis (default from configuration file)
/// pattern: data search pattern (default from configuration file)
+/// friend pattern: friend file search pattern (default from configuration file)
+/// output dir: output directory in Grid home (default gridwork/yyyy-mm-dd_hh-mm)
+/// user: default NULL, using user of active token
///
/// Examples:
/// aliroot -b -q -l run-single-task.C'("full", "146860", "AliAnalysisTaskSample", "myanalysis_LHC11a")'
///
/// aliroot -b -q -l run-single-task.C'("local", "$ALICE_ROOT/test/ppbench/AliESDs.root", "AliAnalysisTaskSample")'
///
-/// aliroot -b -q -l run-single-task.C'("local", "AOD", "AddTaskSample.C"")'
+/// aliroot -b -q -l run-single-task.C'("local", "AOD", "AddTaskSample.C")'
///
-/// aliroot -b -q -l run-single-task.C'("full", "146860", "AliAnalysisTaskSample", "correlation3p_LHC11a", -1, "/alice/data/2011/LHC11a", "*/pass2_without_SDD/AOD*/*/AliAOD.root")'
+/// aliroot -b -q -l run-single-task.C'("full", "146860", "AliAnalysisTaskSample", "correlation3p_LHC11a", 0, -1, "/alice/data/2011/LHC11a", "*/pass2_without_SDD/AOD*/*/AliAOD.root")'
///
/// Data input:
/// depending on the format of the search pattern either the ESD or AOD input handler is used.
///
/// Local analysis:
/// requires only the path to the input file and the task class name. If the specified file is
-/// a text file (.txt) each line can contain an input file path, all files are chained.
-/// Note: AOD mode needs to be implemented
+/// a text file (.txt) each line can contain an input ESD file path, all files are chained.
+/// Analysis on local AOD files needs to be setup prior to this macro. gDirectory must contain
+/// a TChain object of name 'aodTree'. This is for example created by macros like
+/// $ALICE_ROOT/PWGHF/vertexingHF/MakeAODInputChain.C
+/// Set $ALICE_ROOT/PWGHF/correlationHF/macros/setupDxHFE.C for an example.
///
/// Grid analysis:
/// All modes provided by the AliAnalysisAlien plugin can be used, e.g. full, test, offline
/// A couple of settings need to be defined in a configuration file 'grid-config.C' which can be
-/// either in the local directory or home directory.
+/// either in the local directory or home directory. The file can look like
/// <pre>
/// const char* alienAPIVersion="V1.1x";
-/// const char* alienROOTVersion="v5-33-02a";
-/// const char* alienAliROOTVersion="v5-01-Rev-29";
+/// const char* alienROOTVersion="v5-34-01";
+/// const char* alienAliROOTVersion="v5-03-61-AN";
/// const char* defaultGridDataDir="/alice/data/2011/LHC11a";
/// const char* defaultDataPattern="*/pass2_without_SDD/*/AliESDs.root";
+/// const char* defaultFriendDataPattern="";
/// {} // note this empty body
/// </pre>
/// Data path and pattern can also be specified as command line arguments.
/// The working directory in the grid home directory of the user is set to
-/// gridwork/<date>_<time>.
+/// gridwork/<date>_<time> (gridwork/yyyy-mm-dd_hh-mm), can be overridden by command line
+/// parameter.
///
///
TString taskSource=pTaskNames->At(iTaskName)->GetName();
TString taskHeader=pTaskNames->At(iTaskName)->GetName();
bool bIsAddTask=false;
- if (taskSource.EndsWith(".C")) {
- // suppose that's an 'AddTask' macro
- taskHeader="";
- bIsAddTask=true;
- } else if (taskSource.EndsWith(".par")) {
- // par file
- if (gSystem->AccessPathName(taskSource)!=0) {
- ::Error("run_single_task", Form("par file '%s' not found in current directory, you might want to set a symbolic link", taskSource.Data()));
- return;
- }
- parPackages+=" ";
- parPackages+=taskSource;
- continue;
- } else if (taskSource.EndsWith(".h")) {
- taskSource.ReplaceAll(".h", "");
- taskClasses+=" ";
- taskClasses+=taskSource;
- taskSource+=".cxx";
- } else if (taskSource.EndsWith(".cxx")) {
- taskHeader.ReplaceAll(".cxx", "");
- taskClasses+=" ";
- taskClasses+=taskHeader;
- taskHeader+=".h";
- } else {
- taskClasses+=" ";
- taskClasses+=taskSource;
- taskSource+=".cxx";
- taskHeader+=".h";
- }
- TString dependencyHeader;
- TString dependencySource;
- if (gSystem->AccessPathName(taskHeader)==0) {
- GetIncludeHeaders(taskHeader, dependencyHeader, libraries);
- taskHeaders+=" "; taskHeaders+=taskHeader;
- }
- if (gSystem->AccessPathName(taskSource)==0) {
- GetIncludeHeaders(taskSource, dependencyHeader, libraries);
- if (!bIsAddTask) {taskSources+=" "; taskSources+=taskSource;}
- else {addTaskMacros+=" "; addTaskMacros+=taskSource;}
- }
- TObjArray* pTokens=dependencyHeader.Tokenize(" ");
- if (pTokens) {
- for (int i=0; i<pTokens->GetEntriesFast(); i++) {
- TString sourceFile=pTokens->At(i)->GetName();
- sourceFile.ReplaceAll(".h", ".cxx");
- if (gSystem->AccessPathName(sourceFile)!=0) continue;
- if (!dependencySource.IsNull()) dependencySource+=" ";
- dependencySource+=sourceFile;
- if (!libraries.IsNull()) libraries+=" ";
- libraries+=sourceFile;
- }
- delete pTokens;
- }
- dependencySource.ReplaceAll(taskSource, "");
- dependencyHeader.ReplaceAll(taskHeader, "");
+ if (taskSource.EndsWith(".C")) {
+ // suppose that's an 'AddTask' macro
+ taskHeader="";
+ bIsAddTask=true;
+ } else if (taskSource.EndsWith(".par")) {
+ // par file
+ if (gSystem->AccessPathName(taskSource)!=0) {
+ ::Error("run_single_task", Form("par file '%s' not found in current directory, you might want to set a symbolic link", taskSource.Data()));
+ return;
+ }
+ parPackages+=" ";
+ parPackages+=taskSource;
+ continue;
+ } else if (taskSource.EndsWith(".h")) {
+ taskSource.ReplaceAll(".h", "");
+ taskClasses+=" ";
+ taskClasses+=taskSource;
+ taskSource+=".cxx";
+ } else if (taskSource.EndsWith(".cxx")) {
+ taskHeader.ReplaceAll(".cxx", "");
+ taskClasses+=" ";
+ taskClasses+=taskHeader;
+ taskHeader+=".h";
+ } else {
+ taskClasses+=" ";
+ taskClasses+=taskSource;
+ taskSource+=".cxx";
+ taskHeader+=".h";
+ }
+ TString dependencyHeader;
+ TString dependencySource;
+ if (gSystem->AccessPathName(taskHeader)==0) {
+ GetIncludeHeaders(taskHeader, dependencyHeader, libraries);
+ taskHeaders+=" "; taskHeaders+=taskHeader;
+ }
+ if (gSystem->AccessPathName(taskSource)==0) {
+ GetIncludeHeaders(taskSource, dependencyHeader, libraries);
+ if (!bIsAddTask) {taskSources+=" "; taskSources+=taskSource;}
+ else {addTaskMacros+=" "; addTaskMacros+=taskSource;}
+ }
+ TObjArray* pTokens=dependencyHeader.Tokenize(" ");
+ if (pTokens) {
+ for (int i=0; i<pTokens->GetEntriesFast(); i++) {
+ TString sourceFile=pTokens->At(i)->GetName();
+ sourceFile.ReplaceAll(".h", ".cxx");
+ if (gSystem->AccessPathName(sourceFile)!=0) continue;
+ if (!dependencySource.IsNull()) dependencySource+=" ";
+ dependencySource+=sourceFile;
+ if (!libraries.IsNull()) libraries+=" ";
+ libraries+=sourceFile;
+ }
+ delete pTokens;
+ }
+ dependencySource.ReplaceAll(taskSource, "");
+ dependencyHeader.ReplaceAll(taskHeader, "");
}
delete pTaskNames;
}
} else if(strInput.EndsWith("AOD")){
// fetch aod tree from the setup macro
if (gDirectory!=NULL) {
- TObject* chainObject=gDirectory->FindObject("aodTree");
+ const char* aodTreeName="aodTree";
+ TObject* chainObject=gDirectory->FindObject(aodTreeName);
if (chainObject) {
chain=dynamic_cast<TChain*>(chainObject);
}
}
if (!chain) {
- cout << "failed to fetch aod tree object from setup" << endl;
- return -1;
+ ::Error("run_single_task", Form("failed to fetch aod tree object from setup; the chain with name '%s' has to be created before calling this macro", aodTreeName));
+ return;
}
} else {
- cerr << "invalid input" << endl;
- return -1;
+ ::Error("run_single_task", Form("invalid input"));
+ return;
}
} else {
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// grid analysis
//
- alienHandler=new AliAnalysisAlien();
+ bool bSetRun=true;
+ TString strInput(input);
+ if (!strInput.IsDigit()) {
+ // support for external macros specifying the the runs to be
+ // analyzed
+ // the input is expected to be an external plugin with name 'input'
+ // and all run numbers being set
+ TObject* pObj=gDirectory->FindObject(input);
+ if (pObj) alienHandler=dynamic_cast<AliAnalysisAlien*>(pObj);
+ if (!alienHandler) {
+ ::Error("run_single_task", Form("can not find plugin of name '%s', please setup alien handler with name and run numbers before calling this macro", input));
+ return;
+ }
+ bSetRun=false;
+ } else {
+ alienHandler=new AliAnalysisAlien();
+ }
if (!alienHandler) {
- cerr << "failed to create alien handler" << endl;
+ ::Error("run_single_task", Form("failed to create alien handler"));
return;
}
delete packageTokens;
}
- if (!useMC)
- alienHandler->SetRunPrefix("000"); // real data
+ if (bSetRun) {
+ // only set if input is a run number
+ if (!useMC && !strInput.BeginsWith("000"))
+ alienHandler->SetRunPrefix("000"); // real data
- alienHandler->AddRunNumber(input);
+ alienHandler->AddRunNumber(input);
+ }
// define working and output directories
TDatime dt;
alienHandler->SetOutputFiles(ofile);
// Optionally define the files to be archived.
- //-
- //alienHandler->SetOutputArchive("log_archive.zip:stdout,stderr");
+ alienHandler->SetOutputArchive("log_archive.zip:stdout,stderr");
// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
TString macroName; macroName.Form("run_%s.C",analysisName); macroName.ReplaceAll("-","_");
// Optionally resubmit threshold.
alienHandler->SetMasterResubmitThreshold(90); // in %
- alienHandler->SetTTL(30000);// in sec
+ alienHandler->SetTTL(86400);// in sec
// Optionally set input format (default xml-single)
alienHandler->SetInputFormat("xml-single");
TObjArray* taskClassTokens=taskClasses.Tokenize(" ");
if (taskClassTokens) {
for (int iTaskClassToken=0; iTaskClassToken<taskClassTokens->GetEntriesFast(); iTaskClassToken++) {
- AliAnalysisTaskSE *pTask=NULL;
- TString taskName=taskClassTokens->At(iTaskClassToken)->GetName();
- taskName.ReplaceAll(".cxx", "");
- TClass* pCl=TClass::GetClass(taskName);
- if (!pCl) {
- cerr << "can not load class " << taskName << endl;
- return -1;
- }
- TObject* p=pCl->New();
- if (!p) {
- cerr << "failed to instantiate class " << taskName << endl;
- return -1;
- }
- pTask=reinterpret_cast<AliAnalysisTaskSE*>(p);
- pManager->AddTask(pTask);
- AliAnalysisDataContainer *pContainer=pManager->CreateContainer(analysisName ,TObject::Class(), AliAnalysisManager::kOutputContainer, ofile);
- pManager->ConnectInput(pTask,0,pManager->GetCommonInputContainer());
- pManager->ConnectOutput(pTask,1,pContainer);
+ AliAnalysisTaskSE *pTask=NULL;
+ TString taskName=taskClassTokens->At(iTaskClassToken)->GetName();
+ taskName.ReplaceAll(".cxx", "");
+ TClass* pCl=TClass::GetClass(taskName);
+ if (!pCl) {
+ cerr << "can not load class " << taskName << endl;
+ return;
+ }
+ TObject* p=pCl->New();
+ if (!p) {
+ cerr << "failed to instantiate class " << taskName << endl;
+ return;
+ }
+ pTask=reinterpret_cast<AliAnalysisTaskSE*>(p);
+ pManager->AddTask(pTask);
+ AliAnalysisDataContainer *pContainer=pManager->CreateContainer(analysisName ,TObject::Class(), AliAnalysisManager::kOutputContainer, ofile);
+ pManager->ConnectInput(pTask,0,pManager->GetCommonInputContainer());
+ pManager->ConnectOutput(pTask,1,pContainer);
}
delete taskClassTokens;
}
TObjArray* taskMacroTokens=addTaskMacros.Tokenize(" ");
if (taskMacroTokens) {
for (int iTaskMacroToken=0; iTaskMacroToken<taskMacroTokens->GetEntriesFast(); iTaskMacroToken++) {
- taskSource+="+g";
- TString configuration;
- configuration.Form("name=%s file=%s %s", analysisName, ofile.Data(), useMC?"mc":"");
- if (gDirectory) gDirectory->Add(new TNamed("run_single_task_configuration", configuration.Data()));
- gROOT->Macro(taskMacroTokens->At(iTaskMacroToken)->GetName());
+ taskSource+="+g";
+ TString configuration;
+ configuration.Form("name=%s file=%s %s", analysisName, ofile.Data(), useMC?"mc":"");
+ if (gDirectory) gDirectory->Add(new TNamed("run_single_task_configuration", configuration.Data()));
+ gROOT->Macro(taskMacroTokens->At(iTaskMacroToken)->GetName());
}
delete taskMacroTokens;
}
/// Helper macro to initialize the environment for DxHFE. The macro can just
/// prepend other macros like run-single-task in the command line.
/// Usage:
-/// aliroot -b -q -l setupDxHFE.C'("localAodDir")' run-single-task.C'(...)'
+/// aliroot -b -q -l setupDxHFE.C'("localAodDirectory", nofDirectories)' run-single-task.C'(...)'
+/// aliroot -b -q -l setupDxHFE.C'("lhcPeriod", "mcPeriod")' run-single-task.C'(...)'
///
/// Example:
/// aliroot -b -q -l setupDxHFE.C run-single-task.C'(...)'
/// available for the alien handler initialization, a specific configuration
/// object is created
/// - setting a default analysis name via a configuration object
-/// - the optional parameter 'localAodDir' allows to create an input chain from
+/// - the optional parameter 'localAodDirectory' allows to create an input chain from
/// local AODs; either a single AliAOD.root, or a folder containing directories
-/// named "1, 2, ..."
+/// named "1, 2, ...", the number of directories is specified as parameter
+/// nofDirectories
+/// - loading the runs defined by AddGoodRuns of vertexingHF using lhcPeriod and
+/// optional mcPeriod
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// environment specific for DxHFE
//
+const char* analysisName="DxHFECorrelation";
const char* includePath="-I$ALICE_ROOT/PWGHF/correlationHF -I$ALICE_ROOT/PWGHF/vertexingHF -I$ALICE_ROOT/PWGHF/hfe";
const char* libraryDependencies=
"libSTEERBase "
"libPWGHFcorrelationHF.so "
;
-void setupDxHFE(const char* aodDirectory=NULL)
+void setupDxHFE(const char* localAodDirectory, int nofDirectories, const char* lhcPeriod, const char* mcProd="")
{
+ //
+ // adding include path and libraries
+ //
gSystem->AddIncludePath(includePath);
TString libraries=libraryDependencies;
TObjArray* pTokens=libraries.Tokenize(" ");
}
libraries="";
+ //
// allow run-single-task to fetch the analysis name and library names
- if (gDirectory) gDirectory->Add(new TNamed("analysis_name", "DxHFECorrelation"));
+ //
+ if (gDirectory) gDirectory->Add(new TNamed("analysis_name", analysisName));
if (gDirectory) gDirectory->Add(new TNamed("analysis_libraries", libraryDependencies));
- if (aodDirectory) {
+ if (lhcPeriod) {
+ //
+ // setting up the runs for the dpecified period
+ //
+ TString alienHandlerName(analysisName); alienHandlerName+="Handler";
+ AliAnalysisAlien* alienHandler=new AliAnalysisAlien(alienHandlerName);
+ gROOT->LoadMacro("$ALICE_ROOT/PWGHF/vertexingHF/AddGoodRuns.C");
+ int nruns=AddGoodRuns(alienHandler, lhcPeriod, mcProd);
+ if (nruns<=0) {
+ ::Error("setupDxHFE.C", Form("can not find any good runs for period %s", lhcPeriod));
+ return;
+ }
+ gDirectory->Add(alienHandler);
+ ::Info("setupDxHFE.C", Form("setting up alien plugin '%s' for period %s\n>>>>> please use '%s' as input parameter for run-single-task.C <<<<<<", alienHandlerName.Data(), lhcPeriod, alienHandlerName.Data()));
+
+ } else if (localAodDirectory) {
+ //
// create AOD tree from local files
// the created object is added automatically to gDirectory and can be fetched
// from there later
+ //
gROOT->LoadMacro("$ALICE_ROOT/PWGHF/vertexingHF/MakeAODInputChain.C");
- TString aodPathName(aodDirectory);
+ TString aodPathName(localAodDirectory);
if (!aodPathName.EndsWith("/")) aodPathName+="/";
aodPathName+="AliAOD.root";
if (gSystem->AccessPathName(aodPathName)==0) {
// Create a chain with one set of AliAOD.root and AliAOD.VertexingHF.root. The set needs
// to be located in the same folder as you run from (physically or linked)
::Info("setupDxHFE.C", Form("make chain from single chunk %s", aodPathName));
- TChain* chain = MakeAODInputChain(aodDirectory ,1, -1);
+ TChain* chain = MakeAODInputChain(localAodDirectory ,1, -1);
} else {
// Assume several folders containing different AODs.
// The AODs need to be in folders named 1, 2,...
- ::Info("setupDxHFE.C", Form("make chain from directory %s", aodDirectory));
- chain=MakeAODInputChain(aodDirectory, 1, 10);
+ ::Info("setupDxHFE.C", Form("make chain from directory %s", localAodDirectory));
+ chain=MakeAODInputChain(localAodDirectory, 1, nofDirectories);
}
::Info("setupDxHFE.C", Form("local AOD chain: %d entries", chain->GetEntries()));
}
}
+
+void setupDxHFE(const char* lhcPeriod=NULL, const char* mcProd="")
+{
+ // Grid mode with optional calling of AddGoodRuns for specified
+ // period
+ setupDxHFE(NULL, 0, lhcPeriod, mcProd);
+}
+
+void setupDxHFE(const char* localAodDirectory, int nofDirectories)
+{
+ // local mode for AOD data
+ setupDxHFE(localAodDirectory, nofDirectories, NULL);
+}