//////////////////////////////////// // KRATTA Array Event Unpacker // for the Asy-Eos experiment // TKRATMapping IMPLEMENTATION // March 2012 // revison 3/2012 // E.d.F ver 1.0 // sebastian.kupny@uj.edu.pl // Based on TLANDEvent 09/11/2011 //////////////////////////////////// #include "TKRATMapping.h" ClassImp(TKRATMapping); /// %%%%%%%%%%%%%%%%%%%%%%%%%%% TKratMapping %%%%%%%%%%%%%%%%%%%%%%%%%% TKRATMapping::TKRATMapping( void ) { nMappedElements = 0; fIsMappingDefined = kFALSE; } TKRATMapping::~TKRATMapping() { } Int_t TKRATMapping::Init( const string A_FileName) { Int_t result; result = Init( A_FileName.c_str() ); return result; } Int_t TKRATMapping::Init( const char * A_FileName = NULL) { nMappedElements = 0; if ( A_FileName != NULL ) { strcpy( fFileName, A_FileName ); }else{ cout << "TKRATTARawEvent Warining: No mapping file.. \n\t..Trying read from global variable.. "; strcpy( fFileName , gFileNameDetectorMapping ); } Int_t result = Init_GetMappingFromFile(); if ( result > 0 ) { fIsMappingDefined = kTRUE; } return result; } Int_t TKRATMapping::Init_GetMappingFromFile( void ) { ifstream is; char buffer [100]; int module =0; int channel =0; char column =0; int RowAndPhotodiode = 0; string stringFromFile =""; is.open (fFileName, ios::binary ); if ( is.is_open() ) { while( !is.eof() ) { is.getline (buffer, 100); is >> stringFromFile; if (stringFromFile == "MODULE"){ /// Line looks like:MODULE 02 ON ID 02 # at 0a02 is >> module; } if (stringFromFile == "CHANNEL"){ /// Line looks like: CHANNEL 0 "A30" ON is >> channel; is >> stringFromFile; ///Line looks like:"A30" sscanf(stringFromFile.c_str(), "%*c%c%d%*c", &column, &RowAndPhotodiode ); if (column =='A' || column =='B' || column =='C'|| column =='D'|| column =='E'|| column =='F'|| column =='G'){ mappingArray[nMappedElements][0][0] = module; mappingArray[nMappedElements][0][1] = channel; mappingArray[nMappedElements][1][0] = ( RowAndPhotodiode / 10 ) %10; // Row. {1 .. 5} mappingArray[nMappedElements][1][1] = (int)column - 65; // Column. {A .. G} - ASCII('A') = 65 mappingArray[nMappedElements][1][2] = RowAndPhotodiode % 10; // Photodiode. Last digit is photodiode number: {0, 1 or 2} nMappedElements++; } } } cout << "TKRATTARawEvent: Mapping read from \"" << fFileName << "\" successful.. "; is.close(); }else{ cout << "TKRATTARawEvent Error: Unable to open file \"" << fFileName << "\""<< endl; return -1; } return nMappedElements; } void TKRATMapping::PrintMapping() { if ( fIsMappingDefined ){ cout <<"[FADC_modlue.FADC_channel] "; cout <<" <=> [ COLUMN{A,B,C,D,E,F,G}-ROW{1,2,3,4,5}.PHOTODIODE{0,1,2} ] " << endl; for(int i = 0; i< nMappedElements; i++){ cout <<" [" << mappingArray[i][0][0] << "." << mappingArray[i][0][1] << "] "; cout <<" <=> [" << Char_t(mappingArray[i][1][1] + 65) << "-" << mappingArray[i][1][0] <<"." << mappingArray[i][1][2] << "] " << endl; } } else { cout <<"TKRATMapping::PrintMapping: Object is not defined yet!"; } } EnTRow TKRATMapping::GetPositionRow_Enum(Int_t A_FadcModule, Int_t A_Channel) { EnTRow sPositionRow = UNKNOWN_ROW; for(int i = 0; i< nMappedElements; i++){ if( mappingArray[i][0][0] == A_FadcModule && mappingArray[i][0][1] == A_Channel){ sPositionRow = (( EnTRow ) mappingArray[i][1][0]); } } return sPositionRow; } EnTColumn TKRATMapping::GetPositionColumn_Enum( Int_t A_FadcModule, Int_t A_Channel ) { EnTColumn sPositionColumn = UNKNOWN_COLUMN; for(int i = 0; i< nMappedElements; i++){ if( mappingArray[i][0][0] == A_FadcModule && mappingArray[i][0][1] == A_Channel){ sPositionColumn = (( EnTColumn ) mappingArray[i][1][1] ); } } return sPositionColumn; } EnTPhotodiode TKRATMapping::GetPositionPhotodiode_Enum( Int_t A_FadcModule, Int_t A_Channel ){ EnTPhotodiode sPositionPhotodiode = UNKNOWN_PH; for(int i = 0; i< nMappedElements; i++){ if( mappingArray[i][0][0] == A_FadcModule && mappingArray[i][0][1] == A_Channel){ sPositionPhotodiode = ( (EnTPhotodiode) mappingArray[i][1][2] ); } } return sPositionPhotodiode; } Int_t TKRATMapping::GetPositionRow_Int(Int_t A_FadcModule, Int_t A_Channel){ return ( (Int_t) GetPositionRow_Enum ( A_FadcModule, A_Channel ) ) -1 ; // Changing parameter variation range } Int_t TKRATMapping::GetPositionColumn_Int( Int_t A_FadcModule, Int_t A_Channel ){ return ((Int_t) GetPositionColumn_Enum ( A_FadcModule, A_Channel )); } Int_t TKRATMapping::GetPositionPhotodiode_Int( Int_t A_FadcModule, Int_t A_Channel ){ return ((Int_t) GetPositionPhotodiode_Enum ( A_FadcModule, A_Channel )); }