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