00001 #include "BDAnaModule.h"
00002
00003 #include <HistMan/HistMan.h>
00004
00005 #include <MinosObjectMap/MomNavigator.h>
00006 #include <JobControl/JobCModuleRegistry.h>
00007 #include <RawData/RawBeamMonHeaderBlock.h>
00008 #include <RawData/RawBeamMonBlock.h>
00009 #include <RawData/RawBeamData.h>
00010 #include <RawData/RawBeamSwicData.h>
00011 #include <RawData/RawSnarlHeaderBlock.h>
00012 #include <RawData/RawDigitDataBlock.h>
00013 #include <RawData/RawRecord.h>
00014 #include <Validity/VldTimeStamp.h>
00015
00016 #include <TIterator.h>
00017 #include <TFile.h>
00018 #include <TH1D.h>
00019 #include <TH1I.h>
00020 #include <TH2D.h>
00021
00022 #include <iostream>
00023 using namespace std;
00024
00025 JOBMODULE(BDAnaModule,"BDAna","Do some BeamData/DAQ correlation checks");
00026
00027
00028 BDAnaModule::BDAnaModule()
00029 {
00030 n_bd_rec = n_daq_req = 0;
00031 }
00032
00033 BDAnaModule::~BDAnaModule()
00034 {
00035 }
00036
00037 const int nswics = 14;
00038 const char* swics[] = {
00039 "E:M101DS",
00040 "E:M105DS",
00041 "E:M107DS",
00042 "E:M108DS",
00043 "E:M112DS",
00044 "E:M114DS",
00045 "E:M115DS",
00046 "E:M117DS",
00047 "E:M121DS",
00048 "E:MTGTDS",
00049 "E:HADMDS",
00050 "E:MMA1DS",
00051 "E:MMA2DS",
00052 "E:MMA3DS",
00053 0
00054 };
00055 void BDAnaModule::BeginJob()
00056 {
00057 HistMan hm("BDAna");
00058
00059 hm.Book<TH1D>("head_dt","Time between DAQ and BeamData headers",
00060 4000,-2,2);
00061 hm.Book<TH1D>("head_dt_wide","Time between DAQ and BeamData headers",
00062 2400,-120,120);
00063
00064 hm.Book<TH1D>("daq_vme_dt","Time between DAQ trigger and E:MTGTDS VME timestamp",
00065 4000,-2,2);
00066 hm.Book<TH1D>("daq_dae_dt","Time between DAQ trigger and E:TORTGT DAE timestamp",
00067 4000,-2,2);
00068
00069 TH2D* h2d =
00070 hm.Book<TH2D>("dae_vme_dt","Time between DAE and VME ts for various devices",
00071 nswics,0,nswics,200,-10,10);
00072
00073 TH1I *h1i =
00074 hm.Book<TH1I>("swic_count","Count number of times a swic device shows up",
00075 nswics,0,nswics);
00076 for (int ind=0; swics[ind]; ++ind) {
00077 h2d->GetXaxis()->SetBinLabel(ind+1,swics[ind]);
00078 h1i->GetXaxis()->SetBinLabel(ind+1,swics[ind]);
00079 }
00080 }
00081
00082 void BDAnaModule::EndJob()
00083 {
00084 HistMan hm("BDAna");
00085
00086 TFile file("bdana.root","recreate");
00087 hm.WriteOut(file);
00088 }
00089
00090
00091 template<class BlockType>
00092 const BlockType* get_block(const RawRecord& rr)
00093 {
00094 TIter itr = rr.GetRawBlockIter();
00095 const RawDataBlock* rdb = 0;
00096
00097
00098 while ((rdb = dynamic_cast<RawDataBlock*>(itr()))) {
00099 const BlockType *block = dynamic_cast<const BlockType*>(rdb);
00100 if (block) return block;
00101 }
00102 return 0;
00103 }
00104
00105
00106 static void spew_record(const RawRecord& rr)
00107 {
00108 static int count = 0;
00109 ++count;
00110
00111 TIter itr = rr.GetRawBlockIter();
00112 cout << "[" << count << "]\tRawRecord: "
00113 << rr.GetTempTags().GetCharString("stream") << ": ";
00114 TObject* obj = 0;
00115 while ((obj = itr())) {
00116 cout << obj->GetName() << " ";
00117 }
00118 cout << rr.GetTempTags().GetCharString("file") << " ";
00119 cout << endl;
00120 }
00121
00122
00123
00124 JobCResult BDAnaModule::Ana(const MomNavigator *mom)
00125 {
00126
00127 const RawRecord* daq_rec = 0;
00128 const RawRecord* bd_rec = 0;
00129
00130
00131 TIter mitr = mom -> FragmentIter();
00132 TObject* object;
00133 while ( (object = mitr.Next()) ) {
00134 const RawRecord* rr = dynamic_cast<const RawRecord*>(object);
00135 if ( !rr ) continue;
00136
00137 spew_record(*rr);
00138
00139 string stream_name = rr->GetTempTags().GetCharString("stream");
00140 if (stream_name == "BeamMon") bd_rec = rr;
00141 if (stream_name == "DaqSnarl") daq_rec = rr;
00142 }
00143
00144 if (bd_rec) ++ n_bd_rec;
00145 if (daq_rec) ++ n_daq_req;
00146
00147 if (!(bd_rec && daq_rec)) return JobCResult::kFailed;
00148
00149 const RawBeamMonHeaderBlock* bd_head = get_block<RawBeamMonHeaderBlock>(*bd_rec);
00150 const RawBeamMonBlock* bd_block = get_block<RawBeamMonBlock>(*bd_rec);
00151
00152 const RawSnarlHeaderBlock* daq_snarl = get_block<RawSnarlHeaderBlock>(*daq_rec);
00153
00154
00155 HistMan hm("BDAna");
00156
00157 if (bd_block) {
00158 TH1I *swic_count = hm.Get<TH1I>("swic_count");
00159 TH2D *dae_vme_dt = hm.Get<TH2D>("dae_vme_dt");
00160
00161 for (int ind=0; swics[ind]; ++ind) {
00162 const RawBeamData* rbd = (*bd_block)[swics[ind]];
00163
00164 if (!rbd) continue;
00165 swic_count->Fill(ind);
00166
00167 double t_dae = rbd->GetSeconds() + rbd->GetMsecs()*0.001;
00168
00169 RawBeamSwicData swic(*rbd);
00170
00171 double t_vme = swic.VmeSeconds() + swic.VmeNanoseconds()*1.0e-9;
00172
00173
00174
00175 dae_vme_dt->Fill(ind,t_dae-t_vme);
00176 }
00177 }
00178
00179
00180 if (bd_block && daq_snarl) {
00181 const RawBeamData* rbd = 0;
00182
00183 rbd = (*bd_block)["E:MTGTDS"];
00184
00185 if (rbd) {
00186 TH1D *daq_vme_dt = hm.Get<TH1D>("daq_vme_dt");
00187
00188 RawBeamSwicData swic(*rbd);
00189
00190 VldTimeStamp vld_daq = daq_snarl->GetTriggerTime();
00191 VldTimeStamp vld_vme(swic.VmeSeconds(),swic.VmeNanoseconds());
00192
00193 daq_vme_dt->Fill(vld_daq-vld_vme);
00194 }
00195
00196 rbd = (*bd_block)["E:TORTGT"];
00197 if (rbd) {
00198 TH1D *daq_dae_dt = hm.Get<TH1D>("daq_dae_dt");
00199
00200 VldTimeStamp vld_daq = daq_snarl->GetTriggerTime();
00201 VldTimeStamp vld_dae(rbd->GetSeconds(),(int)(rbd->GetMsecs()*1e6));
00202 daq_dae_dt->Fill(vld_daq-vld_dae);
00203 }
00204
00205 }
00206
00207 if (bd_head && daq_snarl) {
00208
00209 VldTimeStamp trig_vts = daq_snarl->GetTriggerTime();
00210 VldTimeStamp bd_vts = bd_head->GetTimeStamp();
00211 double head_dt = trig_vts - bd_vts;
00212 hm.Fill1d("head_dt",head_dt);
00213 hm.Fill1d("head_dt_wide",head_dt);
00214 cout << "daq=" << trig_vts << endl
00215 << "bd= " << bd_vts << endl
00216 << "\tdt=" << head_dt << endl;
00217 }
00218
00219
00220
00221 return JobCResult::kAOK;
00222 }
00223