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

PulserSummaryModule.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PulserSummaryModule.cxx,v 1.13 2005/09/19 18:28:12 murgia Exp $
00003 //
00004 // PulserSummaryModule.cxx
00005 //
00006 // Makes List of averages of pulser summaries
00007 //
00008 // Author: Phil Adamson 4/2001
00009 //
00010 // $Log: PulserSummaryModule.cxx,v $
00011 // Revision 1.13  2005/09/19 18:28:12  murgia
00012 // Remove fSummaryList if no triggers are found, before call to Finish.
00013 //
00014 // Revision 1.12  2005/08/16 15:51:50  tjyang
00015 // Save the last point in the last subrun if the run stopped between two LED pulses. This bug was pointed out by Pat Ward. Thanks Robert H. for showing how to pass an object between two modules.
00016 //
00017 //
00018 //
00019 // Revision 1.11  2004/11/08 22:02:42  murgia
00020 // If empty summaries are encountered, do not calculate trigfrac and print a warning message.
00021 //
00022 // Revision 1.10  2004/10/19 20:33:50  murgia
00023 // Fix bug in Reco: when matching rawLI to fSummaryList, check if it is the same pulser box and whether it is drift point or gain curve to avoid adding pieces of gain curve to drift point.
00024 //
00025 // Revision 1.9  2004/10/05 21:39:48  murgia
00026 // Fixed code to write points with low light levels. Added call to EndFile.
00027 //
00028 // Revision 1.8  2004/09/08 21:50:51  pa
00029 // Checkin of new PulserCalibration version. MIght even work
00030 //
00031 // Revision 1.7  2003/09/03 09:31:16  rjn
00032 // Fixed a couple of little bugs in the code that stopped things working.
00033 //
00034 // Revision 1.6  2003/02/05 22:56:24  rjn
00035 // Changed Pulser Summary List To Output Box As Well As LEd (cosmetic change
00036 // -- not sure if I have CVS write access)
00037 //
00038 // Revision 1.5  2002/10/17 05:55:53  rhatcher
00039 // various mods to reduce the number of complaints about comparing
00040 // signed and unsigned values
00041 //
00042 // Revision 1.4  2002/10/01 16:58:32  phil.adamson
00043 // PulserTimePlotter isn't workimng, but it compiles, so it won't break
00044 // anything else. Cosmetic changes.
00045 //
00046 // Revision 1.3  2002/08/07 16:16:52  phil.adamson
00047 // Minor cosmetic details, plus provide ZeroCorr() methods in PulserSummary.
00048 // Phil.
00049 //
00050 //
00052 
00053 #include "JobControl/JobCModuleRegistry.h"
00054 #include "MinosObjectMap/MomNavigator.h"
00055 #include "PulserCalibration/PulserSummaryModule.h"
00056 #include "MessageService/MsgService.h"
00057 #include "RawData/RawLIAdcSummaryBlock.h"
00058 #include "RawData/RawRecord.h"
00059 #include "RawData/RawHeader.h"
00060 #include "RawData/RawDaqHeaderBlock.h"
00061 
00062 #include "TROOT.h"
00063 #include "TFolder.h"
00064 
00065 #include <cstdio>
00066 #include <iostream>
00067 #include <fstream>
00068 ClassImp(PulserSummaryModule)
00069 
00070   // ......
00071 
00072 CVSID("$Id: PulserSummaryModule.cxx,v 1.13 2005/09/19 18:28:12 murgia Exp $");
00073 JOBMODULE(PulserSummaryModule,"PulserSummaryModule","Average over subaverages of pulser data from online");
00074 
00075 PulserSummaryModule::PulserSummaryModule()
00076 {
00077   MSG("Pulser",Msg::kVerbose) << "PulserSummaryModule ctor\n";
00078   fSummaryList=0;
00079   fFirst = true;
00080 }
00081 
00082 PulserSummaryModule::~PulserSummaryModule()
00083 {
00084   MSG("Pulser",Msg::kVerbose) << "PulserSummaryModule dtor\n";
00085 }
00086 
00087 JobCResult PulserSummaryModule::Reco(MomNavigator *mom)
00088 {
00089   MSG("Pulser",Msg::kVerbose) << "PulserSummaryModule::Reco()\n";
00090   
00091   // Find RawRecord fragment in MOM.
00092   TIter iter = mom->FragmentIter();
00093   while (TObject *obj = iter.Next()) {
00094     RawRecord *rawrec = dynamic_cast<RawRecord *>(obj);
00095     if (rawrec) {
00096       MSG("Pulser",Msg::kVerbose) << "PSM::Reco() got vld: " <<(rawrec->GetRawHeader())->GetVldContext() <<endl;
00097       int sec = rawrec->GetHeader()->GetVldContext().GetTimeStamp().GetSec();
00098       // look for a RawLIAdcSummaryBlock in the RawRecord
00099       VldTimeStamp ts = rawrec->GetHeader()->GetVldContext().GetTimeStamp();
00100       const RawLIAdcSummaryBlock *rawsum = 
00101         dynamic_cast<const RawLIAdcSummaryBlock *>
00102         (rawrec->FindRawBlock("RawLIAdcSummaryBlock"));
00103 
00104       if (rawsum) {
00105         // Got a LI summary
00106         MSG("Pulser",Msg::kVerbose) << 
00107           "PSM::Reco() : Got a LI summary" << sec<<endl;
00108         fLastSec = sec;
00109 
00110 
00111         // Code to use liMaster.log obsolete so now deleted
00112 
00113         //OK - now rawsum definitely contains its header info.
00114         // if (this rawLI doesn't match fSUmmaryList, dispatch list
00115         // elsewhere - if time -fLastSec >5, dispatch...
00116         if (fSummaryList) {
00117           //      if (rawsum->GetLed()==fSummaryList->GetLed() && 
00118           //          rawsum->GetCalibPoint()==fSummaryList->GetPointIndex()) {
00119           // Match pulser box and whether it is a drift point or gain curve
00120           if (rawsum->GetLed()==fSummaryList->GetLed() && 
00121               rawsum->GetCalibPoint()==fSummaryList->GetPointIndex() &&
00122               rawsum->GetCalibType()==fSummaryList->GetExpectedPoints() &&
00123               rawsum->GetPulserBox()==fSummaryList->GetPulserBox()) {
00124             fSummaryList->Add(*rawsum);
00125             
00126             MSG("Pulser",Msg::kDebug) << 
00127               "PSM::Reco() : Existing Point. Pulser Box, Led" << rawsum->GetPulserBox() << ", " << rawsum->GetLed()<<endl;
00128 
00129           }
00130           else {
00131             // We're on a new point now!
00132             MSG("Pulser",Msg::kDebug)<<"New point at "<<sec<<endl;
00133             MSG("Pulser",Msg::kDebug) << 
00134               "PSM::Reco() : New Point. Pulser Box, Led" << rawsum->GetPulserBox() << ", " << rawsum->GetLed()<<endl;
00135             FinishList(mom,ts);
00136             fSummaryList = new PulserSummaryList(*rawsum);
00137           }
00138         } 
00139         else {
00140           fSummaryList = new PulserSummaryList(*rawsum);
00141         }
00142       }
00143       
00144       if (fSummaryList&&(sec-fLastSec>10)) {
00145          // 4 secs without an LI summary? Must be end of point...
00146          MSG("Pulser",Msg::kInfo)<<"Point timed out "<<sec<<endl;
00147          FinishList(mom,ts);
00148       }
00149       
00150       
00151     }
00152   }
00153   return JobCResult::kAOK;
00154 }
00155 
00156 
00157 void PulserSummaryModule::FinishList(MomNavigator* mom, VldTimeStamp ts)
00158 {
00159   MSG("Pulser",Msg::kInfo) <<ts<<" Summary Complete! Box " << fSummaryList->GetPulserBox() << " Led "<< fSummaryList->GetLed()<<", point "<<fSummaryList->GetPointIndex()<<" of "<<fSummaryList->GetExpectedPoints()<<endl;
00160 
00161   // Check if there are triggers:
00162   if (fSummaryList->GetTriggers()==0)  {
00163     MSG("Pulser",Msg::kDebug)<<"Found summary with no triggers. Triggers, Pulses: "
00164                              <<fSummaryList->GetTriggers() << ", "
00165                              <<fSummaryList->GetNumPulses() << endl;
00166     MSG("Pulser",Msg::kDebug)<<"LED, PB, PH, PW: "
00167                              <<fSummaryList->GetLed() << ", "
00168                              <<fSummaryList->GetPulserBox() << ", "
00169                              <<fSummaryList->GetHeight() << ", "
00170                              <<fSummaryList->GetWidth() << endl;
00171 
00172     fSummaryList=0;
00173   }
00174 
00175   if (fSummaryList) {
00176     fSummaryList->Finish();
00177     
00178     // Test to see if SummaryList is OK here - squeal if it isn't.
00179     
00180     float trigfrac; 
00181     if (fSummaryList->GetExpectedPoints()!=0) {
00182       // Do we have enough triggers?
00183       trigfrac = float(fSummaryList->GetTriggers())/float(fSummaryList->GetNumPulses());
00184     } else {
00185       MSG("Pulser",Msg::kWarning)<<"Found empty summary. Triggers, ExpectedPoints, Pulses: "
00186                                  <<fSummaryList->GetTriggers() << ", "<< fSummaryList->GetExpectedPoints()<<", "
00187                                  <<fSummaryList->GetNumPulses() << endl;
00188       trigfrac = 99999.;
00189     }
00190     
00191     if (trigfrac < 0.95) {
00192       MSG("Pulser",Msg::kError)<<"Only saw "<<trigfrac<<" of expected "<<fSummaryList->GetNumPulses()<<" triggers. Dumping point.\n";
00193       delete fSummaryList;
00194       fSummaryList=0;
00195       return;
00196     }
00197   }
00198 
00199   mom->AdoptFragment(fSummaryList);
00200   fSummaryList=0;
00201 }
00202 
00203 void PulserSummaryModule::BeginRun()
00204 {
00205   MSG("Pulser",Msg::kDebug) << "PulserSummaryModule::BeginRun()"<<endl;
00206   fSummaryList=0;
00207 }
00208 
00209 void PulserSummaryModule::EndRun()
00210 {
00211 //  // Drop part-completed point at end of run, as liMaster will repeat it.
00212 //  delete fSummaryList;
00213 //  fSummaryList = 0;
00214   if (!fSummaryList) return;
00215 
00216   fSummaryList->Finish();
00217 
00218   // Test to see if SummaryList is OK here - squeal if it isn't.
00219   
00220   float trigfrac; 
00221   
00222   if (fSummaryList->GetExpectedPoints()!=0) {
00223     // Do we have enough triggers?
00224     trigfrac = float(fSummaryList->GetTriggers())/float(fSummaryList->GetNumPulses());
00225   } else {
00226     delete fSummaryList;
00227     fSummaryList=0;
00228     return;
00229   }
00230   
00231   if (trigfrac < 0.95) {
00232     MSG("Pulser",Msg::kInfo)<<"Only saw "<<trigfrac<<" of expected "<<fSummaryList->GetNumPulses()<<" triggers. Dumping point.\n";
00233     delete fSummaryList;
00234     fSummaryList=0;
00235     return;
00236   }
00237   
00238   MSG("Pulser",Msg::kDebug) <<"PulserSummaryModule::EndRun(): trying to save the last point"<<endl;
00239   
00240   TFolder *lf = dynamic_cast<TFolder *>
00241     (gROOT->GetRootFolder()->FindObject("Loon"));
00242   if (lf==0) {
00243     lf = gROOT->GetRootFolder()->AddFolder("Loon", "Loon analysis");
00244     gROOT->GetListOfBrowsables()->Add(lf, "Loon");
00245   }
00246 
00247   TFolder *fTFolder = lf->AddFolder("Pulser","Pulser analysis");
00248   fTFolder->Add(fSummaryList);
00249   MSG("Pulser",Msg::kDebug) <<"PulserSummaryModule::EndRun(): last point added to a temporary folder: Pulser"<<endl;
00250 
00251 
00252 }
00253 

Generated on Fri Mar 28 15:38:19 2008 for loon by  doxygen 1.3.9.1