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

beamtime/cern-oct12/go4/TMbsCrateProc.cxx (r4864/r3723)

Go to the documentation of this file.
00001 #include "TMbsCrateProc.h"
00002 
00003 #include <stdlib.h>
00004 
00005 #include "TTimeStamp.h"
00006 #include "TSystem.h"
00007 #include "TROOT.h"
00008 
00009 #include "TGo4Log.h"
00010 
00011 // still need this for subevent types:
00012 #include "roc/Message.h"
00013 #include "roc/Board.h"
00014 
00015 
00016 #define L1182_DEBUG 0
00017 #define L1183_DEBUG 0
00018 #define MADC_DEBUG 0
00019 #define V550_READ_PED 1
00020 
00021 #include "../mbs/cbmvme.h"
00022 
00023 const uint32_t vme_setup[MAX__N_MOD*6] = VME__MODULES;
00024 
00025 uint64_t vme_tags[MAX__N_MOD];
00026 
00027 
00028 TMbsCrateProc::TMbsCrateProc(const char* name) : TCBMBeamtimeProc(name),fOutputEvent(0)
00029 {
00030    TGo4Log::Info("TMbsCrateProc: Create instance %s", name);
00031 
00032    fPar = (TMbsCrateParam*) MakeParameter("MbsCratePar", "TMbsCrateParam");
00033 
00034    ExecuteScript("set_MbsPar.C");
00035 
00036    TString obname, obtitle;   
00037 
00038 
00039    /*********** MADCs *************/
00040    for (int mad = 0; mad < MAX_MADC; mad++) {
00041       obname.Form("MADC%d/MADC%d_sample", mad,mad);
00042       obtitle.Form("Sample of MADC%d readout", mad);
00043       fMadc_trace[mad]=MakeTH1('I', obname.Data(), obtitle.Data(), N_MADC_CHA, 0, N_MADC_CHA,"channel No.");
00044 
00045       for (int ch = 0; ch < N_MADC_CHA; ch++) {
00046          obname.Form("MADC%d/MADC%d_ch%d", mad,mad,ch);
00047          obtitle.Form("MADC %d Channel %d", mad, ch);
00048          fMadc_adc[mad][ch] = MakeTH1('I', obname.Data(), obtitle.Data(), 0x3FF, 0, 0x3FF);
00049 
00050          //          obname.Form("MADC%d/MADC%d_ch%d_pion", mad,mad,ch);
00051          //          obtitle.Form("MADC %d Channel %d pion", mad, ch);
00052          //          fMadc_pion[mad][ch] = MakeTH1('I', obname.Data(), obtitle.Data(), 0x3FF, 0, 0x3FF);
00053          //
00054          //          obname.Form("MADC%d/MADC%d_ch%d_electron", mad,mad,ch);
00055          //          obtitle.Form("MADC %d Channel %d electron", mad, ch);
00056          //          fMadc_electron[mad][ch] = MakeTH1('I', obname.Data(), obtitle.Data(), 0x3FF, 0, 0x3FF);
00057 
00058       }
00059 
00060       obname.Form("MADC%d_overview", mad);
00061       pMadc_overview[mad] = GetPicture(obname.Data());
00062       if (pMadc_overview[mad] == 0) {
00063          obtitle.Form("Channels overview MADC %2d", mad);
00064          pMadc_overview[mad] = new TGo4Picture(obname.Data(), obtitle.Data());
00065          pMadc_overview[mad]->SetDivision(8, 4);
00066          for(int y=0; y<8;++y)
00067             for(int x=0;x<4;++x) {
00068                pMadc_overview[mad]->Pic(y, x)->AddObject(fMadc_adc[mad][4*y+x]);
00069                pMadc_overview[mad]->Pic(y, x)->SetFillAtt(5, 3001);
00070                pMadc_overview[mad]->Pic(y, x)->SetRangeX(0, 200);
00071                pMadc_overview[mad]->Pic(y, x)->SetLogScale(1, 1);
00072             }
00073          AddPicture(pMadc_overview[mad],"BucharestMADC");
00074       }
00075 
00076       //       obname.Form("MADC%d_pion", mad);
00077       //       if (GetPicture(obname.Data()) == 0) {
00078       //          obtitle.Form("Pion channels overview MADC %2d", mad);
00079       //          TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00080       //          pic->SetDivision(8, 4);
00081       //          for(int y=0; y<8;++y)
00082       //             for(int x=0;x<4;++x) {
00083       //                pic->Pic(y, x)->AddObject(fMadc_pion[mad][4*y+x]);
00084       //                pic->Pic(y, x)->SetFillAtt(5, 3001);
00085       //                pic->Pic(y, x)->SetRangeX(0, 200);
00086       //                pic->Pic(y, x)->SetLogScale(1, 1);
00087       //             }
00088       //          AddPicture(pic);
00089       //       }
00090       //
00091       //
00092       //       obname.Form("MADC%d_electron", mad);
00093       //       if (GetPicture(obname.Data()) == 0) {
00094       //          obtitle.Form("Electron channels overview MADC %2d", mad);
00095       //          TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00096       //          pic->SetDivision(8, 4);
00097       //          for(int y=0; y<8;++y)
00098       //             for(int x=0;x<4;++x) {
00099       //                pic->Pic(y, x)->AddObject(fMadc_electron[mad][4*y+x]);
00100       //                pic->Pic(y, x)->SetFillAtt(5, 3001);
00101       //                pic->Pic(y, x)->SetRangeX(0, 200);
00102       //                pic->Pic(y, x)->SetLogScale(1, 1);
00103       //             }
00104       //          AddPicture(pic);
00105       //       }
00106 
00107    }
00108 
00109 
00110    for (int n=0;n<MAX_1290;n++)
00111       fTDC[n].MakeHistos(this, Form("TDC%d",n));
00112 
00113    // 1182 histo
00114 
00115    for (int n=0;n<MAX_1182;n++)
00116       for (int ch=0;ch<NUM_1182_CH;ch++) {
00117          obname.Form("118%d/118%d_channel%d", n+2, n+2, ch);
00118          obtitle.Form("118%d Channel %d", n+2, ch);
00119          f1182h[n][ch] = MakeTH1('I', obname.Data(), obtitle.Data(), 1024, 0, 4096.);
00120       }
00121 
00122    for (int n=0;n<MAX_1182;n++)
00123       for (int ch=0;ch<NUM_1182_CH;ch++) {
00124          obname.Form("118%d/118%d_pulser_channel%d", n+2, n+2, ch);
00125          obtitle.Form("118%d Channel %d under pulser", n+2, ch);
00126          f1182Pulserh[n][ch] = MakeTH1('I', obname.Data(), obtitle.Data(), 1024, 0, 4096.);
00127       }
00128 
00129    for (int n=0;n<MAX__N_MOD;n++) {
00130       if (n != (int)vme_setup[n*6]) {
00131          TGo4Log::Error("Wrong setup in cbmvme.h file in row %d",n);
00132          exit(1);
00133       }
00134 
00135       vme_tags[n] = (((uint64_t) vme_setup[n*6+5]) << 32) | vme_setup[n*6+4];
00136 
00137       if ((n>0) && (vme_tags[n]==0)) {
00138          TGo4Log::Error("Wrong setup in cbmvme.h - zero tag in row %d", n);
00139          exit(1);
00140       }
00141    }
00142 
00143    TGo4Log::Info("TMbsCrateProc - Histograms created");
00144 
00145 
00146 //   obname.Form("MADC/SiStrip/Pedestal_Trace");
00147 //   obtitle.Form("SiStrip pedestals trace");
00148 //   fMadc_si_ped_trace= MakeTH1('I', obname.Data(), obtitle.Data(),
00149 //                  N_SISTRIP_CHA, 0, N_SISTRIP_CHA,"channel number");
00150 //   obname.Form("MADC/SiStrip/Pedestal_Acc");
00151 //   obtitle.Form("SiStrip pedestals accumulated");
00152 //   fMadc_si_ped_acc=MakeTH1('I', obname.Data(), obtitle.Data(),
00153 //                  N_SISTRIP_CHA, 0, N_SISTRIP_CHA,"channel number");
00154 
00155 
00156 }
00157 
00158 TMbsCrateProc::~TMbsCrateProc()
00159 {
00160 }
00161 
00162 void TMbsCrateProc::InitEvent(TGo4EventElement* outevnt)
00163 {
00164    TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00165    if(btevent)
00166    {
00167       // since output event object is never discarded within processor lifetime,
00168       // we just search for subevent by name once to speed up processing
00169       if(fOutputEvent==0)
00170          fOutputEvent=dynamic_cast<TMbsCrateEvent*>(btevent->GetSubEvent("MBSCRATE"));
00171    }
00172    else
00173    {
00174 
00175       fOutputEvent= dynamic_cast<TMbsCrateEvent*>(outevnt);
00176    }
00177    if(fOutputEvent==0) {
00178       GO4_STOP_ANALYSIS_MESSAGE("**** TMbsCrateProc: Fatal error: output event is not a TMbsCrateEvent!!! STOP GO4");
00179    }
00180 }
00181 
00182 void TMbsCrateProc::ProcessSubevent(TGo4MbsSubEvent* subevt)
00183 {
00184  // use this to test with old beamtime data JAM:
00185  //  if (subevt->GetProcid() == roc::proc_TRD_MADC) {
00186 
00187    if (subevt->GetProcid() == roc::proc_CERN_Oct12) {
00188       // MBS data from CERN beamtime, October 11
00189       // subevt->GetControl() == 9 from Master MBS, subevt->GetControl() == 10 from Slave MBS
00190 
00191       fOutputEvent->fIsPulser = (GetTriggerNumber()==8);
00192 
00193       Int_t *pdata = subevt->GetDataField();
00194       UInt_t lwords = subevt->GetIntLen();
00195 
00196       // printf("CERN subevent Control %u TOTALLEN = %u\n", subevt->GetControl(), lwords);
00197 
00198       Int_t* tagpos[MAX__N_MOD];
00199       Int_t taglen[MAX__N_MOD];
00200 
00201       for (int n=0;n<MAX__N_MOD;n++) {
00202          tagpos[n] = 0;
00203          taglen[n] = 0;
00204       }
00205 
00206       int lasttag = -1;
00207 
00208       for (UInt_t cur = 0; cur < lwords; ++cur) {
00209          uint64_t* ptag = (uint64_t*) pdata;
00210          bool find = false;
00211 
00212          for (int ntag=1;ntag<MAX__N_MOD;ntag++)
00213             if ((*ptag == vme_tags[ntag]) && (vme_tags[ntag]!=0)) {
00214                if (lasttag>=0) {
00215                   taglen[lasttag] = pdata - tagpos[lasttag];
00216                   lasttag = -1;
00217                }
00218 
00219                if (tagpos[ntag]==0) {
00220                   pdata+=2; cur+=1;
00221                   tagpos[ntag] = pdata;
00222                   lasttag = ntag;
00223                } else {
00224                   TGo4Log::Error("FORMAT ERROR found tag %lld twice\n", vme_tags[ntag]);
00225                   pdata+=2; cur+=1;
00226                }
00227 
00228                find = true;
00229                break;
00230             }
00231 
00232          if (!find) pdata++;
00233       }
00234 
00235       if (lasttag>=0)
00236          taglen[lasttag] = pdata - tagpos[lasttag];
00237 
00238       // for (int ntag=0;ntag<numtags;ntag++)
00239       //    if (tagpos[ntag])
00240       //       printf("TAG %d POS %lu LEN %d\n", ntag, tagpos[ntag] - p0, taglen[ntag]);
00241 
00242 
00243 
00244       // SL: in previous version trigger 8 was excluded at all
00245       //if (GetTriggerNumber()==8) {
00246       //   fOutputEvent->SetValid(kFALSE);
00247       //   return;
00248       //}
00249 
00250       // actually process data in subroutines:
00251 
00252       if (tagpos[VME__ID_1182] && taglen[VME__ID_1182])
00253          Process1182(0, tagpos[VME__ID_1182], taglen[VME__ID_1182]);  // 1182
00254 
00255       if (tagpos[VME__ID_1183] && taglen[VME__ID_1183])
00256          Process1182(1, tagpos[VME__ID_1183], taglen[VME__ID_1183]);  // 1183
00257 
00258       for (int tdc=VME__ID_TDC1;tdc<=VME__ID_TDC7;tdc++)
00259          if (tagpos[tdc] && taglen[tdc])
00260             Process1290(tdc-VME__ID_TDC1, tagpos[tdc], taglen[tdc]);  // all TDCs
00261 
00262       for (int madc=VME__ID_MAD1;madc<=VME__ID_MAD4;madc++)
00263          if (tagpos[madc] && taglen[madc])
00264             ProcessMADC(madc-VME__ID_MAD1, tagpos[madc], taglen[madc]);  // all MADCs
00265 
00266       fOutputEvent->SetValid(kTRUE);
00267 
00268       return;
00269    }
00270 }
00271 
00272 
00273 
00274 
00275 void TMbsCrateProc::Process1182(int num, int* pdata, int len)
00276 {
00277    if (len < 2 + NUM_1182_CH ) {
00278       cout <<"TBeamMonitorProc:Process1182 data length"<< len << "not sufficient!" <<endl;
00279       return;
00280    }
00281 
00282    if (num>=MAX_1182) {
00283       cout << "Wrong ID=" << num << " of 1182 module" << endl;
00284       return;
00285    }
00286 
00287    // skip event header:
00288    int header = *pdata++;
00289    if (L1182_DEBUG)  printf("1182 header:0x%0x \n",header);
00290 
00291    // skip status
00292    int status = *pdata++;
00293    if (L1182_DEBUG)
00294       printf("1182 status:0x%0x :  \n"
00295             "        conversion complete    (bit0): 0x%x\n"
00296             "        conversion in progress (bit1): 0x%x\n"
00297             "        front(1)/rear(0) panel (bit2): 0x%x\n"
00298             "        Event buffer not full  (bit3): 0x%x\n"
00299             "        Event count       (bits 4..7): 0x%x\n"
00300             "        should be 0            (bit8): 0x%x\n"
00301             "        should be 0            (bit9): 0x%x\n",
00302             status, status & 1, (status >> 1) & 1 , (status >> 2) & 1, (status >> 3) & 1,
00303             (status >> 4) & 0xf,  (status >> 8) & 1, (status >> 9) & 1);
00304 
00305    for(int ch=0;ch<NUM_1182_CH;++ch) {
00306       int val = *pdata++;
00307       fOutputEvent->fData1182[num][ch] = val; // output event to root tree
00308    }
00309 
00310    // do not fill histograms if pulser event - used for later analysis
00311    if (fOutputEvent->IsPulser())
00312       for(int ch=0;ch<NUM_1182_CH;++ch)
00313          f1182Pulserh[num][ch]->Fill(fOutputEvent->fData1182[num][ch]);
00314    else
00315       for(int ch=0;ch<NUM_1182_CH;++ch)
00316          f1182h[num][ch]->Fill(fOutputEvent->fData1182[num][ch]);
00317 }
00318 
00319 void TMbsCrateProc::ProcessMADC(int i, int* pdata, int len) 
00320 {
00321    //      printf("MADC %d len %d  \n", i, len);
00322 
00323    if(i>=MAX_MADC) return;
00324    if(len<2) return;
00325 
00326    fMadc_trace[i]->Reset("");
00327 
00328    int* cursor = pdata;
00329    // skip event header:
00330    unsigned int header=*cursor;
00331    if ((header & 0xff000000) >> 24 != 0x40)
00332       printf("madc(%d) header error: 0x%08x, expected 0x40nnnnnn \n",i,header);
00333    cursor++;
00334    for(int cnt=0;cnt<len-2;cnt++) {
00335       unsigned int val=*cursor++;
00336 
00337       if ((val & 0xff000000) != 0x4000000)
00338          printf("madc(%d) seq %u value 0x%08x error, expected 0x04nnnnnn\n", i,cnt, val);
00339 
00340       unsigned chanid= (val >> 16) & 0x1f;
00341       unsigned adc = val & 0x1fff;
00342 
00343       fMadc_trace[i]->Fill(chanid, adc);
00344       if (!fOutputEvent->IsPulser())
00345          fMadc_adc[i][chanid]->Fill(adc);
00346       fOutputEvent->fMadc[i][chanid] = adc; // to output event, store to root tree
00347    }
00348    int trailer=*cursor;
00349    if ((trailer & 0xf0000000) >> 24 != 0xc0)
00350       printf("madc(%d) trailer error: 0x%08x, expected 0xcnnnnnnnn \n",i, trailer);
00351 
00352    //   printf("madc(%d) trailer: 0x%08x \n",i,trailer);
00353    //#endif
00354 }
00355 
00356 void TMbsCrateProc::Process1290(int num, int* pdata, unsigned int len)
00357 {
00358    if (num >= MAX_1290) {
00359       printf ("Wrong V1290 module index %d\n",num);
00360       return;
00361    }
00362 
00363    int expected_geo = 0;
00364 
00365    if (num<0) {
00366       // if number is not specified, try to identify it base on GEO value
00367       expected_geo = T1290Data::FindGeo(pdata, len);
00368       if (expected_geo<=0) {
00369          printf("ERROR: Did not found GEO in the data\n");
00370          return;
00371       }
00372 
00373       num = expected_geo - 9;
00374 
00375       if ((num<0) || (num >= MAX_1290)) {
00376          printf("Wrong GEO value %d found\n", expected_geo);
00377          return;
00378       }
00379 
00380       // printf("Found GEO code %d defined num %d\n", expected_geo, num);
00381 
00382    } else {
00383       expected_geo = num + 9;
00384    }
00385 
00386    // printf("Process1290 num = %d expected GEO = %d len = %u\n", num, expected_geo, len);
00387 
00388    fOutputEvent->fMtdc[num].Unpack(pdata, len, expected_geo);
00389 
00390    if (!fOutputEvent->IsPulser())
00391       fTDC[num].FillHistos(fOutputEvent->fMtdc[num]);
00392 }

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