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

DumpMom.cxx

Go to the documentation of this file.
00001 #include "DumpMom.h"
00002 
00003 #include <MinosObjectMap/MomNavigator.h>
00004 #include <Candidate/CandHandle.h>
00005 #include <CandData/CandRecord.h>
00006 #include <CandData/CandHeader.h>
00007 #include <Record/RecMinos.h>
00008 #include <Record/RecMinosHdr.h>
00009 #include <RawData/RawRecord.h>
00010 #include <RawData/RawHeader.h>
00011 #include <RawData/RawDataBlock.h>
00012 #include "Record/SimSnarlRecord.h"
00013 #include "Record/SimSnarlHeader.h"
00014 
00015 #include <TClass.h>
00016 #include <TNamed.h>
00017 
00018 #include <string>
00019 #include <iostream>
00020 using namespace std;
00021 
00022 bool DataUtil::dump_cand(const CandHandle* ch, 
00023                          std::ostream& os,
00024                          std::string prefix,
00025                          int recurse_depth,
00026                          int max_daughters)
00027 {
00028   // Add name and title if it's a CandHandle.
00029   if(ch) {
00030     os << prefix 
00031        << Form("%s \t\"%s\" %s",ch->ClassName(),ch->GetName(), ch->GetTitle()) 
00032        << std::endl;
00033     int n = ch->GetNDaughters();
00034     if( max_daughters < n ) n = max_daughters;
00035     if( recurse_depth <=0) n = 0;
00036     if(n > 0) {
00037       TIter iter = ch->GetDaughterIterator();
00038       for(int i=0;i<n;i++) {
00039         const CandHandle* next = dynamic_cast<const CandHandle*>(iter.Next());
00040         if(next)
00041           if(! next->InheritsFrom("CandDigitHandle") )
00042             dump_cand(next,
00043                       os,
00044                       prefix+"  ",
00045                       recurse_depth-1,
00046                       max_daughters);
00047         
00048       } 
00049     }
00050     if(ch->GetNDaughters() > 0) {
00051       os << prefix << ".. Total daughters:" <<  ch->GetNDaughters() << endl;
00052     }
00053     
00054     return true;
00055   }
00056   return false;
00057 }
00058 
00059 
00060 bool DataUtil::dump_mom(const MomNavigator* mom, std::ostream& os)
00061 {
00062     if (!mom) {
00063         return false;
00064     }
00065 
00066     os << "Mom holds:\n";
00067     TIter next = mom->FragmentIter();
00068     TObject* obj;
00069     while ( (obj=next()) ) {
00070         RecMinos*  rm  = dynamic_cast<RecMinos*>(obj);
00071         RecRecord* rdr = dynamic_cast<RecRecord*>(obj);
00072         const TObjArray* compArray[2] = {0,0};
00073 
00074         if (!rm && !rdr) {
00075           // It's not a RecMinos/RecRecord, so just dump the class title:
00076           os << obj->ClassName() << endl;
00077           os << "\tNo Components." << endl;
00078           continue;
00079         }
00080 
00081         // If it comes from RecMinos or RecRecord, it's got a name and title.
00082         
00083         if (rm) {
00084           os <<  obj->ClassName()
00085              << "\t\"" << rm->GetName() << "\""
00086              << "\t" << rm->GetTitle() << endl;
00087 
00088           compArray[0] = &(rm->GetComponents());
00089           compArray[1] = &(rm->GetTemporaries());
00090 
00091           // If it's a RawRecord, print the header.
00092           RawRecord* rawrec = dynamic_cast<RawRecord*>(rm);
00093           if(rawrec) {
00094             if(rawrec->GetRawHeader()) {
00095               rawrec->GetRawHeader()->FormatToOStream(os);
00096               os << endl;
00097             }
00098           }
00099 
00100           // If it's a CandRecord, print the header
00101           CandRecord* candrec = dynamic_cast<CandRecord*>(rm);
00102           if (candrec) {
00103             const CandHeader* candhead = candrec->GetCandHeader();
00104             if (candhead) {
00105               candhead->Print();   // currently can't handle other than cout
00106             }
00107           }
00108 
00109         }
00110 
00111         if (rdr) {
00112           os <<  obj->ClassName()
00113              << "\t\"" << rdr->GetName() << "\""
00114              << "\t" << rdr->GetTitle() << endl;
00115 
00116           // If it's a SimSnarlRecord, print the header
00117           SimSnarlRecord* simrec = dynamic_cast<SimSnarlRecord*>(rdr);
00118           if (simrec) {
00119             compArray[0] = &(simrec->GetComponents());
00120             compArray[1] = &(simrec->GetTemporaries());
00121 
00122             const SimSnarlHeader* simhead = simrec->GetSimSnarlHeader();
00123             if (simhead) {
00124               simhead->Print(os);
00125               os << endl;
00126             }
00127           }
00128         }
00129         
00130 
00131         const char* arrayName[2] = {"Components","Temporaries"};
00132         for (int iArray=0; iArray<2; ++iArray) {
00133           if ( compArray[iArray] == 0 || 
00134                compArray[iArray]->GetEntriesFast() <= 0 ) continue;
00135           os << "---" << arrayName[iArray] << ":" << endl;
00136           const TObjArray& oa = *(compArray[iArray]);
00137           TIter next_comp(oa.MakeIterator());
00138           TObject* comp;
00139           while ( (comp=next_comp()) ) {
00140                        
00141             // Try to see what kind o' thing it is
00142             TNamed* named = dynamic_cast<TNamed*>(comp);
00143             CandHandle* ch = dynamic_cast<CandHandle*>(comp);
00144             TCollection* col = dynamic_cast<TCollection*>(comp);
00145             
00146             if(col) {
00147               // Add name and title if it's a collection
00148               os << "      " << comp->ClassName()
00149                  << "\t\"" << col->GetName() << "\"\t with " << col->GetSize() << " elements" << endl;
00150 
00151             } else if(named) {
00152               // Add name and title if it's a named object.
00153               os << "      " << comp->ClassName()
00154                  << "\t\"" << named->GetName() << "\"\t" << named->GetTitle() << endl;
00155 
00156             } else if(ch) {
00157               // It's a candidate. Do something clever.
00158               dump_cand(ch,os,"      ");
00159 
00160             } else {
00161               // Dunno. Print it's name or something.
00162               os << "      " << comp->ClassName() << endl;
00163             };        
00164 
00165             //const RawDataBlock* rdb = dynamic_cast<const RawDataBlock*>(comp);
00166             //if(rdb) rdb->Print(); // keep from printing all the rawdigits in an RDDB
00167           
00168           }
00169         }  // loop over Components/Temporaries
00170         
00171         os << endl;
00172 
00173     } // loop over objects in mom's basket
00174 
00175 #if 0
00176     CandRecord* crec = dynamic_cast<CandRecord*>
00177         (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00178     if (!crec) {
00179         cerr << "dump_mom: no CandRecord\n";
00180         return false;
00181     }
00182 
00183     const TObjArray oa = crec->GetCandHandleList();
00184     int last = oa.GetLast();
00185     cerr << "Contents of PrimaryCandidateRecord:\n";
00186     for (int i = 0; i <= last; ++i) {
00187         TObject* o = oa.At(i);
00188         if (!o) continue;
00189         cerr << "\t" << o->ClassName() << "::" << o->GetName()<< endl;
00190     }
00191     
00192 #endif
00193     return true;
00194 }

Generated on Mon Nov 23 05:26:39 2009 for loon by  doxygen 1.3.9.1