]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Partial implementation of MC event loop
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 3 Dec 2013 14:00:32 +0000 (14:00 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 3 Dec 2013 14:00:32 +0000 (14:00 +0000)
ANALYSIS/AliAnalysisAlien.cxx
ANALYSIS/AliAnalysisAlien.h
ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisManager.h

index 39b390436bced709c90086fa4342d4ecabe2828f..682b5eb8596bd4fc9f20e73a5c227e4e04b0ea7d 100644 (file)
@@ -29,6 +29,7 @@
 #include "TError.h"
 #include "TROOT.h"
 #include "TSystem.h"
+#include "TInterpreter.h"
 #include "TFile.h"
 #include "TFileCollection.h"
 #include "TChain.h"
@@ -94,6 +95,8 @@ AliAnalysisAlien::AliAnalysisAlien()
                   fNproofWorkers(0),
                   fNproofWorkersPerSlave(0),
                   fProofReset(0),
+                  fNMCevents(0),
+                  fNMCjobs(0),
                   fRunNumbers(),
                   fExecutable(),
                   fExecutableCommand(),
@@ -104,6 +107,7 @@ AliAnalysisAlien::AliAnalysisAlien()
                   fValidationScript(),
                   fAdditionalRootLibs(),
                   fAdditionalLibs(),
+                  fGeneratorLibs(),
                   fSplitMode(),
                   fAPIVersion(),
                   fROOTVersion(),
@@ -139,6 +143,7 @@ AliAnalysisAlien::AliAnalysisAlien()
                   fModules(0),
                   fProofParam(),
                   fDropToShell(true),
+                  fMCLoop(false),
                   fGridJobIDs(""),
                   fGridStages(""),
                   fFriendLibs(""),
@@ -172,6 +177,8 @@ AliAnalysisAlien::AliAnalysisAlien(const char *name)
                   fNproofWorkers(0),
                   fNproofWorkersPerSlave(0),
                   fProofReset(0),
+                  fNMCevents(0),
+                  fNMCjobs(0),
                   fRunNumbers(),
                   fExecutable(),
                   fExecutableCommand(),
@@ -182,6 +189,7 @@ AliAnalysisAlien::AliAnalysisAlien(const char *name)
                   fValidationScript(),
                   fAdditionalRootLibs(),
                   fAdditionalLibs(),
+                  fGeneratorLibs(),
                   fSplitMode(),
                   fAPIVersion(),
                   fROOTVersion(),
@@ -217,6 +225,7 @@ AliAnalysisAlien::AliAnalysisAlien(const char *name)
                   fModules(0),
                   fProofParam(),
                   fDropToShell(true),
+                  fMCLoop(false),
                   fGridJobIDs(""),
                   fGridStages(""),
                   fFriendLibs(""),
@@ -250,6 +259,8 @@ AliAnalysisAlien::AliAnalysisAlien(const AliAnalysisAlien& other)
                   fNproofWorkers(other.fNproofWorkers),
                   fNproofWorkersPerSlave(other.fNproofWorkersPerSlave),
                   fProofReset(other.fProofReset),
+                  fNMCevents(other.fNMCevents),
+                  fNMCjobs(other.fNMCjobs),
                   fRunNumbers(other.fRunNumbers),
                   fExecutable(other.fExecutable),
                   fExecutableCommand(other.fExecutableCommand),
@@ -260,6 +271,7 @@ AliAnalysisAlien::AliAnalysisAlien(const AliAnalysisAlien& other)
                   fValidationScript(other.fValidationScript),
                   fAdditionalRootLibs(other.fAdditionalRootLibs),
                   fAdditionalLibs(other.fAdditionalLibs),
+                  fGeneratorLibs(other.fGeneratorLibs),
                   fSplitMode(other.fSplitMode),
                   fAPIVersion(other.fAPIVersion),
                   fROOTVersion(other.fROOTVersion),
@@ -295,6 +307,7 @@ AliAnalysisAlien::AliAnalysisAlien(const AliAnalysisAlien& other)
                   fModules(0),
                   fProofParam(),
                   fDropToShell(other.fDropToShell),
+                  fMCLoop(other.fMCLoop),
                   fGridJobIDs(other.fGridJobIDs),
                   fGridStages(other.fGridStages),
                   fFriendLibs(other.fFriendLibs),
@@ -370,6 +383,8 @@ AliAnalysisAlien &AliAnalysisAlien::operator=(const AliAnalysisAlien& other)
       fNproofWorkers           = other.fNproofWorkers;
       fNproofWorkersPerSlave   = other.fNproofWorkersPerSlave;
       fProofReset              = other.fProofReset;
+      fNMCevents               = other.fNMCevents;
+      fNMCjobs                 = other.fNMCjobs;
       fRunNumbers              = other.fRunNumbers;
       fExecutable              = other.fExecutable;
       fExecutableCommand       = other.fExecutableCommand;
@@ -380,6 +395,7 @@ AliAnalysisAlien &AliAnalysisAlien::operator=(const AliAnalysisAlien& other)
       fValidationScript        = other.fValidationScript;
       fAdditionalRootLibs      = other.fAdditionalRootLibs;
       fAdditionalLibs          = other.fAdditionalLibs;
+      fGeneratorLibs           = other.fGeneratorLibs;
       fSplitMode               = other.fSplitMode;
       fAPIVersion              = other.fAPIVersion;
       fROOTVersion             = other.fROOTVersion;
@@ -411,6 +427,7 @@ AliAnalysisAlien &AliAnalysisAlien::operator=(const AliAnalysisAlien& other)
       fProofProcessOpt         = other.fProofProcessOpt;
       fMergeDirName            = other.fMergeDirName;
       fDropToShell             = other.fDropToShell;
+      fMCLoop                  = other.fMCLoop;
       fGridJobIDs              = other.fGridJobIDs;
       fGridStages              = other.fGridStages;
       fFriendLibs              = other.fFriendLibs;
@@ -536,9 +553,13 @@ AliAnalysisManager *AliAnalysisAlien::CreateAnalysisManager(const char *name, co
 {
 // 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 ");
@@ -2438,7 +2459,39 @@ Bool_t AliAnalysisAlien::IsSingleOutput() const
 // 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
 {
@@ -3960,16 +4013,21 @@ void AliAnalysisAlien::WriteAnalysisMacro()
       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;
@@ -4100,6 +4158,16 @@ void AliAnalysisAlien::WriteAnalysisMacro()
       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;
@@ -4116,7 +4184,7 @@ void AliAnalysisAlien::WriteAnalysisMacro()
             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;
@@ -4161,6 +4229,8 @@ void AliAnalysisAlien::WriteAnalysisMacro()
             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;
@@ -4182,15 +4252,24 @@ void AliAnalysisAlien::WriteAnalysisMacro()
          }
       }   
       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;
index 83d7bfcc9b3e31c5353cfcb4e4d92fab0a819d28..e3a527237f4cc072e0ce51ea4fa0e97e68caf5e4 100644 (file)
@@ -85,6 +85,7 @@ public:
    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;}
@@ -101,6 +102,10 @@ public:
    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);
