00001 #ifndef TGET4EVENT_H
00002 #define TGET4EVENT_H
00003
00004 #include "TGo4EventElement.h"
00005 #include "TGo4CompositeEvent.h"
00006 #include <vector>
00007
00008
00009
00010
00011
00012
00013 #include "roc/Message.h"
00014
00015 namespace get4v10 {
00016
00017 enum SysMessageTypes {
00018 SYSMSG_GET4V1_32BIT_0 = 240,
00019 SYSMSG_GET4V1_32BIT_1 = 241,
00020 SYSMSG_GET4V1_32BIT_2 = 242,
00021 SYSMSG_GET4V1_32BIT_3 = 243,
00022 SYSMSG_GET4V1_32BIT_4 = 244,
00023 SYSMSG_GET4V1_32BIT_5 = 245,
00024 SYSMSG_GET4V1_32BIT_6 = 246,
00025 SYSMSG_GET4V1_32BIT_7 = 247,
00026 SYSMSG_GET4V1_32BIT_8 = 248,
00027 SYSMSG_GET4V1_32BIT_9 = 249,
00028 SYSMSG_GET4V1_32BIT_10 = 250,
00029 SYSMSG_GET4V1_32BIT_11 = 251,
00030 SYSMSG_GET4V1_32BIT_12 = 252,
00031 SYSMSG_GET4V1_32BIT_13 = 253,
00032 SYSMSG_GET4V1_32BIT_14 = 254,
00033 SYSMSG_GET4V1_32BIT_15 = 255,
00034 };
00035 }
00036
00037
00039
00040 #define MAX_ROC 15
00041
00042 #define MAX_AUX 4
00043
00044 #define MAX_SYNC 2
00045
00046
00047 #define MAX_GET4 32
00048
00049 #define MAX_GET4_PER_ROC 16
00050
00051 #define NB_CHAN_GET4 4
00052
00053 #define GET4_PRINT 6 // ROC messages
00054
00055 #define GET4_EPOCH_CYCLE_SIZE 0x007FFFFF
00056 #define MAIN_EPOCH_CYCLE_SIZE 0x000FFFFF
00057
00058
00059 #define GET4_SYNC_CYCLE_SIZE 25 // Epochs ( nb-1 unsynchronized, 1 synchronized)
00060 #define MAIN_CLK_SYNC_SIZE 40 // Epochs ( nb-1 unsynchronized, 1 synchronized)
00061
00062 #define NB_SYNC_JUMP_RESET 2
00063
00064 #define NB_BIN_GET4_FTS 128 // bins ( = 2^NB_BITS_FTS)
00065
00066
00067 #include <stdint.h>
00068
00069
00070
00071
00072
00073
00074
00075
00076 class TGet4v1MessageExtended
00077 {
00078 public:
00079
00080 TGet4v1MessageExtended(const roc::Message& msg, ULong64_t fulltime=0 ) :
00081 fxMessage(msg),
00082 fuFulltime(fulltime),
00083 fdFullTime((Double_t)fulltime),
00084 ffTriggerDeltaT(0),
00085 fbIs32Bit(kFALSE),
00086 uRocEpoch( 0 ),
00087 uRocEpochCycle( 0 ),
00088 fbIsEmpty(kFALSE)
00089 {
00090 }
00091
00092 TGet4v1MessageExtended() :
00093 fxMessage(),
00094 fuFulltime(0),
00095 fdFullTime(0),
00096 ffTriggerDeltaT(0),
00097 fbIs32Bit(kFALSE),
00098 uRocEpoch( 0 ),
00099 uRocEpochCycle( 0 ),
00100 fbIsEmpty(kFALSE)
00101 {
00102 }
00103
00104 virtual ~TGet4v1MessageExtended(){}
00105
00106
00107 TGet4v1MessageExtended(const TGet4v1MessageExtended& src) :
00108 fxMessage(src.fxMessage), fuFulltime(src.fuFulltime), fdFullTime(src.fdFullTime),
00109 ffTriggerDeltaT(src.ffTriggerDeltaT), fbIs32Bit(src.fbIs32Bit),
00110 uRocEpoch(src.uRocEpoch), uRocEpochCycle(src.uRocEpochCycle),
00111 fbIsEmpty(src.fbIsEmpty){}
00112
00113
00114
00115
00116
00117
00118
00119 bool operator<(const TGet4v1MessageExtended &rhs) const
00120 { return (fdFullTime < rhs.fdFullTime); }
00121
00122 void Clear()
00123 {
00124
00125 fxMessage = roc::Message();
00126 fuFulltime = 0;
00127 fdFullTime = 0;
00128 ffTriggerDeltaT = 0;
00129 fbIs32Bit = kFALSE;
00130 uRocEpoch = 0;
00131 uRocEpochCycle = 0;
00132 SetEmptyFlag();
00133 }
00134
00135 void SetRocMessage(const roc::Message & source)
00136 {
00137 fxMessage=source;
00138 }
00139
00140 const roc::Message& GetRocMessage() const
00141 {
00142 return fxMessage;
00143 }
00144
00145 UChar_t GetMessageType() const
00146 {
00147 return fxMessage.getMessageType();
00148 }
00149 UChar_t GetSysMesType() const
00150 {
00151 return fxMessage.getSysMesType();
00152 }
00153
00154 void SetFullTime(ULong64_t ts)
00155 {
00156 fuFulltime=ts;
00157 fdFullTime = (Double_t) ts;
00158 }
00159 void SetFullTimeD(Double_t ts)
00160 {
00161 fdFullTime = ts;
00162 }
00163 ULong64_t GetFullTime() const
00164 {
00165 return fuFulltime;
00166 }
00167 Double_t GetFullTimeD() const
00168 {
00169 return fdFullTime;
00170 }
00171
00172 uint16_t GetRocNumber() const
00173 {
00174 return fxMessage.getRocNumber();
00175 }
00176
00177 uint8_t GetGet4Number() const
00178 {
00179 return fxMessage.getGet4Number();
00180 }
00181
00182 uint8_t GetGet4ChNum() const
00183 {
00184 return fxMessage.getGet4ChNum();
00185 }
00186
00187 uint32_t GetGet4Ts() const
00188 {
00189 return fxMessage.getGet4Ts();
00190 }
00191
00192 Bool_t IsRisingGet4Edge() const
00193 {
00194 return fxMessage.getGet4Edge();
00195 }
00196
00197 void SetTriggerDeltaT(float dt)
00198 {
00199 ffTriggerDeltaT=dt;
00200 }
00201
00202 float GetTriggerDeltaT() const
00203 {
00204 return ffTriggerDeltaT;
00205 }
00206
00207 Bool_t SetGet4MessageFull( const roc::Message & DataMessIn, UInt_t rocEpochIn,
00208 UInt_t rocCycleIn)
00209 {
00210 fxMessage = DataMessIn;
00211 uRocEpoch = rocEpochIn;
00212 uRocEpochCycle = rocCycleIn;
00213
00214 if( roc::MSG_GET4 == fxMessage.getMessageType() )
00215 fuFulltime = fxMessage.getMsgFullTime( uRocEpoch );
00216 else if(roc::MSG_SYS == fxMessage.getMessageType() &&
00217 roc::SYSMSG_GET4_EVENT == fxMessage.getSysMesType() )
00218 fuFulltime = fxMessage.FullTimeStamp2(uRocEpoch, (fxMessage.getField(23,12)<<7) )
00219 / 20 + 512;
00220
00221 return kTRUE;
00222 }
00223
00224 Bool_t SetRocEpoch( UInt_t rocEpochIn)
00225 {
00226 uRocEpoch = rocEpochIn;
00227 if( roc::MSG_GET4 == fxMessage.getMessageType() )
00228 fuFulltime = fxMessage.getMsgFullTime( uRocEpoch );
00229 else if(roc::MSG_SYS == fxMessage.getMessageType() &&
00230 roc::SYSMSG_GET4_EVENT == fxMessage.getSysMesType() )
00231 fuFulltime = fxMessage.FullTimeStamp2(uRocEpoch, (fxMessage.getField(23,12)<<7) )
00232 / 20 + 512;
00233 return kTRUE;
00234 }
00235 Bool_t SetRocCycle( UInt_t rocCycleIn)
00236 {
00237 uRocEpochCycle = rocCycleIn;
00238 return kTRUE;
00239 }
00240
00241 UInt_t GetRocEpoch() const
00242 {
00243 return uRocEpoch;
00244 }
00245 UInt_t GetRocCycle() const
00246 {
00247 return uRocEpochCycle;
00248 }
00249
00250 Bool_t RocOrder( const TGet4v1MessageExtended &messageToCompare )const;
00251 Double_t RocSpacing( const TGet4v1MessageExtended &messageToCompare) const;
00252
00253 void Print( unsigned kind = roc::msg_print_Human ) const;
00254 void Print32Bit( unsigned kind = roc::msg_print_Human ) const;
00255
00256
00257 inline void SetGet4Number( UChar_t ucGet4Index) { fxMessage.setGet4Number(ucGet4Index); }
00258 inline void SetEpoch2ChipNumber(UChar_t ucGet4Index) { fxMessage.setEpoch2ChipNumber(ucGet4Index); }
00259
00260
00261 inline UInt_t getFieldBE(roc::Message rawMessage, UInt_t shift, UInt_t len) const
00262 { return (dataBE(rawMessage) >> shift) & ((((UInt_t)1) << len) - 1); }
00263 inline UChar_t getBitBE(roc::Message rawMessage, UInt_t shift) const
00264 { return (dataBE(rawMessage) >> shift) & 1; }
00265 inline ULong64_t dataBE( roc::Message rawMessage) const
00266 { return (((ULong64_t)rawMessage.getField(0, 8) &0x00000000000000FF)<<56)+
00267 ( ((ULong64_t)rawMessage.getField(0, 16) &0x000000000000FF00)<<40)+
00268 ( ((ULong64_t)rawMessage.getField(0, 24) &0x0000000000FF0000)<<24)+
00269 ( ( ((ULong64_t)rawMessage.getField( 8, 24) <<8 ) &0x00000000FF000000)<< 8)+
00270 ( ( ((ULong64_t)rawMessage.getField(16, 24)) << 8)&0x00000000FF000000)+
00271 ( ((ULong64_t)rawMessage.getField(24, 24) )&0x0000000000FF0000)+
00272 ( ((ULong64_t)rawMessage.getField(40, 16) )&0x000000000000FF00)+
00273 ( ((ULong64_t)rawMessage.getField(56, 8) )&0x00000000000000FF);
00274 }
00275
00276 inline UChar_t getGet4V10R32ChipId() const { return ( (fxMessage.getSysMesType() )&0xF ); }
00277 inline UChar_t getGet4V10R32MessageType() const { return getFieldBE(fxMessage, 46, 2); }
00278
00279 inline UInt_t getGet4V10R32EpochNumber() const { return getFieldBE(fxMessage, 17,24); }
00280 inline Bool_t getGet4V10R32SyncFlag() const { return getBitBE(fxMessage, 16); }
00281
00282 inline UInt_t getGet4V10R32SlData() const { return getFieldBE(fxMessage, 16,24); }
00283 inline UChar_t getGet4V10R32SlType() const { return getFieldBE(fxMessage, 40, 2); }
00284 inline Bool_t getGet4V10R32SlEdge() const { return getBitBE(fxMessage, 42); }
00285 inline UChar_t getGet4V10R32SlChan() const { return getFieldBE(fxMessage, 43, 2); }
00286
00287 inline UChar_t getGet4V10R32ErrorData() const { return getFieldBE(fxMessage, 16, 7); }
00288 inline UChar_t getGet4V10R32ErrorChan() const { return getFieldBE(fxMessage, 42, 2); }
00289 inline Bool_t getGet4V10R32ErrorEdge() const { return getBitBE(fxMessage, 44); }
00290
00291 inline UChar_t getGet4V10R32HitTot() const { return getFieldBE(fxMessage, 16, 8); }
00292 inline UChar_t getGet4V10R32HitFt() const { return getFieldBE(fxMessage, 24, 7); }
00293 inline UInt_t getGet4V10R32HitTs() const { return getFieldBE(fxMessage, 31,12); }
00294 inline UInt_t getGet4V10R32HitTimeBin()const { return getFieldBE(fxMessage, 24,19); }
00295 inline UChar_t getGet4V10R32HitChan() const { return getFieldBE(fxMessage, 43, 2); }
00296 inline Bool_t getGet4V10R32HitDllFlag() const { return getBitBE(fxMessage, 45); }
00297
00298 void Set32BitFlag(){ fbIs32Bit = kTRUE; };
00299 Bool_t Is32Bit(){ return fbIs32Bit; };
00300 void SetEmptyFlag(){ fbIsEmpty = kTRUE; };
00301 Bool_t IsEmpty(){ return fbIsEmpty; };
00302 protected:
00303
00304
00305 roc::Message fxMessage;
00306
00307
00308 ULong64_t fuFulltime;
00309 Double_t fdFullTime;
00310
00311
00312
00313 float ffTriggerDeltaT;
00314
00315 Bool_t fbIs32Bit;
00316 UInt_t uRocEpoch;
00317 UInt_t uRocEpochCycle;
00318
00319 Bool_t fbIsEmpty;
00320 };
00321
00322 class Get4v1Hit : public TObject {
00323 public:
00324 Get4v1Hit() : TObject() { Clear(); }
00325 void Clear(Option_t *t="");
00326 void SetFullHit24Bits( TGet4v1MessageExtended& mesTime, TGet4v1MessageExtended& mesTot);
00327 void SetFullHit32Bits( TGet4v1MessageExtended& mesHit );
00328 void SetTime24Bits( TGet4v1MessageExtended& mesTime );
00329 void SetTot24Bits( TGet4v1MessageExtended& mesTot );
00330
00331 TGet4v1MessageExtended GetTimeMessage() { return fTimeMessage; };
00332 TGet4v1MessageExtended GetTotMessage() { return fTotMessage; };
00333
00334 UChar_t GetChan(){ return (kTRUE == fbIs32Bit? fTimeMessage.getGet4V10R32HitChan() : fTimeMessage.GetGet4ChNum()); };
00335 ULong_t GetHitFullTime(){ return fTimeMessage.GetFullTime(); };
00336 Double_t GetHitFullTimeD(){ return fTimeMessage.GetFullTimeD();};
00337 UInt_t GetHitEpoch(){ return fTimeMessage.GetRocEpoch(); };
00338 UInt_t GetHitCycle(){ return fTimeMessage.GetRocCycle(); };
00339
00340 Double_t GetHitTime();
00341 Double_t GetTot(){ return fdTot; };
00342 Int_t GetHitLeadingFTS();
00343 Int_t GetHitTrailingFTS();
00344 Double_t GetTimeDiff( Get4v1Hit& hitToCompare );
00345
00346 Bool_t IsTimeSet(){ return fbTimeSet;};
00347 Bool_t IsTotSet(){ return fbTotSet;};
00348 Bool_t IsComplete(){ return fbTimeSet && fbTotSet;};
00349 Bool_t Is32Bit(){ return fbIs32Bit; };
00350
00351 protected:
00352 Bool_t fbIs32Bit;
00353 void CalculateTot( Double_t d32bTotRange = 25500.0 );
00354
00355 TGet4v1MessageExtended fTimeMessage;
00356 Bool_t fbTimeSet;
00357 TGet4v1MessageExtended fTotMessage;
00358 Bool_t fbTotSet;
00359 Double_t fdTot;
00360
00361 ClassDef(Get4v1Hit,1)
00362 };
00363
00364 class Get4v1Tdc : public TObject {
00365 public:
00366 Get4v1Tdc() : TObject() { Clear(); }
00367 ~Get4v1Tdc();
00368 void Clear(Option_t *t="");
00369 UInt_t Size();
00370
00371 std::vector<Get4v1Hit> fHits[NB_CHAN_GET4];
00372
00373 ClassDef(Get4v1Tdc,1)
00374 };
00375
00376 class Get4v1Event : public TObject {
00377 public:
00378 Get4v1Event() : TObject() { Clear(); }
00379 ~Get4v1Event();
00380 void Clear(Option_t *t="");
00381 Bool_t IsEmpty();
00382 Bool_t HasTrigger();
00383
00384 Get4v1Tdc fGet4Boards[MAX_GET4];
00385
00386 std::vector<TGet4v1MessageExtended> fPureRocMessages[MAX_ROC];
00387
00388
00389
00390 Double_t fdTriggerFullTime[MAX_ROC];
00391
00392 ClassDef(Get4v1Event,1)
00393 };
00394
00395 class TGet4v1Event : public TGo4EventElement {
00396 public:
00397 TGet4v1Event();
00398 TGet4v1Event(const char* name, Short_t id=0);
00399 virtual ~TGet4v1Event();
00400
00402 virtual void Clear(Option_t *t="");
00403
00405 double GetEventTime() const { return fLastGlobalTriggerTm*1e-9; }
00406
00407
00408
00409 ULong64_t CalcGlobalTime(Double_t deltaTrigger);
00410
00411
00412
00413
00414
00415 ULong64_t fLastGlobalTriggerTm;
00416
00417 ULong64_t fMbsEventNumber;
00418
00419 std::vector<Get4v1Event> fEvents;
00420
00421 ClassDef(TGet4v1Event,1)
00422 };
00423 #endif //TGET4V1EVENT_H
00424
00425
00426