]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskTagCreator.cxx
Adding extra check for GPU_FORCE_64BIT_PTR env var
[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 using std::cout;
39 using std::endl;
40 using std::ofstream;
41 ClassImp(AliAnalysisTaskTagCreator)
42
43 ////////////////////////////////////////////////////////////////////////
44
45 AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator():
46     AliAnalysisTaskSE(),
47     fCreateTags(kFALSE),
48     fFirstFile(kTRUE),
49     fRunTag(0), 
50     fTreeT(0),
51     fTagCreator(0),
52     fAODFileName(""),
53     fGUID(0)
54 {
55   // Default constructor
56 }
57
58 AliAnalysisTaskTagCreator::AliAnalysisTaskTagCreator(const char* name):
59     AliAnalysisTaskSE(name),
60     fCreateTags(kFALSE),
61     fFirstFile(kTRUE),
62     fRunTag(0), 
63     fTreeT(0),
64     fTagCreator(0),
65     fAODFileName(""),
66     fGUID(0)
67 {
68   // Constructor
69     DefineOutput(1, TTree::Class());    
70 }
71
72 void 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();
81     PostData(1, fTreeT);
82 }
83
84 void AliAnalysisTaskTagCreator::Init()
85 {
86
87 }
88
89 void AliAnalysisTaskTagCreator::ConnectInputData(Option_t * /*option*/)
90 {
91     // Initialization
92     const char* turl = gSystem->Getenv("ALIEN_JDL_OUTPUTDIR");
93     TString sturl = turl;
94     
95     if (sturl.Length() != 0) {
96       fAODFileName = "alien://";
97       fAODFileName += turl;
98       fAODFileName += "/AliAOD.root";
99     }  
100 }
101
102 void AliAnalysisTaskTagCreator::UserExec(Option_t */*option*/)
103 {
104
105     // Create Tags for the current event
106     AliEventTag* evtTag = new AliEventTag();
107     fTagCreator->FillEventTag(AODEvent(), evtTag);
108     // Reference to the input file
109     TString fturl, fturltemp, guid;
110     
111     TString opt(fInputHandler->GetAnalysisType());
112     opt.ToLower();
113     
114     TFile *file = OutputTree()->GetCurrentFile();
115     const TUrl *url = file->GetEndpointUrl();
116     guid = file->GetUUID().AsString();
117     if (fAODFileName.Length() != 0) {
118         fturl = fAODFileName;
119         guid  = fGUID;
120     } else {
121         fturl = url->GetFile();
122     }
123
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);
136     }
137     //
138     // Add the event tag
139     fRunTag->AddEventTag(*evtTag);
140     PostData(1, fTreeT);
141 }
142
143
144 void AliAnalysisTaskTagCreator::FinishTaskOutput()
145 {
146 // Terminate analysis
147 //
148     if (fInputHandler->GetRunTag()) fRunTag->CopyStandardContent(fInputHandler->GetRunTag());       
149     fTreeT->Fill();
150 }
151
152 Bool_t AliAnalysisTaskTagCreator::Notify()
153 {
154     // Notify file change
155     fInputHandler = (AliInputEventHandler*) 
156       ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
157     return kTRUE;
158 }
159
160
161 void 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;
173         f->Close();
174     }
175     else cout<<"Output file can't be created..."<<endl;
176 }
177
178
179
180 void AliAnalysisTaskTagCreator::Terminate(Option_t */*option*/)
181 {
182 // Terminate analysis
183 //
184     if (fDebug > 1) printf("AnalysisTagCreator: Terminate() \n");
185 }
186
187