NDSgateTimeLooter Class Reference

#include <NDSgateTimeLooter.h>

Inheritance diagram for NDSgateTimeLooter:

JobCModule List of all members.

Public Member Functions

 NDSgateTimeLooter ()
 ~NDSgateTimeLooter ()
JobCResult Ana (const MomNavigator *mom)
const RegistryDefaultConfig () const
void Config (const Registry &r)
void Write ()

Private Attributes

bool fInitialized
VldTimeStamp fStart
VldTimeStamp fEnd
int fRunStart
int fRunStop
std::vector< VldTimeStampfStamps
Double_t fTableDuration
Int_t fWriteToDB
Int_t fWriteToFile
TTree * fTree
TFile * fFile

Detailed Description

Definition at line 20 of file NDSgateTimeLooter.h.


Constructor & Destructor Documentation

NDSgateTimeLooter::NDSgateTimeLooter (  ) 

Definition at line 44 of file NDSgateTimeLooter.cxx.

00045 {
00046   fFile = 0;
00047   fTree = 0;
00048   fInitialized = false;
00049 }

NDSgateTimeLooter::~NDSgateTimeLooter (  ) 

Definition at line 53 of file NDSgateTimeLooter.cxx.

References fFile, fTree, and Write().

00054 {
00055   Write();
00056   if(fFile) {
00057     if(fTree) fTree->Write();
00058     fFile->Write();
00059     fFile->Close();
00060     delete fFile;
00061   }
00062 }


Member Function Documentation

JobCResult NDSgateTimeLooter::Ana ( const MomNavigator mom  )  [virtual]

Implement this for read only access to the MomNavigator

Reimplemented from JobCModule.

Definition at line 66 of file NDSgateTimeLooter.cxx.

References VldTimeStamp::AsString(), NdSgateRec::dspill, fEnd, fFile, fInitialized, fRunStart, fRunStop, fStamps, fStart, fTableDuration, fTree, fWriteToDB, fWriteToFile, JobCModule::GetConfig(), VldTimeStamp::GetNanoSec(), MINFHeader::GetRun(), VldTimeStamp::GetSec(), VldContext::GetTimeStamp(), header, SpillTimeFinder::Instance(), SimFlag::kData, Msg::kDebug, Detector::kNear, JobCResult::kPassed, Msg::kWarning, NdSgateRec::monitorts, MSG, NdSgateRec::run, Munits::second, NdSgateRec::sgate, NdSgateRec::sgate_53, NdSgateRec::spill, NdSgateRec::subrun, and Write().

