//////////////////////////////////// // KRATTA Array Event Unpacker // for the Asy-Eos experiment // TKRATRawAEvent IMPLEMENTATION // March 2012 // revison 3/2012 // E.d.F ver 1.0 // sebastian.kupny@uj.edu.pl // Based on TLANDEvent 09/11/2011 //////////////////////////////////// #include "TKRATRawEvent.h" ClassImp(TKRATRawEvent); //______________________________________________________________________ //Constructor TKRATRawEvent::TKRATRawEvent() { fDebugModeLvl = 1; if ( fDebugModeLvl > 0 ){ cout << "TKRATRawEvent constructor....... done" << endl; } /// fKrattaMapping = new TKRATMapping(); /// if( gKRATTAevent == 0) gKRATTAevent = this; ///TODO: Is that here necessary? fPhotodiodesArray = new TClonesArray( "TKRATPhotodiode", 1 ); fRawmulti = 0; //for (int i = 0; i < 135; i++) //{ // new((*fCloneArr)[i]) KPhotodiode( i ); //} } //______________________________________________________________________ TKRATRawEvent::~TKRATRawEvent() { if ( fPhotodiodesArray ) delete fPhotodiodesArray; } ///void TKRATRawEvent::LoadMapping( const TString inF ) ///{ /// cout <<"TKRATRawEvent loading mapping....... "; /// ifstream inFile(inF,ios::in); /// /// Int_t mappedElements = fKrattaMapping->Init( inF.Data() ); /// if ( mappedElements > 0) /// { /// cout<<"......done"<PrintMapping(); ///} //void TKRATRawEvent::GetTimeStamp( Int_t *tsl, Int_t *tsm, Int_t *tsh) //{ // cout <<"TKRATRawEvent getting time stamp....... done" << endl; // return; //} //Int_t TKRATRawEvent::GetEvent( int *start ) //{ // cout << "TKRATRawEvent get event....... done" << endl; // return 0; //} //Int_t TKRATRawEvent::GetKRATTAMultiplicity() //{ // cout <<"TKRATRawEvent getting multiplicity....... done" << endl; // return 0; //} //______________________________________________________________________ void TKRATRawEvent::Clear( void ) { if (fPhotodiodesArray ) { fPhotodiodesArray->Delete(); /// delete, not clear! fRawmulti = 0; fMbsEventNo = 0; fMbsRunNo = 0; } } //______________________________________________________________________ ///Function decode signals from KRATTA subevent given by pointer buffer and with length SubEventArrayLengthLongWord/ ///Parameter A_withPrintingSubeventHeader set in true value allow prints information to standard output. Int_t TKRATRawEvent::ProcessCurrentEventMBS(Int_t * buffer, Int_t SubEventArrayLengthLongWord, TKRATMapping & A_krattaMapping, Bool_t A_withPrintingSubeventHeader ){ Int_t f1[8][1024]; Int_t i_EVENT_SIZE0 = SubEventArrayLengthLongWord; /// SubEventArrayLengthWord now is what it shoudl be - see changes of Paolo (emails) on 2012.11.29 Int_t SubEventArrayLengthWord = 2* SubEventArrayLengthLongWord; ///Int_t i_EVENT_SIZE0 = (SubEventArrayLengthWord / 2 - 1 ) ; /// SubEventArrayLengthWord is the size of subevent + two bytes header. This value is given in words (bytes) but we are using long words (two bytes). So we are dividing by two. See same procedure for Land and MBall Int_t addr_mod = 0; Clear(); if ( fDebugModeLvl > 1 ) cout << "[KRATTA.Debug.2] Event size =" << i_EVENT_SIZE0 << ",\tBufferAddr="<< buffer<< endl; if ( fDebugModeLvl > 3 ) cout << "[KRATTA.Debug.4] SubEventLength( Header+Event [word]) =" << SubEventArrayLengthWord << ",\tBufferAddr="<< buffer<< endl; if ( i_EVENT_SIZE0 < 0 ) { cout << "[TKRATRawEvent:] ProcessCurrentEventMBS Error: SubEventArrayLengthWord is negative: " << SubEventArrayLengthWord << ". Subevent skiped." << endl; return -2; } if ( i_EVENT_SIZE0 == 0 ) { if ( fDebugModeLvl > 3 ) cout << "[TKRATRawEvent:] ProcessCurrentEventMBS Warning: SubEventArrayLengthWord is " << SubEventArrayLengthWord << ". Subevent skiped." << endl; return 0; } if ( ! A_krattaMapping.IsMappingDefined() ) { cout << "[TKRATRawEvent:] ProcessCurrentEventMBS Error: Mapping object reference not setted" << endl; return -1; } TKRATMapping *krattaMapping = &A_krattaMapping; EnTColumn enMappColumn = UNKNOWN_COLUMN; EnTPhotodiode enMappPhot = UNKNOWN_PH; EnTRow enMappRow = UNKNOWN_ROW; const Int_t sNumberOfChannelsInOneFDAC = 8; const Int_t sNumberOfColumnsInArray = KRATTA_COLUMNS; /// In each row is 7 modules - i.e. 7 columns. Int_t numberOfFiredChannels = 0; do{ Int_t i_EVENT_SIZE = (buffer[addr_mod]) & 0xfffffff; Char_t i_1010 = Char_t((buffer[addr_mod]>>28) & 0xf); Int_t i_CHANNEL_MASK = (buffer[addr_mod+1]) & 0xff; Int_t i_PATTERN = (buffer[addr_mod+1]>>8) & 0xffff; Int_t i_RES = (buffer[addr_mod+1]>>25) & 0x3; Int_t i_BOARD_ID = (buffer[addr_mod+1]>>27) & 0x1f; Int_t i_EVENT_COUNTER = (buffer[addr_mod+2]) & 0xffffff; Int_t i_TRIG_TIME_TAG = (buffer[addr_mod+3]); /// Wyznaczenie na podsatwie maski numeru kanalu int ich_indx=0; for(int ich = 0; ich < 8; ich++){ if(i_CHANNEL_MASK & (1 << ich)){ ///Count of fired channel ich_indx++; } } Int_t n_sample = 0; if ( ich_indx > 0 ) { n_sample = 2*(i_EVENT_SIZE-4)/ich_indx; } memset( f1, 0, sizeof(f1) ); ich_indx = 0; for ( int ich = 0; ich < sNumberOfChannelsInOneFDAC; ich++ ){ if( i_CHANNEL_MASK & (1 << ich) ) // if channel fired { if ( fDebugModeLvl > 4 ) cout << "[KRATTA.Debug.5] Raw buffor=["; int ii = 0; for(int is = 0; is < n_sample/2 ; is++){ Int_t i_data_lsb = ( buffer[ addr_mod + 3 + ich_indx * n_sample/2 + is + 1] ) & 0x3fff; f1 [ich][ii] = Int_t ( i_data_lsb ); ii++; Int_t i_data_msb = ( buffer[ addr_mod + 3 + ich_indx * n_sample/2 + is + 1 ] >> 16 ) & 0x3fff; f1 [ich][ii] = Int_t ( i_data_msb ); if ( fDebugModeLvl > 4 ) cout << "," << f1[ich][ii]; ii++; } ich_indx++; if ( fDebugModeLvl > 4 ) cout << "]" << endl; /// Only signals with this length are stored if ( n_sample == 512 || n_sample == 1024 ) { enMappRow = krattaMapping->GetPositionRow_Enum ( i_BOARD_ID, ich ); enMappColumn = krattaMapping->GetPositionColumn_Enum ( i_BOARD_ID, ich ); enMappPhot = krattaMapping->GetPositionPhotodiode_Enum ( i_BOARD_ID, ich ); new((*fPhotodiodesArray)[numberOfFiredChannels]) TKRATPhotodiode( enMappColumn, enMappRow, enMappPhot,n_sample, f1 [ich] ); //TKRATPhotodiode vvvvvvvvv( enMappColumn, enMappRow, enMappPhot,n_sample, f1 [ich] ); //TKRATPhotodiode * ptemp = ( TKRATPhotodiode *) fPhotodiodesArray->AddLast( numberOfFiredChannels ); //ptemp->Set(enMappColumn, enMappRow, enMappPhot,n_sample, f1 [ich] ); //new(fPhotodiodesArray [ numberOfFiredChannels ] ) TKRATPhotodiode( enMappColumn, enMappRow, enMappPhot,n_sample, f1 [ich] ); ++numberOfFiredChannels; } if( A_withPrintingSubeventHeader || fDebugModeLvl > 2 ){ Int_t iMappColumn = krattaMapping->GetPositionColumn_Int ( i_BOARD_ID, ich ); Int_t iMappRow = krattaMapping->GetPositionRow_Int ( i_BOARD_ID, ich ); Int_t iMappPhotodiode = krattaMapping->GetPositionPhotodiode_Int ( i_BOARD_ID, ich ); Int_t iModuleIndexInTab = (KRATTA_ROWS * KRATTA_COLUMNS) * iMappPhotodiode + KRATTA_COLUMNS*iMappRow + iMappColumn; ///Be careful! cout << "[KRATTA.Debug.3] Fired channel FADC[" << i_BOARD_ID << "." << ich << "] "; cout << " Hodoscope["<< Char_t(iMappColumn + 65) << "-"<< iMappRow+1 << "." << iMappPhotodiode << "] Tab index=" << iModuleIndexInTab << ", Size=" << n_sample; if ( n_sample == 512 || n_sample == 1024 ) cout << " (stored)"; cout << endl; } } } addr_mod += i_EVENT_SIZE; } while ( addr_mod < i_EVENT_SIZE0 ); fRawmulti = numberOfFiredChannels; return fRawmulti; } //______________________________________________________________________ Int_t TKRATRawEvent::GetModuleNumber(Int_t row, Int_t col) { Int_t moduleNumber; moduleNumber = KRATTA_COLUMNS * row + col; /// 7*row + col return moduleNumber; } Int_t TKRATRawEvent::GetColumnOfModule(Int_t module) { Int_t column = module % KRATTA_COLUMNS ; return column; } Int_t TKRATRawEvent::GetRowOfModule(Int_t module) { Int_t row = Int_t(module / KRATTA_COLUMNS ); return row; } //______________________________________________________________________ Bool_t TKRATRawEvent::ContainSignalFromPh( Int_t id ){ Bool_t contain = kFALSE; for ( Int_t i = 0; i < fRawmulti ; i++) { if ( ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetId() == id ){ contain = kTRUE; } } return contain; } //______________________________________________________________________ Bool_t TKRATRawEvent::ContainSignalFromPh( Int_t module, Int_t photodiodeInModule ){ Bool_t contain = kFALSE; Int_t column = GetColumnOfModule ( module ); Int_t row = GetRowOfModule ( module ); for ( Int_t i = 0; i < fRawmulti ; i++) { if ( ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetColumn_Int() == column && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetRow_Int() == row && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetPhotodiode_Int() == photodiodeInModule ) { contain = kTRUE; } } return contain; } //______________________________________________________________________ Bool_t TKRATRawEvent::ContainSignalFromPh( Int_t column, Int_t row, Int_t photodiodeInModule ) { Bool_t contain = kFALSE; for ( Int_t i = 0; i < fRawmulti ; i++) { if ( ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetColumn_Int() == column && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetRow_Int() == row && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetPhotodiode_Int() == photodiodeInModule ) { contain = kTRUE; } } return contain; } //______________________________________________________________________ Int_t * TKRATRawEvent::GetSignalArray( Int_t id ){ Int_t * ptr = NULL; for ( Int_t i = 0; i < fRawmulti ; i++) { if ( ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetId() == id ){ ptr = ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetSignalArrayPtr_Int(); } } return ptr; } //______________________________________________________________________ Int_t * TKRATRawEvent::GetSignalArray( Int_t module, Int_t photodiodeInModule ){ Int_t * ptr = NULL; Int_t column = GetColumnOfModule ( module ); Int_t row = GetRowOfModule ( module ); for ( Int_t i = 0; i < fRawmulti ; i++) { if ( ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetColumn_Int() == column && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetRow_Int() == row && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetPhotodiode_Int() == photodiodeInModule ) { ptr = ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetSignalArrayPtr_Int(); } } return ptr; } //______________________________________________________________________ Int_t TKRATRawEvent::GetSignalArraySize( Int_t id ){ Int_t size = 0; for ( Int_t i = 0; i < fRawmulti; i++) { if ( ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetId() == id ){ size = ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetSignalArraySize(); } } return size; } //______________________________________________________________________ Int_t TKRATRawEvent::GetSignalArraySize( Int_t module, Int_t photodiodeInModule ){ Int_t size = 0; Int_t column = GetColumnOfModule ( module ); Int_t row = GetRowOfModule ( module ); for ( Int_t i = 0; i < fRawmulti ; i++) { if ( ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetColumn_Int() == column && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetRow_Int() == row && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetPhotodiode_Int() == photodiodeInModule ) { size = ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetSignalArraySize(); } } return size; } //______________________________________________________________________ TKRATPhotodiode* TKRATRawEvent::GetPhotodiode( Int_t id ) { TKRATPhotodiode* returnPhotoidodePtr = NULL; for ( Int_t i = 0; i < fRawmulti; i++) { if ( ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetId() == id ){ returnPhotoidodePtr = ((TKRATPhotodiode*)fPhotodiodesArray->At(i)); } } return returnPhotoidodePtr; } //______________________________________________________________________ TKRATPhotodiode* TKRATRawEvent::GetPhotodiode( Int_t module, Int_t photodiodeInModule ) { TKRATPhotodiode* returnPhotoidodePtr = NULL; Int_t column = GetColumnOfModule ( module ); Int_t row = GetRowOfModule ( module ); for ( Int_t i = 0; i < fRawmulti ; i++) { if ( ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetColumn_Int() == column && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetRow_Int() == row && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetPhotodiode_Int() == photodiodeInModule ) { returnPhotoidodePtr = ((TKRATPhotodiode*)fPhotodiodesArray->At(i)); } } return returnPhotoidodePtr; } //______________________________________________________________________ TKRATPhotodiode* TKRATRawEvent::GetPhotodiode( Int_t column, Int_t row, Int_t photodiodeInModule ) { TKRATPhotodiode* returnPhotoidodePtr = NULL; for ( Int_t i = 0; i < fRawmulti ; i++) { if ( ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetColumn_Int() == column && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetRow_Int() == row && ( (TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetPhotodiode_Int() == photodiodeInModule ) { returnPhotoidodePtr = ((TKRATPhotodiode*)fPhotodiodesArray->At(i)); } } return returnPhotoidodePtr; } //______________________________________________________________________ TString TKRATRawEvent::ToString(){ TString str; str = Form( "[TKRATRawEvent: mult=%d,arraySize=%d]",fRawmulti, fPhotodiodesArray->GetSize() ); return str; } TString TKRATRawEvent::ToStringPhotodiode( Int_t id ) { TString str=""; for ( Int_t i = 0; i < fRawmulti; i++) { if ( ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->GetId() == id ){ str = ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->ToString(); } } return str; } //______________________________________________________________________ TString TKRATRawEvent::ToStringPhotodiode( void ) { TString str=""; for ( Int_t i = 0; i < fRawmulti; i++) { str += ((TKRATPhotodiode*)fPhotodiodesArray->At(i))->ToString() + "\n"; } return str; } //void TKRATRawEvent::SetId ( Int_t id ) //{ // fEventId = id; //}