]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskTagCreator.cxx
Added Protection and Error Message for missing Output Tree
[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     fGUID(0)
51 {
52   // Default constructor
53 }
54
55 AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator(const char* name):
56     AliAnalysisTaskSE(name),
57     fCreateTags(kFALSE),
58     fFirstFile(kTRUE),
59     fRunTag(0), 
60     fTreeT(0),
61     fTagCreator(0),
62     fAODFileName(""),
63     fGUID(0)
64 {
65   // Constructor
66     DefineOutput(1, TTree::Class());    
67 }
68
69 void 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();
78 }
79
80 void AliAnalysisTaskTagCreator::Init()
81 {
82
83 }
84
85 void AliAnalysisTaskTagCreator::ConnectInputData(Option_t * /*option*/)
86 {
87     // Initialization
88     const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
89     TString sturl = turl;
90     
91     if (sturl.Length() != 0) {
92       fAODFileName = "alien://";
93       fAODFileName += turl;
94       fAODFileName += "/AliAOD.root";
95     }  
96 }
97
98 void AliAnalysisTaskTagCreator::UserExec(Option_t */*option*/)
99 {
100
101     // Create Tags for the current event
102     AliEventTag* evtTag = new AliEventTag();
103     fTagCreator->FillEventTag(AODEvent(), evtTag);
104     // Reference to the input file
105     TString fturl, fturltemp, guid;
106     
107     TString opt(fInputHandler->GetAnalysisType());
108     opt.ToLower();
109     
110     TFile *file = OutputTree()->GetCurrentFile();
111     const TUrl *url = file->GetEndpointUrl();
112     guid = file->GetUUID().AsString();
113     if (fAODFileName.Length() != 0) {
114         fturl = fAODFileName;
115         guid  = fGUID;
116     } else {
117         fturl = url->GetFile();
118     }
119
120     evtTag->SetGUID(guid);
121     if(fAODFileName.Length() != 0) {
122         evtTag->SetMD5("");
123         evtTag->SetTURL(fturl);
124         evtTag->SetSize(0);
125     }
126     else evtTag->SetPath(fturl);
127     //
128     // Add the event tag
129     fRunTag->AddEventTag(*evtTag);
130     PostData(1, fTreeT);
131 }
132
133
134 void AliAnalysisTaskTagCreator::FinishTaskOutput()
135 {
136 // Terminate analysis
137 //
138     if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());       
139     fTreeT->Fill();
140 }
141
142 Bool_t AliAnalysisTaskTagCreator::Notify()
143 {
144     // Notify file change
145     fInputHandler = (AliInputEventHandler*) 
146       ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
147     return kTRUE;
148 }
149
150
151 void AliAnalysisTaskTagCreator::GetGUID(TString &guid) {
152     // Get the guid of the AliAOD.root file
153     ofstream myfile ("guid.txt");
154     if (myfile.is_open()) {
155         TFile *f = TFile::Open("AliAOD.root","read");
156         if(f->IsOpen()) {
157             guid = f->GetUUID().AsString();
158             myfile << "AliAOD.root \t"<<f->GetUUID().AsString();
159             cout<<guid.Data()<<endl;
160             myfile.close();
161         }
162         else cout<<"Input file not found"<<endl;
163         f->Close();
164     }
165     else cout<<"Output file can't be created..."<<endl;
166 }
167
168
169
170 void AliAnalysisTaskTagCreator::Terminate(Option_t */*option*/)
171 {
172 // Terminate analysis
173 //
174     if (fDebug > 1) printf("AnalysisTagCreator: Terminate() \n");
175 }
176
177