• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

onlinemonitor/framework/TTriglogProc.cxx (r4864/r3724)

Go to the documentation of this file.
00001 #include "TTriglogProc.h"
00002 
00003 #include <stdio.h>
00004 
00005 #include "TTimeStamp.h"
00006 #include "TH1.h"
00007 #include "TLatex.h"
00008 
00009 #include "TGo4Log.h"
00010 
00011 #include "TCBMBeamtimeEvent.h"
00012 
00013 // still need this for subevent types:
00014 #include "roc/Message.h"
00015 #include "roc/Board.h"
00016 
00017 
00018 TTriglogProc::TTriglogProc() :
00019    TCBMBeamtimeProc(),
00020    fOutputEvent(0)
00021 {
00022 }
00023 
00024 TTriglogProc::TTriglogProc(const char* name, const char* channel_names) :
00025    TCBMBeamtimeProc(name),
00026    fOutputEvent(0)
00027 {
00028    TGo4Log::Info("TTriglogProc: Create instance %s", name);
00029 
00030    fSpillRate = MakeTH1('I', "Triglog/SpillRate", "Number of triggers per second", 1000, 0, 1000, "sec");
00031    fLastSync = 0;
00032 
00033    fVulomSyncs = MakeTH1('I', "Triglog/Syncs", "Number of sync messages from VULOM", 65536, 0, 65536.);
00034 
00035    for (int n=0;n<NUM_SCALERS;n++)
00036       fVulomScalers[n] = MakeTH1('I', Form("Triglog/Scaler%d", n), "Distribution of scaler signals", N_SCALERS_CH, 0, N_SCALERS_CH);
00037 
00038    for (int n=0;n<NUM_SCALERS;n++)
00039       for (int j=0;j<N_SCALERS_CH;j++)
00040         fRate[n][j] = MakeTH1('I', Form("Triglog/ScalerRate%dCh%d", n, j), Form("VULOM Scaler rate on column %d channel %d", n, j), 500, 0, 20000, "Hz");
00041    fPrevMbsTime = 0;
00042 
00043    fVulomInfo = new TLatex(0.5,0.5,"-- demo text --");
00044    fVulomInfo->SetName("TriglogInfo");
00045    fVulomInfo->SetNDC();
00046    AddObject(fVulomInfo); // will replace old one of same name
00047 
00048    fFirstMbsTime = 0;
00049    fLastMbsTime = 0;
00050    fTotalTriggerCount = 0;
00051 
00052    for (int nch=0;nch<N_SCALERS_CH;nch++)
00053       fChannelNames[nch].Form("Ch%02d", nch);
00054 
00055    if (channel_names!=0) {
00056       TObjArray* tokens = TString(channel_names).Tokenize(":");
00057 
00058       if (tokens!=0)
00059          for (int n=0;n<=tokens->GetLast();n++)
00060             if (strlen(tokens->At(n)->GetName())>0)
00061                fChannelNames[n] = tokens->At(n)->GetName();
00062 
00063       delete tokens;
00064    }
00065 }
00066 
00067 TTriglogProc::~TTriglogProc()
00068 {
00069    double runtime = fLastMbsTime - fFirstMbsTime;
00070    printf ("Total MBS run time %6.0f sec \n", runtime);
00071 
00072    if (runtime>0) {
00073        printf ("-------- Total number of triggers %d --------\n", fTotalTriggerCount);
00074 
00075        for (int j=0;j<N_SCALERS_CH;j++) {
00076           printf ("  %7s", fChannelNames[j].Data());
00077           for (int n=0;n<NUM_SCALERS;n++)
00078              printf("   %8u", fLastScaler[n][j] - fFirstScaler[n][j]);
00079           printf("\n");
00080       }
00081 
00082        printf ("------- Trigger rate %8.3f Hz ---------\n", fTotalTriggerCount/runtime);
00083 
00084        for (int j=0;j<N_SCALERS_CH;j++) {
00085           printf ("  %7s", fChannelNames[j].Data());
00086           for (int n=0;n<NUM_SCALERS;n++)
00087           printf("   %8.3f", (fLastScaler[n][j] - fFirstScaler[n][j])/runtime);
00088           printf("\n");
00089       }
00090   }
00091 }
00092 
00093 void TTriglogProc::InitEvent(TGo4EventElement* outevnt)
00094 {
00095    TCBMBeamtimeEvent* btevent = dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00096    if(btevent)
00097    {
00098       // since output event object is never discarded within processor lifetime,
00099       // we just search for subevent by name once to speed up processing
00100       if(fOutputEvent==0)
00101          fOutputEvent = dynamic_cast<TTriglogEvent*>(btevent->GetSubEvent("TRIGLOG"));
00102    }
00103    else
00104    {
00105       fOutputEvent = dynamic_cast<TTriglogEvent*>(outevnt);
00106    }
00107    if(fOutputEvent==0) {
00108       GO4_STOP_ANALYSIS_MESSAGE("**** TTriglogProc: Fatal error: output event is not a TTriglogEvent!!! STOP GO4");
00109    }
00110 }
00111 
00112 void TTriglogProc::ProcessSubevent(TGo4MbsSubEvent* subevt)
00113 {
00114 #if __GO4BUILDVERSION__ > 40500
00115    Bool_t oldevent=IsKeepInputEvent();
00116    SetKeepInputEvent(kFALSE); // need this to reset our flag in case rocproc had requested it.
00117    if(oldevent) return; // ignore this subevent if we already had it
00118 #endif
00119 
00120    if ((subevt->GetProcid() == roc::proc_Triglog) && fOutputEvent) {
00121 
00122       int indx = 0;
00123 
00124       Int_t sync_num = subevt->Data(indx++);
00125 
00126       // cout << " ===================== TRIGLOG EVENT ================= " << sync_num % 0x1000000 <<  endl;
00127 
00128       // just to see that sync number is changing
00129       fVulomSyncs->Fill(sync_num % 65536);
00130       fOutputEvent->SetValid(kTRUE);
00131 
00132       fOutputEvent->fVulomSyncNumber = sync_num;
00133 
00134       fOutputEvent->fVulomTriggerPattern = (UInt_t) subevt->Data(indx++);
00135 
00136       fOutputEvent->fMbsTimeSecs = (UInt_t) subevt->Data(indx++);
00137       fOutputEvent->fMbsTimeMillisec = (UInt_t) subevt->Data(indx++);
00138 
00139       if ((fLastSync!=0) && (sync_num > fLastSync))
00140          fSpillRate->Fill(fOutputEvent->fMbsTimeSecs % 1000,  sync_num-fLastSync);
00141       fLastSync = sync_num;
00142 
00143 
00144       TTimeStamp mbs_time(fOutputEvent->fMbsTimeSecs, fOutputEvent->fMbsTimeMillisec*1000000);
00145 
00146       TString txt;
00147       txt.Form("#splitline{#scale[3.0]{#color[2]{Sync number:%d}}}{#scale[2.0]{#color[4]{MBS time:%s}}}",
00148             sync_num, mbs_time.AsString("s"));
00149       fVulomInfo->SetText(0.2, 0.5, txt.Data());
00150 
00151       for (int nscaler = 0; nscaler < NUM_SCALERS; nscaler++) {
00152          // SL 20.10.11 MBS readout was changed and two more scalers were included
00153          // to be able process old files, add this break condition;
00154 
00155          for (int n = 0; n<N_SCALERS_CH; n++) {
00156               // SL: put protection against different length of this subevent
00157               // also trigger-pattern was not correctly counted
00158             Int_t val = indx < subevt->GetIntLen() ? subevt->Data(indx++) : 0;
00159             //fVulomScalers[nscaler]->Fill(n,val);
00160             fVulomScalers[nscaler]->SetBinContent(n+1,val); // scalers accumulate themselves, just show current value
00161             fOutputEvent->fVulomScaler[nscaler][n] = val;
00162         }
00163       }
00164 
00165       fTotalTriggerCount++;
00166 
00167       fLastMbsTime = fOutputEvent->fMbsTimeSecs;
00168 
00169       for (int n=0;n<NUM_SCALERS;n++)
00170          for (int j=0;j<N_SCALERS_CH;j++) {
00171             fLastScaler[n][j] = fOutputEvent->fVulomScaler[n][j];
00172             if (fFirstMbsTime==0) fFirstScaler[n][j] = fLastScaler[n][j];
00173          }
00174 
00175       if (fFirstMbsTime==0) fFirstMbsTime = fLastMbsTime;
00176 
00177       double tm = fOutputEvent->fMbsTimeSecs + fOutputEvent->fMbsTimeMillisec*1e-3;
00178 
00179       // printf ("MBS time = %10.5f   %d  %d \n", tm, fCrateInputEvent->fMbsTimeSecs, fCrateInputEvent->fMbsTimeMillis);
00180 
00181       if ((fPrevMbsTime==0) || (tm > fPrevMbsTime + 0.1)) {
00182 
00183          double diff = 0;
00184          if ((fPrevMbsTime>0) && (tm < fPrevMbsTime + 0.15)) diff = tm - fPrevMbsTime;
00185 
00186          for (int n=0;n<NUM_SCALERS;n++)
00187             for (int j=0;j<N_SCALERS_CH;j++) {
00188                if (diff>0) {
00189                   fScalerRate[n][j] = (fOutputEvent->fVulomScaler[n][j] - fPrevScaler[n][j])/diff;
00190                   fRate[n][j]->Fill(fScalerRate[n][j]);
00191                }
00192 
00193                fPrevScaler[n][j] = fOutputEvent->fVulomScaler[n][j];
00194             }
00195 
00196          fPrevMbsTime = tm;
00197       }
00198    }
00199 }

Generated on Tue Dec 10 2013 04:52:23 for ROCsoft by  doxygen 1.7.1