Added loop for extraction of clusters really attached to its track.
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskTagCreator.cxx
index 7ceeaef..48c4b96 100644 (file)
@@ -35,6 +35,9 @@
 #include "AliLog.h"
 
 
+using std::cout;
+using std::endl;
+using std::ofstream;
 ClassImp(AliAnalysisTaskTagCreator)
 
 ////////////////////////////////////////////////////////////////////////
@@ -46,7 +49,8 @@ AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator():
     fRunTag(0), 
     fTreeT(0),
     fTagCreator(0),
-    fAODFileName("")
+    fAODFileName(""),
+    fGUID(0)
 {
   // Default constructor
 }
@@ -58,7 +62,8 @@ AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator(const char* name):
     fRunTag(0), 
     fTreeT(0),
     fTagCreator(0),
-    fAODFileName("")
+    fAODFileName(""),
+    fGUID(0)
 {
   // Constructor
     DefineOutput(1, TTree::Class());   
@@ -73,6 +78,7 @@ void AliAnalysisTaskTagCreator::UserCreateOutputObjects()
     TBranch * btag = fTreeT->Branch("AliTAG", "AliRunTag", &fRunTag);
     btag->SetCompressionLevel(9);
     fTagCreator = new AliAODTagCreator();
+    PostData(1, fTreeT);
 }
 
 void AliAnalysisTaskTagCreator::Init()
@@ -100,28 +106,34 @@ void AliAnalysisTaskTagCreator::UserExec(Option_t */*option*/)
     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();
+    guid = file->GetUUID().AsString();
     if (fAODFileName.Length() != 0) {
        fturl = fAODFileName;
-       GetGUID(fguid);
+       guid  = fGUID;
     } else {
        fturl = url->GetFile();
     }
 
-    evtTag->SetGUID(fguid);
-    if(fAODFileName.Length() != 0) {
-       evtTag->SetMD5("");
-       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);
@@ -142,14 +154,6 @@ Bool_t AliAnalysisTaskTagCreator::Notify()
     // Notify file change
     fInputHandler = (AliInputEventHandler*) 
       ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
-
-    if (!fFirstFile) {
-       if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());           
-       fTreeT->Fill();
-       fRunTag->Clear();
-    } else {
-       fFirstFile = kFALSE;
-    }
     return kTRUE;
 }
 
@@ -166,6 +170,7 @@ void AliAnalysisTaskTagCreator::GetGUID(TString &guid) {
            myfile.close();
        }
        else cout<<"Input file not found"<<endl;
+       f->Close();
     }
     else cout<<"Output file can't be created..."<<endl;
 }