]>
Commit | Line | Data |
---|---|---|
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 | |
23 | #include <Riostream.h> | |
24 | #include <TFile.h> | |
25 | #include <TString.h> | |
26 | #include <TTree.h> | |
27 | #include <TSystem.h> | |
28 | #include <TChain.h> | |
29 | #include <TLorentzVector.h> | |
30 | ||
31 | //ROOT-AliEn | |
32 | #include <TGrid.h> | |
33 | #include <TGridResult.h> | |
34 | ||
35 | //AliRoot | |
36 | #include "AliRunTag.h" | |
37 | #include "AliEventTag.h" | |
38 | #include "AliLog.h" | |
39 | ||
40 | #include "AliTagCreator.h" | |
41 | ||
42 | ||
43 | ClassImp(AliTagCreator) | |
44 | ||
45 | ||
46 | //______________________________________________________________________________ | |
47 | AliTagCreator::AliTagCreator() : | |
48 | TObject(), | |
49 | fSE("ALICE::CERN::se"), | |
50 | fgridpath(""), | |
51 | fStorage(0) | |
52 | { | |
53 | //==============Default constructor for a AliTagCreator================== | |
54 | } | |
55 | ||
56 | //______________________________________________________________________________ | |
57 | AliTagCreator::~AliTagCreator() { | |
58 | //================Default destructor for a AliTagCreator======================= | |
59 | } | |
60 | ||
61 | //______________________________________________________________________________ | |
62 | void AliTagCreator::SetStorage(Int_t storage) { | |
63 | // Sets correctly the storage: 0 for local, 1 for GRID | |
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 | ||
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"; | |
83 | ||
84 | if(fStorage == 0) { | |
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); | |
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 | 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); | |
105 | }//grid result loop | |
106 | AliInfo(Form("Chained tag files: %d",fgChain->GetEntries())); | |
107 | }//grid mode | |
108 | ||
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(); | |
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 | } | |
132 | ||
133 | fgChain->Merge(filename); | |
134 | gSystem->Exec("rm Run*.Event*"); | |
135 | ||
136 | return kTRUE; | |
137 | } | |
138 | ||
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"; | |
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; | |
155 | fgChain->SetBranchAddress("AliTAG",&tag); | |
156 | fgChain->GetEntry(0); | |
157 | ||
158 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
159 | localFileName += ".Merged"; localFileName += tagPattern.Data(); | |
160 | ||
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 | } | |
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())); | |
177 | } | |
178 | ||
179 | fgChain->Merge(filename); | |
180 | ||
181 | return kTRUE; | |
182 | } |