LCOV - code coverage report
Current view: top level - ANALYSIS/ANALYSISalice - AliXMLCollection.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 294 0.3 %
Date: 2016-06-14 17:26:59 Functions: 1 27 3.7 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       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             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      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             : //-----------------------------------------------------------------
      23             : 
      24             : #include <cstdlib>
      25             : //ROOT
      26             : #include <Riostream.h>
      27             : #include <TEntryList.h>
      28             : #include <TList.h>
      29             : #include <TMap.h>
      30             : #include <TObjArray.h>
      31             : #include <TObjString.h>
      32             : #include <TString.h>
      33             : #include <TXMLEngine.h>
      34             : #include "AliLog.h"
      35             : 
      36             : #include "AliXMLCollection.h"
      37             : 
      38         170 : ClassImp(AliXMLCollection)
      39             : //___________________________________________________________________________
      40             :   AliXMLCollection::AliXMLCollection() :
      41           0 :     TGridCollection(),
      42           0 :     fXmlFile(),
      43           0 :     fEventList(0),
      44           0 :     fEventListIter(0),
      45           0 :     fCurrent(0),
      46           0 :     fCollectionName(),
      47           0 :     fout(),
      48           0 :     fTotalEvents(0),
      49           0 :     fAcceptedEvents(0),
      50           0 :     fRejectedRun(0),
      51           0 :     fRejectedLHC(0),
      52           0 :     fRejectedDet(0),
      53           0 :     fRejectedEvt(0)
      54           0 : {
      55             :   //Default constructor
      56           0 : }
      57             : 
      58             : //___________________________________________________________________________
      59             : AliXMLCollection::AliXMLCollection(const char *localcollectionfile) :
      60           0 :     TGridCollection(),
      61           0 :     fXmlFile(localcollectionfile),
      62           0 :     fEventList(0),
      63           0 :     fEventListIter(0),
      64           0 :     fCurrent(0),
      65           0 :     fCollectionName(),
      66           0 :     fout(),
      67           0 :     fTotalEvents(0),
      68           0 :     fAcceptedEvents(0),
      69           0 :     fRejectedRun(0),
      70           0 :     fRejectedLHC(0),
      71           0 :     fRejectedDet(0),
      72           0 :     fRejectedEvt(0)
      73           0 :  {
      74             :    // Create Alien event collection, by reading collection for the specified
      75             :    // file.
      76             : 
      77           0 :    fEventList = new TList();
      78           0 :    fEventList->SetOwner(kTRUE);
      79           0 :    fEventListIter = new TIter(fEventList);
      80             : 
      81           0 :    if (localcollectionfile!=0) {
      82           0 :      ParseXML();
      83             :    }
      84           0 : }
      85             : 
      86             : //___________________________________________________________________________
      87             : AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
      88           0 :   TGridCollection(collection),
      89           0 :   fXmlFile(collection.fXmlFile),
      90           0 :   fEventList(0),
      91           0 :   fEventListIter(0),
      92           0 :   fCurrent(0),
      93           0 :   fCollectionName(collection.fCollectionName),
      94           0 :   fout(),
      95           0 :   fTotalEvents(0),
      96           0 :   fAcceptedEvents(0),
      97           0 :   fRejectedRun(0),
      98           0 :   fRejectedLHC(0),
      99           0 :   fRejectedDet(0),
     100           0 :   fRejectedEvt(0)
     101           0 : {
     102             :   //copy constructor
     103             : 
     104           0 :   if (collection.fEventList) fEventList = new TList();
     105           0 :   if (collection.fEventListIter) fEventListIter = new TIter(fEventList);
     106           0 :   if (collection.fCurrent) fCurrent = 0;
     107           0 : }
     108             : 
     109             : //___________________________________________________________________________
     110             : AliXMLCollection::~AliXMLCollection() 
     111           0 : {
     112             :   //Destructor
     113           0 :   delete fEventList;
     114           0 :   delete fEventListIter;
     115           0 : }
     116             : 
     117             : //___________________________________________________________________________
     118             : Bool_t AliXMLCollection::WriteHeader() {
     119             :   //Creates the xml output file
     120             : 
     121           0 :   TString xmlName = fCollectionName;
     122           0 :   xmlName += ".xml";
     123             : 
     124           0 :   TString collectionHeader = "<collection name=";
     125           0 :   collectionHeader += "\"";
     126           0 :   collectionHeader += fCollectionName;
     127           0 :   collectionHeader += "\"";
     128           0 :   collectionHeader += ">";
     129             :   
     130             :   // Open the output stream
     131           0 :   fout.open(xmlName);
     132           0 :   fout<<"<?xml version=\"1.0\"?>\n";
     133           0 :   fout<<"<alien>\n";
     134           0 :   fout<<"  "<<collectionHeader<<"\n";  
     135             : 
     136             :   return kTRUE;
     137           0 : }
     138             : 
     139             : //___________________________________________________________________________
     140             : Bool_t AliXMLCollection::WriteSummary(Int_t aTotal, Int_t aAccepted, Int_t aRejRun, Int_t aRejLHC, Int_t aRejDet, Int_t aRejEvt)
     141             : {
     142             :   // Write selection summary
     143             : 
     144           0 :   TString collectionSummary = "<summary";
     145           0 :   collectionSummary += " acceptedEvents=\"";
     146           0 :   collectionSummary += aAccepted;
     147           0 :   collectionSummary += "\" totalEvent=\"";
     148           0 :   collectionSummary += aTotal;
     149           0 :   collectionSummary += "\" rejectedRun=\"";
     150           0 :   collectionSummary += aRejRun;
     151           0 :   collectionSummary += "\" rejectedLHC=\"";
     152           0 :   collectionSummary += aRejLHC;
     153           0 :   collectionSummary += "\" rejectedDet=\"";
     154           0 :   collectionSummary += aRejDet;
     155           0 :   collectionSummary += "\" rejectedEvt=\"";
     156           0 :   collectionSummary += aRejEvt;
     157           0 :   collectionSummary += "\" />";
     158             :   
     159             :   // Open the output stream
     160           0 :   fout<<"  "<<collectionSummary<<"\n";  
     161             : 
     162             :   return kTRUE;
     163           0 : }
     164             : 
     165             : //___________________________________________________________________________
     166             : Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList* list) 
     167             : {
     168             :   //Writes the body of the xml collection
     169           0 :   TString listline;
     170           0 :   for(Int_t i = 0; i < list->GetN(); i++) {
     171           0 :     listline += list->GetEntry(i);
     172           0 :     listline += ",";
     173             :   }  
     174           0 :   listline = listline(0,listline.Length()-1);
     175             : 
     176           0 :   TString line0 = "<event name=\"";
     177           0 :   line0 += counter;
     178           0 :   line0 += "\">";
     179             :   
     180           0 :   TString line1 = "<file name=\"AliESDs.root\" ";
     181           0 :   line1 += "guid=\"";
     182           0 :   line1 += guid;
     183           0 :   line1 += "\" ";
     184           0 :   line1 += "lfn=\"";
     185           0 :   line1 += lfn;
     186           0 :   line1 += "\" ";
     187           0 :   line1 += "turl=\"";
     188           0 :   line1 += turl;
     189           0 :   line1 += "\" ";
     190           0 :   line1 += "evlist=\"";
     191           0 :   line1 += listline;
     192           0 :   line1 += "\"";
     193           0 :   line1 += " />";
     194             :   
     195           0 :   fout<<"    "<<line0<<"\n";
     196           0 :   fout<<"      "<<line1<<"\n";
     197           0 :   fout<<"    </event>\n";
     198             :   
     199             :   return kTRUE;
     200           0 : }
     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)
     203             : {
     204             :   //Writes the body of the xml collection with tag cuts summary
     205           0 :   TString listline;
     206           0 :   for(Int_t i = 0; i < list->GetN(); i++) {
     207           0 :     listline += list->GetEntry(i);
     208           0 :     listline += ",";
     209             :   }  
     210           0 :   listline = listline(0,listline.Length()-1);
     211             : 
     212           0 :   TString line0 = "<event name=\"";
     213           0 :   line0 += counter;
     214           0 :   line0 += "\">";
     215             :   
     216           0 :   TString line1 = "<file name=\"AliESDs.root\" ";
     217           0 :   line1 += "guid=\"";
     218           0 :   line1 += guid;
     219           0 :   line1 += "\" ";
     220           0 :   line1 += "lfn=\"";
     221           0 :   line1 += lfn;
     222           0 :   line1 += "\" ";
     223           0 :   line1 += "turl=\"";
     224           0 :   line1 += turl;
     225           0 :   line1 += "\" ";
     226           0 :   line1 += "evlist=\"";
     227           0 :   line1 += listline;
     228           0 :   line1 += "\" ";
     229           0 :   line1 += "cutsumm=\"";
     230           0 :   line1 += accSum;
     231           0 :   line1 += ",";
     232           0 :   line1 += rejSum;
     233           0 :   line1 += "\"";
     234           0 :   line1 += " />";
     235             :   
     236           0 :   fout<<"    "<<line0<<"\n";
     237           0 :   fout<<"      "<<line1<<"\n";
     238           0 :   fout<<"    </event>\n";
     239             :   
     240             :   return kTRUE;
     241             :   
     242           0 : }
     243             : //___________________________________________________________________________
     244             : Bool_t AliXMLCollection::Export() {
     245             :   //Closes the stream
     246           0 :   fout<<"  "<<"</collection>\n";
     247           0 :   fout<<"</alien>\n";
     248             : 
     249           0 :   fout.close();
     250             : 
     251           0 :   return kTRUE;
     252             : }
     253             : 
     254             : //___________________________________________________________________________
     255             : void AliXMLCollection::Reset() {
     256             :   // Reset file iterator.
     257             :   
     258           0 :   fEventListIter->Reset();
     259           0 :   fCurrent = 0;
     260           0 : }
     261             : 
     262             : //___________________________________________________________________________
     263             : TMap *AliXMLCollection::Next() {
     264             :   // Return next event file map.
     265             :   
     266           0 :   fCurrent = (TMap*)fEventListIter->Next();
     267           0 :   return fCurrent;
     268             : }
     269             : 
     270             : //___________________________________________________________________________
     271             : const char *AliXMLCollection::GetTURL(const char* filename) {
     272             :   // Get a file's transport URL (TURL). Returns 0 in case of error.
     273             :   
     274           0 :   if (fCurrent) {
     275           0 :     TMap *obj = (TMap*)fCurrent->GetValue(filename);
     276           0 :     if (obj) {
     277           0 :       if (obj->GetValue("turl")) {
     278           0 :         return ( ((TObjString*)obj->GetValue("turl"))->GetName());
     279             :       }
     280             :     }
     281           0 :   }
     282           0 :   AliError(Form("cannot get TURL of file %s",filename));
     283           0 :   return 0;
     284           0 : }
     285             : 
     286             : //___________________________________________________________________________
     287             : const char *AliXMLCollection::GetGUID(const char* filename) {
     288             :   // Get a file's transport UID. Returns 0 in case of error.
     289             :   
     290           0 :   if (fCurrent) {
     291           0 :     TMap *obj = (TMap*)fCurrent->GetValue(filename);
     292           0 :     if (obj) {
     293           0 :       if (obj->GetValue("guid")) {
     294           0 :         return ( ((TObjString*)obj->GetValue("guid"))->GetName());
     295             :       }
     296             :     }
     297           0 :   }
     298           0 :   AliError(Form("cannot get GUID of file %s",filename));
     299           0 :   return 0;
     300           0 : }
     301             : 
     302             : //___________________________________________________________________________
     303             : TEntryList *AliXMLCollection::GetEventList(const char *filename) const {
     304             :   // Get a file's event list. Returns 0 in case of error.
     305             : 
     306           0 :   if (fCurrent) {
     307           0 :     TMap *obj = (TMap *) fCurrent->GetValue(filename);
     308           0 :     if (obj) {
     309           0 :       if (obj->GetValue("evlist")) {
     310           0 :         return ((TEntryList *) obj->GetValue("evlist"));
     311             :       }
     312             :     }
     313           0 :   }
     314           0 :   AliError(Form("cannot get evelist of file %s", filename));
     315           0 :   return 0;
     316           0 : }
     317             : 
     318             : //___________________________________________________________________________
     319             : Bool_t AliXMLCollection::Remove(TMap * map) {
     320             :   // Return next event file map.
     321           0 :   if (fEventList->Remove(map)) {
     322           0 :     return kTRUE;
     323             :   } else {
     324           0 :     return kFALSE;
     325             :   }
     326           0 : }
     327             : 
     328             : //___________________________________________________________________________
     329             : const char *AliXMLCollection::GetLFN(const char* ) {
     330             :   // Get a file's LFN. Returns 0 in case of error.
     331             :   
     332           0 :   if (fCurrent) {
     333           0 :     TMap *obj = (TMap *) fCurrent->GetValue("");
     334           0 :     if (obj) {
     335           0 :       if (obj->GetValue("lfn")) {
     336           0 :         return (((TObjString *) obj->GetValue("lfn"))->GetName());
     337             :       }
     338             :     }
     339           0 :   }
     340           0 :   AliError("cannot get LFN");
     341           0 :   return 0;
     342           0 : }
     343             : 
     344             : //__________________________________________________________________________
     345             : const char *AliXMLCollection::GetCutSumm() {
     346             :   // Get a file's tag cuts summary. Returns 0 in case of error.
     347             :   
     348           0 :   if (fCurrent) {
     349           0 :     TMap *obj = (TMap *) fCurrent->GetValue("");
     350           0 :     if (obj) {
     351           0 :       if (obj->GetValue("cutsumm")) {
     352           0 :         return (((TObjString *) obj->GetValue("cutsumm"))->GetName());
     353             :       }
     354             :     }
     355           0 :   }
     356           0 :   AliError("cannot get Tag Cut Summary");
     357           0 :   return 0;
     358             : 
     359           0 : }
     360             : //__________________________________________________________________________
     361             : Bool_t AliXMLCollection::OverlapCollection(TGridCollection * comparator) {
     362             :   // return kTRUE if comparator overlaps with this
     363           0 :   if ((!comparator)) return kFALSE;
     364             :   
     365             :  loopagain:
     366             :   // loop over col1 and try to find it in col2
     367           0 :   this->Reset();
     368             :   // loop over all elements in reference (=this)
     369             :   TMap *overlapmap;
     370           0 :   while ((overlapmap = this->Next())) {
     371           0 :     comparator->Reset();
     372             :     Bool_t found = kFALSE;
     373             :     // try to find in the comparator collection
     374           0 :     while ((comparator->Next())) {
     375           0 :       TString s1 = this->GetLFN("");
     376           0 :       TString s2 = comparator->GetLFN("");
     377           0 :       if (s1 == s2) {
     378             :         found = kTRUE;
     379           0 :         break;
     380             :       }
     381           0 :     }
     382           0 :     if (!found) {
     383           0 :       this->Remove(overlapmap);
     384           0 :       goto loopagain;
     385             :     }
     386           0 :   }
     387           0 :   return kTRUE;
     388           0 : }
     389             : 
     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.
     394             :   
     395           0 :   AliXMLCollection *collection = new AliXMLCollection(localcollectionfile);
     396           0 :   return collection;
     397           0 : }
     398             : 
     399             : //___________________________________________________________________________
     400             : void AliXMLCollection::ParseXML() {
     401             :   // Parse event file collection XML file.
     402             :   
     403           0 :   TXMLEngine xml;
     404             :   
     405           0 :   XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
     406           0 :   if (!xdoc) {
     407           0 :     AliError(Form("cannot parse the xml file %s",fXmlFile.Data()));
     408           0 :     return;
     409             :   }
     410             : 
     411           0 :   XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
     412           0 :   if (!xalien) {
     413           0 :     AliError(Form("cannot find the <alien> tag in %s",fXmlFile.Data()));
     414           0 :     return;
     415             :   }
     416             :   
     417           0 :   XMLNodePointer_t xcollection = xml.GetChild(xalien);
     418           0 :   if (!xcollection) {
     419           0 :     AliError(Form("cannot find the <collection> tag in %s",fXmlFile.Data()));
     420           0 :     return;
     421             :   }
     422             :   
     423           0 :   XMLNodePointer_t xevent = xml.GetChild(xcollection);;
     424           0 :   if (!xevent) {
     425           0 :     AliError(Form("cannot find the <event> tag in %s",fXmlFile.Data()));
     426           0 :     return;
     427             :   }
     428             :   
     429             :   do {
     430           0 :     if (xml.GetAttr(xevent, "name")) {
     431           0 :       TMap *files = new TMap();
     432             :             
     433             :       // files
     434           0 :       XMLNodePointer_t xfile = xml.GetChild(xevent);
     435           0 :       if (!xfile) continue;
     436             : 
     437             :       Bool_t firstfile=kTRUE;
     438           0 :       do {
     439             :         // here we have an event file
     440             :         // get the attributes;
     441           0 :         xml.GetAttr(xfile, "lfn");
     442           0 :         xml.GetAttr(xfile, "turl");
     443             :         
     444           0 :         TMap *attributes = new TMap();
     445           0 :         TObjString *oname = new TObjString(xml.GetAttr(xfile,"name"));
     446           0 :         TObjString *oturl = new TObjString(xml.GetAttr(xfile,"turl"));
     447           0 :         TObjString *olfn  = new TObjString(xml.GetAttr(xfile,"lfn"));
     448           0 :         TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid"));
     449             : 
     450             :         TObjString *oevlist;
     451           0 :         if (xml.GetAttr(xfile, "evlist"))
     452           0 :           oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
     453             :         else
     454             :           oevlist = 0;
     455             : 
     456             :         TObjString *otagsumm;
     457           0 :         if (xml.GetAttr(xfile, "cutsumm"))
     458           0 :           otagsumm = new TObjString(xml.GetAttr(xfile, "cutsumm"));
     459             :         else 
     460             :           otagsumm = 0;
     461             : 
     462           0 :         if (oevlist) {
     463           0 :           AliDebug(1,Form("Collection: %s - turl: %s eventlist: %s",
     464             :                     fXmlFile.Data(),oturl->GetName(),oevlist->GetName()));
     465           0 :           TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
     466           0 :           if (strcmp(oevlist->GetName(),"") != 0) {
     467           0 :             TString stringevlist = oevlist->GetName();
     468           0 :             TObjArray *evlist = stringevlist.Tokenize(",");
     469           0 :             for (Int_t n = 0; n < evlist->GetEntries(); n++)  xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
     470           0 :             delete evlist;
     471           0 :           }
     472           0 :           attributes->Add(new TObjString("evlist"), xmlevlist);
     473           0 :         }
     474             :         
     475           0 :         attributes->Add(new TObjString("name"),oname);
     476           0 :         attributes->Add(new TObjString("turl"),oturl);
     477           0 :         attributes->Add(new TObjString("lfn"),olfn);
     478           0 :         attributes->Add(new TObjString("guid"),oguid);
     479           0 :         if (otagsumm)
     480           0 :           attributes->Add(new TObjString("cutsumm"),otagsumm);
     481           0 :         files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes);
     482             :         
     483             :         // we add the first file always as a file without name to the map
     484           0 :         if (firstfile) {
     485           0 :           files->Add(new TObjString(""),attributes);
     486             :           firstfile=kFALSE;
     487           0 :         }
     488           0 :       } while ((xfile = xml.GetNext(xfile)));
     489           0 :       fEventList->Add(files);
     490           0 :     }
     491             :     else {
     492           0 :       if (xml.GetAttr(xevent, "acceptedEvents")) {
     493             :         // Read list summary
     494           0 :         fAcceptedEvents = atoi(xml.GetAttr(xevent, "acceptedEvents"));
     495           0 :         fTotalEvents = atoi(xml.GetAttr(xevent, "totalEvent"));
     496           0 :         fRejectedRun = atoi(xml.GetAttr(xevent, "rejectedRun"));
     497           0 :         fRejectedLHC = atoi(xml.GetAttr(xevent, "rejectedLHC"));
     498           0 :         fRejectedDet = atoi(xml.GetAttr(xevent, "rejectedDet"));
     499           0 :         fRejectedEvt = atoi(xml.GetAttr(xevent, "rejectedEvt"));
     500           0 :       }
     501             :     }
     502           0 :   } while ((xevent =  xml.GetNext(xevent)));
     503           0 : }
     504             : 
     505             : Bool_t AliXMLCollection::GetCollectionSummary(Int_t  *aTot, Int_t  *aAcc, Int_t  *aRejRun, Int_t  *aRejLHC, Int_t  *aRejDet, Int_t  *aRejEvt) const
     506             : {
     507             :   // Return read list summary
     508           0 :   *aTot = fTotalEvents;
     509           0 :   *aAcc = fAcceptedEvents;
     510           0 :   *aRejRun = fRejectedRun;
     511           0 :   *aRejLHC = fRejectedLHC;
     512           0 :   *aRejDet = fRejectedDet;
     513           0 :   *aRejEvt = fRejectedEvt;
     514           0 :   return kTRUE;
     515             : }

Generated by: LCOV version 1.11