]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDEvent.cxx
Base class (AliMisaligner); each detector will provide its derived class,
[u/mrichter/AliRoot.git] / STEER / AliESDEvent.cxx
index 2adc3f50c7c5d5f7066b62542385328b3a4623af..2324baf8cd8d95341cef4e96421787b6ce3fe91d 100644 (file)
@@ -212,6 +212,7 @@ AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
   // otherwise only TObject::Copy() will be used
 
 
+
   if((fESDObjects->GetSize()==0)&&(source.fESDObjects->GetSize()>=kESDListN)){
     // We cover the case that we do not yet have the 
     // standard content but the source has it
@@ -225,12 +226,32 @@ AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
     name.Form("%s", its->GetName());
     TObject *mine = fESDObjects->FindObject(name.Data());
     if(!mine){
-      // not in this: can be added to list (to be implemented)
-      AliWarning(Form("%s:%d Could not find %s for copying \n",
-                     (char*)__FILE__,__LINE__,name.Data()));
-      continue;
-    }
+      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"))
+         dynamic_cast<TClonesArray*>(mine)->SetClass(dynamic_cast<TClonesArray*>(its)->GetClass());
+       dynamic_cast<TCollection*>(mine)->SetName(name);
+      }
+      AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
+      AddObject(mine);
+    }  
+   
     if(!its->InheritsFrom("TCollection")){
       // simple objects
       its->Copy(*mine);
@@ -310,25 +331,51 @@ void AliESDEvent::Copy(TObject &obj) const {
 void AliESDEvent::Reset()
 {
 
-  
+  // Handle the cases
+  // Std content + Non std content
+
   // Reset the standard contents
   ResetStdContent(); 
+
+  //  reset for the old data without AliESDEvent...
   if(fESDOld)fESDOld->Reset();
-  //  reset for the friends...
   if(fESDFriendOld){
     fESDFriendOld->~AliESDfriend();
     new (fESDFriendOld) AliESDfriend();
   }
-  // for new data we have to fetch the Pointer from the list 
-  AliESDfriend *fr = (AliESDfriend*)FindListObject("AliESDfriend");
-  if(fr){
-    // delete the content
-    fr->~AliESDfriend();
-    // make a new valid ESDfriend at the same place
-    new (fr) AliESDfriend();
+  // 
+
+  if(fESDObjects->GetSize()>kESDListN){
+    // we have non std content
+    // this also covers esdfriends
+    for(int i = kESDListN;i < fESDObjects->GetSize();++i){
+      TObject *pObject = fESDObjects->At(i);
+      // TClonesArrays
+      if(pObject->InheritsFrom(TClonesArray::Class())){
+       ((TClonesArray*)pObject)->Delete();
+      }
+      else if(!pObject->InheritsFrom(TCollection::Class())){
+       ResetWithPlacementNew(pObject);
+      }
+      else{
+       AliWarning(Form("No reset for %s (%s)\n",
+                       pObject->ClassName()));
+      }
+    }
   }
 
-  // call reset for user supplied data?
+}
+
+Bool_t AliESDEvent::ResetWithPlacementNew(TObject *pObject){
+  Long_t dtoronly = TObject::GetDtorOnly();
+  TClass *pClass = TClass::GetClass(pObject->ClassName()); 
+  TObject::SetDtorOnly(pObject);
+  delete pObject;
+  // Recreate with placement new
+  pClass->New(pObject);
+  // Restore the state.
+  TObject::SetDtorOnly((void*)dtoronly);
+  return kTRUE;
 }
 
 void AliESDEvent::ResetStdContent()
@@ -592,6 +639,15 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
     Int_t idx=cs->GetIndex();
     if (rm==idx) return kFALSE;
     if (idx==last) used++;
+
+    AliESDv0 *v0=cs;
+    idx=v0->GetNindex();
+    if (rm==idx) return kFALSE;
+    if (idx==last) used++;
+
+    idx=v0->GetPindex();
+    if (rm==idx) return kFALSE;
+    if (idx==last) used++;
   }
 
   Int_t nkn=GetNumberOfKinks();
@@ -607,6 +663,20 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
     if (idx==last) used++;
   }
 
+  // Check if this track is associated with a CaloCluster
+  Int_t ncl=GetNumberOfCaloClusters();
+  for (Int_t n=0; n<ncl; n++) {
+    AliESDCaloCluster *cluster=GetCaloCluster(n);
+    TArrayI *arr=cluster->GetTracksMatched();
+    Int_t s=arr->GetSize();
+    while (s--) {
+      Int_t idx=arr->At(s);
+      if (rm==idx) return kFALSE;
+      if (idx==last) used++;     
+    }
+  }
+
+
 
   //Replace the removed track with the last track 
   TClonesArray &a=*fTracks;
@@ -671,6 +741,17 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
        used--;
        if (!used) return kTRUE;
     }
