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>
36 #include "AliXMLCollection.h"
38 ClassImp(AliXMLCollection)
39 //___________________________________________________________________________
40 AliXMLCollection::AliXMLCollection() :
58 //___________________________________________________________________________
59 AliXMLCollection::AliXMLCollection(const char *localcollectionfile) :
61 fXmlFile(localcollectionfile),
74 // Create Alien event collection, by reading collection for the specified
77 fEventList = new TList();
78 fEventList->SetOwner(kTRUE);
79 fEventListIter = new TIter(fEventList);
81 if (localcollectionfile!=0) {
86 //___________________________________________________________________________
87 AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
88 TGridCollection(collection),
89 fXmlFile(collection.fXmlFile),
93 fCollectionName(collection.fCollectionName),
104 if (collection.fEventList) fEventList = new TList();
105 if (collection.fEventListIter) fEventListIter = new TIter(fEventList);
106 if (collection.fCurrent) fCurrent = 0;
109 //___________________________________________________________________________
110 AliXMLCollection::~AliXMLCollection()
114 delete fEventListIter;
117 //___________________________________________________________________________
118 Bool_t AliXMLCollection::WriteHeader() {
119 //Creates the xml output file
121 TString xmlName = fCollectionName;
124 TString collectionHeader = "<collection name=";
125 collectionHeader += "\"";
126 collectionHeader += fCollectionName;
127 collectionHeader += "\"";
128 collectionHeader += ">";
130 // Open the output stream
132 fout<<"<?xml version=\"1.0\"?>\n";
134 fout<<" "<<collectionHeader<<"\n";
139 //___________________________________________________________________________
140 Bool_t AliXMLCollection::WriteSummary(Int_t aTotal, Int_t aAccepted, Int_t aRejRun, Int_t aRejLHC, Int_t aRejDet, Int_t aRejEvt)
142 // Write selection summary
144 TString collectionSummary = "<summary";
145 collectionSummary += " acceptedEvents=\"";
146 collectionSummary += aAccepted;
147 collectionSummary += "\" totalEvent=\"";
148 collectionSummary += aTotal;
149 collectionSummary += "\" rejectedRun=\"";
150 collectionSummary += aRejRun;
151 collectionSummary += "\" rejectedLHC=\"";
152 collectionSummary += aRejLHC;
153 collectionSummary += "\" rejectedDet=\"";
154 collectionSummary += aRejDet;
155 collectionSummary += "\" rejectedEvt=\"";
156 collectionSummary += aRejEvt;
157 collectionSummary += "\" />";
159 // Open the output stream
160 fout<<" "<<collectionSummary<<"\n";
165 //___________________________________________________________________________
166 Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList* list)
168 //Writes the body of the xml collection
170 for(Int_t i = 0; i < list->GetN(); i++) {
171 listline += list->GetEntry(i);
174 listline = listline(0,listline.Length()-1);
176 TString line0 = "<event name=\"";
180 TString line1 = "<file name=\"AliESDs.root\" ";
190 line1 += "evlist=\"";
195 fout<<" "<<line0<<"\n";
196 fout<<" "<<line1<<"\n";
201 //___________________________________________________________________________
202 Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char *lfn, const char *turl, TEntryList* list, Int_t accSum, Int_t rejSum)
204 //Writes the body of the xml collection with tag cuts summary
206 for(Int_t i = 0; i < list->GetN(); i++) {
207 listline += list->GetEntry(i);
210 listline = listline(0,listline.Length()-1);
212 TString line0 = "<event name=\"";
216 TString line1 = "<file name=\"AliESDs.root\" ";
226 line1 += "evlist=\"";
229 line1 += "cutsumm=\"";
236 fout<<" "<<line0<<"\n";
237 fout<<" "<<line1<<"\n";
243 //___________________________________________________________________________
244 Bool_t AliXMLCollection::Export() {
246 fout<<" "<<"</collection>\n";
254 //___________________________________________________________________________
255 void AliXMLCollection::Reset() {
256 // Reset file iterator.
258 fEventListIter->Reset();
262 //___________________________________________________________________________
263 TMap *AliXMLCollection::Next() {
264 // Return next event file map.
266 fCurrent = (TMap*)fEventListIter->Next();
270 //___________________________________________________________________________
271 const char *AliXMLCollection::GetTURL(const char* filename) {
272 // Get a file's transport URL (TURL). Returns 0 in case of error.
275 TMap *obj = (TMap*)fCurrent->GetValue(filename);
277 if (obj->GetValue("turl")) {
278 return ( ((TObjString*)obj->GetValue("turl"))->GetName());
282 AliError(Form("cannot get TURL of file %s",filename));
286 //___________________________________________________________________________
287 const char *AliXMLCollection::GetGUID(const char* filename) {
288 // Get a file's transport UID. Returns 0 in case of error.
291 TMap *obj = (TMap*)fCurrent->GetValue(filename);
293 if (obj->GetValue("guid")) {
294 return ( ((TObjString*)obj->GetValue("guid"))->GetName());
298 AliError(Form("cannot get GUID of file %s",filename));
302 //___________________________________________________________________________
303 TEntryList *AliXMLCollection::GetEventList(const char *filename) const {
304 // Get a file's event list. Returns 0 in case of error.
307 TMap *obj = (TMap *) fCurrent->GetValue(filename);
309 if (obj->GetValue("evlist")) {
310 return ((TEntryList *) obj->GetValue("evlist"));
314 AliError(Form("cannot get evelist of file %s", filename));
318 //___________________________________________________________________________
319 Bool_t AliXMLCollection::Remove(TMap * map) {
320 // Return next event file map.
321 if (fEventList->Remove(map)) {
328 //___________________________________________________________________________
329 const char *AliXMLCollection::GetLFN(const char* ) {
330 // Get a file's LFN. Returns 0 in case of error.
333 TMap *obj = (TMap *) fCurrent->GetValue("");
335 if (obj->GetValue("lfn")) {
336 return (((TObjString *) obj->GetValue("lfn"))->GetName());
340 AliError("cannot get LFN");
344 //__________________________________________________________________________
345 const char *AliXMLCollection::GetCutSumm() {
346 // Get a file's tag cuts summary. Returns 0 in case of error.
349 TMap *obj = (TMap *) fCurrent->GetValue("");
351 if (obj->GetValue("cutsumm")) {
352 return (((TObjString *) obj->GetValue("cutsumm"))->GetName());
356 AliError("cannot get Tag Cut Summary");
360 //__________________________________________________________________________
361 Bool_t AliXMLCollection::OverlapCollection(TGridCollection * comparator) {
362 // return kTRUE if comparator overlaps with this
363 if ((!comparator)) return kFALSE;
366 // loop over col1 and try to find it in col2
368 // loop over all elements in reference (=this)
370 while ((overlapmap = this->Next())) {
372 Bool_t found = kFALSE;
373 // try to find in the comparator collection
374 while ((comparator->Next())) {
375 TString s1 = this->GetLFN("");
376 TString s2 = comparator->GetLFN("");
383 this->Remove(overlapmap);
390 //___________________________________________________________________________
391 AliXMLCollection *AliXMLCollection::Open(const char *localcollectionfile) {
392 // Static method used to create an Alien event collection, by reading
393 // collection for the specified file.
395 AliXMLCollection *collection = new AliXMLCollection(localcollectionfile);
399 //___________________________________________________________________________
400 void AliXMLCollection::ParseXML() {
401 // Parse event file collection XML file.
405 XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
407 AliError(Form("cannot parse the xml file %s",fXmlFile.Data()));
411 XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
413 AliError(Form("cannot find the <alien> tag in %s",fXmlFile.Data()));
417 XMLNodePointer_t xcollection = xml.GetChild(xalien);
419 AliError(Form("cannot find the <collection> tag in %s",fXmlFile.Data()));
423 XMLNodePointer_t xevent = xml.GetChild(xcollection);;
425 AliError(Form("cannot find the <event> tag in %s",fXmlFile.Data()));
430 if (xml.GetAttr(xevent, "name")) {
431 TMap *files = new TMap();
434 XMLNodePointer_t xfile = xml.GetChild(xevent);
435 if (!xfile) continue;
437 Bool_t firstfile=kTRUE;
439 // here we have an event file
440 // get the attributes;
441 xml.GetAttr(xfile, "lfn");
442 xml.GetAttr(xfile, "turl");
444 TMap *attributes = new TMap();
445 TObjString *oname = new TObjString(xml.GetAttr(xfile,"name"));
446 TObjString *oturl = new TObjString(xml.GetAttr(xfile,"turl"));
447 TObjString *olfn = new TObjString(xml.GetAttr(xfile,"lfn"));
448 TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid"));
451 if (xml.GetAttr(xfile, "evlist"))
452 oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
456 TObjString *otagsumm;
457 if (xml.GetAttr(xfile, "cutsumm"))
458 otagsumm = new TObjString(xml.GetAttr(xfile, "cutsumm"));
463 AliDebug(1,Form("Collection: %s - turl: %s eventlist: %s",
464 fXmlFile.Data(),oturl->GetName(),oevlist->GetName()));
465 TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
466 if (strcmp(oevlist->GetName(),"") != 0) {
467 TString stringevlist = oevlist->GetName();
468 TObjArray *evlist = stringevlist.Tokenize(",");
469 for (Int_t n = 0; n < evlist->GetEntries(); n++) xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
472 attributes->Add(new TObjString("evlist"), xmlevlist);
475 attributes->Add(new TObjString("name"),oname);
476 attributes->Add(new TObjString("turl"),oturl);
477 attributes->Add(new TObjString("lfn"),olfn);
478 attributes->Add(new TObjString("guid"),oguid);
480 attributes->Add(new TObjString("cutsumm"),otagsumm);
481 files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes);
483 // we add the first file always as a file without name to the map
485 files->Add(new TObjString(""),attributes);
488 } while ((xfile = xml.GetNext(xfile)));
489 fEventList->Add(files);
492 if (xml.GetAttr(xevent, "acceptedEvents")) {
494 fAcceptedEvents = atoi(xml.GetAttr(xevent, "acceptedEvents"));
495 fTotalEvents = atoi(xml.GetAttr(xevent, "totalEvent"));
496 fRejectedRun = atoi(xml.GetAttr(xevent, "rejectedRun"));
497 fRejectedLHC = atoi(xml.GetAttr(xevent, "rejectedLHC"));
498 fRejectedDet = atoi(xml.GetAttr(xevent, "rejectedDet"));
499 fRejectedEvt = atoi(xml.GetAttr(xevent, "rejectedEvt"));
502 } while ((xevent = xml.GetNext(xevent)));
505 Bool_t AliXMLCollection::GetCollectionSummary(Int_t *aTot, Int_t *aAcc, Int_t *aRejRun, Int_t *aRejLHC, Int_t *aRejDet, Int_t *aRejEvt) const
507 // Return read list summary
508 *aTot = fTotalEvents;
509 *aAcc = fAcceptedEvents;
510 *aRejRun = fRejectedRun;
511 *aRejLHC = fRejectedLHC;
512 *aRejDet = fRejectedDet;
513 *aRejEvt = fRejectedEvt;