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