00067 {
00068   const RawDaqHeader* header = 
00069     DataUtil::GetRawHeader<RawDaqHeader>(mom);
00070   
00071   if(header) {
00072     if(!fInitialized) {
00073       fInitialized = true;
00074       fStart = header->GetVldContext().GetTimeStamp();
00075       fEnd = fStart;
00076       fStamps.clear();                         
00077       fRunStart = fRunStop = header->GetRun();
00078     }
00079     
00080     if(header->GetVldContext().GetTimeStamp()>fEnd) 
00081       fEnd = header->GetVldContext().GetTimeStamp();
00082     if(header->GetRun() > fRunStop) 
00083       fRunStop =  header->GetRun();
00084 
00085   }
00086 
00087   const std::vector<const RawVtmTimeInfoBlock*> vtmBlocks = 
00088     DataUtil::GetRawBlocks<RawVtmTimeInfoBlock>(mom);
00089   
00090   if(vtmBlocks.size()>0) {
00091     
00092     static int last_latch = -1;
00093     if(vtmBlocks[0]->GetSpillTimeGPS() != last_latch) {
00094       last_latch = vtmBlocks[0]->GetSpillTimeGPS();
00095 
00096     if(vtmBlocks[0]->GetTimeFrameNum()!=0) 
00097     {
00098     
00099       // Find the 10MHz latch time. See how it varies from crate to crate.
00100       int latch10_tot = 0;
00101       int latch10_low  = 100000000;
00102       int latch10_high = 0;
00103       int nlatch  = 0;
00104 
00105       for(UInt_t i=0;i<vtmBlocks.size();i++) {
00106         int l = vtmBlocks[i]->GetSpillTimeGPS();
00107         if(l<latch10_low) latch10_low = l;
00108         if(l>latch10_high) latch10_high = l;
00109         latch10_tot += l;         
00110         nlatch++;
00111       }
00112       
00113       double latch10_avg = (double)latch10_tot/(double)nlatch;
00114 
00115       // 53 Mhz quantites:
00116       int nsec_53MHz = (int)(1e9*(double)vtmBlocks[0]->GetSpillTimeRF()
00117                              /(double)vtmBlocks[0]->GetLastTimeStamp());
00118         
00119 
00120       if((latch10_high-latch10_low)>1) {
00121         MSG("SpillTime",Msg::kWarning) << "Not all crates agree on 10MHz time." << endl;
00122         MSG("SpillTime",Msg::kWarning) << "Earliest: " << latch10_low 
00123                                          << "  Latest: " << latch10_high 
00124                                          << "  Mean: " << latch10_avg << endl;
00125       }
00126           
00127       // Get time of nearest second.
00128       VldContext cx = vtmBlocks[0]->GetVldContext();
00129 
00130       // Get second.
00131       int second = cx.GetTimeStamp().GetSec()                   // Raw second
00132         + (int)TMath::Nint(cx.GetTimeStamp().GetNanoSec()/1e9)  // Round up or down.
00133         -1;                                                     // Start of prev second.
00134 
00135       VldTimeStamp sgate_time(second, (int)(latch10_avg * 100.));
00136       VldTimeStamp sgate_53  (second, nsec_53MHz);
00137       
00138       VldContext check_context(Detector::kNear,SimFlag::kData,sgate_time);
00139       VldTimeStamp t_database = SpillTimeFinder::Instance().
00140         GetTimeOfNearestSpill(cx);
00141       
00142       MSG("SpillTime",Msg::kDebug) << "SGATE: " << sgate_time.AsString() << endl;
00143       MSG("SpillTime",Msg::kDebug) << "   DB: " << t_database.AsString() << endl;
00144       MSG("SpillTime",Msg::kDebug) << "   dt: " << (double)(sgate_time - t_database)*1e9 << "ns"
00145                                     << "\t tf: " << vtmBlocks[0]->GetTimeFrameNum() << endl;
00146       if(fWriteToFile) {
00147         static NdSgateRec* rec = 0;
00148         if(fFile==0) {
00149           rec = new NdSgateRec;
00150           fFile = new TFile(GetConfig().GetCharString("FileName"),"RECREATE");
00151           fTree = new TTree("vtm","vtm");
00152           fTree->Branch("ndrec","NdSgateRec",&rec,32000,1);
00153         }
00154 
00155         rec->run       = vtmBlocks[0]->GetRun();
00156         rec->subrun    = vtmBlocks[0]->GetSubRun();
00157         rec->monitorts = cx.GetTimeStamp();
00158         rec->sgate    = sgate_time;
00159         rec->sgate_53 = sgate_53;
00160         rec->spill    = t_database;
00161         rec->dspill   = (double)(sgate_time-t_database);
00162         fTree->Fill();
00163       }
00164 
00165       if(fWriteToDB) 
00166         fStamps.push_back(sgate_time);
00167     }
00168   } 
00169   }
00170   
00171   if((double)(fEnd-fStart) > fTableDuration) {
00172     Write();
00173     fStart = fEnd;
00174     fEnd = fStart;
00175   }
00176   
00177   return JobCResult::kPassed;
00178 }

void NDSgateTimeLooter::Config ( const Registry r  )  [virtual]

Return the actual configuration. If your module directly pulls its configuration from the fConfig Registry, you don't need to override this. Override if you have local config variables.

Reimplemented from JobCModule.

Definition at line 249 of file NDSgateTimeLooter.cxx.

References fTableDuration, fWriteToDB, fWriteToFile, and Registry::Get().

00250 {
00251   r.Get("TableDuration",fTableDuration);
00252   r.Get("WriteToDB",fWriteToDB);
00253   r.Get("WriteToFile",fWriteToFile);
00254 }

const Registry & NDSgateTimeLooter::DefaultConfig (  )  const [virtual]

Get the default configuration registry. This should normally be overridden. One useful idiom is to implement it like:

