aemspillmipp.cc

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 // $Id: aemspillmipp.cc,v 1.1 2005/11/21 20:35:30 hmeyer Exp $
00003 //
00004 // Simple utility to get time and # of events for spills in a run
00005 // Based on rawdump.cc from MippIo/test
00006 //
00007 // hmeyer@fnal.gov
00008 ////////////////////////////////////////////////////////////////////////
00009 #include <iostream>
00010 #include "MippIo/MippIoFile.h"
00011 #include "MippIo/MippIoBlock.h"
00012 #include "MippIo/MippIoFileHeader.h"
00013 #include "MippIo/MippIoEvent.h"
00014 #include "MippIo/MippIoEOFBlock.h"
00015 #include "MippIo/MippIoEventHeader.h"
00016 #include "MippIo/MippIoMDDBlock.h"
00017 #include "MippIo/MippIoStatsBlock.h"
00018 
00019 std::ostream& os = std::cout;
00020 
00021 static void gsDumpFileHeader(const MippIoFileHeader* h) 
00022 {
00023   os <<
00024     "************************************"
00025     "************************************"       << std::endl;
00026   os << "* Run:         " << h->Data().fRunNumber     << 
00027     "."              << h->Data().fSubRunNumber  << std::endl <<
00028     "* Run type:        "   << MippIo::GetRunTypeName(h->GetRunType());
00029   time_t t = h->Data().fCreationDate;
00030   os << "\n* Date opened:   "     << ctime(&t) <<
00031     "* Beam momentum:   " << h->GetMomentum() <<
00032     "\n* Enabled triggers:";
00033   for (int i = 0; i < 16; ++i) 
00034     if(h->IsTrigOn(i)) std::cout << " " << i;
00035   os << "\n* File size:       " << h->Data().fFileSize      <<
00036     "\n* Number of events: "  << h->Data().fNevents       << std::endl <<
00037     "* Run Comment: "         << h->Data().fRunComment    << std::endl <<
00038     "* End of Run Comment: "  << h->Data().fEndRunComment <<
00039     "\n*";
00040 
00041   for (int i = 0; i < MippIoFileHeader::fsNTrigBit; ++i) {
00042     os << "\n* Trigger " << i << ": " << h->GetTrigCfg(i).fName 
00043        << ", prescale: " << h->GetTrigCfg(i).fPrescale;
00044   }
00045   os << "\n*";
00046   for (int i = 0; i < MippIoFileHeader::fsNTrigInput; ++i) {
00047     os << "\n* Trigger input " << i << ": " << h->GetTrigInputName(i);
00048   }
00049 
00050   os << "\n*****" << std::endl;
00051 }
00052 
00053 //......................................................................
00054 
00055 static void gsDumpSpills(const MippIoEvent* evt) 
00056 {
00057 //======================================================================
00058 // Dump Spill data from MDD block
00059 //======================================================================
00060 
00061   static int fNTrigInSpill = 0;
00062 
00063   //Skip inter-spill calibration events
00064   const MippIoStatsBlock* stBlk =
00065     evt->Block<MippIoStatsBlock>(MippIoBlock::kStatsId);
00066   bool calibEvent = false;
00067   if (stBlk) {
00068     const MippIoStat104* st =
00069       dynamic_cast<const MippIoStat104*>(stBlk->GetStat());
00070     if (st) {
00071       if (!st->fLatch.empty()) {
00072         if (st->fLatch[0] & 0x2000)  calibEvent = true;
00073       }
00074     }
00075   }
00076   if (calibEvent) return;
00077   
00078   //Count In-spill triggers for each spill
00079   const MippIoMDDBlock* mddb =
00080     evt->Block<MippIoMDDBlock>(MippIoBlock::kBeamPPCId);
00081   if (mddb) {
00082     const MippIoMDDBlock::Data_t& mddData = mddb->Data();
00083 
00084     if (mddData.fIRQ == 3) {
00085       os << fNTrigInSpill << " events_at " << mddData.fSec << std::endl;
00086       fNTrigInSpill = 0;
00087     }
00088     else {
00089       fNTrigInSpill++;
00090     }
00091 
00092   } // valid mdd block
00093 }
00094 
00095 //......................................................................
00096 
00097 
00098 static void gsDumpEOF(const MippIoEOFBlock* eof) 
00099 {  
00100   os << 
00101     "*" <<
00102     "** File closed" <<
00103     " on "        << eof->Data().fDateClosed <<
00104     " size = "    << eof->Data().fFileSize   << " bytes" <<
00105     " nEvents = " << eof->Data().fNevents    << std::endl << 
00106     "************************************" <<
00107     "************************************" << std::endl;
00108 }
00109 
00110 //......................................................................
00111 
00112 static void gsDumpEvent(const MippIoEvent* evt) 
00113 {
00114   gsDumpSpills(evt);
00115 }
00116 
00117 //......................................................................
00118 
00119 static void gsRawDump(const char* filename) 
00120 {
00121   MippIoFile f(MippIoFile::kReadable);
00122   
00123   f.Open(filename);
00124 
00125   const MippIoBlock* b   = 0;
00126   bool               eof = false;
00127   while (1) {
00128     b = f.ReadBlock();
00129     if (b<=0) {
00130       std::cerr << "rawdump: ReadBlock failed..." << std::endl;
00131       break;
00132     }
00133     switch (b->Prefix().fId) {
00134     case MippIoBlock::kFileHeaderId: 
00135       gsDumpFileHeader((const MippIoFileHeader*)b); 
00136       break;
00137     case MippIoBlock::kEventId:
00138       gsDumpEvent((const MippIoEvent*)b);
00139       break;
00140     case MippIoBlock::kEOFId:
00141       gsDumpEOF((const MippIoEOFBlock*)b); 
00142       eof=true; 
00143       break;
00144     default:
00145       std::cerr << "rawdump: Bad block. prefix="
00146         << (void*)b->Prefix().fId        << " "
00147         << (void*)b->Prefix().fVersion   << " "
00148         << (void*)b->Prefix().fBlockSize << " " 
00149         << std::endl;
00150     }
00151     if (eof) break;
00152   }
00153   f.Close();
00154 }
00155 
00156 //......................................................................
00157 
00158 int main(int argc, char** argv) 
00159 {
00160   for (int i=1; i<argc; ++i) {
00161     gsRawDump(argv[i]); 
00162   }
00163   return 1;
00164 }
00165 
00166 ////////////////////////////////////////////////////////////////////////

Generated on Mon Nov 23 08:01:43 2009 for MIPP(E907) by  doxygen 1.4.7