]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODEvent.cxx
Typo fixed
[u/mrichter/AliRoot.git] / STEER / AliAODEvent.cxx
index 8b2a1f44c47af75c565afc57c302cc0d221c21ca..4c4110c5d4724a7c725b085d22f02e5d9253d18e 100644 (file)
@@ -30,6 +30,7 @@
 #include "AliAODEvent.h"
 #include "AliAODHeader.h"
 #include "AliAODTrack.h"
+#include "AliAODDimuon.h"
 
 ClassImp(AliAODEvent)
 
@@ -45,7 +46,8 @@ ClassImp(AliAODEvent)
                                                      "phosCells",
                                                      "caloClusters",
                                                      "fmdClusters",
-                                                     "pmdClusters"
+                                                     "pmdClusters",
+                                                     "dimuons"
                                                      
 };
 //______________________________________________________________________________
@@ -65,7 +67,8 @@ AliAODEvent::AliAODEvent() :
   fPhosCells(0),
   fCaloClusters(0),
   fFmdClusters(0),
-  fPmdClusters(0)
+  fPmdClusters(0),
+  fDimuons(0)
 {
   // default constructor
 }
@@ -74,7 +77,7 @@ AliAODEvent::AliAODEvent() :
 AliAODEvent::AliAODEvent(const AliAODEvent& aod):
   AliVEvent(aod),
   fAODObjects(new TList()),
-  fAODFolder(new TFolder()),
+  fAODFolder(0),
   fConnected(kFALSE),
   fHeader(new AliAODHeader(*aod.fHeader)),
   fTracks(new TClonesArray(*aod.fTracks)),
@@ -87,7 +90,8 @@ AliAODEvent::AliAODEvent(const AliAODEvent& aod):
   fPhosCells(new AliAODCaloCells(*aod.fPhosCells)),
   fCaloClusters(new TClonesArray(*aod.fCaloClusters)),
   fFmdClusters(new TClonesArray(*aod.fFmdClusters)),
-  fPmdClusters(new TClonesArray(*aod.fPmdClusters))
+  fPmdClusters(new TClonesArray(*aod.fPmdClusters)),
+  fDimuons(new TClonesArray(*aod.fDimuons))
 {
   // Copy constructor
   AddObject(fHeader);
@@ -102,8 +106,10 @@ AliAODEvent::AliAODEvent(const AliAODEvent& aod):
   AddObject(fCaloClusters);
   AddObject(fFmdClusters);
   AddObject(fPmdClusters);
+  AddObject(fDimuons);
   fConnected = aod.fConnected;
   GetStdContent();
+  CreateStdFolders();
 }
 
 //______________________________________________________________________________
