Store total number of produced particles in the header.
[u/mrichter/AliRoot.git] / STEER / AliTagCreator.cxx
CommitLineData
b45e5084 1/**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
4 * *
5 * Permission to use, copy, modify and distribute this software and its *
6 * documentation strictly for non-commercial purposes is hereby granted *
7 * without fee, provided that the above copyright notice appears in all *
8 * copies and that both the copyright notice and this permission notice *
9 * appear in the supporting documentation. The authors make no claims *
10 * about the suitability of this software for any purpose. It is *
11 * provided "as is" without express or implied warranty. *
12 **************************************************************************/
13
14/* $Id$ */
15
16//-----------------------------------------------------------------
17// AliTagCreator class
18// This is the class to deal with the tag creation (post process)
19// Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
20//-----------------------------------------------------------------
21
22//ROOT
c336835b 23#include <Riostream.h>
b45e5084 24#include <TFile.h>
25#include <TString.h>
cb1645b7 26#include <TTree.h>
4fd84456 27#include <TSystem.h>
28#include <TChain.h>
2bdb9d38 29#include <TLorentzVector.h>
b45e5084 30
31//ROOT-AliEn
32#include <TGrid.h>
b45e5084 33#include <TGridResult.h>
b45e5084 34
35//AliRoot
36#include "AliRunTag.h"
37#include "AliEventTag.h"
b45e5084 38#include "AliLog.h"
39
b45e5084 40#include "AliTagCreator.h"
41
42
43ClassImp(AliTagCreator)
44
45
46//______________________________________________________________________________
442646f2 47 AliTagCreator::AliTagCreator() :
48 TObject(),
b2dc099f 49 fSE("ALICE::CERN::se"),
442646f2 50 fgridpath(""),
51 fStorage(0)
52{
b45e5084 53 //==============Default constructor for a AliTagCreator==================
b45e5084 54}
55
56//______________________________________________________________________________
c336835b 57AliTagCreator::~AliTagCreator() {
b45e5084 58//================Default destructor for a AliTagCreator=======================
59}
60
61//______________________________________________________________________________
c336835b 62void AliTagCreator::SetStorage(Int_t storage) {
cb1645b7 63 // Sets correctly the storage: 0 for local, 1 for GRID
28afeb2e 64 fStorage = storage;
65 if(fStorage == 0)
66 AliInfo(Form("Tags will be stored locally...."));
67 if(fStorage == 1)
68 AliInfo(Form("Tags will be stored in the grid...."));
69 if((fStorage != 0)&&(fStorage != 1))
70 {
71 AliInfo(Form("Storage was not properly set!!!"));
72 abort();
73 }
74}
75
4fd84456 76//__________________________________________________________________________
c336835b 77Bool_t AliTagCreator::MergeTags() {
4fd84456 78 //Merges the tags and stores the merged tag file
79 //locally if fStorage=0 or in the grid if fStorage=1
80 AliInfo(Form("Merging tags....."));
81 TChain *fgChain = new TChain("T");
82
83 if(fStorage == 0) {
84 const char * tagPattern = "tag";
85 // Open the working directory
86 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
87 const char * name = 0x0;
88 // Add all files matching *pattern* to the chain
89 while((name = gSystem->GetDirEntry(dirp))) {
22c08f55 90 if (strstr(name,tagPattern)) fgChain->Add(name);
4fd84456 91 }//directory loop
92 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
93 }//local mode
94
95 else if(fStorage == 1) {
96 TString alienLocation = gGrid->Pwd();
97 alienLocation += fgridpath.Data();
98 alienLocation += "/";
99
100 TGridResult *tagresult = gGrid->Query(alienLocation,"*tag.root","","");
101 Int_t nEntries = tagresult->GetEntries();
102 for(Int_t i = 0; i < nEntries; i++) {
103 TString alienUrl = tagresult->GetKey(i,"turl");
104 fgChain->Add(alienUrl);
105 }//grid result loop
106 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
107 }//grid mode
108
109 AliRunTag *tag = new AliRunTag;
4fd84456 110 fgChain->SetBranchAddress("AliTAG",&tag);
b2dc099f 111 fgChain->GetEntry(0);
442646f2 112 TString localFileName = "Run"; localFileName += tag->GetRunId();
113 localFileName += ".Merged"; localFileName += ".ESD.tag.root";
114
115 TString filename = 0x0;
116
117 if(fStorage == 0) {
118 filename = localFileName.Data();
119 AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
120 }
121 else if(fStorage == 1) {
122 TString alienFileName = "/alien";
123 alienFileName += gGrid->Pwd();
124 alienFileName += fgridpath.Data();
125 alienFileName += "/";
126 alienFileName += localFileName;
127 alienFileName += "?se=";
128 alienFileName += fSE.Data();
129 filename = alienFileName.Data();
130 AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
131 }
442646f2 132
b2dc099f 133 fgChain->Merge(filename);
0e7ce776 134 gSystem->Exec("rm Run*.Event*");
442646f2 135
136 return kTRUE;
137}
138
139//__________________________________________________________________________
140Bool_t AliTagCreator::MergeTags(TGridResult *result) {
141 //Merges the tags that are listed in the TGridResult
142 AliInfo(Form("Merging tags....."));
143 TChain *fgChain = new TChain("T");
144
145 Int_t nEntries = result->GetEntries();
146
147 TString alienUrl;
148 for(Int_t i = 0; i < nEntries; i++) {
149 alienUrl = result->GetKey(i,"turl");
150 fgChain->Add(alienUrl);
151 }
152 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
153 AliRunTag *tag = new AliRunTag;
442646f2 154 fgChain->SetBranchAddress("AliTAG",&tag);
b2dc099f 155 fgChain->GetEntry(0);
156
4fd84456 157 TString localFileName = "Run"; localFileName += tag->GetRunId();
158 localFileName += ".Merged"; localFileName += ".ESD.tag.root";
159
4fd84456 160 TString filename = 0x0;
161
162 if(fStorage == 0) {
163 filename = localFileName.Data();
164 AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
165 }
c336835b 166 else if(fStorage == 1) {
167 TString alienFileName = "/alien";
168 alienFileName += gGrid->Pwd();
169 alienFileName += fgridpath.Data();
170 alienFileName += "/";
171 alienFileName += localFileName;
172 alienFileName += "?se=";
173 alienFileName += fSE.Data();
4fd84456 174 filename = alienFileName.Data();
175 AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
176 }
177
b2dc099f 178 fgChain->Merge(filename);
4fd84456 179
180 return kTRUE;
181}