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