Compatibility with ROOT trunk
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskTagCreator.cxx
index 8bdcee0..48c4b96 100644 (file)
  **************************************************************************/
 
 /* $Id$ */
+
+#include <Riostream.h>
+
 #include <TChain.h>
 #include <TTree.h>
 #include <TString.h>
 #include <TFile.h>
+#include <TSystem.h>
 
 #include "AliAnalysisTaskTagCreator.h"
 #include "AliAnalysisManager.h"
 #include "AliAODTagCreator.h"
 #include "AliLog.h"
 
+
+using std::cout;
+using std::endl;
+using std::ofstream;
 ClassImp(AliAnalysisTaskTagCreator)
 
 ////////////////////////////////////////////////////////////////////////
@@ -41,7 +48,9 @@ AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator():
     fFirstFile(kTRUE),
     fRunTag(0), 
     fTreeT(0),
-    fTagCreator(0)
+    fTagCreator(0),
+    fAODFileName(""),
+    fGUID(0)
 {
   // Default constructor
 }
@@ -52,7 +61,9 @@ AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator(const char* name):
     fFirstFile(kTRUE),
     fRunTag(0), 
     fTreeT(0),
-    fTagCreator(0)
+    fTagCreator(0),
+    fAODFileName(""),
+    fGUID(0)
 {
   // Constructor
     DefineOutput(1, TTree::Class());   
@@ -67,44 +78,62 @@ void AliAnalysisTaskTagCreator::UserCreateOutputObjects()
     TBranch * btag = fTreeT->Branch("AliTAG", "AliRunTag", &fRunTag);
     btag->SetCompressionLevel(9);
     fTagCreator = new AliAODTagCreator();
+    PostData(1, fTreeT);
 }
 
 void AliAnalysisTaskTagCreator::Init()
 {
-    // Initialization
-    if (fDebug > 1) AliInfo("Init() \n");
-    // Call configuration file
+
 }
 
+void AliAnalysisTaskTagCreator::ConnectInputData(Option_t * /*option*/)
+{
+    // Initialization
+    const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
+    TString sturl = turl;
+    
+    if (sturl.Length() != 0) {
+      fAODFileName = "alien://";
+      fAODFileName += turl;
+      fAODFileName += "/AliAOD.root";
+    }  
+}
 
 void AliAnalysisTaskTagCreator::UserExec(Option_t */*option*/)
 {
+
     // Create Tags for the current event
     AliEventTag* evtTag = new AliEventTag();
     fTagCreator->FillEventTag(AODEvent(), evtTag);
     // Reference to the input file
-    TString fturl, fturltemp, fguid;
+    TString fturl, fturltemp, guid;
     
     TString opt(fInputHandler->GetAnalysisType());
     opt.ToLower();
     
     TFile *file = OutputTree()->GetCurrentFile();
     const TUrl *url = file->GetEndpointUrl();
-    fguid = file->GetUUID().AsString();
-    if (opt.Contains("grid")) {
-       fturltemp = "alien://"; fturltemp += url->GetFile();
-       fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
+    guid = file->GetUUID().AsString();
+    if (fAODFileName.Length() != 0) {
+       fturl = fAODFileName;
+       guid  = fGUID;
     } else {
        fturl = url->GetFile();
     }
-    evtTag->SetEventId(fInputHandler->GetReadEntry() + 1);
-    evtTag->SetGUID(fguid);
-    if(opt.Contains("grid")) {
-       evtTag->SetMD5(0);
-       evtTag->SetTURL(fturl);
-       evtTag->SetSize(0);
+
+    if (fRunTag->GetFileId(guid) == -1) {
+      AliFileTag *eftag = new AliFileTag();
+
+      eftag->SetGUID(guid);
+      if(fAODFileName.Length() != 0) {
+       eftag->SetMD5("");
+       eftag->SetTURL(fturl);
+       eftag->SetSize(0);
+      }
+      else eftag->SetPath(fturl);
+
+      fRunTag->AddFileTag(eftag);
     }
-    else evtTag->SetPath(fturl);
     //
     // Add the event tag
     fRunTag->AddEventTag(*evtTag);
@@ -123,17 +152,31 @@ void AliAnalysisTaskTagCreator::FinishTaskOutput()
 Bool_t AliAnalysisTaskTagCreator::Notify()
 {
     // Notify file change
-    if (!fFirstFile) {
-       if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());           
-       fTreeT->Fill();
-       fRunTag->Clear();
-    } else {
-       fFirstFile = kFALSE;
-    }
+    fInputHandler = (AliInputEventHandler*) 
+      ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
     return kTRUE;
 }
 
 
+void AliAnalysisTaskTagCreator::GetGUID(TString &guid) {
+    // Get the guid of the AliAOD.root file
+    ofstream myfile ("guid.txt");
+    if (myfile.is_open()) {
+       TFile *f = TFile::Open("AliAOD.root","read");
+       if(f->IsOpen()) {
+           guid = f->GetUUID().AsString();
+           myfile << "AliAOD.root \t"<<f->GetUUID().AsString();
+           cout<<guid.Data()<<endl;
+           myfile.close();
+       }
+       else cout<<"Input file not found"<<endl;
+       f->Close();
+    }
+    else cout<<"Output file can't be created..."<<endl;
+}
+
+
+
 void AliAnalysisTaskTagCreator::Terminate(Option_t */*option*/)
 {
 // Terminate analysis
@@ -141,3 +184,4 @@ void AliAnalysisTaskTagCreator::Terminate(Option_t */*option*/)
     if (fDebug > 1) printf("AnalysisTagCreator: Terminate() \n");
 }
 
+