1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-----------------------------------------------------------------
19 // Implementation of the AliXMLCollection class
20 // This is the class that creates XML collections after querying the tags
21 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 //-----------------------------------------------------------------
25 #include <Riostream.h>
26 #include <TEntryList.h>
29 #include <TObjArray.h>
30 #include <TObjString.h>
32 #include <TXMLEngine.h>
34 #include "AliXMLCollection.h"
36 ClassImp(AliXMLCollection)
38 //___________________________________________________________________________
39 AliXMLCollection::AliXMLCollection() :
50 //___________________________________________________________________________
51 AliXMLCollection::AliXMLCollection(const char *localcollectionfile) {
52 // Create Alien event collection, by reading collection for the specified
55 fXmlFile = localcollectionfile;
56 fEventList = new TList();
57 fEventList->SetOwner(kTRUE);
58 fEventListIter = new TIter(fEventList);
60 if (localcollectionfile!=0) {
65 //___________________________________________________________________________
66 AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
67 TGridCollection(collection),
68 fXmlFile(collection.fXmlFile),
69 fCollectionName(collection.fCollectionName) {
72 if (collection.fEventList) fEventList = new TList();
73 if (collection.fEventListIter) fEventListIter = new TIter(fEventList);
74 if (collection.fCurrent) fCurrent = 0;
77 //___________________________________________________________________________
78 AliXMLCollection::~AliXMLCollection() {
80 if(fEventList) delete fEventList;
81 if(fEventListIter) delete fEventListIter;
84 //___________________________________________________________________________
85 Bool_t AliXMLCollection::WriteHeader() {
86 //Creates the xml output file
88 TString xmlName = fCollectionName;
91 TString collectionHeader = "<collection name=";
92 collectionHeader += "\"";
93 collectionHeader += fCollectionName;
94 collectionHeader += "\"";
95 collectionHeader += ">";
97 // Open the output stream
99 fout<<"<?xml version=\"1.0\"?>\n";
101 fout<<" "<<collectionHeader<<"\n";
106 //___________________________________________________________________________
107 Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList *list) {
108 //Writes the body of the xml collection
110 for(Int_t i = 0; i < list->GetN(); i++) {
111 listline += list->GetEntry(i);
114 listline = listline(0,listline.Length()-1);
116 TString line0 = "<event name=\"";
120 TString line1 = "<file name=\"AliESDs.root\" ";
130 line1 += "evlist=\"";
135 fout<<" "<<line0<<"\n";
136 fout<<" "<<line1<<"\n";
142 //___________________________________________________________________________
143 Bool_t AliXMLCollection::Export() {
145 fout<<" "<<"</collection>\n";
153 //___________________________________________________________________________
154 void AliXMLCollection::Reset() {
155 // Reset file iterator.
157 fEventListIter->Reset();
161 //___________________________________________________________________________
162 TMap *AliXMLCollection::Next() {
163 // Return next event file map.
165 fCurrent = (TMap*)fEventListIter->Next();
169 //___________________________________________________________________________
170 const char *AliXMLCollection::GetTURL(const char* filename) const {
171 // Get a file's transport URL (TURL). Returns 0 in case of error.
174 TMap *obj = (TMap*)fCurrent->GetValue(filename);
176 if (obj->GetValue("turl")) {
177 return ( ((TObjString*)obj->GetValue("turl"))->GetName());
181 Error("GetTURL","cannot get TURL of file %s",filename);
185 //___________________________________________________________________________
186 const char *AliXMLCollection::GetGUID(const char* filename) const {
187 // Get a file's transport UID. Returns 0 in case of error.
190 TMap *obj = (TMap*)fCurrent->GetValue(filename);
192 if (obj->GetValue("guid")) {
193 return ( ((TObjString*)obj->GetValue("guid"))->GetName());
197 Error("GetGUID","cannot get GUID of file %s",filename);
201 //___________________________________________________________________________
202 TEntryList *AliXMLCollection::GetEventList(const char *filename) const {
203 // Get a file's event list. Returns 0 in case of error.
206 TMap *obj = (TMap *) fCurrent->GetValue(filename);
208 if (obj->GetValue("evlist")) {
209 return ((TEntryList *) obj->GetValue("evlist"));
213 Error("GetEvList", "cannot get evelist of file %s", filename);
217 //___________________________________________________________________________
218 Bool_t AliXMLCollection::Remove(TMap * map) {
219 // Return next event file map.
220 if (fEventList->Remove(map)) {
227 //___________________________________________________________________________
228 const char *AliXMLCollection::GetLFN(const char* ) const {
229 // Get a file's LFN. Returns 0 in case of error.
232 TMap *obj = (TMap *) fCurrent->GetValue("");
234 if (obj->GetValue("lfn")) {
235 return (((TObjString *) obj->GetValue("lfn"))->GetName());
239 Error("GetLFN", "cannot get LFN");
243 //__________________________________________________________________________
244 Bool_t AliXMLCollection::OverlapCollection(AliXMLCollection * comparator) {
245 // return kTRUE if comparator overlaps with this
246 if ((!comparator)) return kFALSE;
249 // loop over col1 and try to find it in col2
251 // loop over all elements in reference (=this)
253 while ((overlapmap = this->Next())) {
255 Bool_t found = kFALSE;
256 // try to find in the comparator collection
257 while ((comparator->Next())) {
258 TString s1 = this->GetLFN("");
259 TString s2 = comparator->GetLFN("");
266 this->Remove(overlapmap);
273 //___________________________________________________________________________
274 AliXMLCollection *AliXMLCollection::Open(const char *localcollectionfile) {
275 // Static method used to create an Alien event collection, by reading
276 // collection for the specified file.
278 AliXMLCollection *collection = new AliXMLCollection(localcollectionfile);
282 //___________________________________________________________________________
283 void AliXMLCollection::ParseXML() {
284 // Parse event file collection XML file.
288 XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
290 Error("ParseXML","cannot parse the xml file %s",fXmlFile.Data());
294 XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
296 Error("ParseXML","cannot find the <alien> tag in %s",fXmlFile.Data());
300 XMLNodePointer_t xcollection = xml.GetChild(xalien);
302 Error("ParseXML","cannot find the <collection> tag in %s",fXmlFile.Data());
306 XMLNodePointer_t xevent = xml.GetChild(xcollection);;
308 Error("ParseXML","cannot find the <event> tag in %s",fXmlFile.Data());
314 if (xml.GetAttr(xevent, "name")) {
315 TMap *files = new TMap();
318 XMLNodePointer_t xfile = xml.GetChild(xevent);
319 if (!xfile) continue;
321 Bool_t firstfile=kTRUE;
323 // here we have an event file
324 // get the attributes;
325 xml.GetAttr(xfile, "lfn");
326 xml.GetAttr(xfile, "turl");
328 TMap *attributes = new TMap();
329 TObjString *oname = new TObjString(xml.GetAttr(xfile,"name"));
330 TObjString *oturl = new TObjString(xml.GetAttr(xfile,"turl"));
331 TObjString *olfn = new TObjString(xml.GetAttr(xfile,"lfn"));
332 TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid"));
333 TObjString *oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
334 printf("Collection: %s - The Eventlist is %s\n",fXmlFile.Data(),oevlist->GetName());
335 if (oevlist->GetName() != "") {
336 TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
337 TString stringevlist = oevlist->GetName();
338 TObjArray *evlist = stringevlist.Tokenize(",");
339 for (Int_t n = 0; n < evlist->GetEntries(); n++) xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
340 attributes->Add(new TObjString("evlist"), xmlevlist);
343 attributes->Add(new TObjString("name"),oname);
344 attributes->Add(new TObjString("turl"),oturl);
345 attributes->Add(new TObjString("lfn"),olfn);
346 attributes->Add(new TObjString("guid"),oguid);
347 files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes);
349 // we add the first file always as a file without name to the map
351 files->Add(new TObjString(""),attributes);
354 } while ((xfile = xml.GetNext(xfile)));
355 fEventList->Add(files);
357 } while ((xevent = xml.GetNext(xevent)));