Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CandEvent.cxx

Go to the documentation of this file.
00001 
00002 // $Id: CandEvent.cxx,v 1.15 2006/05/01 20:34:39 musser Exp $
00003 //
00004 // CandEvent.cxx
00005 //
00006 // This is a concrete Event Candidate (Reconstruction) object.
00007 // CandEvent is descended from CandBase.
00008 //
00009 // Each concrete CandBase must define a Dup function.
00010 // CandBase must grant friendship to class CandRefer.
00011 //
00012 // Author:  R. Lee
00014 
00015 #include "TClass.h"
00016 
00017 #include "Algorithm/AlgHandle.h"
00018 #include "MessageService/MsgService.h"
00019 #include "RecoBase/CandEvent.h"
00020 #include "RecoBase/CandEventHandle.h"
00021 #include "RecoBase/CandShowerHandle.h" // Needed for IsEquivalent method
00022 #include "RecoBase/CandSliceHandle.h"  // Needed for IsEquivalent method
00023 #include "RecoBase/CandTrackHandle.h"  // Needed for IsEquivalent method
00024 
00025 ClassImp(CandEvent)
00026 
00027 //______________________________________________________________________
00028 CVSID("$Id: CandEvent.cxx,v 1.15 2006/05/01 20:34:39 musser Exp $");
00029 
00030 #include "Candidate/CandBase.tpl"
00031 
00032 //______________________________________________________________________
00033 CandEvent::CandEvent() :
00034   fPrimaryShower(0)
00035   , fPrimaryTrack(0)
00036   , fContained(0)
00037   ,  fEnergy(0.)
00038 {
00039 }
00040 
00041 //______________________________________________________________________
00042 CandEvent::CandEvent(AlgHandle &ah) :
00043   CandReco(ah)       // Should be the next class up on inheritance chain
00044 , fPrimaryShower(0)
00045 , fPrimaryTrack(0)
00046   ,fContained(0)
00047   ,  fEnergy(0.)
00048 {
00049 
00050 // The sole purpose of this constructor is to transmit the AlgHandle
00051 // up the inheritance chain to CandBase without having to invoke the
00052 // full constructor of an intermediate Candidate type which the highest
00053 // level Candidate might inherit from.  One only wants to create the
00054 // LocalHandle and invoke the RunAlg() method in the lowest level class.
00055 }
00056 
00057 //______________________________________________________________________
00058 CandEvent::CandEvent(AlgHandle &ah, CandHandle &ch, CandContext &cx) :
00059   CandReco(ah)       // Should be the next class up on inheritance chain
00060 , fPrimaryShower(0)
00061 , fPrimaryTrack(0)
00062   , fContained(0)
00063   ,  fEnergy(0.)
00064 {
00065   CreateLocalHandle();
00066 
00067 // Run Algorithm to construct Candidate
00068   {                                                   // Start of scope.
00069     CandEventHandle csh(this);               // csh will go out of scope
00070     ch = csh;                                       // after setting ch.
00071   }                                                     // End of scope.
00072   ah.RunAlg(ch, cx);
00073 }
00074 
00075 //______________________________________________________________________
00076 CandEvent::CandEvent(const CandEvent &rhs) :
00077   CandReco(rhs)      // Should be the next class up on inheritance chain
00078 , fPrimaryShower(0)
00079 , fPrimaryTrack(0)
00080   , fContained(rhs.fContained)
00081   ,  fEnergy(rhs.fEnergy)
00082 {
00083 
00084 //CreateLocalHandle(); // Moved to Dup function following copy-ctor call
00085 
00086 
00087   if (rhs.fPrimaryShower)                   // Make an owned CandHandle*
00088     fPrimaryShower = (rhs.fPrimaryShower)->DupHandle();
00089 
00090   if (rhs.fPrimaryTrack)                    // Make an owned CandHandle*
00091     fPrimaryTrack = (rhs.fPrimaryTrack)->DupHandle();
00092 
00093 // fShowerList and fTrackList contents owned from CandEvent version 2
00094   CandHandle *ch;
00095   TIter shwiter(&rhs.fShowerList);
00096   while ((ch = dynamic_cast<CandHandle *>(shwiter())))
00097     fShowerList.Add(ch->DupHandle());
00098   TIter trkiter(&rhs.fTrackList);
00099   while ((ch = dynamic_cast<CandHandle *>(trkiter())))
00100     fTrackList.Add(ch->DupHandle());
00101 }
00102 
00103 //______________________________________________________________________
00104 CandEvent::~CandEvent()
00105 {
00106 
00107 // fPrimaryShower is owned CandHandle* starting at CandEvent version 2
00108 // fPrimaryTrack is an owned CandHandle* starting at CandEvent version 2
00109 // fCandSlice is an owned CandHandle* starting at CandEvent version 2
00110   delete fPrimaryShower;
00111   delete fPrimaryTrack;
00112 
00113   fShowerList.Delete();  // Owned CandHandle*'s from CandEvent version 2
00114   fTrackList.Delete();   // Owned CandHandle*'s from CandEvent version 2
00115 }
00116 
00117 //______________________________________________________________________
00118 void CandEvent::CreateLocalHandle()
00119 {
00120   SetLocalHandle(new CandEventHandle(this));
00121 }
00122 
00123 //______________________________________________________________________
00124 CandEvent *CandEvent::Dup() const
00125 {
00126 
00127 // Base copy ctor dups owned pointers, but defers copying Daughter List.
00128 // Daughter List copy is made in the derived class Dup() function.
00129 // This is because base class copy constructor hasn't yet created
00130 // fLocalHandle with a CandHandle* of the full derived type.
00131   CandEvent *cb = new CandEvent(*this);           // Copy-ctor dups ptrs
00132   cb->CreateLocalHandle();   // Initializes fLocalHandle after copy-ctor
00133   TIter iterdau = GetDaughterIterator();
00134   CandHandle *dau;
00135   while ((dau=(CandHandle *) iterdau())) cb->AddDaughterLink(*dau);
00136   return cb;
00137 }
00138 
00139 //______________________________________________________________________
00140 Bool_t CandEvent::IsEquivalent(const TObject *rhs) const
00141 {
00142   Bool_t result = true;
00143   if (!CandBase::IsEquivalent(rhs)) result = false;   // superclass test
00144   TestDisplayCandBanner("CandEvent");
00145   const CandEvent* rCnd = dynamic_cast<const CandEvent*>(rhs);
00146   if (rCnd == NULL) return false;
00147 
00148   result = TestTObjArrayCandHandleDup("fShowerList",
00149                                            this->fShowerList,
00150                                            rCnd->fShowerList) && result;
00151   result = TestTObjArrayCandHandleDup("fTrackList",
00152                                             this->fTrackList,
00153                                             rCnd->fTrackList) && result;
00154   result = TestCandHandleDup("fPrimaryShower",
00155                                         this->fPrimaryShower,
00156                                         rCnd->fPrimaryShower) && result;
00157   result = TestCandHandleDup("fPrimaryTrack",
00158                              this->fPrimaryTrack,
00159                              rCnd->fPrimaryTrack) && result;
00160   result = TestEquality("fEnergy",        this->fEnergy,
00161                         rCnd->fEnergy)      && result;
00162   result = TestEquality("fContained",        this->fContained,
00163                         rCnd->fContained)      && result;
00164  
00165   return result;
00166 }
00167 
00168 //______________________________________________________________________
00169 CandEventHandle CandEvent::MakeCandidate(AlgHandle &ah, CandContext &cx)
00170 {
00171   CandEventHandle csh;
00172   new CandEvent(ah, csh, cx);              // csh owns the new CandEvent
00173   return csh;
00174 }
00175 
00176 //______________________________________________________________________
00177 std::ostream& CandEvent::FormatToOStream(std::ostream& os,
00178                                          Option_t *option) const
00179 {
00180   CandBase::FormatToOStream(os,option);
00181 
00182   TString opt(option);
00183   if (!opt.Contains("v0")) { // v0 means suppress the data values
00184     const TString& indent = GetIndentString();
00185     os << " Energy " << fEnergy << " Contained " << fContained << endl;
00186      os << indent << GetDataIndent() << "Primary:" << endl;
00187     IncIndent();
00188     if (fPrimaryShower) fPrimaryShower->Print("nd0");
00189     if (fPrimaryTrack)  fPrimaryTrack->Print("nd0");
00190     DecIndent();
00191  
00192   }
00193   return os;
00194 }
00195 
00196 //______________________________________________________________________
00197 void CandEvent::Streamer(TBuffer &R__b)
00198 {
00199 
00200 // Stream an object of class CandEvent.
00201   if (R__b.IsReading()) {
00202     UInt_t R__s, R__c;
00203     Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00204     CandEvent::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
00205     if (R__v < 2) {
00206       if (fPrimaryShower) fPrimaryShower = fPrimaryShower->DupHandle();
00207       if (fPrimaryTrack) fPrimaryTrack = fPrimaryTrack->DupHandle();
00208 
00209 // fShowerList and fTrackList contents owned from CandEvent version 2
00210       CandHandle *ch;
00211       TIter shwiter(&fShowerList);
00212       while ((ch = dynamic_cast<CandHandle *>(shwiter())))
00213         fShowerList.AddAt(ch->DupHandle(), fShowerList.IndexOf(ch));
00214       TIter trkiter(&fTrackList);
00215       while ((ch = dynamic_cast<CandHandle *>(trkiter())))
00216         fTrackList.AddAt(ch->DupHandle(), fTrackList.IndexOf(ch));
00217     }
00218   }
00219   else {
00220     CandEvent::Class()->WriteBuffer(R__b, this);
00221   }
00222 }
00223 
00224 //______________________________________________________________________

Generated on Mon Feb 15 11:06:28 2010 for loon by  doxygen 1.3.9.1