]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDEvent.cxx
Removing the hard-wired particle masses (B. Hippolyte)
[u/mrichter/AliRoot.git] / STEER / AliESDEvent.cxx
index 2adc3f50c7c5d5f7066b62542385328b3a4623af..016b0fedc54f09f4f17ff91405ae94af85d589e9 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()
@@ -836,9 +883,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 +893,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 +1008,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 +1020,7 @@ void AliESDEvent::SetStdNames(){
     }
   }
   else{
-    printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
+     AliWarning("Std Entries missing");
   }
 } 
 
@@ -1052,7 +1116,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 +1130,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 +1147,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 +1161,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 +1260,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 +1285,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 +1359,8 @@ void AliESDEvent::CopyFromOldESD()
            0,
            fESDOld->GetZDCN2Energy(),
            fESDOld->GetZDCP2Energy(),
-           fESDOld->GetZDCParticipants());
+           fESDOld->GetZDCParticipants(),
+          0);
 
     // FMD
     
@@ -1311,7 +1377,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());