]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisTaskTagCreator.cxx
Protections against missing MC files as requested in https://savannah.cern.ch/bugs...
[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),
49 fAODFileName("")
7e27c6e3 50{
51 // Default constructor
52}
53
54AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator(const char* name):
55 AliAnalysisTaskSE(name),
e7c71df0 56 fCreateTags(kFALSE),
7e27c6e3 57 fFirstFile(kTRUE),
58 fRunTag(0),
59 fTreeT(0),
46f5616d 60 fTagCreator(0),
61 fAODFileName("")
7e27c6e3 62{
63 // Constructor
64 DefineOutput(1, TTree::Class());
65}
66
67void 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
78void AliAnalysisTaskTagCreator::Init()
79{
46f5616d 80
7e27c6e3 81}
82
46f5616d 83void 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}
7e27c6e3 93
94void AliAnalysisTaskTagCreator::UserExec(Option_t */*option*/)
95{
46f5616d 96
7e27c6e3 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();
46f5616d 109 if (fAODFileName.Length() != 0) {
110 fturl = fAODFileName;
111 GetGUID(fguid);
7e27c6e3 112 } else {
113 fturl = url->GetFile();
114 }
46f5616d 115
7e27c6e3 116 evtTag->SetGUID(fguid);
46f5616d 117 if(fAODFileName.Length() != 0) {
9b4aee57 118 evtTag->SetMD5("");
7e27c6e3 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
130void AliAnalysisTaskTagCreator::FinishTaskOutput()
131{
132// Terminate analysis
133//
134 if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());
135 fTreeT->Fill();
136}
137
138Bool_t AliAnalysisTaskTagCreator::Notify()
139{
140 // Notify file change
46f5616d 141 fInputHandler = (AliInputEventHandler*)
142 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
143
7e27c6e3 144 if (!fFirstFile) {
145 if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());
146 fTreeT->Fill();
147 fRunTag->Clear();
148 } else {
149 fFirstFile = kFALSE;
150 }
f9f9c880 151 return kTRUE;
7e27c6e3 152}
153
154
46f5616d 155void 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
7e27c6e3 173void AliAnalysisTaskTagCreator::Terminate(Option_t */*option*/)
174{
175// Terminate analysis
176//
177 if (fDebug > 1) printf("AnalysisTagCreator: Terminate() \n");
178}
179
46f5616d 180