00001 #ifndef __CCAENV1X90DATA_H
00002 #define __CCAENV1X90DATA_H
00003
00008 #ifndef __STL_STRING
00009 #include <string>
00010 #endif
00011 namespace CCAENV1x90Data {
00012
00013
00014
00015 static const unsigned long TYPE_MASK (0xf8000000);
00016 static const unsigned long GLOBAL_HEADER(0x40000000);
00017 static const unsigned long TDC_HEADER (0x08000000);
00018 static const unsigned long TDC_TRAILER (0x18000000);
00019 static const unsigned long MEASUREMENT (0x00000000);
00020 static const unsigned long TDC_ERROR (0x20000000);
00021 static const unsigned long TRIGGER_TIME (0x88000000);
00022 static const unsigned long GLOBAL_TRAILER(0x80000000);
00023 static const unsigned long FILLER_LONG (0xc0000000);
00024
00025
00026
00027 static const unsigned long EVENTCOUNT_MASK (0x07ffffe0);
00028 static const unsigned int EVENT_RSHIFT (0x5);
00029 static const unsigned int GEO_MASK (0x1f);
00030
00031
00032
00033 static const unsigned long TDC_MASK (0x03000000);
00034 static const unsigned int TDC_RSHIFT (24);
00035 static const unsigned long EVENTID_MASK (0x007ff800);
00036 static const unsigned int EVENTID_RSHIFT (12);
00037 static const unsigned int BUNCHID_MASK (0x000007ff);
00038 static const unsigned int TDCWORDCOUNT_MASK (0x000007ff);
00039
00040
00041
00042 static const unsigned int TRAILING_BIT (0x04000000);
00043 static const unsigned long V1190CHANNEL_MASK(0x03f80000);
00044 static const unsigned long V1290CHANNEL_MASK(0x03e00000);
00045 static const unsigned int V1190CHANNEL_RSHIFT(19);
00046 static const unsigned int V1290CHANNEL_RSHIFT(21);
00047 static const unsigned long V1190DATA_MASK (0x0007ffff);
00048 static const unsigned long V1290DATA_MASK (0x001fffff);
00049
00055 static const unsigned long HITLOST_0_FIFO (0x0001);
00056 static const unsigned long HITLOST_0_L1 (0x0002);
00057 static const unsigned long HITERROR_0 (0x0004);
00058 static const unsigned long HITLOST_1_FIFO (0x0008);
00059 static const unsigned long HITLOST_1_L1 (0x0010);
00060 static const unsigned long HITERROR_1 (0x0020);
00061 static const unsigned long HITLOST_2_FIFO (0x0040);
00062 static const unsigned long HITLOST_2_L1 (0x0080);
00063 static const unsigned long HITERROR_2 (0x0100);
00064 static const unsigned long HITLOST_3_FIFO (0x0200);
00065 static const unsigned long HITLOST_3_L1 (0x0400);
00066 static const unsigned long HITERROR_3 (0x0800);
00067 static const unsigned long HITS_EXCEEDED (0x1000);
00068 static const unsigned long EVENTLOST_FIFO (0x2000);
00069 static const unsigned long FATALCHIP_ERROR(0x4000);
00070 static const unsigned long ERROR_MASK (0x7fff);
00071
00072
00073
00074 static const unsigned long TRIGGERTIME_MASK (0x07ffffff);
00075
00076
00077
00078 static const unsigned long TRIGGERLOST_MASK (0x04000000);
00079 static const unsigned long TDCERROR_MASK (0x02000000);
00080 static const unsigned long OVERFLOW_MASK (0x01000000);
00081 static const unsigned long WORDCOUNT_MASK (0x001fffe0);
00082 static const unsigned int WORDCOUNT_RSHIFT (5);
00083
00095 static inline bool
00096 isGlobalHeader(unsigned long Data) {
00097 return ((Data & TYPE_MASK) == GLOBAL_HEADER);
00098 }
00112 static inline bool
00113 isGlobalTrailer(unsigned long datum)
00114 {
00115 return ((datum & TYPE_MASK) == GLOBAL_TRAILER);
00116 }
00128 static inline int
00129 TriggerNumber(unsigned long Header) throw (STD(string))
00130 {
00131 if(!isGlobalHeader(Header)) {
00132 throw STD(string)("CCAENV1x90Data::TriggerNumber - given non global header");
00133 }
00134 else {
00135 return ((Header & EVENTCOUNT_MASK) >> EVENT_RSHIFT);
00136 }
00137 }
00152 static inline unsigned int
00153 BoardNumber(unsigned long Header) throw (STD(string))
00154 {
00155 if((!isGlobalHeader(Header)) && (!isGlobalTrailer(Header))) {
00156 throw STD(string)("CCAENV1x90Data::BoardNumber - given non global header");
00157 }
00158 else {
00159 return (Header & GEO_MASK);
00160 }
00161 }
00162
00177 static inline bool
00178 isTDCHeader(unsigned long Header)
00179 {
00180 return ((Header & TYPE_MASK) == TDC_HEADER);
00181 }
00182
00197 static inline bool
00198 isTDCTrailer(unsigned long header)
00199 {
00200 return ((header & TYPE_MASK) == TDC_TRAILER);
00201 }
00214 static inline bool
00215 isTDCError(unsigned long Datum)
00216 {
00217 return ((Datum & TYPE_MASK) == TDC_ERROR);
00218 }
00219
00232 static inline unsigned int
00233 TDCChip(unsigned long Header) throw (STD(string))
00234 {
00235 if(! isTDCHeader(Header) &&
00236 !isTDCTrailer(Header) &&
00237 !isTDCError(Header)) {
00238 throw STD(string)("CCAENV1x90Data::TDCChip - not data with chip no.");
00239 } else {
00240 return ((Header & TDC_MASK) >> TDC_RSHIFT);
00241 }
00242 }
00243
00255 static inline unsigned int
00256 EventId(unsigned long Header) throw (STD(string))
00257 {
00258 if (!isTDCHeader(Header) && !isTDCTrailer(Header)) {
00259 throw STD(string)("CAENV1x90Data::EventId - not a tdc header");
00260 }
00261 else {
00262 return ((Header & EVENTID_MASK) >> EVENTID_RSHIFT);
00263 }
00264 }
00281 static inline unsigned int
00282 BunchId(unsigned long Header) throw (STD(string))
00283 {
00284 if(!isTDCHeader(Header)) {
00285 throw STD(string)("CCAENV1x90Data::Bundhid - not a tdc header");
00286 }
00287 else {
00288 return (Header & BUNCHID_MASK);
00289 }
00290 }
00291
00303 static inline short
00304 TDCWordCount(unsigned long Header) throw (STD(string))
00305 {
00306 if(!isTDCTrailer(Header)) {
00307 throw STD(string)("CCAENV1x90Data::TDCWordCount not a tdc trailer");
00308 }
00309 else {
00310 return (Header & TDCWORDCOUNT_MASK);
00311 }
00312
00313 }
00326 static inline bool
00327 isMeasurement(unsigned long data)
00328 {
00329 return ((data & TYPE_MASK) == MEASUREMENT);
00330 }
00345 static inline bool
00346 isTrailing(unsigned long datum) throw (STD(string))
00347 {
00348 if(!isMeasurement(datum)) {
00349 throw STD(string)("CCAENV1x90Data::isTrailing not a measurement word");
00350 } else {
00351 return ((datum & TRAILING_BIT) != 0);
00352 }
00353 }
00369 static inline int
00370 ChannelNumber(unsigned long Datum, bool is1190 = true) throw (STD(string))
00371 {
00372 if(!isMeasurement(Datum)) {
00373 throw STD(string)("CCAENV1x90Data::ChannelNumber is not a measurement");
00374 }
00375 else {
00376 unsigned long mask = V1190CHANNEL_MASK;
00377 unsigned long shift= V1190CHANNEL_RSHIFT;
00378
00379
00380
00381
00382 if(!is1190) {
00383 mask = V1290CHANNEL_MASK;
00384 shift= V1290CHANNEL_RSHIFT;
00385 }
00386
00387 return ((Datum & mask) >> shift);
00388 }
00389 }
00407 static inline long
00408 ChannelValue(unsigned long datum, bool is1190=true) throw (STD(string))
00409 {
00410 if (!isMeasurement(datum)) {
00411 throw STD(string)("CCAENV1sx90Data::ChannelValue - is not a measurement");
00412 } else {
00413 unsigned long mask = is1190 ? V1190DATA_MASK :
00414 V1290DATA_MASK;
00415 return (datum & mask);
00416 }
00417 }
00430 static inline unsigned long
00431 TDCErrorBits(unsigned long datum) throw (STD(string))
00432 {
00433 if(!isTDCError(datum)) {
00434 throw STD(string)("CCAENV1x90DATA:: not an error flag word");
00435 }
00436 else {
00437 return datum & ERROR_MASK;
00438 }
00439
00440 }
00457 static inline bool
00458 isTriggerTimeTag(unsigned long datum)
00459 {
00460 return ((datum & TYPE_MASK) == TRIGGER_TIME);
00461 }
00474 static inline unsigned long
00475 ExtendedTriggerTime(unsigned long datum) throw (STD(string))
00476 {
00477 if(!isTriggerTimeTag(datum)) {
00478 throw STD(string)("CCAENV1x90DATA::ExtendedTriggerTime not a trigger time word");
00479 }
00480 else {
00481 return (datum & TRIGGERTIME_MASK);
00482 }
00483 }
00484
00499 static inline bool
00500 Overflow(unsigned long datum) throw (STD(string))
00501 {
00502 if(!isGlobalTrailer(datum)) {
00503 throw STD(string)("CCAENV1x90DATA::Overflow - not a global trailer");
00504 }
00505 else {
00506 return ((datum & OVERFLOW_MASK) == OVERFLOW_MASK);
00507 }
00508 }
00509
00526 static inline bool
00527 Error(unsigned long datum) throw (STD(string))
00528 {
00529 if(!isGlobalTrailer(datum)) {
00530 throw STD(string)("CCAENV1x90DATA::Error - not a global trailer");
00531 }
00532 else {
00533 return ((datum & TDCERROR_MASK) == TDCERROR_MASK);
00534 }
00535 }
00549 static inline bool
00550 Lost(unsigned long datum) throw (STD(string))
00551 {
00552 if(!isGlobalTrailer(datum)) {
00553 throw STD(string)("CAENV1x90DATA::Lost - not a trailer long");
00554 }
00555 else {
00556 return ((datum & TRIGGERLOST_MASK) & TRIGGERLOST_MASK);
00557 }
00558 }
00570 static inline unsigned long
00571 EventSize(unsigned long datum)
00572 {
00573 if(!isGlobalTrailer(datum)) {
00574 throw STD(string)("CAENV1x90DATA::EventSize - not a trailer long");
00575 }
00576 else {
00577 return ((datum & WORDCOUNT_MASK) >> WORDCOUNT_RSHIFT);
00578 }
00579 }
00595 static inline bool isFiller(unsigned long datum)
00596 {
00597 return ((datum & TYPE_MASK) == FILLER_LONG);
00598 }
00602 }
00603
00604
00605
00606 #endif