1 /**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //-----------------------------------------------------------------
23 #include <Riostream.h>
29 #include <TLorentzVector.h>
33 #include <TGridResult.h>
36 #include "AliRunTag.h"
37 #include "AliEventTag.h"
40 #include "AliTagCreator.h"
43 ClassImp(AliTagCreator)
46 //______________________________________________________________________________
47 AliTagCreator::AliTagCreator() :
49 fSE("ALICE::CERN::se"),
53 //==============Default constructor for a AliTagCreator==================
56 //______________________________________________________________________________
57 AliTagCreator::~AliTagCreator() {
58 //================Default destructor for a AliTagCreator=======================
61 //______________________________________________________________________________
62 void AliTagCreator::SetStorage(Int_t storage) {
63 // Sets correctly the storage: 0 for local, 1 for GRID
66 AliInfo(Form("Tags will be stored locally...."));
68 AliInfo(Form("Tags will be stored in the grid...."));
69 if((fStorage != 0)&&(fStorage != 1))
71 AliInfo(Form("Storage was not properly set!!!"));
76 //__________________________________________________________________________
77 Bool_t AliTagCreator::MergeTags(const char *type) {
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 TString tagPattern = type; tagPattern += ".tag.root";
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))) {
90 if (strstr(name,tagPattern)) fgChain->Add(name);
92 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
95 else if(fStorage == 1) {
96 TString alienLocation = gGrid->Pwd();
97 alienLocation += fgridpath.Data();
99 TString queryPattern = "*."; queryPattern += tagPattern;
100 TGridResult *tagresult = gGrid->Query(alienLocation,queryPattern.Data(),"","");
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);
106 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
109 AliRunTag *tag = new AliRunTag;
110 fgChain->SetBranchAddress("AliTAG",&tag);
111 fgChain->GetEntry(0);
112 TString localFileName = "Run"; localFileName += tag->GetRunId();
113 localFileName += ".Merged."; localFileName += tagPattern.Data();
115 TString filename = 0x0;
118 filename = localFileName.Data();
119 AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
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()));
133 fgChain->Merge(filename);
134 gSystem->Exec("rm Run*.Event*");
139 //__________________________________________________________________________
140 Bool_t AliTagCreator::MergeTags(const char *type, TGridResult *result) {
141 //Merges the tags that are listed in the TGridResult
142 AliInfo(Form("Merging tags....."));
143 TChain *fgChain = new TChain("T");
144 TString tagPattern = "."; tagPattern += type; tagPattern += ".tag.root";
146 Int_t nEntries = result->GetEntries();
149 for(Int_t i = 0; i < nEntries; i++) {
150 alienUrl = result->GetKey(i,"turl");
151 fgChain->Add(alienUrl);
153 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
154 AliRunTag *tag = new AliRunTag;
155 fgChain->SetBranchAddress("AliTAG",&tag);
156 fgChain->GetEntry(0);
158 TString localFileName = "Run"; localFileName += tag->GetRunId();
159 localFileName += ".Merged"; localFileName += tagPattern.Data();
161 TString filename = 0x0;
164 filename = localFileName.Data();
165 AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
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();
175 filename = alienFileName.Data();
176 AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
179 fgChain->Merge(filename);