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

beamtime/gsi-aug12/prod/go4/MBSUNPACK/TMbsCrateProc.cxx (r4864/r3742)

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 #include "TGo4Log.h"
00009 
00010 #include "TTriglogEvent.h"
00011 
00012 // still need this for subevent types:
00013 #include "roc/Message.h"
00014 #include "roc/Board.h"
00015 
00016 #if defined(VERSION_VFTX) || defined(VERSION_VFTX_28)  // For Heidelberg tests!
00017    #include "../mbs/cbmvme0.h"
00018 #else
00019    #include "../mbs/cbmvme.h"
00020 #endif
00021 
00022 const uint32_t vme_setup[MAX__N_MOD*6] = VME__MODULES;
00023 
00024 uint64_t vme_tags[MAX__N_MOD];
00025 
00026 #define CAEN1290_DEBUG 0
00027 #define L1182_DEBUG 0
00028 
00029 TMbsCrateProc::TMbsCrateProc() :
00030    TCBMBeamtimeProc(),
00031    fOutputEvent(0)
00032 {
00033 }
00034 
00035 TMbsCrateProc::TMbsCrateProc(const char* name) :
00036    TCBMBeamtimeProc(name),
00037    fOutputEvent(0)
00038 {
00039    TGo4Log::Info("TMbsCrateProc: Create instance %s", name);
00040 
00041    TString obname, obtitle;   
00042 
00043    fPar = (TMbsCrateParam*) MakeParameter("MbsCratePar", "TMbsCrateParam");
00044    
00045    // v1290 histograms
00046 
00047    iCaenEnabled = 0;
00048    for (int n=0;n<MAX_1290;n++)
00049       if( 1 == fPar->uCaenTdcHistosEnabled[n] )
00050       {
00051          if( kTRUE == fPar->bCaenDebug || kTRUE == fPar->bCaenTriggerTime )
00052             fTDC[n].MakeHistos(this, fPar->bCaenDebug, fPar->bCaenTriggerTime, Form("TDC%d",n));
00053          else {
00054             fTDC[n].MakeHistos(this, Form("TDC%d",n));
00055             if( CAEN1290_DEBUG )
00056                fTDC[n].MakeDebugHistos(this, Form("TDC%d",n));
00057          }
00058          iCaenEnabled++;
00059       }
00060 
00061    if( 1 < iCaenEnabled && 1 == fPar->uCaenCoincidenceMap)
00062    {
00063       /*
00064       fAllTDC_chanMapL = MakeTH2('I', "CAEN/chanMap_CaenTdcL", "Channel (L) during same event?",
00065             MAX_1290*T1290Data::NumChan, -0.5, MAX_1290*T1290Data::NumChan-0.5,
00066             MAX_1290*T1290Data::NumChan, -0.5, MAX_1290*T1290Data::NumChan-0.5,
00067            "Channel 1 []", "Channel 2[]", "Events []");
00068       */
00069       iMapIndex = 0;
00070       for( Int_t iModule1 = 0; iModule1 < MAX_1290; iModule1 ++)
00071          for( Int_t iModule2 = iModule1; iModule2 < MAX_1290; iModule2 ++)
00072          {
00073             if( MAX_1290*(MAX_1290+1)/2 < iMapIndex )
00074             {
00075                TGo4Log::Info("****Mbs unpacker: Error creating caen mapping histos: index out of boundary : %d / %d (tdc #%d VS tdc #%d)",
00076                      iMapIndex, MAX_1290*(MAX_1290+1)/2, iModule1, iModule2);
00077                break;
00078             }
00079             fTDC_chanMapL[ iMapIndex ] =
00080                      MakeTH2('I', Form("CAEN/Mapping/Mapp%d_%dCaen", iModule1, iModule2 ),
00081                                   Form("Channel during same event?, Tdc %d VS Tdc %d", iModule1, iModule2),
00082                                   T1290Data::NumChan, -0.5, T1290Data::NumChan - 0.5,
00083                                   T1290Data::NumChan, -0.5, T1290Data::NumChan - 0.5,
00084                                   Form("Channel Tdc #%d []", iModule1),
00085                                   Form("Channel Tdc #%d []", iModule2),"Events []");
00086             iMapIndex++;
00087          }
00088    }
00089 
00090    for (int n=0;n<MAX_965;n++)
00091       if( 1 == fPar->uCaenQdcHistosEnabled[n] )
00092          for (int ch=0;ch<MQDC_t::NumChan;ch++) {
00093             obname.Form("QDC%d/Charge%d_%d",n,n,ch);
00094             obtitle.Form("Charge of QDC %d channel %d",n,ch);
00095             fQdc_Charge[n][ch] = MakeTH1('I',obname.Data(),obtitle.Data(),4096,1,4096,"charge");
00096          }
00097 
00098    for (int n=0;n<MAX_FPGA_TDC;n++)
00099       if( 1 == fPar->uVftxHistosEnabled[n] )
00100          for (int ch=0;ch<FPGA_TDC_NBCHAN;ch++) {
00101             obname.Form("FPGA_TDC%d/FPGA_TDC%d_Ch%d", n, n, ch);
00102             obtitle.Form("Fine counter of TDC%d channel %d", n, ch);
00103             fFPGA_Ch[n][ch] = MakeTH1('I', obname.Data(), obtitle.Data(), 0x800, 0, 0x800, "cnt");
00104          }
00105 
00106    // 1182 histograms
00107    for (int n=0;n<MAX_1182;n++)
00108       if( 1 == fPar->uLecroyQdcHistosEnabled[n] )
00109          for (int ch=0;ch<NUM_1182_CH;ch++) {
00110             obname.Form("118%d/118%d_channel%d", n+2, n+2, ch);
00111             obtitle.Form("118%d Channel %d", n+2, ch);
00112             f1182h[n][ch] = MakeTH1('I', obname.Data(), obtitle.Data(), 1024, 0, 4096.);
00113          }
00114 
00115 
00116    // QFW histograms
00117    if( 1 == fPar->uQFWHistosEnabled )
00118    {
00119       fQFWcnt = MakeTH1('I', "QFW/QFWcnt", "Counts in QFW channels", 4, 0, 4, "cnt");
00120       fQFWerr = MakeTH1('I', "QFW/QFWerr", "Error counts in QFW channels", 4, 0, 4, "err");
00121 
00122       fQFWInfo = new TLatex(0.5,0.5,"-- demo text --");
00123       fQFWInfo->SetName("QFWInfo");
00124       fQFWInfo->SetNDC();
00125       AddObject(fQFWInfo);
00126    }
00127 
00128    for (int n=0;n<MAX__N_MOD;n++) {
00129       if (n != (int)vme_setup[n*6]) {
00130          TGo4Log::Error("Wrong setup in cbmvme.h file in row %d",n);
00131          exit(1);
00132       }
00133 
00134       vme_tags[n] = (((uint64_t) vme_setup[n*6+5]) << 32) | vme_setup[n*6+4];
00135 
00136       if ((n>0) && (vme_tags[n]==0)) {
00137          TGo4Log::Error("Wrong setup in cbmvme.h - zero tag in row %d", n);
00138          exit(1);
00139       }
00140    }
00141 
00142    // Initial value of event number
00143    iLastEventNumber = -1;
00144 
00145    TGo4Log::Info("TMbsCrateProc - Histograms created");
00146 }
00147 
00148 TMbsCrateProc::~TMbsCrateProc()
00149 {
00150    TGo4Log::Info("Last Event: %d", iLastEventNumber);
00151    cout << "**** TMbsCrateProc: Delete instance " << endl;
00152 }
00153 
00154 void TMbsCrateProc::InitEvent(TGo4EventElement* outevnt)
00155 {
00156    TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00157    if(btevent)
00158    {
00159       // since output event object is never discarded within processor lifetime,
00160       // we just search for subevent by name once to speed up processing
00161       if(fOutputEvent==0)
00162          fOutputEvent=dynamic_cast<TMbsCrateEvent*>(btevent->GetSubEvent("MBSCRATE"));
00163    }
00164    else
00165    {
00166 
00167       fOutputEvent= dynamic_cast<TMbsCrateEvent*>(outevnt);
00168    }
00169    if(fOutputEvent==0) {
00170       GO4_STOP_ANALYSIS_MESSAGE("**** TMbsCrateProc: Fatal error: output event is not a TMbsCrateEvent!!! STOP GO4");
00171    }
00172 }
00173 
00174 void TMbsCrateProc::ProcessSubevent(TGo4MbsSubEvent* subevt)
00175 {
00176 // uncomment this to test with previous beamtime lmds:
00177    if (subevt->GetProcid() == roc::proc_Triglog) {
00178       if( -1 == iLastEventNumber )
00179       {
00180          iLastEventNumber = GetEventNumber();
00181          TGo4Log::Info("First Event: %d", iLastEventNumber);
00182       }
00183          else iLastEventNumber =  GetEventNumber();
00184 
00185       UInt_t lwords = subevt->GetIntLen();
00186       Int_t  indx = 0;
00187       if(  4+ NUM_SCALERS*N_SCALERS_CH < lwords)
00188       {
00189          indx = 4+ NUM_SCALERS*N_SCALERS_CH;
00190          fOutputEvent->fTriglogInputPattern = subevt->Data(indx++);
00191 
00192          if( indx < subevt->GetIntLen() )
00193             fOutputEvent->fTriglogReferenceClock = subevt->Data(indx++) ;
00194       }
00195    }
00196    if (subevt->GetProcid() == roc::proc_COSY_Nov11) {
00197 // comment this to test with previous beamtime lmds:
00198 //   if (subevt->GetProcid() == roc::proc_GSI_Aug12) {
00199       // MBS data from GSI beamtime, August 11
00200       // subevt->GetControl() == 9 from Master MBS, subevt->GetControl() == 10 from Slave MBS
00201 
00202       Int_t *pdata = subevt->GetDataField();
00203       UInt_t lwords = subevt->GetIntLen();
00204 
00205       // printf("CERN subevent Control %u TOTALLEN = %u\n", subevt->GetControl(), lwords);
00206 
00207       Int_t* tagpos[MAX__N_MOD];
00208       Int_t taglen[MAX__N_MOD];
00209 
00210       for (int n=0;n<MAX__N_MOD;n++) {
00211          tagpos[n] = 0;
00212          taglen[n] = 0;
00213       }
00214 
00215       int lasttag = -1;
00216 
00217       for (UInt_t cur = 0; cur < lwords; ++cur) {
00218          uint64_t* ptag = (uint64_t*) pdata;
00219          bool find = false;
00220 
00221          for (int ntag=1;ntag<MAX__N_MOD;ntag++)
00222             if ((*ptag == vme_tags[ntag]) && (vme_tags[ntag]!=0)) {
00223                if (lasttag>=0) {
00224                   taglen[lasttag] = pdata - tagpos[lasttag];
00225                   lasttag = -1;
00226                }
00227 
00228                if (tagpos[ntag]==0) {
00229                   pdata+=2; cur+=1;
00230                   tagpos[ntag] = pdata;
00231                   lasttag = ntag;
00232                } else {
00233                   TGo4Log::Error("FORMAT ERROR found tag %lld twice\n", vme_tags[ntag]);
00234                   pdata+=2; cur+=1;
00235                }
00236 
00237                find = true;
00238                break;
00239             }
00240 
00241          if (!find) pdata++;
00242       }
00243 
00244       if (lasttag>=0)
00245          taglen[lasttag] = pdata - tagpos[lasttag];
00246 
00247       // for (int ntag=0;ntag<numtags;ntag++)
00248       //    if (tagpos[ntag])
00249       //       printf("TAG %d POS %lu LEN %d\n", ntag, tagpos[ntag] - p0, taglen[ntag]);
00250 
00251 
00252       // if (GetTriggerNumber()==8) {
00253       //   fOutputEvent->SetValid(kFALSE);
00254       //   return;
00255       // }
00256 
00257 
00258       // actually process data in subroutines:
00259 
00260       if (tagpos[VME__ID_1182] && taglen[VME__ID_1182])
00261          Process1182(0, tagpos[VME__ID_1182], taglen[VME__ID_1182]);  // 1182
00262       if (tagpos[VME__ID_1183] && taglen[VME__ID_1183])
00263          Process1182(1, tagpos[VME__ID_1183], taglen[VME__ID_1183]);  // 1183
00264 
00265       for (int tdc=VME__ID_TDC1;tdc<=VME__ID_TDC8;tdc++)
00266          if (tagpos[tdc] && taglen[tdc])
00267             Process1290(tdc-VME__ID_TDC1, tagpos[tdc], taglen[tdc]);  // all TDCs
00268 
00269       for (int qdc=VME__ID_QDC1;qdc<=VME__ID_QDC2;qdc++)
00270          if (tagpos[qdc] && taglen[qdc])
00271             Process965(qdc-VME__ID_QDC1, tagpos[qdc], taglen[qdc]);  // all QDCs
00272 
00273       for (int fpga=VME__ID_FPGA1;fpga<=VME__ID_FPGA11;fpga++)
00274          if (tagpos[fpga] && taglen[fpga])
00275             ProcessVFTX(fpga-VME__ID_FPGA1, (uint32_t*) tagpos[fpga], taglen[fpga]);  // all FPGAs
00276 
00277       if (tagpos[VME__ID_QFW] && taglen[VME__ID_QFW])
00278          ProcessQFW((uint32_t*)tagpos[VME__ID_QFW], taglen[VME__ID_QFW]);  // QFW
00279 
00280       if (tagpos[VME__ID_SCOM] && taglen[VME__ID_SCOM])
00281          ProcessScalOrMu((uint32_t*)tagpos[VME__ID_SCOM], taglen[VME__ID_SCOM]);  // Scaler Or Multiplicity
00282 
00283       if( 1 < iCaenEnabled && 1 == fPar->uCaenCoincidenceMap)
00284          for (Int_t iCaentdc1 = 0; iCaentdc1 < MAX_1290; iCaentdc1++)
00285             if( 1 == fPar->uCaenTdcHistosEnabled[iCaentdc1] )
00286                for (Int_t iChannel1 = 0; iChannel1 < T1290Data::NumChan; iChannel1++)
00287                {
00288                   // Go back to index for VFTX internal map
00289                   iMapIndex = MAX_1290*(MAX_1290+1)/2
00290                            - (MAX_1290-iCaentdc1)*((MAX_1290-iCaentdc1)+1)/2;
00291 
00292                   if( MAX_1290*(MAX_1290+1)/2 < iMapIndex )
00293                   {
00294                      TGo4Log::Info("****Vftx monitor: Error filling mapping histos: index out of boundary : %d / %d (tdc #%d VS tdc #%d)",
00295                            iMapIndex, MAX_1290*(MAX_1290+1)/2, iCaentdc1, iCaentdc1);
00296                      return;
00297                   } // if( MAX_1290*(MAX_1290+1)/2 < iMapIndex )
00298 
00299                   //if( 0 < fOutputEvent->fMtdc[iCaentdc1].hit_lead[iChannel1] &&
00300                   //    0 < fOutputEvent->fMtdc[iCaentdc1].hit_trail[iChannel1] )
00301                   if( 0 < fOutputEvent->fMtdc[iCaentdc1].hit_lead[iChannel1] )
00302                   {
00303                      for (Int_t iChannel2 = iChannel1+1; iChannel2 < T1290Data::NumChan; iChannel2++)
00304                         //if( 0 < fOutputEvent->fMtdc[iCaentdc1].hit_lead[iChannel2] &&
00305                         //    0 < fOutputEvent->fMtdc[iCaentdc1].hit_trail[iChannel2])
00306                         if( 0 < fOutputEvent->fMtdc[iCaentdc1].hit_lead[iChannel2] )
00307                            /*
00308                            fAllTDC_chanMapL->Fill( iCaentdc1*T1290Data::NumChan + iChannel1,
00309                                                   iCaentdc1*T1290Data::NumChan + iChannel2);
00310                                                   */
00311                            fTDC_chanMapL[iMapIndex] ->Fill( iChannel1, iChannel2);
00312 
00313                      for (Int_t iCaentdc2 = iCaentdc1+1; iCaentdc2 < MAX_1290; iCaentdc2++)
00314                      {
00315                         // Find index for corresponding VFTX against VFTX map
00316                         iMapIndex = MAX_1290*(MAX_1290+1)/2
00317                                  - (MAX_1290-iCaentdc1)*((MAX_FPGA_TDC-iCaentdc1)+1)/2
00318                                  + (iCaentdc2 - iCaentdc1);
00319                         if( MAX_1290*(MAX_1290+1)/2 < iMapIndex )
00320                         {
00321                            TGo4Log::Info("****Vftx monitor: Error filling mapping histos: index out of boundary : %d / %d (tdc #%d VS tdc #%d)",
00322                                  iMapIndex, MAX_1290*(MAX_1290+1)/2, iCaentdc1, iCaentdc2);
00323                            return;
00324                         } // if( MAX_1290*(MAX_1290+1)/2 < iMapIndex )
00325 
00326                         if( 1 == fPar->uCaenTdcHistosEnabled[iCaentdc2] )
00327                            for (Int_t iChannel2 = 0; iChannel2 < T1290Data::NumChan; iChannel2++)
00328                               //if( 0 < fOutputEvent->fMtdc[iCaentdc2].hit_lead[iChannel2] &&
00329                               //    0 < fOutputEvent->fMtdc[iCaentdc2].hit_trail[iChannel2] )
00330                               if( 0 < fOutputEvent->fMtdc[iCaentdc2].hit_lead[iChannel2]  )
00331                               /*
00332                                  fAllTDC_chanMapL->Fill( iCaentdc1*T1290Data::NumChan + iChannel1,
00333                                                         iCaentdc2*T1290Data::NumChan + iChannel2);
00334                               */
00335                                  fTDC_chanMapL[iMapIndex] ->Fill( iChannel1, iChannel2);
00336                      } // for (Int_t iCaentdc2 = iCaentdc1+1; iCaentdc2 < MAX_1290; iCaentdc2++)
00337                   } // if( 0 < fOutputEvent->fMtdc[iCaentdc1].hit_lead[iChannel1] && same for trail )
00338                } // for (Int_t iChannel1 = 0; iChannel1 < T1290Data::NumChan; iChannel1++)
00339 
00340       fOutputEvent->SetValid(kTRUE);
00341    }
00342 }
00343 
00344 
00345 
00346 
00347 void TMbsCrateProc::Process1182(int num, int* pdata, int len)
00348 {
00349    if (len < 2 + NUM_1182_CH ) {
00350       cout <<"TBeamMonitorProc:Process1182 data length"<< len << "not sufficient!" <<endl;
00351       return;
00352    }
00353 
00354    if (num>=MAX_1182) {
00355       cout << "Wrong ID=" << num << " of 1182 module" << endl;
00356       return;
00357    }
00358 
00359    // skip event header:
00360    int header = *pdata++;
00361    if (L1182_DEBUG)  printf("1182 header:0x%0x \n",header);
00362 
00363    // skip status
00364    int status = *pdata++;
00365    if (L1182_DEBUG)
00366       printf("1182 status:0x%0x :  \n"
00367             "        conversion complete    (bit0): 0x%x\n"
00368             "        conversion in progress (bit1): 0x%x\n"
00369             "        front(1)/rear(0) panel (bit2): 0x%x\n"
00370             "        Event buffer not full  (bit3): 0x%x\n"
00371             "        Event count       (bits 4..7): 0x%x\n"
00372             "        should be 0            (bit8): 0x%x\n"
00373             "        should be 0            (bit9): 0x%x\n",
00374             status, status & 1, (status >> 1) & 1 , (status >> 2) & 1, (status >> 3) & 1,
00375             (status >> 4) & 0xf,  (status >> 8) & 1, (status >> 9) & 1);
00376 
00377    for(int ch=0;ch<NUM_1182_CH;++ch) {
00378       int val = *pdata++;
00379       
00380       if( 1 == fPar->uLecroyQdcHistosEnabled[num] )
00381          f1182h[num][ch]->Fill(val);
00382 
00383       fOutputEvent->fData1182[num][ch] = val; // output event to root tree
00384    }
00385 
00386    fOutputEvent->SetValid(kTRUE);
00387 }
00388 
00389 void TMbsCrateProc::Process1290(int num, int* pdata, unsigned int len)
00390 {
00391    if (num >= MAX_1290) {
00392       cout << "Wrong 1290 index " << num << endl;
00393       return;
00394    }
00395 
00396    int expected_geo = 0;
00397 
00398    if (num<0) {
00399       // if number is not specified, try to identify it base on GEO value
00400       expected_geo = T1290Data::FindGeo(pdata, len);
00401       if (expected_geo<=0) {
00402          printf("ERROR: Did not found GEO in the data\n");
00403          return;
00404       }
00405 
00406       switch (expected_geo) {
00407          case 5: num = 8; break;
00408          case 6: num = 9; break;
00409          case 7: num = 10; break;
00410          case 8: num = 11; break;
00411          case 9: num = 12; break;
00412          case 10: num = 13; break;
00413          case 11: num = 14; break;
00414          default:
00415             printf("Unsupported GEO code %d\n", expected_geo);
00416             return;
00417       }
00418 
00419       // printf("Found GEO code %d defined num %d\n", expected_geo, num);
00420 
00421    } else {
00422       switch(num) {
00423          case 0: expected_geo = 8; break;
00424          case 1: expected_geo = 9; break;
00425          case 2: expected_geo = 10; break;
00426          case 3: expected_geo = 11; break;
00427          case 4: expected_geo = 12; break;
00428          case 5: expected_geo = 13; break;
00429          case 6: expected_geo = 14; break;
00430          case 7: expected_geo = 15; break;
00431        }
00432    }
00433    // printf("Process1290 num = %d expected GEO = %d len = %u\n", num, expected_geo, len);
00434 
00435    fOutputEvent->fMtdc[num].Unpack(pdata, len, expected_geo);
00436 
00437    if( 1 == fPar->uCaenTdcHistosEnabled[num] )
00438    {
00439       if( kTRUE == fPar->bCaenDebug || kTRUE == fPar->bCaenTriggerTime )
00440          fTDC[num].FillHistos(fOutputEvent->fMtdc[num], fPar->bCaenDebug, fPar->bCaenTriggerTime);
00441       else
00442       {
00443          fTDC[num].FillHistos(fOutputEvent->fMtdc[num]);
00444          if( CAEN1290_DEBUG )
00445             fTDC[num].FillDebugHistos(fOutputEvent->fMtdc[num]);
00446       }
00447    }
00448 
00449    fOutputEvent->SetValid(kTRUE);
00450 }
00451 
00452 void TMbsCrateProc::Process965(int num, int* pdata, unsigned int len)
00453 {
00454         int geo, crate, count;
00455         Int_t timeOffset;
00456         int data;
00457         
00458         if (num >= MAX_965) {
00459                 cout << "Wrong 965 index " << num << endl;
00460                 return;
00461         }
00462         geo = 0;
00463         timeOffset = 0;
00464         data = *pdata++;
00465         len--;
00466         count = 0;
00467         if (num<0) {
00468                 // if number is not specified, try to identify it base on GEO value
00469                 geo = MQDC_t::FindGeo(pdata, &count, &crate);
00470                 if (geo<=0) {
00471                         printf("ERROR: Did not found GEO in the data\n");
00472                         return;
00473                 }
00474                 switch (geo) {
00475                         case 0: num = 0; break;
00476                         case 1: num = 1; break;
00477                         case 2: num = 2; break;
00478                         default:
00479                                 printf("Unsupported GEO code %d\n", geo);
00480                                 return;
00481                 }
00482         }
00483         else
00484         {
00485                 if(((data>>24) & 0x7) == 0x2)
00486                 {
00487                         count = (data >> 8) & 0x3f;
00488                 }
00489                 switch(num) {
00490                         case 0: geo = 0; break;
00491                         case 1: geo = 1; break;
00492                         case 2: geo = 2; break;
00493                 }
00494         }
00495         fOutputEvent->fMqdc[num].Unpack(pdata, count, geo);
00496         
00497    if( 1 == fPar->uCaenQdcHistosEnabled[num] )
00498       for (int ch=0; ch<MQDC_t::NumChan; ch++) {
00499          if(fOutputEvent->fMqdc[num].charge[ch]>0)
00500             fQdc_Charge[num][ch]->Fill(fOutputEvent->fMqdc[num].charge[ch]);
00501        }
00502         
00503         fOutputEvent->SetValid(kTRUE);
00504 }
00505 
00506 void TMbsCrateProc::ProcessVFTX(int num, uint32_t* pdata, unsigned int len)
00507 {
00508    if ((num<0) || (num>=MAX_FPGA_TDC)) 
00509    {
00510       TGo4Log::Error("Error VFTX number %d out of bound (max %d) ", num, MAX_FPGA_TDC);
00511       return;
00512    }
00513 
00514    uint32_t l_dat = *pdata++; // module header
00515    if ( (l_dat & TDC_EVT_HEADER_KEY_MASK)>>TDC_EVT_HEADER_KEY_SHIFT != TDC_EVT_HEADER_KEYWORD ) 
00516    {
00517       TGo4Log::Warn("this is not a vftx %d header, jumping this sub-event...", num);
00518       //return;
00519    }
00520    FPGA_TDC_header header;
00521    uint32_t l_nr_cha   = (l_dat & TDC_EVT_HEADER_NB_MASK);
00522    header.nr_data = l_nr_cha;
00523    header.mod_nr = ((l_dat & TDC_EVT_HEADER_MOD_MASK) >> TDC_EVT_HEADER_MOD_SHIFT); 
00524    if (l_nr_cha+2 != len && l_nr_cha+2 + 256 != len)
00525    {
00526      TGo4Log::Warn("wrong length in vftx %d header, jumping this sub-event... %d vs %d", num, l_nr_cha+2, len);
00527      // Return commented: MBS vftxlib.c for gsi aug 12 not compatible with too many data in event: 
00528      // only 8 bit where used to code event size => effective limitation to 256 hits then loop
00529       //return;
00530    }
00531    
00532    l_dat = *pdata++;  // vulom tdc fifo header
00533    if (l_dat & TDC_FIFO_MESSAGE_TYPE) 
00534    {
00535       header.fpga_fifo_tt = (l_dat & TDC_FIFO_HEADER_TRIG_TYPE) >> TDC_FIFO_HEADER_TRIG_TYPE_SHIFT;
00536       header.fpga_fifo_ct = (l_dat & TDC_FIFO_HEADER_TRIG_TIME) >> TDC_FIFO_HEADER_TRIG_TIME_SHIFT;
00537       header.fpga_fifo_nd = (l_dat & TDC_FIFO_HEADER_DATA_CNT);
00538    } // if (l_dat & TDC_FIFO_MESSAGE_TYPE) 
00539    else 
00540    {
00541       TGo4Log::Warn("vftx %d fifo header missing... ", num);
00542    }
00543    
00544       
00545    // cout << "mod: " << num << " ct: " << header.fpga_fifo_ct << endl;
00546    fOutputEvent->fFPGAHEAD[num].push_back(header);
00547    // cout << "TDC" << num << " , data items: " << header.nr_data << endl;
00548    // cout << "trigger ct: " << header.fpga_fifo_ct << "data nb: " << header.fpga_fifo_nd << endl;
00549    while (l_nr_cha-- > 0) 
00550    {
00551       uint32_t l_da0 = *pdata++;
00552 
00553       FPGA_TDC_hit hit;
00554       if ((l_da0 & TDC_FIFO_MESSAGE_TYPE) == TDC_FIFO_MESSAGE_TYPE) 
00555       {
00556          TGo4Log::Warn("wrong data item in vftx %d: type %d (message %08x, header %08x), jumping this sub-event...", 
00557                        num, (l_da0 & TDC_FIFO_MESSAGE_TYPE)>>TDC_FIFO_MESSAGE_TYPE_SHIFT, l_da0, l_dat);
00558          TGo4Log::Warn("Message: tt %01u ct %5u nd %3u", 
00559                       (l_da0 & TDC_FIFO_HEADER_TRIG_TYPE) >> TDC_FIFO_HEADER_TRIG_TYPE_SHIFT,
00560                       (l_da0 & TDC_FIFO_HEADER_TRIG_TIME) >> TDC_FIFO_HEADER_TRIG_TIME_SHIFT,
00561                       (l_da0 & TDC_FIFO_HEADER_DATA_CNT) );
00562          TGo4Log::Warn("Header : tt %01u ct %5u nd %3u", 
00563                       (l_dat & TDC_FIFO_HEADER_TRIG_TYPE) >> TDC_FIFO_HEADER_TRIG_TYPE_SHIFT,
00564                       (l_dat & TDC_FIFO_HEADER_TRIG_TIME) >> TDC_FIFO_HEADER_TRIG_TIME_SHIFT,
00565                       (l_dat & TDC_FIFO_HEADER_DATA_CNT) );
00566          return;
00567       }
00568       hit.ch_ix        = (l_da0 & TDC_FIFO_DATA_CHAN) >> TDC_FIFO_DATA_CHAN_SHIFT; //4-5 bit
00569       if (hit.ch_ix > FPGA_TDC_NBCHAN - 1)
00570          TGo4Log::Warn("channel number larger then %d found in vftx %d", FPGA_TDC_NBCHAN -1, num);
00571          
00572       hit.future_bit   = (l_da0 & TDC_FIFO_FUTURE_BIT) >> TDC_FIFO_FUTURE_BIT_SHIFT;  //  1 bit
00573       hit.coarse_ct    = (l_da0 & TDC_FIFO_COARSE_CT) >> TDC_FIFO_COARSE_CT_SHIFT;   // 15 bit
00574       hit.ch_tim       = (l_da0 & TDC_FIFO_FINE_CT);        // 10 bit, 11th bit empty
00575 
00576       // cout << "data: "<< l_nr_cha << " ch: " << hit.ch_ix << " ct: " << hit.coarse_ct;
00577       // cout << " ft: " << hit.ch_tim << " fut: " << hit.future_bit << endl;
00578       fOutputEvent->fFPGA[num].push_back(hit);
00579       
00580       if( 1 == fPar->uVftxHistosEnabled[num] )
00581          if (hit.ch_ix<FPGA_TDC_NBCHAN)
00582             fFPGA_Ch[num][hit.ch_ix]->Fill(hit.ch_tim);
00583     } // while (l_nr_cha-- > 0) 
00584     
00585     //cout<<" FPGA TDC num "<<num<<" finished"<<endl;
00586    fOutputEvent->SetValid(kTRUE);
00587 }
00588 
00589 void TMbsCrateProc::ProcessQFW(uint32_t* pdata, unsigned int len)
00590 {
00591    if (len!=9) {
00592       TGo4Log::Error("Wrong QFW format");
00593       return;
00594    }
00595 
00596    for (int n=0;n<4;n++) {
00597       fOutputEvent->fQFW.counters[n] = *pdata++;
00598       if( 1 == fPar->uQFWHistosEnabled )
00599          fQFWcnt->SetBinContent(n+1, fOutputEvent->fQFW.counters[n]);
00600    }
00601 
00602    TString txt = "#splitline";
00603 
00604    for (int n=0;n<4;n++) {
00605       fOutputEvent->fQFW.errcnt[n] = *pdata++;
00606       if( 1 == fPar->uQFWHistosEnabled )
00607          fQFWerr->SetBinContent(n+1, fOutputEvent->fQFW.errcnt[n]);
00608 
00609       txt+=Form("{#scale[2.0]{#color[2]{Ch%d cnt:%10u err:%10u}}}", n, fOutputEvent->fQFW.counters[n], fOutputEvent->fQFW.errcnt[n]);
00610    }
00611 
00612    fOutputEvent->fQFW.setup = *pdata;
00613 
00614    txt+=Form("{#scale[2.0]{#color[2]{Setup: %d}}}", fOutputEvent->fQFW.setup);
00615 
00616    if( 1 == fPar->uQFWHistosEnabled )
00617       fQFWInfo->SetText(0.2, 0.5, txt.Data());
00618 
00619    fOutputEvent->SetValid(kTRUE);
00620 }
00621 
00622 void TMbsCrateProc::ProcessScalOrMu(uint32_t* pdata, unsigned int len)
00623 {
00624    if( 16 == SCALORMU_NB_SCAL )
00625    {
00626       if (len != SCALORMU_NB_SCAL) {
00627          TGo4Log::Error("Wrong Scaler Or Multiplicity sub-event length: %u instead of %d",
00628                len, SCALORMU_NB_SCAL);
00629          return;
00630       }
00631       if( 1 == fPar->uDebug )
00632          TGo4Log::Info("Scaler Or Multiplicity sub-event found!");
00633       for( Int_t iScalerInd=0; iScalerInd < SCALORMU_NB_SCAL; iScalerInd++)
00634          fOutputEvent->fScalOrMu.uScaler[iScalerInd] = (UInt_t)*pdata++;
00635    }
00636       else
00637       {
00638          if (len != SCALORMU_NB_SCAL + 1) {
00639             TGo4Log::Error("Wrong Scaler Or Multiplicity sub-event length: %u instead of %d",
00640                   len, SCALORMU_NB_SCAL + 1);
00641             return;
00642          }
00643          if( 1 == fPar->uDebug )
00644             TGo4Log::Info("Scaler Or Multiplicity sub-event found!");
00645          for( Int_t iScalerInd=0; iScalerInd < SCALORMU_NB_SCAL; iScalerInd++)
00646             fOutputEvent->fScalOrMu.uScaler[iScalerInd] = (UInt_t)*pdata++;
00647          fOutputEvent->fScalOrMu.uReferenceClock = (UInt_t)*pdata++;
00648       }
00649 }
00650 

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