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 //-----------------------------------------------------------------
26 #include <Riostream.h>
27 #include <TEntryList.h>
30 #include <TObjArray.h>
31 #include <TObjString.h>
33 #include <TXMLEngine.h>
35 #include "AliXMLCollection.h"
37 ClassImp(AliXMLCollection)
38 //___________________________________________________________________________
39 AliXMLCollection::AliXMLCollection() :
50 //___________________________________________________________________________
51 AliXMLCollection::AliXMLCollection(const char *localcollectionfile) :
53 fXmlFile(localcollectionfile),
60 // Create Alien event collection, by reading collection for the specified
63 fEventList = new TList();
64 fEventList->SetOwner(kTRUE);
65 fEventListIter = new TIter(fEventList);
67 if (localcollectionfile!=0) {
72 //___________________________________________________________________________
73 AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
74 TGridCollection(collection),
75 fXmlFile(collection.fXmlFile),
79 fCollectionName(collection.fCollectionName),
84 if (collection.fEventList) fEventList = new TList();
85 if (collection.fEventListIter) fEventListIter = new TIter(fEventList);
86 if (collection.fCurrent) fCurrent = 0;
89 //___________________________________________________________________________
90 AliXMLCollection::~AliXMLCollection() {
92 if(fEventList) delete fEventList;
93 if(fEventListIter) delete fEventListIter;
96 //___________________________________________________________________________
97 Bool_t AliXMLCollection::WriteHeader() {
98 //Creates the xml output file
100 TString xmlName = fCollectionName;
103 TString collectionHeader = "<collection name=";
104 collectionHeader += "\"";
105 collectionHeader += fCollectionName;
106 collectionHeader += "\"";
107 collectionHeader += ">";
109 // Open the output stream
111 fout<<"<?xml version=\"1.0\"?>\n";
113 fout<<" "<<collectionHeader<<"\n";
118 //___________________________________________________________________________
119 Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList *list) {
120 //Writes the body of the xml collection
122 for(Int_t i = 0; i < list->GetN(); i++) {
123 listline += list->GetEntry(i);
126 listline = listline(0,listline.Length()-1);
128 TString line0 = "<event name=\"";
132 TString line1 = "<file name=\"AliESDs.root\" ";
142 line1 += "evlist=\"";
147 fout<<" "<<line0<<"\n";
148 fout<<" "<<line1<<"\n";
154 //___________________________________________________________________________
155 Bool_t AliXMLCollection::Export() {
157 fout<<" "<<"</collection>\n";
165 //___________________________________________________________________________
166 void AliXMLCollection::Reset() {
167 // Reset file iterator.
169 fEventListIter->Reset();
173 //___________________________________________________________________________
174 TMap *AliXMLCollection::Next() {
175 // Return next event file map.
177 fCurrent = (TMap*)fEventListIter->Next();
181 //___________________________________________________________________________
182 const char *AliXMLCollection::GetTURL(const char* filename) {
183 // Get a file's transport URL (TURL). Returns 0 in case of error.
186 TMap *obj = (TMap*)fCurrent->GetValue(filename);
188 if (obj->GetValue("turl")) {
189 return ( ((TObjString*)obj->GetValue("turl"))->GetName());
193 Error("GetTURL","cannot get TURL of file %s",filename);
197 //___________________________________________________________________________
198 const char *AliXMLCollection::GetGUID(const char* filename) {
199 // Get a file's transport UID. Returns 0 in case of error.
202 TMap *obj = (TMap*)fCurrent->GetValue(filename);
204 if (obj->GetValue("guid")) {
205 return ( ((TObjString*)obj->GetValue("guid"))->GetName());
209 Error("GetGUID","cannot get GUID of file %s",filename);
213 //___________________________________________________________________________
214 TEntryList *AliXMLCollection::GetEventList(const char *filename) const {
215 // Get a file's event list. Returns 0 in case of error.
218 TMap *obj = (TMap *) fCurrent->GetValue(filename);
220 if (obj->GetValue("evlist")) {
221 return ((TEntryList *) obj->GetValue("evlist"));
225 Error("GetEvList", "cannot get evelist of file %s", filename);
229 //___________________________________________________________________________
230 Bool_t AliXMLCollection::Remove(TMap * map) {
231 // Return next event file map.
232 if (fEventList->Remove(map)) {
239 //___________________________________________________________________________
240 const char *AliXMLCollection::GetLFN(const char* ) {
241 // Get a file's LFN. Returns 0 in case of error.
244 TMap *obj = (TMap *) fCurrent->GetValue("");
246 if (obj->GetValue("lfn")) {
247 return (((TObjString *) obj->GetValue("lfn"))->GetName());
251 Error("GetLFN", "cannot get LFN");
255 //__________________________________________________________________________
256 Bool_t AliXMLCollection::OverlapCollection(TGridCollection * comparator) {
257 // return kTRUE if comparator overlaps with this
258 if ((!comparator)) return kFALSE;
261 // loop over col1 and try to find it in col2
263 // loop over all elements in reference (=this)
265 while ((overlapmap = this->Next())) {
267 Bool_t found = kFALSE;
268 // try to find in the comparator collection
269 while ((comparator->Next())) {
270 TString s1 = this->GetLFN("");
271 TString s2 = comparator->GetLFN("");
278 this->Remove(overlapmap);
285 //___________________________________________________________________________
286 AliXMLCollection *AliXMLCollection::Open(const char *localcollectionfile) {
287 // Static method used to create an Alien event collection, by reading
288 // collection for the specified file.
290 AliXMLCollection *collection = new AliXMLCollection(localcollectionfile);
294 //___________________________________________________________________________
295 void AliXMLCollection::ParseXML() {
296 // Parse event file collection XML file.
300 XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
302 Error("ParseXML","cannot parse the xml file %s",fXmlFile.Data());
306 XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
308 Error("ParseXML","cannot find the <alien> tag in %s",fXmlFile.Data());
312 XMLNodePointer_t xcollection = xml.GetChild(xalien);
314 Error("ParseXML","cannot find the <collection> tag in %s",fXmlFile.Data());
318 XMLNodePointer_t xevent = xml.GetChild(xcollection);;
320 Error("ParseXML","cannot find the <event> tag in %s",fXmlFile.Data());
326 if (xml.GetAttr(xevent, "name")) {
327 TMap *files = new TMap();
330 XMLNodePointer_t xfile = xml.GetChild(xevent);
331 if (!xfile) continue;
333 Bool_t firstfile=kTRUE;
335 // here we have an event file
336 // get the attributes;
337 xml.GetAttr(xfile, "lfn");
338 xml.GetAttr(xfile, "turl");
340 TMap *attributes = new TMap();
341 TObjString *oname = new TObjString(xml.GetAttr(xfile,"name"));
342 TObjString *oturl = new TObjString(xml.GetAttr(xfile,"turl"));
343 TObjString *olfn = new TObjString(xml.GetAttr(xfile,"lfn"));
344 TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid"));
345 TObjString *oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
346 Info("ParseXML","Collection: %s - turl: %s eventlist: %s",
347 fXmlFile.Data(),oturl->GetName(),oevlist->GetName());
348 if (strcmp(oevlist->GetName(),"") != 0) {
349 TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
350 TString stringevlist = oevlist->GetName();
351 TObjArray *evlist = stringevlist.Tokenize(",");
352 for (Int_t n = 0; n < evlist->GetEntries(); n++) xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
353 attributes->Add(new TObjString("evlist"), xmlevlist);
356 attributes->Add(new TObjString("name"),oname);
357 attributes->Add(new TObjString("turl"),oturl);
358 attributes->Add(new TObjString("lfn"),olfn);
359 attributes->Add(new TObjString("guid"),oguid);
360 files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes);
362 // we add the first file always as a file without name to the map
364 files->Add(new TObjString(""),attributes);
367 } while ((xfile = xml.GetNext(xfile)));
368 fEventList->Add(files);
370 } while ((xevent = xml.GetNext(xevent)));