]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTagCreator.cxx
1.The QA data created on demand according to the event species at filling time. 2...
[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
b45e5084 56//______________________________________________________________________________
c336835b 57AliTagCreator::~AliTagCreator() {
b45e5084 58//================Default destructor for a AliTagCreator=======================
59}
60
28afeb2e 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//__________________________________________________________________________
5b8d5d69 77Bool_t AliTagCreator::MergeTags(const char *type) {
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");
5b8d5d69 82 TString tagPattern = type; tagPattern += ".tag.root";
4fd84456 83
84 if(fStorage == 0) {
4fd84456 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 += "/";
5b8d5d69 99 TString queryPattern = "*."; queryPattern += tagPattern;
100 TGridResult *tagresult = gGrid->Query(alienLocation,queryPattern.Data(),"","");
4fd84456 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();
5b8d5d69 113 localFileName += ".Merged."; localFileName += tagPattern.Data();
442646f2 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//__________________________________________________________________________
5b8d5d69 140Bool_t AliTagCreator::MergeTags(const char *type, TGridResult *result) {
442646f2 141 //Merges the tags that are listed in the TGridResult
142 AliInfo(Form("Merging tags....."));
143 TChain *fgChain = new TChain("T");
5b8d5d69 144 TString tagPattern = "."; tagPattern += type; tagPattern += ".tag.root";
442646f2 145
146 Int_t nEntries = result->GetEntries();
147
148 TString alienUrl;
149 for(Int_t i = 0; i < nEntries; i++) {
150 alienUrl = result->GetKey(i,"turl");
151 fgChain->Add(alienUrl);
152 }
153 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
154 AliRunTag *tag = new AliRunTag;
442646f2 155 fgChain->SetBranchAddress("AliTAG",&tag);
b2dc099f 156 fgChain->GetEntry(0);
157
4fd84456 158 TString localFileName = "Run"; localFileName += tag->GetRunId();
5b8d5d69 159 localFileName += ".Merged"; localFileName += tagPattern.Data();
4fd84456 160
4fd84456 161 TString filename = 0x0;
162
163 if(fStorage == 0) {
164 filename = localFileName.Data();
165 AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
166 }
c336835b 167 else if(fStorage == 1) {
168 TString alienFileName = "/alien";
169 alienFileName += gGrid->Pwd();
170 alienFileName += fgridpath.Data();
171 alienFileName += "/";
172 alienFileName += localFileName;
173 alienFileName += "?se=";
174 alienFileName += fSE.Data();
4fd84456 175 filename = alienFileName.Data();
176 AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
177 }
178
b2dc099f 179 fgChain->Merge(filename);
4fd84456 180
181 return kTRUE;
182}