]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliXMLCollection.cxx
Fix
[u/mrichter/AliRoot.git] / ANALYSIS / AliXMLCollection.cxx
index e1246d887613fe7a5d6fd9aa3ce52e740771d1d2..3a39bc922910cea89780eefb448f331f303ab831 100644 (file)
@@ -21,6 +21,7 @@
 //   Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
 //-----------------------------------------------------------------
 
+#include <cstdlib>
 //ROOT
 #include <Riostream.h>
 #include <TEntryList.h>
@@ -30,6 +31,7 @@
 #include <TObjString.h>
 #include <TString.h>
 #include <TXMLEngine.h>
+#include "AliLog.h"
 
 #include "AliXMLCollection.h"
 
@@ -42,7 +44,14 @@ ClassImp(AliXMLCollection)
     fEventListIter(0),
     fCurrent(0),
     fCollectionName(),
-    fout() {
+    fout(),
+    fTotalEvents(0),
+    fAcceptedEvents(0),
+    fRejectedRun(0),
+    fRejectedLHC(0),
+    fRejectedDet(0),
+    fRejectedEvt(0)
+{
   //Default constructor
 }
 
@@ -54,7 +63,13 @@ AliXMLCollection::AliXMLCollection(const char *localcollectionfile) :
     fEventListIter(0),
     fCurrent(0),
     fCollectionName(),
-    fout()
+    fout(),
+    fTotalEvents(0),
+    fAcceptedEvents(0),
+    fRejectedRun(0),
+    fRejectedLHC(0),
+    fRejectedDet(0),
+    fRejectedEvt(0)
  {
    // Create Alien event collection, by reading collection for the specified
    // file.
@@ -76,7 +91,13 @@ AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
   fEventListIter(0),
   fCurrent(0),
   fCollectionName(collection.fCollectionName),
-  fout()
+  fout(),
+  fTotalEvents(0),
+  fAcceptedEvents(0),
+  fRejectedRun(0),
+  fRejectedLHC(0),
+  fRejectedDet(0),
+  fRejectedEvt(0)
 {
   //copy constructor
 
@@ -86,10 +107,11 @@ AliXMLCollection::AliXMLCollection(const AliXMLCollection& collection):
 }
 
 //___________________________________________________________________________
-AliXMLCollection::~AliXMLCollection() {
+AliXMLCollection::~AliXMLCollection() 
+{
   //Destructor
-  if(fEventList) delete fEventList;
-  if(fEventListIter) delete fEventListIter;
+  delete fEventList;
+  delete fEventListIter;
 }
 
 //___________________________________________________________________________
@@ -115,7 +137,34 @@ Bool_t AliXMLCollection::WriteHeader() {
 }
 
 //___________________________________________________________________________
-Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList *list) {
+Bool_t AliXMLCollection::WriteSummary(Int_t aTotal, Int_t aAccepted, Int_t aRejRun, Int_t aRejLHC, Int_t aRejDet, Int_t aRejEvt)
+{
+  // Write selection summary
+
+  TString collectionSummary = "<summary";
+  collectionSummary += " acceptedEvents=\"";
+  collectionSummary += aAccepted;
+  collectionSummary += "\" totalEvent=\"";
+  collectionSummary += aTotal;
+  collectionSummary += "\" rejectedRun=\"";
+  collectionSummary += aRejRun;
+  collectionSummary += "\" rejectedLHC=\"";
+  collectionSummary += aRejLHC;
+  collectionSummary += "\" rejectedDet=\"";
+  collectionSummary += aRejDet;
+  collectionSummary += "\" rejectedEvt=\"";
+  collectionSummary += aRejEvt;
+  collectionSummary += "\" />";
+  
+  // Open the output stream
+  fout<<"  "<<collectionSummary<<"\n";  
+
+  return kTRUE;
+}
+
+//___________________________________________________________________________
+Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList* list) 
+{
   //Writes the body of the xml collection
   TString listline;
   for(Int_t i = 0; i < list->GetN(); i++) {
@@ -149,7 +198,48 @@ Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char*
   
   return kTRUE;
 }
+//___________________________________________________________________________
+Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char *lfn, const char *turl, TEntryList* list, Int_t accSum, Int_t rejSum)
+{
+  //Writes the body of the xml collection with tag cuts summary
+  TString listline;
+  for(Int_t i = 0; i < list->GetN(); i++) {
+    listline += list->GetEntry(i);
+    listline += ",";
+  }  
+  listline = listline(0,listline.Length()-1);
 
+  TString line0 = "<event name=\"";
+  line0 += counter;
+  line0 += "\">";
+  
+  TString line1 = "<file name=\"AliESDs.root\" ";
+  line1 += "guid=\"";
+  line1 += guid;
+  line1 += "\" ";
+  line1 += "lfn=\"";
+  line1 += lfn;
+  line1 += "\" ";
+  line1 += "turl=\"";
+  line1 += turl;
+  line1 += "\" ";
+  line1 += "evlist=\"";
+  line1 += listline;
+  line1 += "\" ";
+  line1 += "cutsumm=\"";
+  line1 += accSum;
+  line1 += ",";
+  line1 += rejSum;
+  line1 += "\"";
+  line1 += " />";
+  
+  fout<<"    "<<line0<<"\n";
+  fout<<"      "<<line1<<"\n";
+  fout<<"    </event>\n";
+  
+  return kTRUE;
+  
+}
 //___________________________________________________________________________
 Bool_t AliXMLCollection::Export() {
   //Closes the stream
@@ -189,7 +279,7 @@ const char *AliXMLCollection::GetTURL(const char* filename) {
       }
     }
   }
-  Error("GetTURL","cannot get TURL of file %s",filename);
+  AliError(Form("cannot get TURL of file %s",filename));
   return 0;
 }
 