const Registry& MyModule::DefaultConfig() const { static Registry cfg; // never is destroyed if (cfg.Size()) return cfg; // already filled it // set defaults: cfg.Set("TheAnswer",42); cfg.Set("Units","unknown"); return cfg; }

Reimplemented from JobCModule.

Definition at line 222 of file NDSgateTimeLooter.cxx.

References JobCModule::GetName(), Munits::hour, Registry::LockValues(), Registry::Set(), and Registry::UnLockValues().

00223 {
00224 //======================================================================
00225 // Supply the default configuration for the module
00226 //======================================================================
00227   static Registry r; // Default configuration for module
00228 
00229   // Set name of config
00230   std::string name = this->GetName();
00231   name += ".config.default";
00232   r.SetName(name.c_str());
00233 
00234   // Set values in configuration
00235   r.UnLockValues();
00236 
00237   r.Set("TableDuration",8.0*Munits::hour);
00238   r.Set("WriteToDB",1);
00239   r.Set("WriteToFile",0);
00240   r.Set("FileName","nd_sgates.root");
00241 
00242   r.LockValues();
00243 
00244   return r;
00245 }

void NDSgateTimeLooter::Write (  ) 

Definition at line 180 of file NDSgateTimeLooter.cxx.

References VldRange::AsString(), VldTimeStamp::AsString(), DbiWriter< T >::Close(), fEnd, fInitialized, Form(), fRunStart, fRunStop, fStamps, fStart, fWriteToDB, SimFlag::kData, Msg::kInfo, Detector::kNear, SpillTimeND::kTask_Vtm, and MSG.

Referenced by Ana(), and ~NDSgateTimeLooter().

00181 {
00182   if(fWriteToDB) {
00183     
00184     MSG("SpillTime",Msg::kInfo) << "Time start: " << fStart.AsString() << endl;
00185     MSG("SpillTime",Msg::kInfo) << "Time end: "   << fEnd.AsString() << endl;  
00186     
00187     VldTimeStamp vldCreate = fStart;
00188     
00189     VldRange range( (int)Detector::kNear,
00190                     (int)SimFlag::kData,
00191                     fStart,
00192                     fEnd,
00193                     Form("Timestamps looted from ND VTM data, runs %d-%d",fRunStart,fRunStop)
00194                     );
00195     
00196     MSG("SpillTime",Msg::kInfo) << "Starting write: " << range.AsString() << endl;
00197     
00198     DbiWriter<SpillTimeND> writer (range,
00199                                    -1, //Aggregate
00200                                    SpillTimeND::kTask_Vtm, // task
00201                                    vldCreate, // Creation date
00202                                    0,   // db no
00203                                    Form("Timestamps looted from ND VTM data, runs %d-%d",fRunStart,fRunStop)
00204                                    );
00205     
00206     for(UInt_t i = 0; i<fStamps.size(); i++) {
00207       SpillTimeND datum(fStamps[i]);
00208       writer << datum;
00209     }
00210     
00211     writer.Close();
00212   }
00213   
00214   
00215   fStamps.clear();
00216   fInitialized = false;
00217 }


Member Data Documentation

VldTimeStamp NDSgateTimeLooter::fEnd [private]

Definition at line 41 of file NDSgateTimeLooter.h.

Referenced by Ana(), and Write().

TFile* NDSgateTimeLooter::fFile [private]

Definition at line 51 of file NDSgateTimeLooter.h.

Referenced by Ana(), and ~NDSgateTimeLooter().

bool NDSgateTimeLooter::fInitialized [private]

Definition at line 39 of file NDSgateTimeLooter.h.

Referenced by Ana(), and Write().

int NDSgateTimeLooter::fRunStart [private]

Definition at line 42 of file NDSgateTimeLooter.h.

Referenced by Ana(), and Write().

int NDSgateTimeLooter::fRunStop [private]

Definition at line 42 of file NDSgateTimeLooter.h.

Referenced by Ana(), and Write().

std::vector<VldTimeStamp> NDSgateTimeLooter::fStamps [private]

Definition at line 43 of file NDSgateTimeLooter.h.

Referenced by Ana(), and Write().

VldTimeStamp NDSgateTimeLooter::fStart [private]

Definition at line 40 of file NDSgateTimeLooter.h.

Referenced by Ana(), and Write().

Double_t NDSgateTimeLooter::fTableDuration [private]

Definition at line 45 of file NDSgateTimeLooter.h.

Referenced by Ana(), and Config().

TTree* NDSgateTimeLooter::fTree [private]

Definition at line 50 of file NDSgateTimeLooter.h.

Referenced by Ana(), and ~NDSgateTimeLooter().

Int_t NDSgateTimeLooter::fWriteToDB [private]

Definition at line 46 of file NDSgateTimeLooter.h.

Referenced by Ana(), Config(), and Write().

Int_t NDSgateTimeLooter::fWriteToFile [private]

Definition at line 47 of file NDSgateTimeLooter.h.

Referenced by Ana(), and Config().


The documentation for this class was generated from the following files:
Generated on Mon Sep 1 00:52:01 2014 for loon by  doxygen 1.4.7