#include "TError.h"
#include "TROOT.h"
#include "TSystem.h"
+#include "TInterpreter.h"
#include "TFile.h"
#include "TFileCollection.h"
#include "TChain.h"
fNproofWorkers(0),
fNproofWorkersPerSlave(0),
fProofReset(0),
+ fNMCevents(0),
+ fNMCjobs(0),
fRunNumbers(),
fExecutable(),
fExecutableCommand(),
fValidationScript(),
fAdditionalRootLibs(),
fAdditionalLibs(),
+ fGeneratorLibs(),
fSplitMode(),
fAPIVersion(),
fROOTVersion(),
fModules(0),
fProofParam(),
fDropToShell(true),
+ fMCLoop(false),
fGridJobIDs(""),
fGridStages(""),
fFriendLibs(""),
fNproofWorkers(0),
fNproofWorkersPerSlave(0),
fProofReset(0),
+ fNMCevents(0),
+ fNMCjobs(0),
fRunNumbers(),
fExecutable(),
fExecutableCommand(),
fValidationScript(),
fAdditionalRootLibs(),
fAdditionalLibs(),
+ fGeneratorLibs(),
fSplitMode(),
fAPIVersion(),
fROOTVersion(),
fModules(0),
fProofParam(),
fDropToShell(true),
+ fMCLoop(false),
fGridJobIDs(""),
fGridStages(""),
fFriendLibs(""),
fNproofWorkers(other.fNproofWorkers),
fNproofWorkersPerSlave(other.fNproofWorkersPerSlave),
fProofReset(other.fProofReset),
+ fNMCevents(other.fNMCevents),
+ fNMCjobs(other.fNMCjobs),
fRunNumbers(other.fRunNumbers),
fExecutable(other.fExecutable),
fExecutableCommand(other.fExecutableCommand),
fValidationScript(other.fValidationScript),
fAdditionalRootLibs(other.fAdditionalRootLibs),
fAdditionalLibs(other.fAdditionalLibs),
+ fGeneratorLibs(other.fGeneratorLibs),
fSplitMode(other.fSplitMode),
fAPIVersion(other.fAPIVersion),
fROOTVersion(other.fROOTVersion),
fModules(0),
fProofParam(),
fDropToShell(other.fDropToShell),
+ fMCLoop(other.fMCLoop),
fGridJobIDs(other.fGridJobIDs),
fGridStages(other.fGridStages),
fFriendLibs(other.fFriendLibs),
fNproofWorkers = other.fNproofWorkers;
fNproofWorkersPerSlave = other.fNproofWorkersPerSlave;
fProofReset = other.fProofReset;
+ fNMCevents = other.fNMCevents;
+ fNMCjobs = other.fNMCjobs;
fRunNumbers = other.fRunNumbers;
fExecutable = other.fExecutable;
fExecutableCommand = other.fExecutableCommand;
fValidationScript = other.fValidationScript;
fAdditionalRootLibs = other.fAdditionalRootLibs;
fAdditionalLibs = other.fAdditionalLibs;
+ fGeneratorLibs = other.fGeneratorLibs;
fSplitMode = other.fSplitMode;
fAPIVersion = other.fAPIVersion;
fROOTVersion = other.fROOTVersion;
fProofProcessOpt = other.fProofProcessOpt;
fMergeDirName = other.fMergeDirName;
fDropToShell = other.fDropToShell;
+ fMCLoop = other.fMCLoop;
fGridJobIDs = other.fGridJobIDs;
fGridStages = other.fGridStages;
fFriendLibs = other.fFriendLibs;
{
// Create the analysis manager and optionally execute the macro in filename.
AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
- if (mgr) return mgr;
+ if (mgr) {
+ mgr->SetMCLoop(fMCLoop);
+ return mgr;
+ }
mgr = new AliAnalysisManager(name);
mgr->SetGridHandler((AliAnalysisGrid*)this);
+ mgr->SetMCLoop(fMCLoop);
if (strlen(filename)) {
TString line = gSystem->ExpandPathName(filename);
line.Prepend(".x ");
// Check if single-ouput option is on.
return (!fOutputSingle.IsNull());
}
-
+
+//______________________________________________________________________________
+Long64_t AliAnalysisAlien::RunMacroAndExtractLibs(const char* macro, const char *args, TString &libs)
+{
+// Tries to run the specified macro and return the libraries that it loads.
+ TString expname;
+ if (strlen(macro)) expname = gSystem->ExpandPathName(macro);
+ if (expname.IsNull() || gSystem->AccessPathName(expname)) {
+ ::Error("RunMacroAndExtractLibs","Cannot find macro %s in current directory", macro);
+ return -1;
+ }
+ TString oldlibs = gSystem->GetLibraries();
+ TMacro m(expname);
+ Int_t error = 0;
+ Long64_t retval = m.Exec(args, &error);
+ if (error != TInterpreter::kNoError)
+ {
+ ::Error("RunMacroAndExtractLibs", "Macro interpretation %s failed", macro);
+ return -1;
+ }
+ libs = gSystem->GetLibraries();
+ libs.ReplaceAll(oldlibs, "");
+ libs.Strip(TString::kLeading);
+ TObjArray *libTokens = libs.Tokenize(" ");
+ libs = "";
+ for (Int_t i=0; i<libTokens->GetEntries(); i++) {
+ if (!libs.IsNull()) libs += " ";
+ libs += gSystem->BaseName(libTokens->At(i)->GetName());
+ }
+ delete libTokens;
+ return retval;
+}
+
//______________________________________________________________________________
void AliAnalysisAlien::Print(Option_t *) const
{
TString func = fAnalysisMacro;
TString type = "ESD";
TString comment = "// Analysis using ";
- if (IsUseMCchain()) {
- type = "MC";
- comment += "MC";
- } else {
- if (TObject::TestBit(AliAnalysisGrid::kUseESD)) comment += "ESD";
- if (TObject::TestBit(AliAnalysisGrid::kUseAOD)) {
- type = "AOD";
- comment += "AOD";
- }
- }
+ if (fMCLoop) {
+ type = "MCGEN";
+ comment += "MCGEN";
+ } else {
+ if (IsUseMCchain()) {
+ type = "MC";
+ comment += "MC";
+ } else {
+ if (TObject::TestBit(AliAnalysisGrid::kUseESD)) comment += "ESD";
+ if (TObject::TestBit(AliAnalysisGrid::kUseAOD)) {
+ type = "AOD";
+ comment += "AOD";
+ }
+ }
+ }
if (type!="AOD" && fFriendChainName!="") {
Error("WriteAnalysisMacro", "Friend chain can be attached only to AOD");
return;
if (fIncludePath.Length()) out << " gSystem->AddIncludePath(\"" << fIncludePath.Data() << "\");" << endl;
out << " gROOT->ProcessLine(\".include $ALICE_ROOT/include\");" << endl;
out << " printf(\"Include path: %s\\n\", gSystem->GetIncludePath());" << endl << endl;
+ if (fMCLoop && !fGeneratorLibs.IsNull()) {
+ out << "// MC generator libraries" << endl;
+ TObjArray *list = fGeneratorLibs.Tokenize(" ");
+ TIter next(list);
+ TObjString *str;
+ while((str=(TObjString*)next())) {
+ out << " gSystem->Load(\"" << str->GetName() << "\");" << endl;
+ }
+ delete list;
+ }
if (fAdditionalLibs.Length()) {
out << "// Add aditional AliRoot libraries" << endl;
TString additionalLibs = fAdditionalLibs;
if (str->GetString().Contains(".par"))
out << " if (!" << setupPar << "(\"" << str->GetString() << "\")) return;" << endl;
}
- if (list) delete list;
+ delete list;
}
out << endl;
out << "// analysis source to be compiled at runtime (if any)" << endl;
out << " plugin->SetFriendChainName(\"" << fFriendChainName << "\",\"" << fFriendLibs << "\");" << endl;
if (IsUseMCchain())
out << " plugin->SetUseMCchain();" << endl;
+ if (fMCLoop)
+ out << " plugin->SetMCLoop(kTRUE);" << endl;
out << " mgr->SetGridHandler(plugin);" << endl;
if (AliAnalysisManager::GetAnalysisManager()) {
out << " mgr->SetDebugLevel(" << AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() << ");" << endl;
}
}
if (!IsLocalTest()) {
- out << " TChain *chain = CreateChain(\"wn.xml\", anatype);" << endl << endl;
- out << " mgr->StartAnalysis(\"localfile\", chain);" << endl;
+ if (fMCLoop) {
+ out << " mgr->SetCacheSize(0);" << endl;
+ out << " mgr->EventLoop(" << fNMCevents << ");" << endl;
+ } else {
+ out << " TChain *chain = CreateChain(\"wn.xml\", anatype);" << endl << endl;
+ out << " mgr->StartAnalysis(\"localfile\", chain);" << endl;
+ }
} else {
+ if (fMCLoop) {
+ out << " mgr->SetCacheSize(0);" << endl;
+ out << " mgr->EventLoop(" << fNMCevents << ");" << endl;
+ }
out << " mgr->StartAnalysis(\"localfile\");" << endl;
}
out << " timer.Stop();" << endl;
out << " timer.Print();" << endl;
out << "}" << endl << endl;
- if (!IsLocalTest()) {
+ if (!IsLocalTest() && !fMCLoop) {
out <<"//________________________________________________________________________________" << endl;
out << "TChain* CreateChain(const char *xmlfile, const char *type=\"ESD\")" << endl;
out << "{" << endl;
virtual void SetMergeViaJDL(Bool_t on=kTRUE) {fMergeViaJDL = on ? 1 : 0;}
virtual void SetMergeDirName(const char *name) {fMergeDirName = name;}
virtual void SetMasterResubmitThreshold(Int_t percentage) {fMasterResubmitThreshold = percentage;}
+ void SetMCLoop(Bool_t flag=kTRUE) {fMCLoop = flag;}
virtual void SetNtestFiles(Int_t nfiles) {fNtestFiles = nfiles;}
virtual void SetNumberOfReplicas(Int_t ncopies) {fNreplicas = TMath::Min(ncopies,4);}
virtual void SetJDLName(const char *name="analysis.jdl") {fJDLName = name;}
TGridJDL *GetGridJDL() const {return fGridJDL;}
TGridJDL *GetMergingJDL() const {return fMergingJDL;}
const char *GetGridOutputDir() const {return fGridOutputDir;}
+ Int_t GetNMCevents() const {return fNMCevents;}
+ Int_t GetNMCjobs() const {return fNMCjobs;}
+ void SetNMCevents(Int_t nevents) {fNMCevents = nevents;}
+ void SetNMCjobs(Int_t njobs) {fNMCjobs = njobs;}
//Utilities
void AddModule(AliAnalysisTaskCfg *module);
void AddModules(TObjArray *list);
static Bool_t MergeOutput(const char *output, const char *basedir, Int_t nmaxmerge, Int_t stage=0);
virtual Bool_t MergeOutputs();
virtual void Print(Option_t *option="") const;
+ static Long64_t RunMacroAndExtractLibs(const char* macro, const char *args, TString &libs);
virtual Bool_t StartAnalysis(Long64_t nentries=123456789, Long64_t firstentry=0);
static Bool_t SetupPar(const char *package);
virtual Bool_t Submit();
Bool_t SubmitNext();
Bool_t IsCollection(const char *lfn) const;
+ Bool_t IsMCLoop() const {return fMCLoop;}
virtual Bool_t IsSingleOutput() const;
Bool_t IsUsingTags() const {return TObject::TestBit(AliAnalysisGrid::kUseTags);}
Bool_t LoadModule(AliAnalysisTaskCfg *mod);
Int_t fNproofWorkers; // Number of workers in proof mode
Int_t fNproofWorkersPerSlave; // Max number of workers per slave in proof mode
Int_t fProofReset; // Proof reset mode: 0=no reset, 1=soft, 2=hard
+ Int_t fNMCevents; // Number of MC events in MC loop mode
+ Int_t fNMCjobs; // Number of MC jobs in MC loop mode
TString fRunNumbers; // List of runs to be processed
TString fExecutable; // Executable script for AliEn job
TString fExecutableCommand; // Command(s) to be executed in the executable script
TString fValidationScript; // Name of the validation script
TString fAdditionalRootLibs; // List (separated by blacs) of additional libraries needed for/before analysis libs/par file compilation
TString fAdditionalLibs; // List (separated by blacs) of additional libraries needed for the analysis loaded AFTER all par files
+ TString fGeneratorLibs; // Extra libraries needed by the generator
TString fSplitMode; // Job split mode
TString fAPIVersion; // API version
TString fROOTVersion; // ROOT version
TObjArray *fModules; // List of AliAnalysisTaskCfg modules
TMap fProofParam; // Key-value pairs for proof mode
Bool_t fDropToShell; // If true, execute aliensh on start
+ Bool_t fMCLoop; // MC loop flag
TString fGridJobIDs; // List of last committed jobs
TString fGridStages; // List of last committed jobs
TString fFriendLibs; // List of libs (separated by blacs) needed for friends processing
TString fTreeName; // Name of the tree to be analyzed
- ClassDef(AliAnalysisAlien, 25) // Class providing some AliEn utilities
+ ClassDef(AliAnalysisAlien, 26) // Class providing some AliEn utilities
};
#endif
static Double_t GetGlobalDbl(const char *key, Bool_t &valid);
TMap *GetGlobals() {return fGlobals;}
static Bool_t IsMacroLoaded(const char filename);
+ Bool_t IsMCLoop() const {return fMCLoop;}
static Bool_t IsPipe(std::ostream &out);
Bool_t IsProofMode() const {return (fMode==kProofAnalysis)?kTRUE:kFALSE;}
Bool_t IsRemote() const {return fIsRemote;}
void SetDisableBranches(Bool_t disable=kTRUE) {Changed(); TObject::SetBit(kDisableBranches,disable);}
void SetAsyncReading(Bool_t flag=kTRUE) {fAsyncReading = flag;}
void SetExternalLoop(Bool_t flag) {Changed(); TObject::SetBit(kExternalLoop,flag);}
+ void SetMCLoop(Bool_t flag=kTRUE) {fMCLoop = flag;}
void SetEventPool(AliVEventPool* const epool) {Changed(); fEventPool = epool;}
void SetFileInfoLog(const char *name) {TObject::SetBit(kCollectThroughput,kTRUE); fFileInfoLog = name;}
void SetGridHandler(AliAnalysisGrid * const handler) {Changed(); fGridHandler = handler;}
Bool_t fMustClean; // Flag to let ROOT do cleanup
Bool_t fIsRemote; //! Flag is set for remote analysis
Bool_t fLocked; //! Lock for the manager and handlers
+ Bool_t fMCLoop; // External MC generator loop
UInt_t fDebug; // Debug level
TString fSpecialOutputLocation; // URL/path where the special outputs will be copied
TObjArray *fTasks; // List of analysis tasks
static TString fgCommonFileName; //! Common output file name (not streamed)
static TString fgMacroNames; //! Loaded macro names
static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
- ClassDef(AliAnalysisManager,18) // Analysis manager class
+ ClassDef(AliAnalysisManager,19) // Analysis manager class
};
#endif