]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Corrections for report #60705: AliTagAnalysis fixes
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 6 Jan 2010 14:44:54 +0000 (14:44 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 6 Jan 2010 14:44:54 +0000 (14:44 +0000)
ANALYSIS/AliTagAnalysis.cxx
ANALYSIS/AliTagAnalysis.h
ANALYSIS/AliXMLCollection.cxx

index caa5cac613384930dc34f18debc528ff3788cac6..ecadf55ddbbc49fddb34bc21b739221116e7aaa7 100644 (file)
@@ -78,22 +78,26 @@ AliTagAnalysis::~AliTagAnalysis() {
 }
 
 //___________________________________________________________________________
-Bool_t  AliTagAnalysis::AddTagsFile(const char *alienUrl) {
-  // Add a single tags file to the chain
-
-  Bool_t rv = kTRUE ;
-
-  if (! fChain) fChain = new TChain("T");
-
-  TFile *f = TFile::Open(alienUrl,"READ");
-  fChain->Add(alienUrl);
-  AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
-  delete f;
+Bool_t  
+AliTagAnalysis::AddTagsFile(const char* alienUrl, Bool_t checkFile) 
+{
+  /// Add a single tags file to the chain
+  ///
+  /// If checkFile=kTRUE (default) the file is opened to check
+  /// it can be and that it contains data.
+  /// It's safer but a lot longer...
+  
+  if (!fChain) fChain = new TChain("T");
 
-  if (fChain->GetEntries() == 0 )
-    rv = kFALSE ;
+  if ( checkFile )
+  {
+    return ( fChain->AddFile(alienUrl,-1) > 0 );
+  }
+  else
+  {
+    return ( fChain->AddFile(alienUrl) > 0 );
+  }
 
-  return rv ;
 }
 
 //___________________________________________________________________________
@@ -346,111 +350,137 @@ TChain *AliTagAnalysis::QueryTags(const char *fRunCut,
 }
 
 //___________________________________________________________________________
-Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, 
-                                          AliRunTagCuts *runTagCuts, 
-                                          AliLHCTagCuts *lhcTagCuts, 
-                                          AliDetectorTagCuts *detTagCuts, 
-                                          AliEventTagCuts *evTagCuts) {
-  //Queries the tag chain using the defined 
-  //event tag cuts from the AliEventTagCuts object
-  //and returns a XML collection
+Bool_t 
+AliTagAnalysis::CreateXMLCollection(const char* name, 
+                                    AliRunTagCuts *runTagCuts, 
+                                    AliLHCTagCuts *lhcTagCuts, 
+                                    AliDetectorTagCuts *detTagCuts, 
+                                    AliEventTagCuts *evTagCuts) 
+{
+  /// Queries the tag chain using the defined run, lhc, detector and event tag objects
+  /// and create a XML collection named "name.xml"
+  /// if any of the runTagCuts, lhcTagCuts, detTagCuts or evTagCuts is NULL
+  /// check on that object will be skipped.
+  
   AliInfo(Form("Creating the collection........"));
-
+  
+  if (!fChain) 
+  {
+    AliError("fChain is NULL. Cannot make a collection from that !");
+    return kFALSE;
+  }
+  
   Bool_t aod = kFALSE;
   if(fAnalysisType == "AOD") aod = kTRUE;
-
-
-  AliXMLCollection *collection = new AliXMLCollection();
-  collection->SetCollectionName(name);
-  collection->WriteHeader();
-
+  
+  
+  AliXMLCollection collection;
+  collection.SetCollectionName(name);
+  collection.WriteHeader();
+  
   TString guid;
   TString turl;
   TString lfn;
   
   TTree*      cTree = 0; 
-  TEntryList* localList = new TEntryList();
+  TEntryList localList;
   Int_t iAccepted = 0;
   Int_t iev       = 0;
   Int_t ientry    = 0;
   Int_t cEntries  = 0;
-
+  
   Int_t iRejectedRun = 0;
   Int_t iRejectedLHC = 0;
   Int_t iRejectedDet = 0;
   Int_t iRejectedEvt = 0;
-
+  
   Int_t iTotalEvents = 0;
-
+  
   Int_t iAcceptedEvtInFile = 0;
   Int_t iRejectedEvtInFile = 0;
-
+  
   //Defining tag objects
-  AliRunTag   *tag   = new AliRunTag;
-  AliEventTag *evTag = new AliEventTag;
+  AliRunTag* tag = new AliRunTag;
   fChain->SetBranchAddress("AliTAG",&tag);
-
-  for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
-
+  
+  for(Int_t iTagFiles = 0; iTagFiles < fChain->GetListOfFiles()->GetEntries(); ++iTagFiles) 
+  {
     fChain->GetEntry(iTagFiles);
     TTree* tree = fChain->GetTree();
     if (cTree != tree) {
-       // Fix for aod tags: for each tree in the chain, merge the entries
-       cTree    = tree;
-       cEntries = tree->GetEntries();
-       iev      = 0;
-       ientry   = 0;
+      // Fix for aod tags: for each tree in the chain, merge the entries
+      cTree    = tree;
+      cEntries = tree->GetEntries();
+      iev      = 0;
+      ientry   = 0;
     }
     //Event list
     iTotalEvents += tag->GetNEvents();
-    if ((iev == 0) || !aod) localList->Reset();
-    if(runTagCuts->IsAccepted(tag)) {
-      if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) {
-       if(detTagCuts->IsAccepted(tag->GetDetectorTags())) {
-         Int_t iEvents = tag->GetNEvents();
-         const TClonesArray *tagList = tag->GetEventTags();
-         iRejectedEvtInFile = 0;
-         iAcceptedEvtInFile = 0;
-         for(Int_t i = 0; i < iEvents; i++) {
-           evTag = (AliEventTag *) tagList->At(i);
-           guid = evTag->GetGUID(); 
-           turl = evTag->GetTURL(); 
-           lfn = turl(8,turl.Length());
-           if(evTagCuts->IsAccepted(evTag)) {
-               if(aod) localList->Enter(iev);
-               else localList->Enter(i);
-               iAcceptedEvtInFile++;
-           }
-           else {
-             iRejectedEvt++;
-             iRejectedEvtInFile++;
-           }
-           iev++;
-         }//event loop
-         if ((ientry == cEntries-1) || !aod) {
-           iAccepted += localList->GetN();
-           collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList,iAcceptedEvtInFile,iRejectedEvtInFile);
-         }
-       }//detector tag cuts
-       else {
-         iRejectedDet += tag->GetNEvents();
-       }
+    if ((iev == 0) || !aod) localList.Reset();
+
+    if ( !runTagCuts || ( runTagCuts && runTagCuts->IsAccepted(tag) ) ) 
+    {
+      if ( !lhcTagCuts || ( lhcTagCuts && lhcTagCuts->IsAccepted(tag->GetLHCTag())) ) 
+      {
+        if ( !detTagCuts || ( detTagCuts && detTagCuts->IsAccepted(tag->GetDetectorTags())) )
+        {
+          Int_t i(0);
+          TIter next(tag->GetEventTags());
+          AliEventTag* evTag(0x0);
+          iRejectedEvtInFile = 0;
+          iAcceptedEvtInFile = 0;
+          while ( ( evTag = static_cast<AliEventTag*>(next()) ) )
+          {
+            guid = evTag->GetGUID(); 
+            turl = evTag->GetTURL(); 
+            lfn = turl(8,turl.Length());
+            if( !evTagCuts || ( evTagCuts && evTagCuts->IsAccepted(evTag)) )
+            {
+              if (aod) localList.Enter(iev);
+              else localList.Enter(i);
+              iAcceptedEvtInFile++;
+              
+//              AliInfo(Form("Period %5d Orbit# %12d BC %10d (%5d ? in TURL %s) Trigger %s nmus %d",
+//                           evTag->GetPeriodNumber(),
+//                           evTag->GetOrbitNumber(),
+//                           evTag->GetBunchCrossNumber(),
+//                           i,
+//                           evTag->GetTURL(),
+//                           evTag->GetFiredTriggerClasses().Data(),
+//                           evTag->GetNumOfMuons()));              
+            }
+            else 
+            {
+              ++iRejectedEvt;
+              ++iRejectedEvtInFile;
+            }
+            ++i;
+            ++iev;
+          }//event loop
+          if ((ientry == cEntries-1) || !aod) 
+          {
+            iAccepted += localList.GetN();
+            collection.WriteBody(iTagFiles+1,guid,lfn,turl,&localList,iAcceptedEvtInFile,iRejectedEvtInFile);
+          }
+        }//detector tag cuts
+        else {
+          iRejectedDet += tag->GetNEvents();
+        }
       }//lhc tag cuts 
       else {
-       iRejectedLHC += tag->GetNEvents();
+        iRejectedLHC += tag->GetNEvents();
       }
     }//run tag cuts
     else {
       iRejectedRun += tag->GetNEvents();
     }
     tag->Clear();
-    ientry++;
-  }//tag file loop
-  collection->WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt);
-  collection->Export();
+    ++ientry;
+  } //tag file loop
+  
+  collection.WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt);
+  collection.Export();
   
