00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
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
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
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
00106 MSG("Pulser",Msg::kVerbose) <<
00107 "PSM::Reco() : Got a LI summary" << sec<<endl;
00108 fLastSec = sec;
00109
00110
00111
00112
00113
00114
00115
00116 if (fSummaryList) {
00117
00118
00119
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
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
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
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
00179
00180 float trigfrac;
00181 if (fSummaryList->GetExpectedPoints()!=0) {
00182
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
00212
00213
00214 if (!fSummaryList) return;
00215
00216 fSummaryList->Finish();
00217
00218
00219
00220 float trigfrac;
00221
00222 if (fSummaryList->GetExpectedPoints()!=0) {
00223
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