@@ -125,6 +130,7 @@ public:
    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();
@@ -166,6 +172,7 @@ protected:
    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);
@@ -195,6 +202,8 @@ private:
    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
@@ -205,6 +214,7 @@ private:
    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
@@ -240,11 +250,12 @@ private:
    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
index 5490de9b11cbd57168668cd7e4ea5fd146bc0e93..e32806b8e0bfb9917f91357e38d8382ae7402072 100644 (file)
@@ -81,6 +81,7 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
                     fMustClean(kFALSE),
                     fIsRemote(kFALSE),
                     fLocked(kFALSE),
+                    fMCLoop(kFALSE),
                     fDebug(0),
                     fSpecialOutputLocation(""), 
                     fTasks(0),
@@ -151,6 +152,7 @@ AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
                     fMustClean(other.fMustClean),
                     fIsRemote(other.fIsRemote),
                     fLocked(other.fLocked),
+                    fMCLoop(other.fMCLoop),
                     fDebug(other.fDebug),
                     fSpecialOutputLocation(""), 
                     fTasks(NULL),
@@ -216,6 +218,7 @@ AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& othe
       fInitOK     = other.fInitOK;
       fIsRemote   = other.fIsRemote;
       fLocked     = other.fLocked;
+      fMCLoop     = other.fMCLoop;
       fDebug      = other.fDebug;
       fTasks      = new TObjArray(*other.fTasks);
       fTopTasks   = new TObjArray(*other.fTopTasks);
index a10466504c4db23f7d48cf4d51d3be59b0b496db..538e8fa99c13885038b1a75470f1093f26530111 100644 (file)
@@ -134,6 +134,7 @@ enum EAliAnalysisFlags {
    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;}
@@ -152,6 +153,7 @@ enum EAliAnalysisFlags {
    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;}
@@ -246,6 +248,7 @@ private:
    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
@@ -285,6 +288,6 @@ private:
    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