00001
00002
00003
00004
00005
00006
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"
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
00044 }
00045
00046
00047
00048 JobCResult PulserTimingMaker::Ana(const MomNavigator* mom)
00049 {
00055
00056
00057
00058
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
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
00077 TIter itr = rawrec->GetRawBlockIter();
00078 RawDataBlock* rawBlk;
00079 while ( ( rawBlk = dynamic_cast<RawDataBlock*>(itr.Next()) ) ) {
00080
00081
00082 const RawLITimingSummaryBlock *sumblock =
00083 dynamic_cast<const RawLITimingSummaryBlock *>(rawBlk);
00084
00085 if(sumblock) {
00086
00087 result = JobCResult::kPassed;
00088
00089
00090
00091
00092 if(fCurrentPoint) {
00093
00094 if(fCurrentPoint->AddSummaryBlock(sumblock)) {
00095
00096 MSG("PulserTiming",Msg::kInfo) << "Summary block added successfully to "
00097 << fCurrentPoint->AsString() << endl;
00098 } else {
00099
00100 FinishPoint();
00101
00102 fCurrentPoint = new PulserTimingPoint(sumblock);
00103 MSG("PulserTiming",Msg::kInfo) << "Started new point: "
00104 << fCurrentPoint->AsString() << endl;
00105 }
00106 } else {
00107
00108 fCurrentPoint = new PulserTimingPoint(sumblock);
00109 MSG("PulserTiming",Msg::kInfo) << "Started new point: "
00110 << fCurrentPoint->AsString() << endl;
00111 }
00112
00113 }
00114
00115 }
00116 }
00117 }
00118
00119 if(anyData) {
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
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;
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
00169
00170 static Registry r;
00171
00172
00173 std::string name = this->GetName();
00174 name += ".config.default";
00175 r.SetName(name.c_str());
00176
00177
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
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