+    AliESDv0 *v0=cs;
+    if (v0->GetIndex(0)==last) {
+       v0->SetIndex(0,rm);
+       used--;
+       if (!used) return kTRUE;
+    }
+    if (v0->GetIndex(1)==last) {
+       v0->SetIndex(1,rm);
+       used--;
+       if (!used) return kTRUE;
+    }
   }
 
   for (Int_t n=0; n<nkn; n++) {
@@ -687,6 +768,21 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
     }
   }
 
+  // Remap the indices of the tracks accosicated with CaloClusters
+  for (Int_t n=0; n<ncl; n++) {
+    AliESDCaloCluster *cluster=GetCaloCluster(n);
+    TArrayI *arr=cluster->GetTracksMatched();
+    Int_t s=arr->GetSize();
+    while (s--) {
+      Int_t idx=arr->At(s);
+      if (idx==last) {
+         arr->AddAt(rm,s);
+         used--; 
+         if (!used) return kTRUE;
+      }
+    }
+  }
+
   return kTRUE;
 }
 
@@ -836,9 +932,9 @@ void  AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex)
   }
 }
 
-void  AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex) 
+void  AliESDEvent::SetPrimaryVertexTracks(const AliESDVertex *vertex) 
 {
-  // Set the primary vertex
+  // Set the primary vertex reconstructed using he ESD tracks.
   // use already allocated space
   if(fPrimaryVertex){
     *fPrimaryVertex = *vertex;
@@ -846,6 +942,23 @@ void  AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex)
   }
 }
 
