]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskTagCreator.cxx
Add histos from all analyses to the output
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskTagCreator.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17  
18 #include <TChain.h>
19 #include <TTree.h>
20 #include <TString.h>
21 #include <TFile.h>
22
23 #include "AliAnalysisTaskTagCreator.h"
24 #include "AliAnalysisManager.h"
25 #include "AliESDEvent.h"
26 #include "AliAODEvent.h"
27 #include "AliESDInputHandler.h"
28 #include "AliAODHandler.h"
29 #include "AliRunTag.h"
30 #include "AliEventTag.h"
31 #include "AliAODTagCreator.h"
32 #include "AliLog.h"
33
34 ClassImp(AliAnalysisTaskTagCreator)
35
36 ////////////////////////////////////////////////////////////////////////
37
38 AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator():
39     AliAnalysisTaskSE(),
40     fCreateTags(kFALSE),
41     fFirstFile(kTRUE),
42     fRunTag(0), 
43     fTreeT(0),
44     fTagCreator(0)
45 {
46   // Default constructor
47 }
48
49 AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator(const char* name):
50     AliAnalysisTaskSE(name),
51     fCreateTags(kFALSE),
52     fFirstFile(kTRUE),
53     fRunTag(0), 
54     fTreeT(0),
55     fTagCreator(0)
56 {
57   // Constructor
58     DefineOutput(1, TTree::Class());    
59 }
60
61 void AliAnalysisTaskTagCreator::UserCreateOutputObjects()
62 {
63 // Create the output container
64     OpenFile(1);
65     fTreeT  = new TTree("T", "AOD Tags");
66     fRunTag = new AliRunTag();
67     TBranch * btag = fTreeT->Branch("AliTAG", "AliRunTag", &fRunTag);
68     btag->SetCompressionLevel(9);
69     fTagCreator = new AliAODTagCreator();
70 }
71
72 void AliAnalysisTaskTagCreator::Init()
73 {
74     // Initialization
75     if (fDebug > 1) AliInfo("Init() \n");
76     // Call configuration file
77 }
78
79
80 void AliAnalysisTaskTagCreator::UserExec(Option_t */*option*/)
81 {
82     // Create Tags for the current event
83     AliEventTag* evtTag = new AliEventTag();
84     fTagCreator->FillEventTag(AODEvent(), evtTag);
85     // Reference to the input file
86     TString fturl, fturltemp, fguid;
87     
88     TString opt(fInputHandler->GetAnalysisType());
89     opt.ToLower();
90     
91     TFile *file = OutputTree()->GetCurrentFile();
92     const TUrl *url = file->GetEndpointUrl();
93     fguid = file->GetUUID().AsString();
94     if (opt.Contains("grid")) {
95         fturltemp = "alien://"; fturltemp += url->GetFile();
96         fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
97     } else {
98         fturl = url->GetFile();
99     }
100     evtTag->SetEventId(fInputHandler->GetReadEntry() + 1);
101     evtTag->SetGUID(fguid);
102     if(opt.Contains("grid")) {
103         evtTag->SetMD5(0);
104         evtTag->SetTURL(fturl);
105         evtTag->SetSize(0);
106     }
107     else evtTag->SetPath(fturl);
108     //
109     // Add the event tag
110     fRunTag->AddEventTag(*evtTag);
111     PostData(1, fTreeT);
112 }
113
114
115 void AliAnalysisTaskTagCreator::FinishTaskOutput()
116 {
117 // Terminate analysis
118 //
119     if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());       
120     fTreeT->Fill();
121 }
122
123 Bool_t AliAnalysisTaskTagCreator::Notify()
124 {
125     // Notify file change
126     if (!fFirstFile) {
127         if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());           
128         fTreeT->Fill();
129         fRunTag->Clear();
130     } else {
131         fFirstFile = kFALSE;
132     }
133     return kTRUE;
134 }
135
136
137 void AliAnalysisTaskTagCreator::Terminate(Option_t */*option*/)
138 {
139 // Terminate analysis
140 //
141     if (fDebug > 1) printf("AnalysisTagCreator: Terminate() \n");
142 }
143