@@ -111,41 +117,94 @@ AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) {
 
     // Assignment operator
 
-    if(&aod == this) return *this;
-    AliVEvent::operator=(aod);
-
-    fAODObjects      = new TList();
-    fAODFolder       = new TFolder();
-    fConnected       = aod.fConnected;
-    fHeader          = new AliAODHeader(*aod.fHeader);
-    fTracks          = new TClonesArray(*aod.fTracks);
-    fVertices        = new TClonesArray(*aod.fVertices);
-    fV0s             = new TClonesArray(*aod.fV0s);
-    fCascades        = new TClonesArray(*aod.fCascades);
-    fTracklets       = new AliAODTracklets(*aod.fTracklets);
-    fJets            = new TClonesArray(*aod.fJets);
-    fEmcalCells      = new AliAODCaloCells(*aod.fEmcalCells);
-    fPhosCells       = new AliAODCaloCells(*aod.fPhosCells);
-    fCaloClusters    = new TClonesArray(*aod.fCaloClusters);
-    fFmdClusters     = new TClonesArray(*aod.fFmdClusters);
-    fPmdClusters     = new TClonesArray(*aod.fPmdClusters);
-    
-    fAODObjects = new TList();
-    
-    AddObject(fHeader);
-    AddObject(fTracks);
-    AddObject(fVertices);
-    AddObject(fV0s);
-    AddObject(fCascades);
-    AddObject(fTracklets);
-    AddObject(fJets);
-    AddObject(fEmcalCells);
-    AddObject(fPhosCells);
-    AddObject(fCaloClusters);
-    AddObject(fFmdClusters);
-    AddObject(fPmdClusters);
-    GetStdContent();
-    return *this;
+  if(&aod == this) return *this;
+  AliVEvent::operator=(aod);
+
+  // This assumes that the list is already created
+  // and that the virtual void Copy(Tobject&) function
+  // is correctly implemented in the derived class
+  // otherwise only TObject::Copy() will be used
+
+  if((fAODObjects->GetSize()==0)&&(aod.fAODObjects->GetSize()>=kAODListN)){
+    // We cover the case that we do not yet have the 
+    // standard content but the source has it
+    CreateStdContent();
+  }
+  
+  // Here we have the standard content without user additions, but the content is 
+  // not matching the aod source.
+  
+  // Iterate the list of source objects
+  TIter next(aod.GetList());
+  TObject *its = 0;
+  TString name;
+  while ((its = next())) {
+    name = its->GetName();
+    // Check if we have this object type in out list
+    TObject *mine = fAODObjects->FindObject(name);    
+    if(!mine) {
+      // We have to create the same type of object.
+      TClass* pClass=TClass::GetClass(its->ClassName());     
+      if (!pClass) {
+        AliWarning(Form("Can not find class description for entry %s (%s)\n",
+                   its->ClassName(), name.Data()));
+        continue;
+      }
+      mine=(TObject*)pClass->New();
+      if(!mine){
+        // not in this: can be added to list
+        AliWarning(Form("%s:%d Could not find %s for copying \n",
+                   (char*)__FILE__,__LINE__,name.Data()));
+        continue;
+      }  
+      if(mine->InheritsFrom("TNamed")) {
+        ((TNamed*)mine)->SetName(name);
+      } else if(mine->InheritsFrom("TCollection")){
+        if(mine->InheritsFrom("TClonesArray")) {
+          TClonesArray *itscl = dynamic_cast<TClonesArray*>(its);
+          if (!itscl) {
+            AliWarning(Form("Class description for entry %s (%s) not TClonesArray\n",
+                   its->ClassName(), name.Data()));
+            continue;
+          
+          }
+              dynamic_cast<TClonesArray*>(mine)->SetClass(itscl->GetClass(), itscl->GetSize());
+        }
+        dynamic_cast<TCollection*>(mine)->SetName(name);
+      }
+      AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
+      AddObject(mine);
+    }
+    // Now we have an object of the same type and name, but different content.        
+    if(!its->InheritsFrom("TCollection")){
+      // simple objects (do they have a Copy method that calls operator= ?)
+      its->Copy(*mine);
+    } else if (its->InheritsFrom("TClonesArray")) {
+      // Create or expand the tclonesarray pointers
+      // so we can directly copy to the object
+      TClonesArray *its_tca = (TClonesArray*)its;
+      TClonesArray *mine_tca = (TClonesArray*)mine;
+      // this leaves the capacity of the TClonesArray the same
+      // except for a factor of 2 increase when size > capacity
+      // does not release any memory occupied by the tca
+      Int_t its_entries = its_tca->GetEntriesFast();
+      mine_tca->ExpandCreate(its_entries);
+      for(int i=0; i<its_entries; i++){
+        // copy 
+        TObject *mine_tca_obj = mine_tca->At(i);
+        TObject *its_tca_obj = its_tca->At(i);
+        // no need to delete first
+        // pointers within the class should be handled by Copy()...
+        // Can there be Empty slots?
+        its_tca_obj->Copy(*mine_tca_obj);
+      }
+    } else {
+      AliWarning(Form("%s:%d cannot copy TCollection \n",
+                     (char*)__FILE__,__LINE__));
+    }
+  }  
+  fConnected = aod.fConnected;
+  return *this;
 }
 
 
@@ -160,6 +219,7 @@ AliAODEvent::~AliAODEvent()
     }
 
     delete fAODFolder;
+    fAODFolder = 0;
 }
 
 //______________________________________________________________________________
@@ -181,7 +241,7 @@ void AliAODEvent::RemoveObject(TObject* obj)
 }
 
 //______________________________________________________________________________
