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

CandRecord.cxx

Go to the documentation of this file.
00001 
00002 // $Id: CandRecord.cxx,v 1.14 2007/11/11 20:43:56 schubert Exp $
00003 //
00004 // CandRecord.cxx
00005 //
00006 // CandRecord is the top level object for Cand MINOS data from Reco.
00007 // This is the primary key for I/O of records of Cand data.
00008 //
00009 // Author:  G. Irwin 11/2000
00011 
00012 #include "CandData/CandRecord.h"
00013 #include "CandData/CandHeader.h"
00014 #include "Candidate/CandHandle.h"
00015 
00016 ClassImp(CandRecord)
00017 
00018 //______________________________________________________________________
00019 CandRecord::CandRecord()
00020 {
00021 }
00022 
00023 //______________________________________________________________________
00024 CandRecord::CandRecord(CandHeader *head) :
00025   RecMinos(head)
00026 {
00027 
00028 // adopt the CandHeader for ownership
00029 }
00030 
00031 //______________________________________________________________________
00032 CandRecord::~CandRecord()
00033 {
00034 }
00035 
00036 //______________________________________________________________________
00037 CandHandle *CandRecord::FindCandHandle(const char *classname,
00038                                              const char *objname) const
00039 {
00040 
00041 // Returns the *last* selected CandHandle.  If classname is a null ptr
00042 // or blank string, no class selection is done.  If classname is
00043 // provided, the qualifying object must InheritFrom() or be a classname.
00044 // The objname is optional, but, if filled, will further qualify the
00045 // selection by requiring agreement with the GetName() method of the
00046 // selected object.
00047 
00048 // RecMinos::FindComponent() returns a "const TObject *".  This gets
00049 // converted to a "CandHandle *" using dynamic_cast to make sure the
00050 // original is a "CandHandle *".  The "const" is removed by const_cast
00051 // because CandHandles are "ref-counted" pointers to "copy-on-write"
00052 // CandBase objects.  CandHandles allow controlled modification of
00053 // their CandBase objects and have their own const-like protection.
00054 // Look in persistent TObjArray first, then in temporary TObjArray.
00055 // Both searches are in reverse order of insertion.
00056 
00057   CandHandle *ch = 0;
00058 
00059 // Look in persistent TObjArray
00060   ch =  dynamic_cast<CandHandle *>
00061    (const_cast<TObject *>(RecMinos::FindComponent(classname, objname)));
00062 
00063 // Look in temporary TObjArray if not in persistent TObjArray
00064   if (ch == 0) ch =  dynamic_cast<CandHandle *>
00065    (const_cast<TObject *>(RecMinos::FindTemporary(classname, objname)));
00066 
00067   return ch;
00068 }
00069 
00070 //______________________________________________________________________
00071 TIter CandRecord::GetCandHandleIter(Bool_t dir)
00072 {
00073   return TIter(&RecMinos::GetComponents(),dir);
00074 }
00075 
00076 
00077 //______________________________________________________________________
00078 const CandHeader *CandRecord::GetCandHeader() const
00079 {
00080   return dynamic_cast<const CandHeader *>(RecMinos::GetHeader());
00081 }
00082 
00083 //______________________________________________________________________
00084 Bool_t CandRecord::RemoveCandHandle(CandHandle *ch)
00085 {
00086 
00087 // Remove CandHandle from fComponents or fTemporaries and delete it.
00088 // Return true if successfully removed, false otherwise.
00089   CandHandle *chremove = 0;
00090   if ((chremove =
00091            dynamic_cast<CandHandle *>(RecMinos::RemoveComponent(ch)))) {
00092     delete chremove;
00093     return true;
00094   }
00095   else if ((chremove =
00096            dynamic_cast<CandHandle *>(RecMinos::RemoveTemporary(ch)))) {
00097     delete chremove;
00098     return true;
00099   }
00100   return false;
00101 }
00102 
00103 //______________________________________________________________________
00104 void CandRecord::SecureCandHandle(CandHandle &ch)
00105 {
00106 
00107 // Secure a CandHandle derived object.  It saves a cloned CandHandle.
00108   ch.SetCandRecord(this);
00109   CandHandle *chnew = ch.DupHandle();   // Create a new owned CandHandle
00110   chnew->SetLock();    // Cand mods can't be made through new CandHandle
00111   RecMinos::AdoptComponent(chnew);
00112 }
00113 
00114 //______________________________________________________________________
00115 void CandRecord::SwitchCandHandlePersToTemp(CandHandle *ch)
00116 {
00117 
00118 // Switch a CandHandle from "fComponents" to "fTemporaries"
00119   CandHandle *chswitch = dynamic_cast<CandHandle *>
00120                                         (RecMinos::RemoveComponent(ch));
00121   if (chswitch) RecMinos::AdoptTemporary(chswitch);
00122 }
00123 
00124 //______________________________________________________________________
00125 void CandRecord::Print(Option_t *option) const
00126 {
00127    // Print header, loop over raw blocks, print those
00128    // unless passed "l" option, then just list the blocks.
00129 
00130    if (fHeader) fHeader->Print();
00131    else std::cout << "CandRecord: has no header" << std::endl;
00132    GetJobHistory().Print();
00133    
00134    std::string opt = option;
00135    bool doList = ( opt.find("l") != std::string::npos );
00136    bool doTemp = ( opt.find("T") != std::string::npos ) && fTemporaries.GetSize() != 0;
00137 
00138    const TObject *tobj = 0;
00139 
00140    if (doTemp)
00141      std::cout << "   --------- Components ---------" << std::endl;
00142    TIter iterComp(&fComponents);
00143    while ((tobj = iterComp())) {
00144      if (doList) tobj->Print("ntd0v0");
00145      else        tobj->Print(option);
00146    }
00147 
00148    if (doTemp) {
00149      std::cout << "   --------- Temporaries ---------" << std::endl;
00150      TIter iterTemp(&fTemporaries);
00151      while ((tobj = iterTemp())) {
00152        if (doList) tobj->Print("ntd0v0");
00153        else        tobj->Print(option);
00154      }
00155    }
00156 
00157 }
00158 
00159 //______________________________________________________________________

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