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

NtpMCRecord.cxx

Go to the documentation of this file.
00001 
00002 // 
00003 // NtpMCRecord
00004 //
00005 // NtpMCRecord is an ntuple record serving the monte carlo data
00006 //
00008 
00009 #include <iostream>
00010 using namespace std;
00011 
00012 #include "TClonesArray.h"
00013 #include "Record/RecArrayAllocator.h"
00014 #include "MCNtuple/NtpMCRecord.h"
00015 #include "MCNtuple/NtpMCTruth.h"
00016 #include "MCNtuple/NtpMCStdHep.h"
00017 #include "PhotonTransport/PhotonEventResult.h"
00018 #include "DetSim/SimEventResult.h"
00019 #include "MessageService/MsgService.h"
00020 
00021 ClassImp(NtpMCRecord)
00022 
00023 CVSID("$Id: NtpMCRecord.cxx,v 1.15 2007/03/27 18:53:01 schubert Exp $");
00024 
00025 NtpMCRecord::NtpMCRecord() : RecRecordImp<RecCandHeader>(),mc(0),stdhep(0),
00026                              flsdigit(0),digihit(0) {
00027   // Purpose: Default constructor
00028   MSG("NtpMC",Msg::kVerbose) << "NtpMCRecord def ctor @ " << this << endl;
00029   this -> Init();  
00030 }
00031 
00032 NtpMCRecord::NtpMCRecord(const RecCandHeader& hdr) : 
00033   RecRecordImp<RecCandHeader>(hdr),mc(0),stdhep(0),flsdigit(0),digihit(0) {
00034   // Purpose: Normal constructor
00035 
00036   MSG("NtpMC",Msg::kVerbose) << "NtpMCRecord normal ctor @ " << this << endl;
00037   this -> Init(); 
00038 }
00039 
00040 NtpMCRecord::~NtpMCRecord() {
00041   // Purpose: Destructor
00042 
00043   MSG("NtpMC",Msg::kVerbose) << "NtpMCRecord dtor @ " << this << endl;
00044   
00045   // Release arrays back to TClonesArray pool for reuse
00046   // Allocated memory of stored objects is retrieved via object Clear call
00047   RecArrayAllocator& allocator = RecArrayAllocator::Instance();
00048   if ( mc ) { allocator.ReleaseArray(mc); mc = 0; }
00049   if ( stdhep ) { allocator.ReleaseArray(stdhep); stdhep = 0; }
00050   if ( flsdigit ) { allocator.ReleaseArray(flsdigit); flsdigit = 0; }
00051   if ( digihit ) { allocator.ReleaseArray(digihit); digihit = 0; }
00052   
00053 }
00054 
00055 void NtpMCRecord::Clear(Option_t* /* option */) {
00056   // Purpose: Clear memory allocated to arrays so that record can
00057   // be reused.  
00058 
00059   detsim.Clear();
00060   if ( mc ) { mc -> Clear("C"); }
00061   if ( stdhep ) { stdhep -> Clear("C"); }
00062   if ( flsdigit ) { flsdigit -> Clear("C"); }
00063   if ( digihit ) { digihit -> Clear("C"); }
00064 }
00065 
00066 void NtpMCRecord::Init() {
00067   // 
00068   // Purpose: Initialize ntuple TClonesArrays
00069   //
00070 
00071   // Set variable in record base class to indicate that it is possible
00072   // to recover dynamic memory using Clear() method for this record type
00073   SetClearable(true);
00074 
00075   RecArrayAllocator& allocator = RecArrayAllocator::Instance();
00076   if ( !mc ) mc = allocator.GetArray("NtpMCTruth");
00077   if ( !stdhep ) stdhep = allocator.GetArray("NtpMCStdHep");
00078   if ( !flsdigit ) flsdigit = allocator.GetArray("NtpMCFLSDigit");
00079   if ( !digihit ) digihit = allocator.GetArray("NtpMCDigiScintHit");
00080 }
00081 
00082 std::ostream& NtpMCRecord::Print(std::ostream& os) const {
00083   //
00084   // Purpose: Print status of ntuple record on ostream
00085   //
00086 
00087   os << "NtpMCRecord::Print" << endl;
00088   RecRecordImp<RecCandHeader>::Print(os);
00089   mchdr.Print(os);
00090   if ( mc ) {
00091     for ( int imc = 0; imc < mc->GetLast()+1; imc++ ) {
00092       (dynamic_cast<NtpMCTruth*>(mc -> At(imc))) -> Print(os);
00093     }
00094   }
00095   if ( stdhep ) {
00096     Int_t nstdhep = stdhep->GetLast()+1;
00097     std::string entrystr = " entries:";
00098     if ( nstdhep == 1 ) entrystr = " entry:";
00099 
00100     os << "\nPrint stdhep array of NtpMCStdHep w/"
00101        << nstdhep << entrystr.c_str() << endl;
00102     for ( int istd = 0; istd < nstdhep; istd++ ) {
00103       const NtpMCStdHep* ntpstdhep
00104         = dynamic_cast<const NtpMCStdHep*>(stdhep->At(istd));
00105       if ( ntpstdhep->parent[0] == -1 ) 
00106         ntpstdhep->Print(std::cout,"","",stdhep);
00107     }
00108   }
00109   else {
00110     os << "Null stdhep array." << endl;
00111   }
00112   
00113   return os;
00114 
00115 }
00116 
00117 void NtpMCRecord::Print(const Option_t* /* option */) const {
00118   //
00119   // Purpose: Print record in form supported by TObject::Print
00120   //
00121 
00122   Print(std::cout);
00123   return;
00124 
00125 }

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