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

DemoEventDump.cxx

Go to the documentation of this file.
00001 
00002 // $Id: DemoEventDump.cxx,v 1.34 2005/06/03 20:52:42 rhatcher Exp $
00004 #include "Demo/DemoEventDump.h"
00005 #include <cstdio>
00006 #include <csignal>
00007 // ROOT include files
00008 #include "TObject.h"
00009 #include "TCollection.h"
00010 #include "TIterator.h"
00011 #include "TObjectTable.h"
00012 // MINOS include files
00013 #include "CandData/CandRecord.h"
00014 #include "CandDigit/CandDigitHandle.h"
00015 #include "CandDigit/CandDigitListHandle.h"
00016 #include "DataUtil/GetCandidate.h"
00017 #include "RawData/RawRecord.h"
00018 #include "RawData/RawHeader.h"
00019 #include "RawData/RawDataBlock.h"
00020 #include "RawData/RawDaqSnarlHeader.h"
00021 #include "Record/RecRecord.h"
00022 #include "JobControl/JobCommand.h"
00023 #include "JobControl/JobCModuleRegistry.h"
00024 #include "MinosObjectMap/MomNavigator.h"
00025 #include "MessageService/MsgService.h"
00026 #include "LeakChecker/LeaMemMonitor.h"
00027 
00028 CVSID("$Id: DemoEventDump.cxx,v 1.34 2005/06/03 20:52:42 rhatcher Exp $");
00029 JOBMODULE(DemoEventDump, 
00030           "EventDump", "A module to print text info. about a data record.");
00031 
00032 //......................................................................
00033 
00034 DemoEventDump::DemoEventDump() : 
00035   fDump(0), 
00036   fFirst(0),
00037   fLast(999999),
00038   fFreq(1),
00039   fCount(0),
00040   fWait(false) 
00041 {}
00042 
00043 //......................................................................
00044 
00045 DemoEventDump::~DemoEventDump() {}
00046 
00047 //......................................................................
00048   
00049 JobCResult DemoEventDump::Ana(const MomNavigator* mom)
00050 {
00051   // Increment event counter
00052   ++fCount;  
00053 
00054   // Check counts to see if we should not dump this event
00055   if (fCount>fLast || (fCount-fFirst)%fFreq!=0) {
00056     return JobCResult::kAOK;
00057   }
00058 
00059   if (fDump) {
00060     if (fDump & kPrintSeparator) 
00061       MSG("Demo",Msg::kInfo) 
00062         << "********************************* Event " 
00063         << "Dump ***********************************" << endl 
00064         << "*                                       " 
00065         << "                                       *" << endl;
00066   }
00067   if (fDump & kDumpFragments)         this->DumpFragments(mom);
00068   if (fDump & kDumpRawHeader)         this->DumpRawHeader(mom);
00069   if (fDump & kDumpRawData)           this->DumpRawData(mom);
00070   if (fDump & kDumpCandDigits)        this->DumpCandDigits(mom);
00071   if (fDump & kDumpCandRecords)       this->DumpCandRecords(mom);
00072   if (fDump & kDumpObjectTable)       this->DumpObjectTable();
00073   if (fDump & kPrintMemStat)          
00074     LeaMemMonitor::PrintMemStat("DemoEventDump/PrintMemStat:");
00075 
00076   if (fDump & kPrintSeparator) MSG("Demo",Msg::kInfo) << endl;
00077   if (fWait) {
00078     std::cerr << "***** press enter to continue *****";
00079     int achar = getchar();
00080     // signal self (JobControl) to quit
00081     if (achar == 'Q' || achar == 'q') raise(SIGHUP);
00082   }
00083   return JobCResult::kAOK;
00084 }
00085 
00086 //......................................................................
00087 
00088 const Registry& DemoEventDump::DefaultConfig() const 
00089 {
00090 //======================================================================
00091 // The default configuration for this module
00092 //======================================================================
00093   int itrue  = 1; // Work around for Registry's lack of bool
00094   int ifalse = 0; // Work around for Registry's lack of bool
00095   static Registry r;
00096   
00097   std::string name = this->GetName();
00098   name += ".config.default";
00099   r.SetName(name.c_str());
00100   
00101   r.UnLockValues();
00102   r.Set("DumpFragments",        itrue);
00103   r.Set("DumpRawHeader",        itrue);
00104   r.Set("DumpRawBlockList",     ifalse);  // must also have DumpRawHeader
00105   r.Set("DumpRawDaqSnarlHeader",ifalse);  // obsolete ...now just DumpRawHeader
00106   r.Set("DumpRawData",          ifalse);
00107   r.Set("DumpCandDigits",       ifalse);
00108   r.Set("DumpObjectTable",      ifalse);
00109   r.Set("DumpAll",              ifalse);
00110   r.Set("First",                0);
00111   r.Set("Last",                 999999999);
00112   r.Set("Freq",                 1);
00113   r.Set("Wait",                 ifalse);
00114   r.Set("RawBlockList",         "");
00115   r.Set("DumpCandRecords",      ifalse);
00116   r.Set("CandRecOption",        "ntid99"); // e.g. "l", "dv0" "nd1" "ntid99v9"
00117   r.Set("PrintMemStat",         ifalse);
00118   r.Set("PrintSeparator",       itrue);
00119 
00120   r.LockValues();
00121 
00122   return r;
00123 }
00124 
00125 //......................................................................
00126 
00127 void DemoEventDump::Config(const Registry& r) 
00128 {
00129 //======================================================================
00130 // Configure the module using the registry r
00131 //======================================================================
00132   int  tmpb; // bool's get stored as ints in Registrys. Go w/ the flow..
00133   int  tmpi;
00134 
00135   // Which object to dump?
00136   if (r.Get("DumpFragments",tmpb)) { 
00137     tmpb ? fDump |= kDumpFragments : fDump &= ~kDumpFragments;
00138   }
00139   if (r.Get("DumpDaqSnarlRawHeader",tmpb)) {  // obsolete
00140     tmpb ? fDump |= kDumpRawHeader : fDump &= ~kDumpRawHeader;
00141   }
00142   if (r.Get("DumpRawHeader",tmpb)) { 
00143     tmpb ? fDump |= kDumpRawHeader : fDump &= ~kDumpRawHeader;
00144   }
00145   if (r.Get("DumpRawBlockList",tmpb)) { 
00146     tmpb ? fDump |= kDumpRawBlockList : fDump &= ~kDumpRawBlockList;
00147   }
00148   if (r.Get("DumpRawData",tmpb)) { 
00149     tmpb ? fDump |= kDumpRawData : fDump &= ~kDumpRawData;
00150   }
00151   if (r.Get("DumpCandDigits",tmpb)) { 
00152     tmpb ? fDump |= kDumpCandDigits : fDump &= ~kDumpCandDigits;
00153   }
00154   if (r.Get("DumpCandRecords",tmpb)) { 
00155     tmpb ? fDump |= kDumpCandRecords : fDump &= ~kDumpCandRecords;
00156   }
00157   if (r.Get("DumpObjectTable",tmpb)) {
00158     tmpb ? fDump |= kDumpObjectTable : fDump &= ~kDumpObjectTable;
00159   }
00160   if (r.Get("PrintMemStat",tmpb)) {
00161     tmpb ? fDump |= kPrintMemStat : fDump &= ~kPrintMemStat;
00162   }
00163   if (r.Get("PrintSeparator",tmpb)) {
00164     tmpb ? fDump |= kPrintSeparator : fDump &= ~kPrintSeparator;
00165   }
00166   if (r.Get("DumpAll",tmpb)) {
00167     if (tmpb) fDump |= 0xFFFF;
00168   }
00169 
00170   if (r.Get("First",tmpi)) fFirst = tmpi;
00171   if (r.Get("Last", tmpi)) fLast  = tmpi;
00172   if (r.Get("Freq", tmpi)) fFreq  = tmpi;
00173   if (r.Get("Wait", tmpb)) fWait  = tmpb;
00174 
00175   const char* tmpcs = 0;
00176   if (r.Get("RawBlockList",tmpcs))  fRawBlockList  = tmpcs;
00177   if (r.Get("CandRecOption",tmpcs)) fCandRecOption = tmpcs;
00178 
00179 }
00180 
00181 //......................................................................
00182 
00183 void DemoEventDump::HandleCommand(JobCommand* cmd) 
00184 {
00185   const char* c = cmd->PopCmd();
00186   if (c) {
00187     string sc(c);
00188     if (sc == "Dump") {
00189       int  which = 0; // Which flag to set
00190       bool on = true; // Turn on or off?
00191       while (const char* opt = cmd->PopOpt()) {
00192         string sopt(opt);
00193         if      (sopt=="Fragments")         which |= kDumpFragments;
00194         else if (sopt=="RawHeader")         which |= kDumpRawHeader;
00195         else if (sopt=="RawDaqBlockList")   which |= kDumpRawBlockList;
00196         else if (sopt=="RawData")           which |= kDumpRawData;
00197         else if (sopt=="CandDigits")        which |= kDumpCandDigits;
00198         else if (sopt=="CandRecords")       which |= kDumpCandRecords;
00199         else if (sopt=="TObjectTable")      which |= kDumpObjectTable;
00200         else if (sopt=="MemStat")           which |= kPrintMemStat;
00201         else if (sopt=="Separator")         which |= kPrintSeparator;
00202         else if (sopt=="All")               which  = 0xFFFFFFFF;
00203         else if (sopt=="Off")               on     = false;
00204         else if (sopt=="off")               on     = false;
00205         else if (sopt=="On")                on     = true;
00206         else if (sopt=="on")                on     = true;
00207         else {
00208           which = 0;
00209           MSG("Demo",Msg::kWarning)
00210             << "No Dump available for '" << opt << "'." << endl;
00211           break;
00212         }
00213         if (which) {
00214           if (on) fDump |=  which; // Set bits
00215           else    fDump &= ~which; // Lower bits
00216         }
00217       }
00218     }
00219     else if (sc == "Wait") {
00220       fWait = true;              // Default is to turn wait on
00221       if ((c = cmd->PopOpt())) { // Check for options
00222         string sopt(c); 
00223         // If option is "off" turn wait off
00224         if (sopt == "Off" || sopt == "off" || sopt == "OFF") {
00225           fWait = false;
00226         }
00227       }
00228     }
00229     else if (sc == "Set") {
00230       while (cmd->HaveOpt()) {
00231         string opts(cmd->PopOpt());
00232         if (opts == "First") {
00233           fFirst = cmd->PopIntOpt();
00234         }
00235         else if (opts == "Last") {
00236           fLast = cmd->PopIntOpt();
00237         }
00238         else if (opts == "Freq") {
00239           fFreq = cmd->PopIntOpt();
00240         }
00241         else if (opts == "RawBlockList") {
00242           fRawBlockList = cmd->PopOpt();
00243         }
00244       }
00245     }
00246   }
00247   else {
00248     MSG("Demo",Msg::kInfo) << "Valid commands are Dump and Wait" << endl;
00249   }
00250 }
00251 
00252 //......................................................................
00253 
00254 void DemoEventDump::DumpRawHeader(const MomNavigator* mom) const
00255 {
00256 //======================================================================
00257 // Print the raw data header information for each record
00258 // Optionally print the list of raw blocks in the record
00259 //======================================================================
00260   MSG("Demo",Msg::kInfo) << "List of RawRecords in RecordSet:" << endl;
00261 
00262   // For each RawRecord object contained in mom print the inforamation
00263   // The dynamic cast from TObject is ugly but necessary
00264   const TObjArray* objTbl = mom->GetFragmentArray();
00265   int iLast = objTbl->GetLast();
00266 
00267   TObject* obj = 0;
00268   for (int i=0; i<=iLast; ++i) {
00269     obj = objTbl->At(i);
00270     RawRecord* rawRec = dynamic_cast<RawRecord*>(obj);
00271     if (!rawRec) continue;
00272 
00273     // Get the header attached to this record
00274     const RawHeader *rawHead = rawRec->GetRawHeader();
00275     if (rawHead == 0) {
00276       MSG("Demo",Msg::kError) << "Failed to get RawHeader!" << endl;
00277       return;
00278     }
00279     MSG("Demo",Msg::kInfo) << "[" << setw(2) << i <<"] " 
00280                            << (*rawHead) << endl;
00281     if (fDump & kDumpRawBlockList) {
00282 
00283        TIter itr = rawRec->GetRawBlockIter();
00284        RawDataBlock* rdb = 0;
00285        // The dynamic cast from TObject is ugly but necessary
00286        // Careful! the itr() advances the iterator as a side effect!
00287        int i=0;
00288        while ((rdb = dynamic_cast<RawDataBlock*>(itr()))) {
00289            MSG("Demo",Msg::kInfo) << "    (" << setw(2) << i << ") "
00290                                   << rdb->GetName() << endl;
00291            i++;
00292         }
00293     } // list of blocks
00294   } // records
00295 }
00296 
00297 //......................................................................
00298 
00299 void DemoEventDump::DumpRawData(const MomNavigator* mom) const
00300 {
00301   // For each RawRecord object contained in mom print the information
00302   // The dynamic cast from TObject is ugly but necessary
00303 
00304   bool checklist = (fRawBlockList != "");
00305 
00306   TObject* obj = 0;
00307   for (int i=0; (obj=mom->At(i)); ++i) {
00308     RawRecord* rawRec = dynamic_cast<RawRecord*>(obj);
00309     if (!rawRec) continue;
00310 
00311     TIter itr = rawRec->GetRawBlockIter();
00312     RawDataBlock* rdb = 0;
00313     // The dynamic cast from TObject is ugly but necessary
00314     // Careful! the itr() advances the iterator as a side effect!
00315     while ((rdb = dynamic_cast<RawDataBlock*>(itr()))) {
00316        bool dumpit = true;
00317        if (checklist) {
00318          string blkname = rdb->GetName();
00319          if (fRawBlockList.find(blkname) == string::npos) dumpit = false;
00320        }
00321        if (dumpit) MSG("Demo",Msg::kInfo) << *rdb << endl;
00322     }
00323   }
00324 
00325 }
00326 
00327 //......................................................................
00328 
00329 void DemoEventDump::DumpFragments(const MomNavigator *mom) const
00330 {
00331 //======================================================================
00332 // Dump the list of objects held by mom
00333 //======================================================================
00334   const TObjArray* objTbl = mom->GetFragmentArray();
00335   int iLast = objTbl->GetLast();
00336   if (iLast<0) {
00337     MSG("Demo",Msg::kInfo) << "<<empty record>>" << endl;
00338     return;
00339   }
00340   
00341   MSG("Demo",Msg::kInfo) << "List of fragments in RecordSet:" << endl;
00342   for (int i=0; i<=iLast; ++i) {
00343     TObject*  obj;
00344     RecMinos* record;
00345     RecRecord* recrecord;
00346 
00347     obj    = objTbl->At(i);
00348     if ( ! obj ) {
00349       MSG("Demo",Msg::kInfo)
00350          << "  [" << setw(2) << i << "] no TObject at this index." << endl;
00351       continue;  // move on to next index
00352     }
00353 
00354     record = dynamic_cast<RecMinos*>(obj);
00355     recrecord = dynamic_cast<RecRecord*>(obj);
00356 
00357     // Unpack the names of things...
00358     // All TObject can give their class name and "name"
00359     string recClassName = obj->ClassName();
00360     string recUserName = obj->GetName();
00361 
00362     string recStream("?stream?");
00363     string recTree("?tree?");
00364     string recFile("?file?");
00365     string recVld("?vld?");
00366     //string recIndex("?index?");
00367     int recIndex = -1;
00368 
00369     const Registry *reg = 0;
00370     if (record != 0) {
00371       reg = &(record->GetTempTags());
00372       const RecMinosHdr* header = record->GetHeader();
00373       if ( header ) {
00374         const VldContext& vld = header->GetVldContext();
00375         recVld = vld.AsString();
00376       }
00377     }
00378     else if (recrecord != 0) {
00379       reg = &(recrecord->GetTempTags());
00380       const VldContext& vld = (recrecord->GetHeader()).GetVldContext();
00381       recVld = vld.AsString();
00382     }
00383 
00384     if (reg) {
00385       // This is safe:
00386       const char* tmp = 0;
00387       if (reg->Get("stream",tmp))   recStream = tmp;
00388       const char* tmpfile = 0;
00389       if (reg->Get("file",tmpfile)) recFile   = tmpfile;
00390       int indx = -1;
00391       if (reg->Get("index",indx))   recIndex  = indx;
00392     }
00393       
00394     // This will abort() if keys not found
00395     // recTree = record->GetTempTags().GetCharString("tree");
00396     // recIndex = record->GetTempTags().GetCharString("index");
00397     // recFile = record->GetTempTags().GetCharString("file");
00398 
00399     MSG("Demo",Msg::kInfo) << 
00400       "  [" << setw(2) << i << "] "
00401       "\\" << recClassName <<
00402       "\\" << recUserName <<
00403       "\\" << recStream <<
00404       // "\\" << recTree <<
00405       "(" << recIndex << ")" <<
00406       "\\" << recFile <<
00407       "\\" << recVld << 
00408       endl;
00409 
00410   }
00411 }
00412 
00413 //......................................................................
00414 
00415 void DemoEventDump::DumpCandDigits(const MomNavigator *mom) const
00416 {
00417   
00418   // Find PrimaryCandidateRecord fragment in MOM.
00419   const CandDigitListHandle *canddigit = 
00420       DataUtil::GetCandidate<CandDigitListHandle>(mom,
00421                                                   "CandDigitListHandle", 
00422                                                   "canddigitlist");
00423   if (canddigit == 0) {
00424     MSG("Demo",Msg::kWarning) << "Failed to get CandDigitListHandle!" << endl;
00425     return;                                                // Fail event
00426   }
00427   
00428   CandDigitHandleItr cdhItr(canddigit->GetDaughterIterator());
00429   for (; cdhItr.IsValid(); cdhItr.Next()) {
00430     MSG("Demo",Msg::kInfo) <<
00431       (*cdhItr)->GetChannelId() <<
00432       " q=" << (*cdhItr)->GetCharge() << 
00433       (*cdhItr)->GetPlexSEIdAltL() <<
00434       " t=" << (*cdhItr)->GetTime() << endl;
00435   }
00436 }
00437 
00438 //......................................................................
00439 
00440 void DemoEventDump::DumpCandRecords(const MomNavigator* mom) const
00441 {
00442   // For each CandRecord object contained in mom print the information
00443   // The dynamic cast from TObject is ugly but necessary
00444 
00445   TObject* obj = 0;
00446   TIter momIter = mom->FragmentIter();
00447   momIter.Reset();
00448   while ( (obj = momIter.Next()) ) {
00449     const CandRecord* candRec = dynamic_cast<const CandRecord*>(obj);
00450     if (!candRec) continue;
00451     candRec->Print(fCandRecOption.c_str());
00452   }
00453 }
00454 
00455 //......................................................................
00456 
00457 void DemoEventDump::DumpObjectTable() const
00458 {
00459   extern TObjectTable* gObjectTable;
00460   if (gObjectTable) gObjectTable->Print();
00461 }
00462 
00463 //......................................................................
00464 
00465 void DemoEventDump::Help()
00466 {
00467   const char* n = this->GetName();
00468 
00469   MSG("Demo",Msg::kInfo) << 
00470     "Help for module " << n << "\n" <<
00471     "\n" <<
00472     "  EventDump is a module to print information about data records\n"
00473     "  to the screen or log file. It can be configured with the following\n"
00474     "  commands:\n"
00475     "\n" <<
00476     "  /" << n << "/Dump [which] [off] ...\n" << 
00477     "    controls which information about the data record is printed.\n" <<
00478     "    [which] is:\n" <<
00479     "      Fragments    - list of fragments held by MinosObjectMap\n" <<
00480     "      RawHeader    - the header information\n" <<
00481     "      RawData      - all the raw data in the record\n" <<
00482     "      CandDigits   - any candidate digits held in the record\n" <<
00483     "      TObjectTable - the ROOT object table (requires root config)\n"
00484     "      All          - Dump everything!\n"
00485     "\n"
00486     "    To suppress printing of certain information, follow it by the\n" <<
00487     "    key word 'off'. Here is an example:\n" <<
00488     "    /" << n << "Dump Fragments RawHeader RawData off CandDigits\n" <<
00489     "    This turning printing of Fragments, RawHeader, and CandDigits on\n" <<
00490     "    while turning printing of RawData off.\n" <<
00491     "\n" <<
00492     "  /" << n << "/Wait\n"
00493     "    Prompts user to press key to continue before going to next record\n"<<
00494     "\n" <<
00495     "  /" << n << "/Set [First,Last,Freq] [n]\n" <<
00496     "    Set when to start, stop, and how often to dump data record\n" <<
00497     "    information. For example:\n" <<
00498     "      /" << n << "/Dump First 100\n" <<
00499     "      /" << n << "/Dump Last  1000\n" <<
00500     "      /" << n << "/Dump Freq  10\n" <<
00501     "    will cause the module to start printing on the 100th event,\n" <<
00502     "    stop after the 1000th event, and print only every 10 events\n" <<
00503     "    in between.\n" <<
00504     endl;    
00505 }
00506 

Generated on Sat Nov 21 22:45:57 2009 for loon by  doxygen 1.3.9.1