]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/TGliteXmlEventlist.cxx
Use MSTU(16) = 2 for heavy flavor. HF Hadrons point to the
[u/mrichter/AliRoot.git] / ANALYSIS / TGliteXmlEventlist.cxx
CommitLineData
2589e668 1#include "TGliteXmlEventlist.h"
2
3///////////////////////////////////////////////////////////////////////////////////////
4// class to read gLite XML collections
5// Autor: Dr. A.-J. Peters - CERN 2004/ALICE Mail-to: Andreas.Joachim.Peters@cern.ch
6///////////////////////////////////////////////////////////////////////////////////////
7
8// example:
9// ---------------------------------------------------------------------------------
10// TGliteXmlEventlist* evlist = new TGliteXmlEventlist("/tmp/fileset.rxml");
11// evlist->Reset()
12// // loop over all events
13// while (evlist->Next()) {
14// printf("URL for file AliESDs.root is: \n", evlist->GetURL("AliESDs.root"));
15// }
16// delete evlist;
17// ---------------------------------------------------------------------------------
18
19#include <TCollection.h>
20#include <TMap.h>
21#include <TObjString.h>
22#include <TXMLEngine.h>
23#include <TList.h>
24
25
26ClassImp(TGliteXmlEventlist)
27
28
29TGliteXmlEventlist::TGliteXmlEventlist(const char* localfilename) {
30//Andi - please put a comment
31 fXmlFile = localfilename;
32 fEventList = new TList();
33 fEventList->SetOwner(kTRUE);
34 fEventListIter = new TIter(fEventList);
35 fCurrent = 0;
36 ReadXML();
37}
38
39TGliteXmlEventlist::~TGliteXmlEventlist() {
40//Andi - please put a comment
41 delete fEventList;
42 delete fEventListIter;
43}
44
45void
46TGliteXmlEventlist::Reset() {
47//Andi - please put a comment
48 fEventListIter->Reset();
49 fCurrent = 0;
50}
51
52TMap* TGliteXmlEventlist::Next() {
53//Andi - please put a comment
54 fCurrent = (TMap*)fEventListIter->Next();
55 return fCurrent;
56}
57
58void TGliteXmlEventlist::ReadXML() {
59//Andi - please put a comment
60 TXMLEngine* xml = new TXMLEngine();
010ba687 61#if ROOT_VERSION_CODE < 328704
2589e668 62 xmlDocPointer xdoc = xml->ParseFile(fXmlFile);
63 xmlNodePointer xglite = xml->DocGetRootElement(xdoc);
64 xmlNodePointer xdtext = xml->GetChild(xglite);
65 xmlNodePointer xcollection = xml->GetNext(xdtext);
010ba687 66
2589e668 67 xmlNodePointer xtext = 0;
68 xmlNodePointer xevent = 0;
69 xmlNodePointer xtextnext = 0;
70 xmlNodePointer xeventnext = 0;
010ba687 71#else
72 XMLDocPointer_t xdoc = xml->ParseFile(fXmlFile);
73 XMLNodePointer_t xglite = xml->DocGetRootElement(xdoc);
74 XMLNodePointer_t xdtext = xml->GetChild(xglite);
75 XMLNodePointer_t xcollection = xml->GetNext(xdtext);
76
77 XMLNodePointer_t xtext = 0;
78 XMLNodePointer_t xevent = 0;
79 XMLNodePointer_t xtextnext = 0;
80 XMLNodePointer_t xeventnext = 0;
81#endif
2589e668 82 Bool_t first_event=kTRUE;
83 do {
84 if (first_event) {
85 xtextnext = xml->GetChild(xcollection);
86 first_event = kFALSE;
87 } else {
88 xtextnext = xml->GetNext(xevent);
89 }
90
91 if (xtextnext) {
92 xeventnext = xml->GetNext(xtextnext);
93 xtext = xeventnext;
94 xevent = xeventnext;
95 } else {
96 xtext = 0;
97 }
98
99 if (xevent) {
100 if (xml->GetAttr(xevent,"name")) {
101 TMap* files = new TMap();
102
103 // here is our event
104 // printf("Found xevent: %s\n",xml->GetAttr(xevent,"name"));
105
106 Bool_t first_file = kTRUE;
107
010ba687 108#if ROOT_VERSION_CODE < 328704
109 xmlNodePointer xfile = 0;
110 xmlNodePointer xfiletext = 0;
111
112 xmlNodePointer xfilenext = 0;
113 xmlNodePointer xfiletextnext = 0;
114#else
115 XMLNodePointer_t xfile = 0;
116 XMLNodePointer_t xfiletext = 0;
2589e668 117
010ba687 118 XMLNodePointer_t xfilenext = 0;
119 XMLNodePointer_t xfiletextnext = 0;
120#endif
2589e668 121 do {
122 if (first_file) {
123 xfiletextnext = xml->GetChild(xevent);
124 first_file = kFALSE;
125 } else {
126 xfiletextnext = xml->GetNext(xfile);
127 }
128
129 if (xfiletextnext) {
130 xfilenext = xml->GetNext(xfiletextnext);
131 xfiletext = xfilenext;
132 xfile = xfilenext;
133 } else {
134 xfile = 0;
135 xfiletext = 0;
136 }
137 if (xfile) {
138 // here we have an event file
139 // printf("Found file: %s\n",xml->GetAttr(xfile,"name"));
140
141 // get the attributes;
142 // xml->GetAttr(xfile,"comment");
143 // xml->GetAttr(xfile,"date");
144 // xml->GetAttr(xfile,"group");
145 // xml->GetAttr(xfile,"guid");
146 // xml->GetAttr(xfile,"path");
147 // xml->GetAttr(xfile,"permissions");
148 // xml->GetAttr(xfile,"pfn");
149 // xml->GetAttr(xfile,"se");
150 // xml->GetAttr(xfile,"size");
151 // xml->GetAttr(xfile,"user");
152
153 Bool_t first_mirror = kTRUE;
154
010ba687 155#if ROOT_VERSION_CODE < 328704
156 xmlNodePointer xmirror = 0;
157 xmlNodePointer xmirrortext = 0;
158
159 xmlNodePointer xmirrornext = 0;
160 xmlNodePointer xmirrortextnext = 0;
161#else
162 XMLNodePointer_t xmirror = 0;
163 XMLNodePointer_t xmirrortext = 0;
2589e668 164
010ba687 165 XMLNodePointer_t xmirrornext = 0;
166 XMLNodePointer_t xmirrortextnext = 0;
167#endif
2589e668 168
169 do {
170 if (first_mirror) {
171 xmirrortextnext = xml->GetChild(xfile);
172 first_mirror = kFALSE;
173 } else {
174 xmirrortextnext = xml->GetNext(xmirror);
175 }
176
177 if (xmirrortextnext) {
178 xmirrornext = xml->GetNext(xmirrortextnext);
179 xmirrortext = xmirrornext;
180 xmirror = xmirrornext;
181 } else {
182 xmirror = 0;
183 xmirrortext = 0;
184 }
185 if (xmirror) {
186 // here we have a file mirror
187 xml->GetAttr(xmirror,"name");
188 xml->GetAttr(xmirror,"domain");
189 xml->GetAttr(xmirror,"latitude");
190 xml->GetAttr(xmirror,"longitude");
191 xml->GetAttr(xmirror,"location");
192 xml->GetAttr(xmirror,"master");
193 xml->GetAttr(xmirror,"site");
194 xml->GetAttr(xmirror,"rootd");
195 const char* master = 0;
196 if ( (master = xml->GetAttr(xmirror,"master"))) {
197 if (atoi(master) == 1) {
198 files->Add(new TObjString(xml->GetAttr(xfile,"name")) , new TObjString(xml->GetAttr(xmirror,"rootd")));
199 }
200 }
201 // printf("Found File Mirror: %s\n",xml->GetAttr(xmirror,"name"));
202 }
203 } while (xmirror);
204 }
205 } while (xfile);
206 // printf("Adding files\n");
207 fEventList->Add(files);
208 }
209 }
210 } while ( xtext );
211 delete xml;
212}
213
214const char* TGliteXmlEventlist::GetURL(const char* filename) const {
215//Andi - please put a comment
216 if (fCurrent) {
217 TObjString* obj = (TObjString*)fCurrent->GetValue(filename);
218 if (obj) {
219 if (strlen(obj->GetName()))
220 return (obj->GetName());
221 else
222 return 0;
223 } else {
224 return 0;
225 }
226 } else {
227 return 0;
228 }
229}
230
231
232void TGliteXmlEventlist::Print(Option_t */*opt*/) const {
233//Andi - please put a comment
234 printf("Dumping %d elements\n",fEventList->GetSize());
235 TIter next(fEventList);
236 TMap* filemap;
237 Int_t count=0;
238 while ( (filemap = (TMap*)next()) ) {
239 count++;
240 printf("Printing Element %d\n",count);
241 filemap->Print();
242 }
243}
244
245
246