+const AliESDVertex * AliESDEvent::GetPrimaryVertex() const 
+{
+  //
+  // Get the "best" available reconstructed primary vertex.
+  //
+  if(fPrimaryVertex){
+    if (fPrimaryVertex->GetStatus()) return fPrimaryVertex;
+  }
+  if(fSPDVertex){
+    if (fSPDVertex->GetStatus()) return fSPDVertex;
+  }
+  if(fTPCVertex) return fTPCVertex;
+  
+  AliWarning("No primary vertex available. Returning the \"default\"...");
+  return fSPDVertex;
+}
+
 void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) 
 {
   // Set the SPD Multiplicity
@@ -944,8 +1057,8 @@ void AliESDEvent::GetStdContent()
 void AliESDEvent::SetStdNames(){
   // Set the names of the standard contents
   // 
-  if(fESDObjects->GetEntries()==kESDListN){
-    for(int i = 0;i < fESDObjects->GetEntries();i++){
+  if(fESDObjects->GetEntries()>=kESDListN){
+    for(int i = 0;i < fESDObjects->GetEntries() && i<kESDListN;i++){
       TObject *fObj = fESDObjects->At(i);
       if(fObj->InheritsFrom("TNamed")){
        ((TNamed*)fObj)->SetName(fgkESDListName[i]);
@@ -956,7 +1069,7 @@ void AliESDEvent::SetStdNames(){
     }
   }
   else{
-    printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
+     AliWarning("Std Entries missing");
   }
 } 
 
@@ -1052,7 +1165,7 @@ Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
   return clusters->GetEntriesFast();
 }
 
-const void AliESDEvent::WriteToTree(TTree* tree) const {
+void AliESDEvent::WriteToTree(TTree* tree) const {
   // Book the branches as in TTree::Branch(TCollection*)
   // but add a "." at the end of top level branches which are
   // not a TClonesArray
@@ -1066,13 +1179,15 @@ const void AliESDEvent::WriteToTree(TTree* tree) const {
 
   while ((obj = next())) {
     branchname.Form("%s", obj->GetName());
+    if(branchname.CompareTo("AliESDfriend")==0)branchname = "ESDfriend.";
     if ((kSplitlevel > 1) &&  !obj->InheritsFrom(TClonesArray::Class())) {
       if(!branchname.EndsWith("."))branchname += ".";
     }
-    tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),
-                kBufsize, kSplitlevel - 1);
+    if (!tree->FindBranch(branchname)) {
+      tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),
+                  kBufsize, kSplitlevel - 1);
+    }
   }
-
 }
 
 
@@ -1081,7 +1196,7 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* /*opt*/){
 // Connect the ESDEvent to a tree
 //
   if(!tree){
-    Printf("%s %d AliESDEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
+    AliWarning("AliESDEvent::ReadFromTree() Zero Pointer to Tree \n");
     return;
   }
   // load the TTree
@@ -1095,14 +1210,14 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* /*opt*/){
     char ** addressF = 0;
     if(esdFB)addressF = (char **)(esdFB->GetAddress());
     if (!address) {
-      printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
+      AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
       tree->SetBranchAddress("ESD",       &fESDOld);
       if(esdFB){
        tree->SetBranchAddress("ESDfriend.",&fESDFriendOld);
       }
     } else {
-      printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
-      printf("%s %d Branch already connected. Using existing branch address. \n",(char*)__FILE__,__LINE__);
+      AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
+      AliInfo("Branch already connected. Using existing branch address.");
       fESDOld       = (AliESD*)       (*address);
       // addressF can still be 0, since branch needs to switched on
       if(addressF)fESDFriendOld = (AliESDfriend*) (*addressF);
@@ -1194,8 +1309,8 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* /*opt*/){
     // TODO just add new entries
 
     if(fESDObjects->GetEntries()<kESDListN){
-      printf("%s %d AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
-            (char*)__FILE__,__LINE__,fESDObjects->GetEntries(),kESDListN);
+      AliWarning(Form("AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
+                     fESDObjects->GetEntries(),kESDListN));
     }
     // set the branch addresses
     TIter next(fESDObjects);
@@ -1219,8 +1334,7 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* /*opt*/){
             tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
           }
           else{
-            printf("%s %d AliESDEvent::ReadFromTree() No Branch found with Name %s or %s. \n",
-                  (char*)__FILE__,__LINE__,bname.Data(),bname.Data());
+            AliWarning(Form("AliESDEvent::ReadFromTree() No Branch found with Name %s or %s.",bname.Data(),bname.Data()));
           }
 
        }
@@ -1294,7 +1408,8 @@ void AliESDEvent::CopyFromOldESD()
            0,
            fESDOld->GetZDCN2Energy(),
            fESDOld->GetZDCP2Energy(),
-           fESDOld->GetZDCParticipants());
+           fESDOld->GetZDCParticipants(),
+          0);
 
     // FMD
     
@@ -1311,7 +1426,7 @@ void AliESDEvent::CopyFromOldESD()
 
     if(fESDOld->GetVertex())SetPrimaryVertexSPD(fESDOld->GetVertex());
 
-    if(fESDOld->GetPrimaryVertex())SetPrimaryVertex(fESDOld->GetPrimaryVertex());
+    if(fESDOld->GetPrimaryVertex())SetPrimaryVertexTracks(fESDOld->GetPrimaryVertex());
 
     if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());