-  delete tag;
-  delete localList;
   return kTRUE;
 }
 
@@ -605,42 +635,55 @@ TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) {
 }
 
 //___________________________________________________________________________
-TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, 
-                                              const char* treename) {
-  //returns the TChain+TEntryList object- used in batch sessions
-  TString aliceFile = treename;
-  Int_t iAccepted = 0;
-  TChain *fAnalysisChain = 0;
-  if(aliceFile == "esdTree") fAnalysisChain = new TChain("esdTree");
-  else if(aliceFile == "aodTree") fAnalysisChain = new TChain("aodTree");
-  else AliFatal("Inconsistent tree name - use esdTree or aodTree!");
+TChain*
+AliTagAnalysis::CreateChainFromCollection(const char* collectionname, const char* treename)
+{
+  /// Build a TChain (with its TEntryList object attached) from an XML collection.
+  /// Returned chain must be deleted by the client.
+
+  TString streename(treename);
+  if ( streename != "esdTree" && streename != "aodTree" )
+  {
+    AliErrorClass("Only esdTree and aodTree implemented so far...");
+    return 0x0;
+  }
+  
+  TChain* chain = new TChain(streename.Data());
 
-  //Event list
-  fGlobalList = new TEntryList();
-  AliXMLCollection *collection = AliXMLCollection::Open(collectionname);
+  // create the event list for the chain. Will be attached to the chain
+  // which thus becomes the owner of it.
+  TEntryList* elist = new TEntryList; 
+  
+  AliXMLCollection* collection = AliXMLCollection::Open(collectionname);
 
   // Tag selection summary per file
-  TMap *tagCutSummary = new TMap();
+  TMaptagCutSummary = new TMap();
   tagCutSummary->SetName("TagCutSumm");
 
+  Int_t iAccepted = 0;
+  
   collection->Reset();
-  while (collection->Next()) {
-    AliInfo(Form("Adding: %s",collection->GetTURL("")));
-    fAnalysisChain->Add(collection->GetTURL(""));
-    TEntryList *list = (TEntryList *)collection->GetEventList("");
-    list->SetTreeName(aliceFile.Data());
+  
+  while (collection->Next()) 
+  {
+    AliDebugClass(1,Form("Adding: %s",collection->GetTURL("")));
+    chain->Add(collection->GetTURL(""));
+    TEntryList *list = collection->GetEventList("");
+    list->SetTreeName(streename.Data());
     list->SetFileName(collection->GetTURL(""));
-    fGlobalList->Add(list);
+    elist->Add(list);
     iAccepted += list->GetN();
     if (collection->GetCutSumm())
+    {
       tagCutSummary->Add(new TObjString(collection->GetTURL("")), new TObjString(collection->GetCutSumm()));
+    }
   }
 
-  fAnalysisChain->SetEntryList(fGlobalList,"ne");
+  chain->SetEntryList(elist,"ne"); // ne => do not expand tree name and/or file names
   
-  AliInfo(Form("Number of selected events: %d",iAccepted));
+  AliDebugClass(1,Form("Number of selected events: %d",iAccepted));
 
-  TList *aUserInfo = fAnalysisChain->GetUserInfo();
+  TList *aUserInfo = chain->GetUserInfo();
   aUserInfo->Add(tagCutSummary);
 
   Int_t iAccEv;
@@ -678,5 +721,5 @@ TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname,
   TObjString *iRejEvtStr = new TObjString(nstr);
   aUserInfo->Add(iRejEvtStr);
 
-  return fAnalysisChain;
+  return chain;
 }
index 1adb84e09be3b380ebd82ca842ca96d785efcfe4..ff057678e09b3385219c981dc3ab1aef1f10299d 100644 (file)
@@ -46,7 +46,7 @@ class AliTagAnalysis : public TObject {
   
   void SetType(const char* type) {fAnalysisType = type;}
   const char* GetType() {return fAnalysisType.Data();}
-  Bool_t AddTagsFile(const char *alienUrl);
+  Bool_t AddTagsFile(const char *alienUrl, Bool_t checkFile=kTRUE);
   void ChainLocalTags(const char *dirname);
   TChain *ChainGridTags(TGridResult *result);
   
@@ -71,8 +71,8 @@ class AliTagAnalysis : public TObject {
                             const char *fEventCut);
 
   TChain *GetInputChain(const char* system, const char *wn);
-  TChain *GetChainFromCollection(const char* collectionname, 
-                                const char* treename);
+  
+  static TChain* CreateChainFromCollection(const char* collectionname, const char* treename);
   
   TEntryList *GetGlobalList() {return fGlobalList;}
   //____________________________________________________//
index 539de387889b9f0e1f6f3cc696a88cecc47c513d..9b1d457cbc16dd6158a216908bd96ee4c43d6799 100644 (file)
@@ -31,6 +31,7 @@
 #include <TObjString.h>
 #include <TString.h>
 #include <TXMLEngine.h>
+#include "AliLog.h"
 
 #include "AliXMLCollection.h"
 
@@ -106,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;
 }
 
 //___________________________________________________________________________
@@ -161,7 +163,8 @@ Bool_t AliXMLCollection::WriteSummary(Int_t aTotal, Int_t aAccepted, Int_t aRejR
 }
 
 //___________________________________________________________________________
-Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char* lfn, const char* turl, TEntryList *list) {
+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++) {
@@ -196,7 +199,7 @@ 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)
+Bool_t AliXMLCollection::WriteBody(Int_t counter, const char* guid, const char *lfn, const char *turl, TEntryListlist, Int_t accSum, Int_t rejSum)
 {
   //Writes the body of the xml collection with tag cuts summary
   TString listline;
@@ -276,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;
 }
 
@@ -292,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;
 }
 
@@ -308,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;
 }
 
@@ -334,7 +337,7 @@ const char *AliXMLCollection::GetLFN(const char* ) {
       }
     }
   }
-  Error("GetLFN", "cannot get LFN");
+  AliError("cannot get LFN");
   return 0;
 }
 
@@ -350,7 +353,7 @@ const char *AliXMLCollection::GetCutSumm() {
       }
     }
   }
-  Error("GetTagSumm", "cannot get Tag Cut Summary");
+  AliError("cannot get Tag Cut Summary");
   return 0;
 
 }
@@ -401,25 +404,25 @@ 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;
@@ -458,8 +461,8 @@ void AliXMLCollection::ParseXML() {
          otagsumm = 0;
 
        if (oevlist) {
-         Info("ParseXML","Collection: %s - turl: %s eventlist: %s",
-              fXmlFile.Data(),oturl->GetName(),oevlist->GetName());
+         AliDebug(1,Form("Collection: %s - turl: %s eventlist: %s",
+                    fXmlFile.Data(),oturl->GetName(),oevlist->GetName()));
          TEntryList *xmlevlist = new TEntryList(oturl->GetName(), oguid->GetName());
          if (strcmp(oevlist->GetName(),"") != 0) {
            TString stringevlist = oevlist->GetName();