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"
28 #include "TObjString.h"
29 #include "TXMLEngine.h"
30 #include "TEntryList.h"
31 #include "TObjArray.h"
33 #include "AliXMLCollection.h"
35 ClassImp(AliXMLCollection)
37 //___________________________________________________________________________
38 AliXMLCollection::AliXMLCollection() :
49 //___________________________________________________________________________
50 AliXMLCollection::AliXMLCollection(const char *localcollectionfile) {
51 // Create Alien event collection, by reading collection for the specified
54 fXmlFile = localcollectionfile;
55 fEventList = new TList();
56 fEventList->SetOwner(kTRUE);
57 fEventListIter = new TIter(fEventList);
59 if (localcollectionfile!=0) {
64 //___________________________________________________________________________
65 AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
66 TGridCollection(collection),
67 fXmlFile(collection.fXmlFile),
68 fCollectionName(collection.fCollectionName) {
71 if (collection.fEventList) fEventList = new TList();
72 if (collection.fEventListIter) fEventListIter = new TIter(fEventList);
73 if (collection.fCurrent) fCurrent = 0;
76 //___________________________________________________________________________
77 AliXMLCollection::~AliXMLCollection() {
79 if(fEventList) delete fEventList;
80 if(fEventListIter) delete fEventListIter;
83 //___________________________________________________________________________
84 Bool_t AliXMLCollection::WriteHeader() {
85 //Creates the xml output file
87 TString xmlName = fCollectionName;
90 TString collectionHeader = "<collection name=";
91 collectionHeader += "\"";
92 collectionHeader += fCollectionName;
93 collectionHeader += "\"";
94 collectionHeader += ">";
96 // Open the output stream
98 fout<<"<?xml version=\"1.0\"?>\n";
100 fout<<" "<<collectionHeader<<"\n";
105 //___________________________________________________________________________
106 Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList *list) {
107 //Writes the body of the xml collection
109 for(Int_t i = 0; i < list->GetN(); i++) {
110 listline += list->GetEntry(i);
113 listline = listline(0,listline.Length()-1);
115 TString line0 = "<event name=\"";
119 TString line1 = "<file name=\"AliESDs.root\" ";
129 line1 += "evlist=\"";
134 fout<<" "<<line0<<"\n";
135 fout<<" "<<line1<<"\n";
141 //___________________________________________________________________________
142 Bool_t AliXMLCollection::Export() {
144 fout<<" "<<"</collection>\n";
152 //___________________________________________________________________________
153 void AliXMLCollection::Reset() {
154 // Reset file iterator.
156 fEventListIter->Reset();
160 //___________________________________________________________________________
161 TMap *AliXMLCollection::Next() {
162 // Return next event file map.
164 fCurrent = (TMap*)fEventListIter->Next();
168 //___________________________________________________________________________
169 const char *AliXMLCollection::GetTURL(const char* filename) const {
170 // Get a file's transport URL (TURL). Returns 0 in case of error.
173 TMap *obj = (TMap*)fCurrent->GetValue(filename);
175 if (obj->GetValue("turl")) {
176 return ( ((TObjString*)obj->GetValue("turl"))->GetName());
180 Error("GetTURL","cannot get TURL of file %s",filename);
184 //___________________________________________________________________________
185 const char *AliXMLCollection::GetGUID(const char* filename) const {
186 // Get a file's transport UID. Returns 0 in case of error.
189 TMap *obj = (TMap*)fCurrent->GetValue(filename);
191 if (obj->GetValue("guid")) {
192 return ( ((TObjString*)obj->GetValue("guid"))->GetName());
196 Error("GetGUID","cannot get GUID of file %s",filename);
200 //___________________________________________________________________________
201 TEntryList *AliXMLCollection::GetEventList(const char *filename) const {
202 // Get a file's event list. Returns 0 in case of error.
205 TMap *obj = (TMap *) fCurrent->GetValue(filename);
207 if (obj->GetValue("evlist")) {
208 return ((TEntryList *) obj->GetValue("evlist"));
212 Error("GetEvList", "cannot get evelist of file %s", filename);
216 //___________________________________________________________________________
217 Bool_t AliXMLCollection::Remove(TMap * map) {
218 // Return next event file map.
219 if (fEventList->Remove(map)) {
226 //___________________________________________________________________________
227 const char *AliXMLCollection::GetLFN(const char* ) const {
228 // Get a file's LFN. Returns 0 in case of error.
231 TMap *obj = (TMap *) fCurrent->GetValue("");
233 if (obj->GetValue("lfn")) {
234 return (((TObjString *) obj->GetValue("lfn"))->GetName());
238 Error("GetLFN", "cannot get LFN");
242 //__________________________________________________________________________
243 Bool_t AliXMLCollection::OverlapCollection(AliXMLCollection * comparator) {
244 // return kTRUE if comparator overlaps with this
245 if ((!comparator)) return kFALSE;
248 // loop over col1 and try to find it in col2
250 // loop over all elements in reference (=this)
252 while ((overlapmap = this->Next())) {
254 Bool_t found = kFALSE;
255 // try to find in the comparator collection
256 while ((comparator->Next())) {
257 TString s1 = this->GetLFN("");
258 TString s2 = comparator->GetLFN("");
265 this->Remove(overlapmap);
272 //___________________________________________________________________________
273 AliXMLCollection *AliXMLCollection::Open(const char *localcollectionfile) {
274 // Static method used to create an Alien event collection, by reading
275 // collection for the specified file.
277 AliXMLCollection *collection = new AliXMLCollection(localcollectionfile);
281 //___________________________________________________________________________
282 void AliXMLCollection::ParseXML() {
283 // Parse event file collection XML file.
287 XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
289 Error("ParseXML","cannot parse the xml file %s",fXmlFile.Data());
293 XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
295 Error("ParseXML","cannot find the <alien> tag in %s",fXmlFile.Data());
299 XMLNodePointer_t xcollection = xml.GetChild(xalien);
301 Error("ParseXML","cannot find the <collection> tag in %s",fXmlFile.Data());
305 XMLNodePointer_t xevent = xml.GetChild(xcollection);;
307 Error("ParseXML","cannot find the <event> tag in %s",fXmlFile.Data());
313 if (xml.GetAttr(xevent, "name")) {
314 TMap *files = new TMap();
317 XMLNodePointer_t xfile = xml.GetChild(xevent);
318 if (!xfile) continue;
320 Bool_t firstfile=kTRUE;
322 // here we have an event file
323 // get the attributes;
324 xml.GetAttr(xfile, "lfn");
325 xml.GetAttr(xfile, "turl");
327 TMap *attributes = new TMap();
328 TObjString *oname = new TObjString(xml.GetAttr(xfile,"name"));
329 TObjString *oturl = new TObjString(xml.GetAttr(xfile,"turl"));
330 TObjString *olfn = new TObjString(xml.GetAttr(xfile,"lfn"));
331 TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid"));
332 TObjString *oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
333 printf("Collection: %s - The Eventlist is %s\n",fXmlFile.Data(),oevlist->GetName());
334 if (oevlist->GetName() != "") {
335 TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
336 TString stringevlist = oevlist->GetName();
337 TObjArray *evlist = stringevlist.Tokenize(",");
338 for (Int_t n = 0; n < evlist->GetEntries(); n++) xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
339 attributes->Add(new TObjString("evlist"), xmlevlist);
342 attributes->Add(new TObjString("name"),oname);
343 attributes->Add(new TObjString("turl"),oturl);
344 attributes->Add(new TObjString("lfn"),olfn);
345 attributes->Add(new TObjString("guid"),oguid);
346 files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes);
348 // we add the first file always as a file without name to the map
350 files->Add(new TObjString(""),attributes);
353 } while ((xfile = xml.GetNext(xfile)));
354 fEventList->Add(files);
356 } while ((xevent = xml.GetNext(xevent)));