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)
37 //___________________________________________________________________________
38 AliXMLCollection::AliXMLCollection() :
49 //___________________________________________________________________________
50 AliXMLCollection::AliXMLCollection(const char *localcollectionfile) :
52 fXmlFile(localcollectionfile),
59 // Create Alien event collection, by reading collection for the specified
62 fEventList = new TList();
63 fEventList->SetOwner(kTRUE);
64 fEventListIter = new TIter(fEventList);
66 if (localcollectionfile!=0) {
71 //___________________________________________________________________________
72 AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
73 TGridCollection(collection),
74 fXmlFile(collection.fXmlFile),
78 fCollectionName(collection.fCollectionName),
83 if (collection.fEventList) fEventList = new TList();
84 if (collection.fEventListIter) fEventListIter = new TIter(fEventList);
85 if (collection.fCurrent) fCurrent = 0;
88 //___________________________________________________________________________
89 AliXMLCollection::~AliXMLCollection() {
91 if(fEventList) delete fEventList;
92 if(fEventListIter) delete fEventListIter;
95 //___________________________________________________________________________
96 Bool_t AliXMLCollection::WriteHeader() {
97 //Creates the xml output file
99 TString xmlName = fCollectionName;
102 TString collectionHeader = "<collection name=";
103 collectionHeader += "\"";
104 collectionHeader += fCollectionName;
105 collectionHeader += "\"";
106 collectionHeader += ">";
108 // Open the output stream
110 fout<<"<?xml version=\"1.0\"?>\n";
112 fout<<" "<<collectionHeader<<"\n";
117 //___________________________________________________________________________
118 Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList *list) {
119 //Writes the body of the xml collection
121 for(Int_t i = 0; i < list->GetN(); i++) {
122 listline += list->GetEntry(i);
125 listline = listline(0,listline.Length()-1);
127 TString line0 = "<event name=\"";
131 TString line1 = "<file name=\"AliESDs.root\" ";
141 line1 += "evlist=\"";
146 fout<<" "<<line0<<"\n";
147 fout<<" "<<line1<<"\n";
153 //___________________________________________________________________________
154 Bool_t AliXMLCollection::Export() {
156 fout<<" "<<"</collection>\n";
164 //___________________________________________________________________________
165 void AliXMLCollection::Reset() {
166 // Reset file iterator.
168 fEventListIter->Reset();
172 //___________________________________________________________________________
173 TMap *AliXMLCollection::Next() {
174 // Return next event file map.
176 fCurrent = (TMap*)fEventListIter->Next();
180 //___________________________________________________________________________
181 const char *AliXMLCollection::GetTURL(const char* filename) {
182 // Get a file's transport URL (TURL). Returns 0 in case of error.
185 TMap *obj = (TMap*)fCurrent->GetValue(filename);
187 if (obj->GetValue("turl")) {
188 return ( ((TObjString*)obj->GetValue("turl"))->GetName());
192 Error("GetTURL","cannot get TURL of file %s",filename);
196 //___________________________________________________________________________
197 const char *AliXMLCollection::GetGUID(const char* filename) {
198 // Get a file's transport UID. Returns 0 in case of error.
201 TMap *obj = (TMap*)fCurrent->GetValue(filename);
203 if (obj->GetValue("guid")) {
204 return ( ((TObjString*)obj->GetValue("guid"))->GetName());
208 Error("GetGUID","cannot get GUID of file %s",filename);
212 //___________________________________________________________________________
213 TEntryList *AliXMLCollection::GetEventList(const char *filename) const {
214 // Get a file's event list. Returns 0 in case of error.
217 TMap *obj = (TMap *) fCurrent->GetValue(filename);
219 if (obj->GetValue("evlist")) {
220 return ((TEntryList *) obj->GetValue("evlist"));
224 Error("GetEvList", "cannot get evelist of file %s", filename);
228 //___________________________________________________________________________
229 Bool_t AliXMLCollection::Remove(TMap * map) {
230 // Return next event file map.
231 if (fEventList->Remove(map)) {
238 //___________________________________________________________________________
239 const char *AliXMLCollection::GetLFN(const char* ) {
240 // Get a file's LFN. Returns 0 in case of error.
243 TMap *obj = (TMap *) fCurrent->GetValue("");
245 if (obj->GetValue("lfn")) {
246 return (((TObjString *) obj->GetValue("lfn"))->GetName());
250 Error("GetLFN", "cannot get LFN");
254 //__________________________________________________________________________
255 Bool_t AliXMLCollection::OverlapCollection(TGridCollection * comparator) {
256 // return kTRUE if comparator overlaps with this
257 if ((!comparator)) return kFALSE;
260 // loop over col1 and try to find it in col2
262 // loop over all elements in reference (=this)
264 while ((overlapmap = this->Next())) {
266 Bool_t found = kFALSE;
267 // try to find in the comparator collection
268 while ((comparator->Next())) {
269 TString s1 = this->GetLFN("");
270 TString s2 = comparator->GetLFN("");
277 this->Remove(overlapmap);
284 //___________________________________________________________________________
285 AliXMLCollection *AliXMLCollection::Open(const char *localcollectionfile) {
286 // Static method used to create an Alien event collection, by reading
287 // collection for the specified file.
289 AliXMLCollection *collection = new AliXMLCollection(localcollectionfile);
293 //___________________________________________________________________________
294 void AliXMLCollection::ParseXML() {
295 // Parse event file collection XML file.
299 XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
301 Error("ParseXML","cannot parse the xml file %s",fXmlFile.Data());
305 XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
307 Error("ParseXML","cannot find the <alien> tag in %s",fXmlFile.Data());
311 XMLNodePointer_t xcollection = xml.GetChild(xalien);
313 Error("ParseXML","cannot find the <collection> tag in %s",fXmlFile.Data());
317 XMLNodePointer_t xevent = xml.GetChild(xcollection);;
319 Error("ParseXML","cannot find the <event> tag in %s",fXmlFile.Data());
325 if (xml.GetAttr(xevent, "name")) {
326 TMap *files = new TMap();
329 XMLNodePointer_t xfile = xml.GetChild(xevent);
330 if (!xfile) continue;
332 Bool_t firstfile=kTRUE;
334 // here we have an event file
335 // get the attributes;
336 xml.GetAttr(xfile, "lfn");
337 xml.GetAttr(xfile, "turl");
339 TMap *attributes = new TMap();
340 TObjString *oname = new TObjString(xml.GetAttr(xfile,"name"));
341 TObjString *oturl = new TObjString(xml.GetAttr(xfile,"turl"));
342 TObjString *olfn = new TObjString(xml.GetAttr(xfile,"lfn"));
343 TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid"));
344 TObjString *oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
345 printf("Collection: %s - The Eventlist is %s\n",fXmlFile.Data(),oevlist->GetName());
346 if (oevlist->GetName() != "") {
347 TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
348 TString stringevlist = oevlist->GetName();
349 TObjArray *evlist = stringevlist.Tokenize(",");
350 for (Int_t n = 0; n < evlist->GetEntries(); n++) xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
351 attributes->Add(new TObjString("evlist"), xmlevlist);
354 attributes->Add(new TObjString("name"),oname);
355 attributes->Add(new TObjString("turl"),oturl);
356 attributes->Add(new TObjString("lfn"),olfn);
357 attributes->Add(new TObjString("guid"),oguid);
358 files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes);
360 // we add the first file always as a file without name to the map
362 files->Add(new TObjString(""),attributes);
365 } while ((xfile = xml.GetNext(xfile)));
366 fEventList->Add(files);
368 } while ((xevent = xml.GetNext(xevent)));