-TObject *AliAODEvent::FindListObject(const char *objName)
+TObject *AliAODEvent::FindListObject(const char *objName) const
 {
   // Return the pointer to the object with the given name.
 
@@ -206,6 +266,7 @@ void AliAODEvent::CreateStdContent()
   AddObject(new TClonesArray("AliAODCaloCluster", 0));
   AddObject(new TClonesArray("AliAODFmdCluster", 0));
   AddObject(new TClonesArray("AliAODPmdCluster", 0));
+  AddObject(new TClonesArray("AliAODDimuon", 0));
   // set names
   SetStdNames();
 
@@ -254,6 +315,7 @@ void AliAODEvent::SetStdNames()
 void AliAODEvent::CreateStdFolders()
 {
     // Create the standard folder structure
+  if(fAODFolder)delete fAODFolder;
     fAODFolder = gROOT->GetRootFolder()->AddFolder("AOD", "AOD");
     if(fAODObjects->GetEntries()==kAODListN){
        for(int i = 0;i < fAODObjects->GetEntries();i++){
@@ -287,6 +349,7 @@ void AliAODEvent::GetStdContent()
   fCaloClusters  = (TClonesArray*)fAODObjects->FindObject("caloClusters");
   fFmdClusters   = (TClonesArray*)fAODObjects->FindObject("fmdClusters");
   fPmdClusters   = (TClonesArray*)fAODObjects->FindObject("pmdClusters");
+  fDimuons       = (TClonesArray*)fAODObjects->FindObject("dimuons");
 }
 
 //______________________________________________________________________________
@@ -297,7 +360,8 @@ void AliAODEvent::ResetStd(Int_t trkArrSize,
                           Int_t jetSize, 
                           Int_t caloClusSize, 
                           Int_t fmdClusSize, 
-                          Int_t pmdClusSize
+                          Int_t pmdClusSize,
+                          Int_t dimuonArrSize
                           )
 {
   // deletes content of standard arrays and resets size 
@@ -333,6 +397,10 @@ void AliAODEvent::ResetStd(Int_t trkArrSize,
   fPmdClusters->Delete();
   if (pmdClusSize > fPmdClusters->GetSize()) 
     fPmdClusters->Expand(pmdClusSize);
+    
+  fDimuons->Delete();
+  if (dimuonArrSize > fDimuons->GetSize()) 
+    fDimuons->Expand(dimuonArrSize);
 
   // Reset the tracklets
   fTracklets->DeleteContainer();
@@ -356,6 +424,7 @@ void AliAODEvent::ClearStd()
   fCaloClusters  ->Delete();
   fFmdClusters   ->Clear();
   fPmdClusters   ->Clear();
+  fDimuons       ->Clear();
 }
 
 //_________________________________________________________________
@@ -424,6 +493,21 @@ Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
 }
 
 
+//______________________________________________________________________________
+Int_t AliAODEvent::GetNumberOfMuonTracks() const
+{
+  // get number of muon tracks
+  Int_t nMuonTracks=0;
+  AliAODTrack *track = 0;
+  for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
+    if ((track = GetTrack(iTrack))->IsMuonTrack()) {
+       nMuonTracks++;
+    }
+  }
+  
+  return nMuonTracks;
+}
+
 void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
 {
   // Connects aod event to tree
@@ -443,8 +527,6 @@ void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
     TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
     if (connectedList && (strcmp(opt, "reconnect"))) {
        // If connected use the connected list of objects
-       printf("Delete and reconnect \n");
-       
        fAODObjects->Delete();
        fAODObjects = connectedList;
        GetStdContent(); 
@@ -453,13 +535,12 @@ void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
     } 
     // Connect to tree
     // prevent a memory leak when reading back the TList
-    if (!(strcmp(opt, "reconnect"))) fAODObjects->Delete();
-    delete fAODObjects;
-    fAODObjects = 0;
+    // if (!(strcmp(opt, "reconnect"))) fAODObjects->Delete();
+
     // create a new TList from the UserInfo TList... 
     // copy constructor does not work...
     fAODObjects = (TList*)(aodEvent->GetList()->Clone());
-    fAODObjects->SetOwner(kFALSE);
+    fAODObjects->SetOwner(kTRUE);
     if(fAODObjects->GetEntries()<kAODListN){
       printf("%s %d AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
             (char*)__FILE__,__LINE__,fAODObjects->GetEntries(),kAODListN);
@@ -514,7 +595,7 @@ void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
     GetStdContent();
     // when reading back we are not owner of the list 
     // must not delete it
-    fAODObjects->SetOwner(kFALSE);
+    fAODObjects->SetOwner(kTRUE);
     fAODObjects->SetName("AODObjectsConnectedToTree");
     // we are not owner of the list objects 
     // must not delete it
@@ -534,14 +615,21 @@ void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
     GetStdContent();
     // when reading back we are not owner of the list 
     // must not delete it
-    fAODObjects->SetOwner(kFALSE);
+    fAODObjects->SetOwner(kTRUE);
   }
 }
 
 //______________________________________________________________________________
 void AliAODEvent::Print(Option_t *) const
 {
-  // Something meaningful should be implemented here.
+  // Print the names of the all branches
+  TIter next(fAODObjects);
+  TNamed *el;
+  Printf(">>>>>  AOD  Content <<<<<");    
+  while((el=(TNamed*)next())){
+    Printf(">> %s ",el->GetName());      
+  }
+  Printf(">>>>>                <<<<<");    
   
   return;
 }