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