@@ -205,7 +295,7 @@ const char *AliXMLCollection::GetGUID(const char* filename) {
       }
     }
   }
-  Error("GetGUID","cannot get GUID of file %s",filename);
+  AliError(Form("cannot get GUID of file %s",filename));
   return 0;
 }
 
@@ -221,7 +311,7 @@ TEntryList *AliXMLCollection::GetEventList(const char *filename) const {
       }
     }
   }
-  Error("GetEvList", "cannot get evelist of file %s", filename);
+  AliError(Form("cannot get evelist of file %s", filename));
   return 0;
 }
 
@@ -247,10 +337,26 @@ const char *AliXMLCollection::GetLFN(const char* ) {
       }
     }
   }
-  Error("GetLFN", "cannot get LFN");
+  AliError("cannot get LFN");
   return 0;
 }
 
+//__________________________________________________________________________
+const char *AliXMLCollection::GetCutSumm() {
+  // Get a file's tag cuts summary. Returns 0 in case of error.
+  
+  if (fCurrent) {
+    TMap *obj = (TMap *) fCurrent->GetValue("");
+    if (obj) {
+      if (obj->GetValue("cutsumm")) {
+       return (((TObjString *) obj->GetValue("cutsumm"))->GetName());
+      }
+    }
+  }
+  AliError("cannot get Tag Cut Summary");
+  return 0;
+
+}
 //__________________________________________________________________________
 Bool_t AliXMLCollection::OverlapCollection(TGridCollection * comparator) {
   // return kTRUE if comparator overlaps with this
@@ -298,28 +404,27 @@ void AliXMLCollection::ParseXML() {
   
   XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
   if (!xdoc) {
-    Error("ParseXML","cannot parse the xml file %s",fXmlFile.Data());
+    AliError(Form("cannot parse the xml file %s",fXmlFile.Data()));
     return;
   }
 
   XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
   if (!xalien) {
-    Error("ParseXML","cannot find the <alien> tag in %s",fXmlFile.Data());
+    AliError(Form("cannot find the <alien> tag in %s",fXmlFile.Data()));
     return;
   }
   
   XMLNodePointer_t xcollection = xml.GetChild(xalien);
   if (!xcollection) {
-    Error("ParseXML","cannot find the <collection> tag in %s",fXmlFile.Data());
+    AliError(Form("cannot find the <collection> tag in %s",fXmlFile.Data()));
     return;
   }
   
   XMLNodePointer_t xevent = xml.GetChild(xcollection);;
   if (!xevent) {
-    Error("ParseXML","cannot find the <event> tag in %s",fXmlFile.Data());
+    AliError(Form("cannot find the <event> tag in %s",fXmlFile.Data()));
     return;
   }
-  if (!xevent) return;
   
   do {
     if (xml.GetAttr(xevent, "name")) {
@@ -328,7 +433,7 @@ void AliXMLCollection::ParseXML() {
       // files
       XMLNodePointer_t xfile = xml.GetChild(xevent);
       if (!xfile) continue;
-      
+
       Bool_t firstfile=kTRUE;
       do {
        // here we have an event file
@@ -341,13 +446,28 @@ void AliXMLCollection::ParseXML() {
        TObjString *oturl = new TObjString(xml.GetAttr(xfile,"turl"));
        TObjString *olfn  = new TObjString(xml.GetAttr(xfile,"lfn"));
        TObjString *oguid = new TObjString(xml.GetAttr(xfile,"guid"));
-       TObjString *oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
-       printf("Collection: %s - The Eventlist is %s\n",fXmlFile.Data(),oevlist->GetName());
-       if (oevlist->GetName() != "") {
+
+       TObjString *oevlist;
+       if (xml.GetAttr(xfile, "evlist"))
+         oevlist = new TObjString(xml.GetAttr(xfile, "evlist"));
+       else
+         oevlist = 0;
+
+       TObjString *otagsumm;
+       if (xml.GetAttr(xfile, "cutsumm"))
+         otagsumm = new TObjString(xml.GetAttr(xfile, "cutsumm"));
+       else 
+         otagsumm = 0;
+
+       if (oevlist) {
+         AliDebug(1,Form("Collection: %s - turl: %s eventlist: %s",
+                    fXmlFile.Data(),oturl->GetName(),oevlist->GetName()));
          TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
-         TString stringevlist = oevlist->GetName();
-         TObjArray *evlist = stringevlist.Tokenize(",");
-         for (Int_t n = 0; n < evlist->GetEntries(); n++)  xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
+         if (strcmp(oevlist->GetName(),"") != 0) {
+           TString stringevlist = oevlist->GetName();
+           TObjArray *evlist = stringevlist.Tokenize(",");
+           for (Int_t n = 0; n < evlist->GetEntries(); n++)  xmlevlist->Enter(atol(((TObjString *) evlist->At(n))->GetName()));
+         }
          attributes->Add(new TObjString("evlist"), xmlevlist);
        }
        
@@ -355,6 +475,8 @@ void AliXMLCollection::ParseXML() {
        attributes->Add(new TObjString("turl"),oturl);
        attributes->Add(new TObjString("lfn"),olfn);
        attributes->Add(new TObjString("guid"),oguid);
+       if (otagsumm)
+         attributes->Add(new TObjString("cutsumm"),otagsumm);
        files->Add(new TObjString(xml.GetAttr(xfile,"name")) , attributes);
        
        // we add the first file always as a file without name to the map
@@ -365,6 +487,28 @@ void AliXMLCollection::ParseXML() {
       } while ((xfile = xml.GetNext(xfile)));
       fEventList->Add(files);
     }
+    else {
+      if (xml.GetAttr(xevent, "acceptedEvents")) {
+       // Read list summary
+       fAcceptedEvents = atoi(xml.GetAttr(xevent, "acceptedEvents"));
+       fTotalEvents = atoi(xml.GetAttr(xevent, "totalEvent"));
+       fRejectedRun = atoi(xml.GetAttr(xevent, "rejectedRun"));
+       fRejectedLHC = atoi(xml.GetAttr(xevent, "rejectedLHC"));
+       fRejectedDet = atoi(xml.GetAttr(xevent, "rejectedDet"));
+       fRejectedEvt = atoi(xml.GetAttr(xevent, "rejectedEvt"));
+      }
+    }
   } while ((xevent =  xml.GetNext(xevent)));
 }
 
+Bool_t AliXMLCollection::GetCollectionSummary(Int_t  *aTot, Int_t  *aAcc, Int_t  *aRejRun, Int_t  *aRejLHC, Int_t  *aRejDet, Int_t  *aRejEvt) const
+{
+  // Return read list summary
+  *aTot = fTotalEvents;
+  *aAcc = fAcceptedEvents;
+  *aRejRun = fRejectedRun;
+  *aRejLHC = fRejectedLHC;
+  *aRejDet = fRejectedDet;
+  *aRejEvt = fRejectedEvt;
+  return kTRUE;
+}