00001
00002
00003 #include "TGet4v1Event.h"
00004
00005 #include "TGo4Version.h"
00006 #if __GO4BUILDVERSION__ > 40502
00007 #include "go4iostream.h"
00008 #else
00009 #include "Riostream.h"
00010 #endif
00011
00012 Bool_t TGet4v1MessageExtended::RocOrder( const TGet4v1MessageExtended &messageToCompare) const
00013 {
00014
00015
00016
00017 if( uRocEpochCycle < messageToCompare.GetRocCycle() )
00018 return kTRUE;
00019 else if( uRocEpochCycle > messageToCompare.GetRocCycle() )
00020 return kFALSE;
00021 else if( uRocEpoch < messageToCompare.GetRocEpoch() )
00022 return kTRUE;
00023 else if( uRocEpoch > messageToCompare.GetRocEpoch() )
00024 return kFALSE;
00025 else
00026 {
00027 UInt_t typ1 = fxMessage.getMessageType();
00028 UInt_t typ2 = (messageToCompare.GetRocMessage()).getMessageType();
00029 if( typ1 == roc::MSG_SYS && typ2 == roc::MSG_SYS)
00030 {
00031 if( fxMessage.getField(23,12) <= (messageToCompare.GetRocMessage()).getField(23,12) )
00032 return kTRUE;
00033 else return kFALSE;
00034 }
00035 else if( typ1 == roc::MSG_SYS )
00036 {
00037 if( ((fxMessage.getField(23,12))<<7) <= (messageToCompare.GetRocMessage()).getGet4Ts() )
00038 return kTRUE;
00039 else return kFALSE;
00040 }
00041 else if( typ2 == roc::MSG_SYS)
00042 {
00043 if( fxMessage.getGet4Ts() <= (((messageToCompare.GetRocMessage()).getField(23,12))<<7) )
00044 return kTRUE;
00045 else return kFALSE;
00046 }
00047 else
00048 {
00049 if( fxMessage.getGet4Ts() <= (messageToCompare.GetRocMessage()).getGet4Ts() )
00050 return kTRUE;
00051 else return kFALSE;
00052 }
00053 }
00054 }
00055
00056 Double_t TGet4v1MessageExtended::RocSpacing( const TGet4v1MessageExtended &messageToCompare) const
00057 {
00058
00059
00060
00061 UInt_t typ1 = fxMessage.getMessageType();
00062 UInt_t typ2 = (messageToCompare.GetRocMessage()).getMessageType();
00063 if( roc::MSG_GET4 != typ1 || roc::MSG_GET4 != typ2 )
00064 return -1;
00065
00066 double dSpacing = GET4_BIN_SIZE_IN_PS * (double) ( (double) (messageToCompare.GetRocMessage()).getGet4Ts() -
00067 (double)fxMessage.getGet4Ts() );
00068
00069
00070 if ( uRocEpoch != messageToCompare.GetRocEpoch() )
00071 {
00072 if( uRocEpochCycle != messageToCompare.GetRocCycle() )
00073 {
00074 dSpacing += GET4_EPOCH_IN_PS * (double) ( (double)messageToCompare.GetRocEpoch() -
00075 (double)uRocEpoch +
00076 (double)GET4_CYCLE_IN_EPOCHS * (double) ( (double)messageToCompare.GetRocCycle() -
00077 (double)uRocEpochCycle ) );
00078 }
00079 else
00080 {
00081 dSpacing += GET4_EPOCH_IN_PS * (double) ( (double)messageToCompare.GetRocEpoch() -
00082 (double)uRocEpoch );
00083 }
00084 }
00085
00086 return dSpacing;
00087 }
00088
00089 void TGet4v1MessageExtended::Print( unsigned kind ) const
00090 {
00091 if( roc::MSG_SYS == fxMessage.getMessageType() )
00092 {
00093 UChar_t ucSysMesType = fxMessage.getSysMesType();
00094 if( get4v10::SYSMSG_GET4V1_32BIT_0 <= ucSysMesType &&
00095 get4v10::SYSMSG_GET4V1_32BIT_15 >= ucSysMesType )
00096 {
00097 Print32Bit( kind );
00098 }
00099 else fxMessage.printData( kind, uRocEpoch + GET4_CYCLE_IN_EPOCHS*uRocEpochCycle );
00100 }
00101 else fxMessage.printData( kind, uRocEpoch + GET4_CYCLE_IN_EPOCHS*uRocEpochCycle );
00102
00103 }
00104 void TGet4v1MessageExtended::Print32Bit( unsigned kind ) const
00105 {
00106
00107 TString sPrintout ="";
00108 ULong64_t data = ((ULong64_t)fxMessage.getField( 48, 16 ) )<<48 |
00109 ((ULong64_t)fxMessage.getField( 32, 16 ) )<<32 |
00110 ((ULong64_t)fxMessage.getField( 16, 16 ) )<<16 |
00111 ((ULong64_t)fxMessage.getField( 0, 16 ) );
00112
00113 if( kind & roc::msg_print_Hex )
00114 {
00115 UChar_t* arr = (uint8_t*) &data;
00116 sPrintout += Form("%02X:%02X:%02X:%02X:%02X:%02X ",
00117 arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]);
00118 }
00119
00120 if( kind & roc::msg_print_Prefix )
00121 {
00122 sPrintout += Form( "Msg:%u Roc:%u ", fxMessage.getMessageType(), fxMessage.getRocNumber());
00123 }
00124 if (kind & roc::msg_print_Human)
00125 {
00126 Double_t timeInSec = fxMessage.getMsgFullTimeD(fuFulltime >> 14)/1.e9;
00127 sPrintout += Form( "SysType:%2x Data:%8x @%17.11f : ", fxMessage.getSysMesType(), fxMessage.getSysMesData(), timeInSec);
00128 }
00129 else sPrintout += Form( "SysType:%2x Data:%8x : ", fxMessage.getSysMesType(), fxMessage.getSysMesData());
00130
00131 UInt_t get4_32b_type = getFieldBE(fxMessage, 46, 2);
00132 switch(get4_32b_type)
00133 {
00134 case 0:
00135 {
00136 UInt_t get4_32b_ep_epoch = getFieldBE(fxMessage, 17,24);
00137 UInt_t get4_32b_ep_sync = getBitBE(fxMessage, 16);
00138 sPrintout += Form( "Get4 V1 32 bits, type:0x%02x => Epoch %08d Sync: %1d",
00139 get4_32b_type, get4_32b_ep_epoch, get4_32b_ep_sync );
00140 break;
00141 }
00142 case 1:
00143 {
00144 UInt_t get4_32b_sl_data = getFieldBE(fxMessage, 16, 24);
00145 UInt_t get4_32b_sl_type = getFieldBE(fxMessage, 40, 2);
00146 UInt_t get4_32b_sl_edge = getBitBE(fxMessage, 42);
00147 UInt_t get4_32b_sl_chan = getFieldBE(fxMessage, 43, 2);
00148 sPrintout += Form("Get4 V1 32 bits, type:0x%02x => Slow control Chan:%01d Edge:%01d Type:%01x Data:0x%06x",
00149 get4_32b_type, get4_32b_sl_chan, get4_32b_sl_edge, get4_32b_sl_type, get4_32b_sl_data );
00150 break;
00151 }
00152 case 2:
00153 {
00154 UInt_t get4_32b_er_code = getFieldBE(fxMessage, 16,7);
00155 UInt_t get4_32b_er_chan = getFieldBE(fxMessage, 42,2);
00156 UInt_t get4_32b_er_edge = getBitBE(fxMessage, 44);
00157 sPrintout += Form("Get4 V1 32 bits, type:0x%02x => Error 0x%02x Channel %1d Edge %1d",
00158 get4_32b_type, get4_32b_er_code, get4_32b_er_chan, get4_32b_er_edge );
00159 break;
00160 }
00161 case 3:
00162 {
00163 UInt_t get4_32b_dat_tot = getFieldBE(fxMessage, 16, 8);
00164 UInt_t get4_32b_dat_ft = getFieldBE(fxMessage, 24, 7);
00165 UInt_t get4_32b_dat_ts = getFieldBE(fxMessage, 31,12);
00166 UInt_t get4_32b_dat_chan = getFieldBE(fxMessage, 43, 2);
00167 UInt_t get4_32b_dat_dll = getBitBE(fxMessage, 45);
00168 sPrintout += Form("Get4 V1 32 bits, type:0x%02x => Data Dll %1d Channel %1d Ts:0x%04d Ft:0x%03d Tot:0x%03d",
00169 get4_32b_type, get4_32b_dat_dll, get4_32b_dat_chan, get4_32b_dat_ts,
00170 get4_32b_dat_ft, get4_32b_dat_tot);
00171 break;
00172 }
00173 default:
00174 sPrintout += Form("Get4 V1 32 bits, type:0x%02x ", get4_32b_type );
00175 break;
00176 }
00177 cout<<sPrintout<<endl;
00178 }
00179
00180
00181
00182 void Get4v1Hit::Clear( Option_t *t )
00183 {
00184 fbTimeSet = kFALSE;
00185 fbTotSet = kFALSE;
00186 fdTot = 0.0;
00187 fbIs32Bit = kFALSE;
00188 }
00189 void Get4v1Hit::SetFullHit24Bits( TGet4v1MessageExtended& mesTime, TGet4v1MessageExtended& mesTot)
00190 {
00191 if( kFALSE == mesTime.Is32Bit() && kFALSE == mesTot.Is32Bit() )
00192 {
00193
00194
00195
00196 fTimeMessage = mesTime;
00197 fTotMessage = mesTot;
00198 fbTimeSet = kTRUE;
00199 fbTotSet = kTRUE;
00200 fbIs32Bit = kFALSE;
00201 CalculateTot();
00202 }
00203 }
00204 void Get4v1Hit::SetFullHit32Bits( TGet4v1MessageExtended& mesHit, Double_t d32bTotRange )
00205 {
00206 if( kTRUE == mesHit.Is32Bit() )
00207 {
00208 fTimeMessage = mesHit;
00209 fbTimeSet = kTRUE;
00210 fbTotSet = kTRUE;
00211 fbIs32Bit = kTRUE;
00212 CalculateTot( d32bTotRange );
00213 }
00214 }
00215 void Get4v1Hit::SetTime24Bits( TGet4v1MessageExtended& mesTime )
00216 {
00217 if( kFALSE == mesTime.Is32Bit() )
00218 {
00219 fTimeMessage = mesTime;
00220 fbTimeSet = kTRUE;
00221 fbIs32Bit = kFALSE;
00222
00223
00224
00225 if( kTRUE == IsComplete() )
00226 CalculateTot();
00227 }
00228 }
00229 void Get4v1Hit::SetTot24Bits( TGet4v1MessageExtended& mesTot )
00230 {
00231 if( kFALSE == mesTot.Is32Bit() )
00232 {
00233 fTotMessage = mesTot;
00234 fbTotSet = kTRUE;
00235 fbIs32Bit = kFALSE;
00236
00237
00238
00239 if( kTRUE == IsComplete() )
00240 CalculateTot();
00241 }
00242 }
00243 void Get4v1Hit::CalculateTot( Double_t d32bTotRange )
00244 {
00245 if( kTRUE == fbIs32Bit )
00246 fdTot = ((Double_t)fTimeMessage.getGet4V10R32HitTot() ) * (d32bTotRange/255.0);
00247 else fdTot = fTimeMessage.RocSpacing( fTotMessage);
00248 }
00249 Double_t Get4v1Hit::GetHitTime()
00250 {
00251
00252
00253
00254 if( kTRUE == fbIs32Bit )
00255 return GET4_BIN_SIZE_IN_PS * fTimeMessage.getGet4V10R32HitTimeBin();
00256 else return GET4_BIN_SIZE_IN_PS * (fTimeMessage.GetRocMessage()).getGet4Ts();
00257 }
00258 Int_t Get4v1Hit::GetHitLeadingFTS()
00259 {
00260 if( kTRUE == fbIs32Bit )
00261 return (Int_t)(fTimeMessage.getGet4V10R32HitFt());
00262 else return (Int_t)( ( (fTimeMessage.GetRocMessage()).getGet4Ts() )%NB_BIN_GET4_FTS );
00263 }
00264 Int_t Get4v1Hit::GetHitTrailingFTS()
00265 {
00266 if( kTRUE == fbIs32Bit )
00267 return 0;
00268 else return (Int_t)( ( (fTotMessage.GetRocMessage()).getGet4Ts() )%NB_BIN_GET4_FTS );
00269 }
00270 Double_t Get4v1Hit::GetTimeDiff( Get4v1Hit& hitToCompare )
00271 {
00272 if( kTRUE == fbIs32Bit &&
00273 kTRUE == hitToCompare.Is32Bit() )
00274 {
00275
00276
00277
00278
00279
00280 return (hitToCompare.GetHitFullTimeD() - GetHitFullTimeD())*1000.0;
00281 }
00282 else if( kTRUE == fbIs32Bit )
00283 return -1000000.0;
00284 else if( kTRUE == hitToCompare.Is32Bit() )
00285 return 1000000.0;
00286 else
00287 return fTimeMessage.RocSpacing( (hitToCompare.GetTimeMessage()) );
00288 }
00289
00290
00291 Get4v1Tdc::~Get4v1Tdc()
00292 {
00293 Clear();
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 void Get4v1Tdc::Clear(Option_t *t )
00314 {
00315 for(UInt_t uChannelIndex = 0; uChannelIndex < NB_CHAN_GET4; uChannelIndex++)
00316 {
00317 for(UInt_t uHitIndex = 0; uHitIndex < fHits[uChannelIndex].size(); uHitIndex++)
00318 fHits[uChannelIndex][uHitIndex].Clear();
00319 fHits[uChannelIndex].clear();
00320 }
00321 }
00322 UInt_t Get4v1Tdc::Size()
00323 {
00324 UInt_t uSize = 0;
00325 for(UInt_t uChannelIndex = 0; uChannelIndex < NB_CHAN_GET4; uChannelIndex++)
00326 uSize += fHits[uChannelIndex].size();
00327 return uSize;
00328 }
00329
00330
00331
00332 Get4v1Event::~Get4v1Event()
00333 {
00334 Clear();
00335 }
00336 void Get4v1Event::Clear( Option_t *t )
00337 {
00338
00339 for(UInt_t uGet4Index = 0; uGet4Index < MAX_GET4; uGet4Index++)
00340 fGet4Boards[uGet4Index].Clear( );
00341
00342 for(UInt_t uRocIndex = 0; uRocIndex < MAX_ROC; uRocIndex++)
00343 {
00344 fPureRocMessages[uRocIndex].clear();
00345 fdTriggerFullTime[uRocIndex] = 0.0;
00346 }
00347
00348 fuMbsEventNumber = 0;
00349 fuEventNbInsideMbsEvt = 0;
00350 fuGlobalEventNumber = 0;
00351 fbMbsSyncedEvent = kFALSE;
00352 fuSyncEventNumber = 0;
00353 }
00354 UInt_t Get4v1Event::Size()
00355 {
00356 UInt_t uSize = 0;
00357 for(UInt_t uGet4Index = 0; uGet4Index < MAX_GET4; uGet4Index++)
00358 uSize += fGet4Boards[uGet4Index].Size( );
00359 return uSize;
00360 }
00361 Bool_t Get4v1Event::IsEmpty()
00362 {
00363 Bool_t bEmpty = kTRUE;
00364 for(UInt_t uGet4Index = 0; uGet4Index < MAX_GET4; uGet4Index++)
00365 bEmpty &= ( 0 == fGet4Boards[uGet4Index].Size( ) );
00366 return bEmpty;
00367 }
00368 Bool_t Get4v1Event::HasTrigger()
00369 {
00370 Bool_t bTrigger = kFALSE;
00371 for(UInt_t uRocIndex = 0; uRocIndex < MAX_ROC; uRocIndex++)
00372 if( 0 < fdTriggerFullTime[uRocIndex] )
00373 {
00374 bTrigger = kTRUE;
00375 break;
00376 }
00377 return bTrigger;
00378 }
00379
00381
00382 TGet4v1Event::TGet4v1Event(const char* name, Short_t id) :
00383 TGo4EventElement(name,name,id)
00384 {
00385 cout << "**** TGet4v1Event: Create instance " << name <<" with composite id "<<id<< endl;
00386 }
00387
00388 TGet4v1Event::TGet4v1Event() :
00389 TGo4EventElement()
00390 {
00391 }
00392
00393 TGet4v1Event::~TGet4v1Event()
00394 {
00395 Clear();
00396 }
00397
00398 void TGet4v1Event::Clear( Option_t *t )
00399 {
00400
00401 for(UInt_t uEventIndex = 0; uEventIndex < fEvents.size(); uEventIndex++)
00402 fEvents[uEventIndex].Clear();
00403 fEvents.clear();
00404 SetValid(kFALSE);
00405 }
00406
00407 ULong64_t TGet4v1Event::CalcGlobalTime(Double_t deltaTrigger)
00408 {
00409
00410 ULong64_t rev=fLastGlobalTriggerTm;
00411 rev+=deltaTrigger;
00412 return rev;
00413 }
00414