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

PulserTimingMaker.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PulserTimingMaker.cxx,v 1.6 2007/03/01 17:06:40 rhatcher Exp $
00003 //
00004 // FILL_IN: [Document your code!!]
00005 //
00006 // n.tagg1@physics.ox.ac.uk
00008 #include "PulserTimingMaker.h"
00009 #include "PulserTimingPoint.h"
00010 #include "RawData/RawRecord.h"
00011 #include "RawData/RawHeader.h"
00012 #include "RawData/RawLITimingSummary.h"
00013 #include "RawData/RawLITimingSummaryBlock.h"
00014 #include "MessageService/MsgService.h"
00015 #include "MinosObjectMap/MomNavigator.h"
00016 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00017 #include "DataUtil/DumpMom.h"
00018 #include "TFile.h"
00019 
00020 
00021 JOBMODULE(PulserTimingMaker, "PulserTimingMaker",
00022           "Makes pulser timing points from LI summaries");
00023 CVSID("$Id: PulserTimingMaker.cxx,v 1.6 2007/03/01 17:06:40 rhatcher Exp $");
00024 //......................................................................
00025 
00026 PulserTimingMaker::PulserTimingMaker()
00027 {
00028   fCurrentPoint = 0;
00029   TFile savefile("PulserTimingPoint.open.root","READ");
00030   if(!(savefile.IsZombie())) {
00031     fCurrentPoint = dynamic_cast<PulserTimingPoint*> (savefile.Get("PulserTimingPoint"));
00032     if(fCurrentPoint) MSG("PulserTiming",Msg::kInfo) << "Loaded saved point: " << fCurrentPoint->AsString() << endl;
00033   }
00034 
00035   if(fCurrentPoint==0) 
00036     MSG("PulserTiming",Msg::kInfo) << "Failed to load saved point" << endl;
00037 }
00038 
00039 //......................................................................
00040 
00041 PulserTimingMaker::~PulserTimingMaker()
00042 {
00043   //FinishPoint();
00044 }
00045 
00046 //......................................................................
00047 
00048 JobCResult PulserTimingMaker::Ana(const MomNavigator* mom)
00049 {
00055 
00056   // Find the RawRecord, if any.
00057 
00058   //DataUtil::dump_mom(mom,std::cout);
00059 
00060   JobCResult result = JobCResult::kFailed;
00061 
00062   Bool_t anyData = false;
00063   VldContext now;
00064 
00065   TObject* tobj;
00066   const RawRecord* rawrec = 0;
00067   // Find the raw record. Assumes only 1.
00068   TIter    fragiter = mom->FragmentIter();
00069   while( ( tobj = fragiter.Next() ) ) {
00070     rawrec = dynamic_cast<const RawRecord*>(tobj);
00071     if(rawrec) {
00072 
00073       anyData = true;
00074       now = (rawrec->GetRawHeader())->GetVldContext();
00075       
00076       // Ask the RawRecord for an iterator over its RawDatBlocks
00077       TIter itr = rawrec->GetRawBlockIter();
00078       RawDataBlock* rawBlk;
00079       while ( ( rawBlk = dynamic_cast<RawDataBlock*>(itr.Next()) ) ) {
00080         
00081         // Find the timing summary block, if any.
00082         const RawLITimingSummaryBlock *sumblock =
00083           dynamic_cast<const RawLITimingSummaryBlock *>(rawBlk);
00084         
00085         if(sumblock) {
00086 
00087           result = JobCResult::kPassed;
00088  
00089           // Ok, we have a summary block.
00090           // Do we already have a point running?
00091           
00092           if(fCurrentPoint) {
00093             // See if the new block fits in with the current one.
00094             if(fCurrentPoint->AddSummaryBlock(sumblock)) {
00095               // All is well. We added it sucessfully.
00096               MSG("PulserTiming",Msg::kInfo) << "Summary block added successfully to " 
00097                                              << fCurrentPoint->AsString() << endl;
00098             } else {
00099               // The old point must be done. Finish it off.
00100               FinishPoint();
00101               // And start a new one.
00102               fCurrentPoint = new PulserTimingPoint(sumblock);
00103               MSG("PulserTiming",Msg::kInfo) << "Started new point:                  "
00104                                              << fCurrentPoint->AsString() << endl;
00105             }
00106           } else {
00107             // Don't have a point going yet; add it.
00108         fCurrentPoint = new PulserTimingPoint(sumblock);
00109         MSG("PulserTiming",Msg::kInfo) << "Started new point:                    "
00110                                        << fCurrentPoint->AsString() << endl;
00111           }
00112           
00113         } // if(sumblock)
00114         
00115       }
00116     }
00117   }
00118    
00119   if(anyData) { // There was at least a VldTimeStamp on this Mom.
00120 
00121     if(fCurrentPoint) {
00122       if(fCurrentPoint->PointTimedOut(now.GetTimeStamp(),fSummaryTimeout)) {
00123         MSG("PulserTiming",Msg::kInfo) << "Point timed out. " << now.AsString() << "  " << fSummaryTimeout << endl;
00124         FinishPoint();
00125       } else if( fCurrentPoint->PointIsFinished() ) {
00126         MSG("PulserTiming",Msg::kInfo) << "Point finished.  ";
00127         FinishPoint();
00128       }
00129     }
00130     
00131     // Save progress.
00132     if(fCurrentPoint) {
00133       TFile savefile("PulserTimingPoint.open.root","RECREATE");
00134       fCurrentPoint->Write("PulserTimingPoint",TObject::kOverwrite);
00135       savefile.Close();
00136     }
00137     
00138   }
00139   return result; // kNoDecision, kFailed, etc.
00140 }
00141 
00142 
00143 //......................................................................
00144 void PulserTimingMaker::FinishPoint()
00145 {
00146   if(fCurrentPoint) {
00147     MSG("PulserTiming",Msg::kInfo) << "Current timing point finishing." << endl;
00148     if(fCurrentPoint->PointIsGood()) 
00149       if(fWriteDatabase) {
00150         MSG("PulserTiming",Msg::kInfo) << "Writing point to DB..." << endl;
00151         fCurrentPoint->WriteToDatabase();
00152       }
00153     if(fWriteTextfile) {
00154       MSG("PulserTiming",Msg::kInfo) << "Writing point to text file..." << endl;
00155       fCurrentPoint->WriteToTextfile("endrun");      
00156     }
00157     
00158     delete fCurrentPoint;
00159     fCurrentPoint = 0;
00160   }
00161 }
00162 
00163 //......................................................................
00164 
00165 const Registry& PulserTimingMaker::DefaultConfig() const
00166 {
00167 //======================================================================
00168 // Supply the default configuration for the module
00169 //======================================================================
00170   static Registry r; // Default configuration for module
00171 
00172   // Set name of config
00173   std::string name = this->GetName();
00174   name += ".config.default";
00175   r.SetName(name.c_str());
00176 
00177   // Set values in configuration
00178   r.UnLockValues();
00179   r.Set("writeDatabase",  1);
00180   r.Set("writeTextfile",  0);
00181   r.Set("summaryTimeout", 600.0);
00182   r.LockValues();
00183 
00184   return r;
00185 }
00186 
00187 //......................................................................
00188 
00189 void PulserTimingMaker::Config(const Registry& r)
00190 {
00191 //======================================================================
00192 // Configure the module given the Registry r
00193 //======================================================================
00194   int    tmpi;
00195   double tmpd;
00196 
00197   if (r.Get("writeDatabase",tmpi)) { fWriteDatabase = tmpi; }
00198   if (r.Get("writeTextfile",tmpi)) { fWriteTextfile = tmpi; }
00199   if (r.Get("summaryTimeout",tmpd)) { fSummaryTimeout = tmpd; }
00200 }
00201 

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