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