TV1190Data.cxx
Go to the documentation of this file.00001 #include "TV1190Data.hxx"
00002
00003 #include <iostream>
00004
00005
00006 void TDCMeasurement::SetTrailer(uint32_t trailer){
00007 tdc_trailer_word = trailer;
00008 }
00009
00010
00011
00012 uint32_t TDCMeasurement::GetTDCNumber() const {
00013 if(HasTDCHeader())
00014 return ((tdc_header_word & 0x3000000) >> 24 );
00015 if(HasTDCTrailer())
00016 return ((tdc_trailer_word & 0x3000000) >> 24 );
00017 return 0xdeadbeef;
00018 }
00019
00020
00021 uint32_t TDCMeasurement::GetEventID() const {
00022 if(HasTDCHeader())
00023 return ((tdc_header_word & 0xfff000) >> 12 );
00024 if(HasTDCTrailer())
00025 return ((tdc_trailer_word & 0xfff000) >> 12 );
00026 return 0xdeadbeef;
00027 }
00028
00029
00030 uint32_t TDCMeasurement::GetBunchID() const {
00031 if(HasTDCHeader())
00032 return ((tdc_header_word & 0xfff));
00033 return 0xdeadbeef;
00034 }
00035
00036
00037 uint32_t TDCMeasurement::GetErrors() const{
00038 if(HasTDCErrorWord())
00039 return ((tdc_error_error & 0x7fff));
00040 return 0xdeadbeef;
00041
00042
00043 }
00044
00045
00046 TV1190Data::TV1190Data(int bklen, int bktype, const char* name, void *pdata):
00047 TGenericData(bklen, bktype, name, pdata)
00048 {
00049
00050
00051
00052
00053
00054
00055
00056
00057 if( (GetData32()[0] & 0xf8000000) != 0x40000000)
00058 std::cerr << "First word has wrong identifier; first word = 0x"
00059 << std::hex << GetData32()[0] << std::dec << std::endl;
00060
00061
00062 int found_trailer_word = -1;
00063
00064
00065 uint32_t current_tdc_header =0;
00066 int index_for_trailer = 0;
00067 int index_for_error = 0;
00068 int numberEventsInBank = 0;
00069 fWordCountTotal =0;
00070 for(int i = 0; i < GetSize(); i++){
00071 uint32_t word = GetData32()[i];
00072
00073
00074
00075 if( (word & 0xf8000000) == 0x40000000){
00076 fGlobalHeader.push_back(word);
00077 numberEventsInBank++;
00078 }
00079
00080
00081 if( (word & 0xf8000000) == 0x08000000){
00082 current_tdc_header = word;
00083 }
00084
00085 if( (word & 0xf8000000) == 0x00000000){
00086 fMeasurements.push_back(TDCMeasurement(current_tdc_header,word,numberEventsInBank-1));
00087 }
00088
00089
00090 if( (word & 0xf8000000) == 0x18000000){
00091
00092
00093 for(unsigned int i = index_for_trailer; i < fMeasurements.size(); i++){
00094 fMeasurements[i].SetTrailer(word);
00095 }
00096 index_for_trailer = fMeasurements.size();
00097 }
00098
00099
00100 if( (word & 0xf8000000) == 0x20000000){
00101
00102
00103 std::cout << "Error word: " << std::hex << "0x"<<word<< std::dec << std::endl;
00104 for(unsigned int i = index_for_trailer; i < fMeasurements.size(); i++){
00105 fMeasurements[i].SetErrors(word);
00106 }
00107 index_for_error = fMeasurements.size();
00108 }
00109
00110
00111
00112 if( (word & 0xf8000000) == 0x88000000) fExtendedTriggerTimeTag.push_back((int)(word & 0x07ffffff));
00113
00114
00115 if( (word & 0xf8000000) == 0x80000000){
00116 found_trailer_word = i;
00117 fWordCountTotal += (word & 0x0001fffe0) >> 5;
00118 fStatus.push_back( (word & 0x07000000) >> 24);
00119 }
00120
00121 }
00122
00123 if(found_trailer_word == -1){
00124 std::cerr << "Error in decoding V1190 data; didn't find trailer." << std::endl;
00125 std::cerr << "Bank dump: " << std::endl;
00126 for(int i = 0; i < GetSize(); i++){
00127 uint32_t word = GetData32()[i];
00128 std::cout << "0x"<<std::hex << word << std::dec << std::endl;
00129 }
00130 }
00131 if(found_trailer_word != GetSize()-1)
00132 std::cerr << "Error; did not find trailer on last word of bank. trailer word = " << found_trailer_word
00133 << " last word = " << GetSize()-1 << std::endl;
00134
00135 if(fWordCountTotal != GetSize()){
00136 std::cerr << "Error in decoding V1190 data; word count in all trailers ("<<fWordCountTotal
00137 << ") doesn't match bank size ("<< GetSize() << ")." << std::endl;
00138 }
00139
00140
00141 }
00142
00143 void TV1190Data::Print(){
00144
00145 std::cout << "V1190 decoder for bank " << GetName().c_str() << std::endl;
00146 std::cout << "event counter = " << GetEventCounter() << ", geographic address: " << GetGeoAddress() << std::endl;
00147 std::cout << "Number of events in this bank: " << GetEventsInBank() << std::endl;
00148 for(unsigned int i = 0; i < fMeasurements.size(); i++){
00149 std::cout << "Measurement: " << fMeasurements[i].GetMeasurement() << " for tdc/chan " <<
00150 fMeasurements[i].GetTDCNumber() << "/"<< fMeasurements[i].GetChannel();
00151 if(fMeasurements[i].IsLeading())
00152 std::cout << " (leading edge meas)";
00153 if(fMeasurements[i].IsTrailing())
00154 std::cout << " (trailing edge meas)";
00155
00156 std::cout << "[event_id = " << fMeasurements[i].GetEventID() << ",bunch_id="
00157 << fMeasurements[i].GetBunchID()<< "]" << "Event index=" << fMeasurements[i].GetEventIndex();
00158 if(fMeasurements[i].HasTDCErrorWord())
00159 std::cout << "[errors=0x"<< std::hex << fMeasurements[i].GetErrors() << std::dec << "]";
00160 std::cout << std::endl;
00161 }
00162
00163
00164 }