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() :
57 //___________________________________________________________________________
58 AliXMLCollection::AliXMLCollection(const char *localcollectionfile) :
60 fXmlFile(localcollectionfile),
73 // Create Alien event collection, by reading collection for the specified
76 fEventList = new TList();
77 fEventList->SetOwner(kTRUE);
78 fEventListIter = new TIter(fEventList);
80 if (localcollectionfile!=0) {
85 //___________________________________________________________________________
86 AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
87 TGridCollection(collection),
88 fXmlFile(collection.fXmlFile),
92 fCollectionName(collection.fCollectionName),
103 if (collection.fEventList) fEventList = new TList();
104 if (collection.fEventListIter) fEventListIter = new TIter(fEventList);
105 if (collection.fCurrent) fCurrent = 0;
108 //___________________________________________________________________________
109 AliXMLCollection::~AliXMLCollection() {
111 if(fEventList) delete fEventList;
112 if(fEventListIter) delete fEventListIter;
115 //___________________________________________________________________________
116 Bool_t AliXMLCollection::WriteHeader() {
117 //Creates the xml output file
119 TString xmlName = fCollectionName;
122 TString collectionHeader = "<collection name=";
123 collectionHeader += "\"";
124 collectionHeader += fCollectionName;
125 collectionHeader += "\"";
126 collectionHeader += ">";
128 // Open the output stream
130 fout<<"<?xml version=\"1.0\"?>\n";
132 fout<<" "<<collectionHeader<<"\n";
137 //___________________________________________________________________________
138 Bool_t AliXMLCollection::WriteSummary(Int_t aTotal, Int_t aAccepted, Int_t aRejRun, Int_t aRejLHC, Int_t aRejDet, Int_t aRejEvt)
140 // Write selection summary
142 TString collectionSummary = "<summary";
143 collectionSummary += " acceptedEvents=\"";
144 collectionSummary += aAccepted;
145 collectionSummary += "\" totalEvent=\"";
146 collectionSummary += aTotal;
147 collectionSummary += "\" rejectedRun=\"";
148 collectionSummary += aRejRun;
149 collectionSummary += "\" rejectedLHC=\"";
150 collectionSummary += aRejLHC;
151 collectionSummary += "\" rejectedDet=\"";
152 collectionSummary += aRejDet;
153 collectionSummary += "\" rejectedEvt=\"";
154 collectionSummary += aRejEvt;
155 collectionSummary += "\" />";
157 // Open the output stream
158 fout<<" "<<collectionSummary<<"\n";
163 //___________________________________________________________________________
164 Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList *list) {
165 //Writes the body of the xml collection
167 for(Int_t i = 0; i < list->GetN(); i++) {
168 listline += list->GetEntry(i);
171 listline = listline(0,listline.Length()-1);
173 TString line0 = "<event name=\"";
177 TString line1 = "<file name=\"AliESDs.root\" ";
187 line1 += "evlist=\"";
192 fout<<" "<<line0<<"\n";
193 fout<<" "<<line1<<"\n";
198 //___________________________________________________________________________
199 Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char *lfn, const char *turl, TEntryList *list, Int_t accSum, Int_t rejSum)
201 //Writes the body of the xml collection with tag cuts summary
203 for(Int_t i = 0; i < list->GetN(); i++) {
204 listline += list->GetEntry(i);
207 listline = listline(0,listline.Length()-1);
209 TString line0 = "<event name=\"";
213 TString line1 = "<file name=\"AliESDs.root\" ";
223 line1 += "evlist=\"";
226 line1 += "cutsumm=\"";
233 fout<<" "<<line0<<"\n";
234 fout<<" "<<line1<<"\n";
240 //___________________________________________________________________________
241 Bool_t AliXMLCollection::Export() {
243 fout<<" "<<"</collection>\n";
251 //___________________________________________________________________________
252 void AliXMLCollection::Reset() {
253 // Reset file iterator.
255 fEventListIter->Reset();
259 //___________________________________________________________________________
260 TMap *AliXMLCollection::Next() {
261 // Return next event file map.
263 fCurrent = (TMap*)fEventListIter->Next();
267 //___________________________________________________________________________
268 const char *AliXMLCollection::GetTURL(const char* filename) {
269 // Get a file's transport URL (TURL). Returns 0 in case of error.
272 TMap *obj = (TMap*)fCurrent->GetValue(filename);
274 if (obj->GetValue("turl")) {
275 return ( ((TObjString*)obj->GetValue("turl"))->GetName());
279 Error("GetTURL","cannot get TURL of file %s",filename);
283 //___________________________________________________________________________
284 const char *AliXMLCollection::GetGUID(const char* filename) {
285 // Get a file's transport UID. Returns 0 in case of error.
288 TMap *obj = (TMap*)fCurrent->GetValue(filename);
290 if (obj->GetValue("guid")) {
291 return ( ((TObjString*)obj->GetValue("guid"))->GetName());
295 Error("GetGUID","cannot get GUID of file %s",filename);
299 //___________________________________________________________________________
300 TEntryList *AliXMLCollection::GetEventList(const char *filename) const {
301 // Get a file's event list. Returns 0 in case of error.
304 TMap *obj = (TMap *) fCurrent->GetValue(filename);
306 if (obj->GetValue("evlist")) {
307 return ((TEntryList *) obj->GetValue("evlist"));
311 Error("GetEvList", "cannot get evelist of file %s", filename);
315 //___________________________________________________________________________
316 Bool_t AliXMLCollection::Remove(TMap * map) {
317 // Return next event file map.
318 if (fEventList->Remove(map)) {
325 //___________________________________________________________________________
326 const char *AliXMLCollection::GetLFN(const char* ) {
327 // Get a file's LFN. Returns 0 in case of error.
330 TMap *obj = (TMap *) fCurrent->GetValue("");
332 if (obj->GetValue("lfn")) {
333 return (((TObjString *) obj->GetValue("lfn"))->GetName());
337 Error("GetLFN", "cannot get LFN");
341 //__________________________________________________________________________
342 const char *AliXMLCollection::GetCutSumm() {
343 // Get a file's tag cuts summary. Returns 0 in case of error.
346 TMap *obj = (TMap *) fCurrent->GetValue("");
348 if (obj->GetValue("cutsumm")) {
349 return (((TObjString *) obj->GetValue("cutsumm"))->GetName());
353 Error("GetTagSumm", "cannot get Tag Cut Summary");
357 //__________________________________________________________________________
358 Bool_t AliXMLCollection::OverlapCollection(TGridCollection * comparator) {
359 // return kTRUE if comparator overlaps with this
360 if ((!comparator)) return kFALSE;
363 // loop over col1 and try to find it in col2
365 // loop over all elements in reference (=this)
367 while ((overlapmap = this->Next())) {
369 Bool_t found = kFALSE;
370 // try to find in the comparator collection
371 while ((comparator->Next())) {
372 TString s1 = this->GetLFN("");
373 TString s2 = comparator->GetLFN("");
380 this->Remove(overlapmap);
387 //___________________________________________________________________________
388 AliXMLCollection *AliXMLCollection::Open(const char *localcollectionfile) {
389 // Static method used to create an Alien event collection, by reading
390 // collection for the specified file.
392 AliXMLCollection *collection = new AliXMLCollection(localcollectionfile);
396 //___________________________________________________________________________
397 void AliXMLCollection::ParseXML() {
398 // Parse event file collection XML file.
402 XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
404 Error("ParseXML","cannot parse the xml file %s",fXmlFile.Data());
408 XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
410 Error("ParseXML","cannot find the <alien> tag in %s",fXmlFile.Data());
414 XMLNodePointer_t xcollection = xml.GetChild(xalien);
416 Error("ParseXML","cannot find the <collection> tag in %s",fXmlFile.Data());
420 XMLNodePointer_t xevent = xml.GetChild(xcollection);;
422 Error("ParseXML","cannot find the <event> tag in %s",fXmlFile.Data());
428 if (xml.GetAttr(xevent, "name")) {
429 TMap *files = new TMap();
432 XMLNodePointer_t xfile = xml.GetChild(xevent);
433 if (!xfile) continue;
435 Bool_t firstfile=kTRUE;
437 // here we have an event file
438 // get the attributes;
439 xml.GetAttr(xfile, "lfn");
440 xml.GetAttr(xfile, "turl");
442 TMap *attributes = new TMap();
443 TObjString *oname = new TObjString(xml.GetAttr(xfile,"name"));
444 TObjString *oturl = new TObjString(xml.GetAttr(xfile,"turl"));
445 TObjString *olfn = new TObjString(xml.GetAttr(xfile,"lfn"));
446 TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid"));
449 if (xml.GetAttr(xfile, "evlist"))
450 oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
454 TObjString *otagsumm;
455 if (xml.GetAttr(xfile, "cutsumm"))
456 otagsumm = new TObjString(xml.GetAttr(xfile, "cutsumm"));
461 Info("ParseXML","Collection: %s - turl: %s eventlist: %s",
462 fXmlFile.Data(),oturl->GetName(),oevlist->GetName());
463 TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
464 if (strcmp(oevlist->GetName(),"") != 0) {
465 TString stringevlist = oevlist->GetName();
466 TObjArray *evlist = stringevlist.Tokenize(",");
467 for (Int_t n = 0; n < evlist->GetEntries(); n++) xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
469 attributes->Add(new TObjString("evlist"), xmlevlist);
472 attributes->Add(new TObjString("name"),oname);
473 attributes->Add(new TObjString("turl"),oturl);
474 attributes->Add(new TObjString("lfn"),olfn);
475 attributes->Add(new TObjString("guid"),oguid);
477 attributes->Add(new TObjString("cutsumm"),otagsumm);
478 files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes);
480 // we add the first file always as a file without name to the map
482 files->Add(new TObjString(""),attributes);
485 } while ((xfile = xml.GetNext(xfile)));
486 fEventList->Add(files);
489 if (xml.GetAttr(xevent, "acceptedEvents")) {
491 fAcceptedEvents = atoi(xml.GetAttr(xevent, "acceptedEvents"));
492 fTotalEvents = atoi(xml.GetAttr(xevent, "totalEvent"));
493 fRejectedRun = atoi(xml.GetAttr(xevent, "rejectedRun"));
494 fRejectedLHC = atoi(xml.GetAttr(xevent, "rejectedLHC"));
495 fRejectedDet = atoi(xml.GetAttr(xevent, "rejectedDet"));
496 fRejectedEvt = atoi(xml.GetAttr(xevent, "rejectedEvt"));
499 } while ((xevent = xml.GetNext(xevent)));
502 Bool_t AliXMLCollection::GetCollectionSummary(Int_t *aTot, Int_t *aAcc, Int_t *aRejRun, Int_t *aRejLHC, Int_t *aRejDet, Int_t *aRejEvt)
504 // Return read list summary
505 *aTot = fTotalEvents;
506 *aAcc = fAcceptedEvents;
507 *aRejRun = fRejectedRun;
508 *aRejLHC = fRejectedLHC;
509 *aRejDet = fRejectedDet;
510 *aRejEvt = fRejectedEvt;