]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskTagCreator.cxx
Correct reference to AOD file in AliEventTag.
[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 <Riostream.h>
19
20 #include <TChain.h>
21 #include <TTree.h>
22 #include <TString.h>
23 #include <TFile.h>
24 #include <TSystem.h>
25
26 #include "AliAnalysisTaskTagCreator.h"
27 #include "AliAnalysisManager.h"
28 #include "AliESDEvent.h"
29 #include "AliAODEvent.h"
30 #include "AliESDInputHandler.h"
31 #include "AliAODHandler.h"
32 #include "AliRunTag.h"
33 #include "AliEventTag.h"
34 #include "AliAODTagCreator.h"
35 #include "AliLog.h"
36
37
38 ClassImp(AliAnalysisTaskTagCreator)
39
40 ////////////////////////////////////////////////////////////////////////
41
42 AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator():
43     AliAnalysisTaskSE(),
44     fCreateTags(kFALSE),
45     fFirstFile(kTRUE),
46     fRunTag(0), 
47     fTreeT(0),
48     fTagCreator(0),
49     fAODFileName("")
50 {
51   // Default constructor
52 }
53
54 AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator(const char* name):
55     AliAnalysisTaskSE(name),
56     fCreateTags(kFALSE),
57     fFirstFile(kTRUE),
58     fRunTag(0), 
59     fTreeT(0),
60     fTagCreator(0),
61     fAODFileName("")
62 {
63   // Constructor
64     DefineOutput(1, TTree::Class());    
65 }
66
67 void AliAnalysisTaskTagCreator::UserCreateOutputObjects()
68 {
69 // Create the output container
70     OpenFile(1);
71     fTreeT  = new TTree("T", "AOD Tags");
72     fRunTag = new AliRunTag();
73     TBranch * btag = fTreeT->Branch("AliTAG", "AliRunTag", &fRunTag);
74     btag->SetCompressionLevel(9);
75     fTagCreator = new AliAODTagCreator();
76 }
77
78 void AliAnalysisTaskTagCreator::Init()
79 {
80
81 }
82
83 void AliAnalysisTaskTagCreator::ConnectInputData(Option_t * /*option*/)
84 {
85     // Initialization
86     const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
87     if (turl != "") {
88       fAODFileName = "alien://";
89       fAODFileName += turl;
90       fAODFileName += "/AliAOD.root";
91     }  
92 }
93
94 void AliAnalysisTaskTagCreator::UserExec(Option_t */*option*/)
95 {
96
97     // Create Tags for the current event
98     AliEventTag* evtTag = new AliEventTag();
99     fTagCreator->FillEventTag(AODEvent(), evtTag);
100     // Reference to the input file
101     TString fturl, fturltemp, fguid;
102     
103     TString opt(fInputHandler->GetAnalysisType());
104     opt.ToLower();
105     
106     TFile *file = OutputTree()->GetCurrentFile();
107     const TUrl *url = file->GetEndpointUrl();
108     fguid = file->GetUUID().AsString();
109     if (fAODFileName.Length() != 0) {
110         fturl = fAODFileName;
111         GetGUID(fguid);
112     } else {
113         fturl = url->GetFile();
114     }
115
116     evtTag->SetGUID(fguid);
117     if(fAODFileName.Length() != 0) {
118         evtTag->SetMD5("");
119         evtTag->SetTURL(fturl);
120         evtTag->SetSize(0);
121     }
122     else evtTag->SetPath(fturl);
123     //
124     // Add the event tag
125     fRunTag->AddEventTag(*evtTag);
126     PostData(1, fTreeT);
127 }
128
129
130 void AliAnalysisTaskTagCreator::FinishTaskOutput()
131 {
132 // Terminate analysis
133 //
134     if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());       
135     fTreeT->Fill();
136 }
137
138 Bool_t AliAnalysisTaskTagCreator::Notify()
139 {
140     // Notify file change
141     fInputHandler = (AliInputEventHandler*) 
142       ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
143
144     if (!fFirstFile) {
145         if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());           
146         fTreeT->Fill();
147         fRunTag->Clear();
148     } else {
149         fFirstFile = kFALSE;
150     }
151     return kTRUE;
152 }
153
154
155 void AliAnalysisTaskTagCreator::GetGUID(TString &guid) {
156     // Get the guid of the AliAOD.root file
157     ofstream myfile ("guid.txt");
158     if (myfile.is_open()) {
159         TFile *f = TFile::Open("AliAOD.root","read");
160         if(f->IsOpen()) {
161             guid = f->GetUUID().AsString();
162             myfile << "AliAOD.root \t"<<f->GetUUID().AsString();
163             cout<<guid.Data()<<endl;
164             myfile.close();
165         }
166         else cout<<"Input file not found"<<endl;
167     }
168     else cout<<"Output file can't be created..."<<endl;
169 }
170
171
172
173 void AliAnalysisTaskTagCreator::Terminate(Option_t */*option*/)
174 {
175 // Terminate analysis
176 //
177     if (fDebug > 1) printf("AnalysisTagCreator: Terminate() \n");
178 }
179
180