/*************************************************************************** * * * $Log: MDdataWordV1290.cpp,v $ * Revision 1.1 2008/04/14 11:40:45 daq * Initial revision * * Revision 1.4 2008/01/30 14:56:55 daq * Changed return types to unsigned * * Revision 1.3 2008/01/25 09:59:40 daq * Change GetGeo type to unsigned * * Revision 1.2 2007/06/28 16:29:01 daq * First working version * * Revision 1.1 2007/06/27 12:00:59 daq * Initial revision * * * * Originally created by J.S. Graulich, June 2007 * * * ***************************************************************************/ #include "MDdataWordV1290.h" MDdataWordV1290::MDdataWordV1290(void *d):MDdataWord(d){} unsigned long32 MDdataWordV1290::GetDataType(){ return ( ( *(unsigned long32*)(_data)>>27 ) & 0x1f ); } unsigned long32 MDdataWordV1290::GetChannel(){ if ( GetDataType() != (uint32_t)DWV1290_Measurement ) _valid = false; else _valid = true; return ( ( *(unsigned long32*)(_data)>>21 ) & 0x1F ); } unsigned long32 MDdataWordV1290::GetMeasurement(){ if ( GetDataType() != (uint32_t)DWV1290_Measurement ) _valid = false; else _valid = true; return ( *(unsigned long32*)(_data) & 0x1FFFFF ); } unsigned long32 MDdataWordV1290::GetMeasurementType(){ if ( GetDataType() != (uint32_t)DWV1290_Measurement ) _valid = false; else _valid = true; return ( ( *(unsigned long32*)(_data)>>26 ) & 0x1 ); } unsigned long32 MDdataWordV1290::GetTdc(){ long32 dt = GetDataType(); if ( dt != (uint32_t)DWV1290_TdcHeader && dt != (uint32_t)DWV1290_TdcTrailer && dt != (uint32_t)DWV1290_TdcError ) _valid = false; else _valid = true; return ( ( *(unsigned long32*)(_data)>>24 ) & 0x3 ); } unsigned long32 MDdataWordV1290::GetEventID(){ long32 dt = GetDataType(); if ( dt != (uint32_t)DWV1290_TdcHeader && dt != (uint32_t)DWV1290_TdcTrailer ) _valid = false; else _valid = true; return ( ( *(unsigned long32*)(_data)>>12 ) & 0x0FFF ); } unsigned long32 MDdataWordV1290::GetBunchID(){ if ( GetDataType() != (uint32_t)DWV1290_TdcHeader ) _valid = false; else _valid = true; return ( *(unsigned long32*)(_data) & 0x0FFF ); } unsigned long32 MDdataWordV1290::GetTriggerTimeTag(){ if ( GetDataType() != (uint32_t)DWV1290_TriggerTimeTag ) _valid = false; else _valid = true; return ( *(unsigned long32*)(_data) & 0x7FFFFFF ); } unsigned long32 MDdataWordV1290::GetWordCount(){ long32 dt = GetDataType(); switch (dt) { case DWV1290_TdcTrailer: return ( *(unsigned long32*)(_data) & 0x0FFF ); break; case DWV1290_GlobalTrailer: return ( ( *(unsigned long32*)(_data)>>5 ) & 0xFFFF ); break; default: return DWV1290_InvalidData; break; } } unsigned long32 MDdataWordV1290::GetStatus(){ if ( GetDataType() != (uint32_t)DWV1290_GlobalTrailer ) _valid = false; else _valid = true; return ( ( *(unsigned long32*)(_data)>>24 ) & 0x7 ); } unsigned long32 MDdataWordV1290::GetGeo(){ long32 dt = GetDataType(); if ( dt != (uint32_t)DWV1290_GlobalHeader && dt != (uint32_t)DWV1290_GlobalTrailer ) _valid = false; else _valid = true; return ( *(unsigned long32*)(_data) & 0x1F ); } unsigned long32 MDdataWordV1290::GetEventCount(){ if ( GetDataType() != (uint32_t)DWV1290_GlobalHeader ) _valid = false; else _valid = true; return ( ( *(unsigned long32*)(_data)>>5 ) & 0x3FFFFF ); } unsigned long32 MDdataWordV1290::GetError(){ if ( GetDataType() != (uint32_t)DWV1290_TdcError ) _valid = false; else _valid = true; return ( *(unsigned long32*)(_data) & 0x7FFF ); } void MDdataWordV1290::Dump(int atTheTime){ cout << *this; return; } //////////////////////////////////////////////////////////////////////// ostream &operator<<(ostream &s,MDdataWordV1290 &dw){ long32 dt= dw.GetDataType(); s << showbase << hex; s << " CAEN V1290 "; switch (dt) { case DWV1290_Measurement: switch(dw.GetMeasurementType()){ case DWV1290_LeadingMeas: s << "Leading edge Measurement: "; break; case DWV1290_TrailingMeas: s << "Trailing edge Measurement: "; break; default: s << "Invalid Measurement!"; s << dec << noshowbase << endl; return s; break; } s << dec << dw.GetMeasurement() << "; Channel: " ; s << dw.GetChannel() << endl; break; case DWV1290_TdcHeader: s << "TDC Header: TDC # " ; s << dec << dw.GetTdc(); s << "; Event ID: " ; s << dw.GetEventID(); s << "; Bunch ID: "; s << dw.GetBunchID()<< endl; break; case DWV1290_TdcTrailer: s << "TDC Trailer: TDC # " ; s << dec << dw.GetTdc(); s << "; Event ID: " ; s << dw.GetEventID(); s << "; Word Count: " ; s << dw.GetWordCount()<< endl; break; case DWV1290_TdcError: s << "TDC Error: " ; s << showbase << hex << dw.GetError() << " TDC #" ; s << dec << dw.GetTdc()<< endl; break; case DWV1290_GlobalHeader: s << "Global Header: Event Count: " ; s << dec << dw.GetEventCount(); s << "; Geo Address: " ; s << showbase << hex << dw.GetGeo() << endl; break; case DWV1290_GlobalTrailer: s << "Global Trailer: Word Count: "; s << dec << dw.GetWordCount(); s << "; Geo Address: " ; s << showbase << hex << dw.GetGeo() << endl << endl; break; case DWV1290_TriggerTimeTag: s << "Trigger Time: "; s << dec << dw.GetTriggerTimeTag()<< endl; break; case DWV1290_Filler: s << "No data"<< endl; break; case DWV1290_InvalidData: s << "Invalid data"<< endl; break; default: s << "Data Type not implemented" << endl; break; } s << dec << noshowbase; return s; }