Skip to content

Commit

Permalink
Merge pull request #1072 from JeffersonLab/davidl_data_format_exceptions
Browse files Browse the repository at this point in the history
Davidl data format exceptions
  • Loading branch information
markito3 authored Mar 7, 2018
2 parents 1ab3681 + 5e1343f commit 83864c3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 17 deletions.
30 changes: 30 additions & 0 deletions src/libraries/DANA/JExceptionDataFormat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// $Id$
//
// File: JExceptionDataFormat.h
// Created: Tue Mar 6 15:57:29 EST 2018
// Creator: davidl (on Linux gluon119.jlab.org 2.6.32-642.3.1.el6.x86_64 x86_64)
//

#ifndef _JExceptionDataFormat_
#define _JExceptionDataFormat_

#include <JANA/jerror.h>
#include <JANA/JException.h>

/// This is a subclass of JException that is used to indicate a
/// parsing error. This was motivated by hdmon needing to catch
/// this specific type of error and set an alarm. hdmon is used
/// for online monitoring and the source is kept in subversion.

class JExceptionDataFormat: public JException{
public:
JExceptionDataFormat(const std::string &txt):JException(txt){}
JExceptionDataFormat(const std::string &txt, const char *file, int line):JException(txt, file, line){}
virtual ~JExceptionDataFormat(){}

protected:

};

#endif // _JExceptionDataFormat_

52 changes: 35 additions & 17 deletions src/libraries/DAQ/DEVIOWorkerThread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "LinkAssociations.h"

#include <swap_bank.h>
#include <DANA/JExceptionDataFormat.h>

using namespace std;
using namespace std::chrono;
Expand Down Expand Up @@ -110,12 +111,21 @@ void DEVIOWorkerThread::Run(void)

if( !current_parsed_events.empty() ) PublishEvents();

} catch( JExceptionDataFormat &e ){
for(auto pe : parsed_event_pool) delete pe; // delete all parsed events any any objects they hold
parsed_event_pool.clear();
current_parsed_events.clear(); // (these are also in parsed_event_pool so were already deleted)
jerr << "Data format error exception caught" << endl;
jerr << "Stack trace follows:" << endl;
jerr << e.getStackTrace() << endl;
jerr << e.what() << endl;
japp->Quit(10);
} catch (exception &e) {
jerr << e.what() << endl;
for(auto pe : parsed_event_pool) delete pe; // delete all parsed events any any objects they hold
parsed_event_pool.clear();
current_parsed_events.clear(); // (these are also in parsed_event_pool so were already deleted)
//exit(-1);
japp->Quit(-1);
}

// Reset and mark us as available for use
Expand Down Expand Up @@ -407,6 +417,7 @@ void DEVIOWorkerThread::ParseEPICSbank(uint32_t* &iptr, uint32_t *iend)
// Unknown tag. Bail
_DBG_ << "Unknown tag 0x" << hex << tag << dec << " in EPICS event!" <<endl;
DumpBinary(istart, iend_epics, 32, &iptr[-1]);
throw JExceptionDataFormat("Unknown tag in EPICS bank", __FILE__, __LINE__);
}

iptr = &iptr[bank_len];
Expand Down Expand Up @@ -452,7 +463,7 @@ void DEVIOWorkerThread::ParseBORbank(uint32_t* &iptr, uint32_t *iend)
if(current_parsed_events.size() != 1){
stringstream ss;
ss << "DEVIOWorkerThread::ParseBORbank called for EVIO event with " << current_parsed_events.size() << " events in it. (Should be exactly 1!)";
throw JException(ss.str(), __FILE__, __LINE__);
throw JExceptionDataFormat(ss.str(), __FILE__, __LINE__);
}

// Create new DBORptrs object and set pointer to it in DParsedEvent
Expand All @@ -468,7 +479,7 @@ void DEVIOWorkerThread::ParseBORbank(uint32_t* &iptr, uint32_t *iend)
if(borevent_len > bank_len){
stringstream ss;
ss << "BOR: Size of bank doesn't match amount of data given (" << borevent_len << " > " << bank_len << ")";
throw JException(ss.str(), __FILE__, __LINE__);
throw JExceptionDataFormat(ss.str(), __FILE__, __LINE__);
}
iend = &iptr[borevent_len]; // in case they give us too much data!

Expand All @@ -477,7 +488,7 @@ void DEVIOWorkerThread::ParseBORbank(uint32_t* &iptr, uint32_t *iend)
if(bor_header != 0x700e01){
stringstream ss;
ss << "Bad BOR header: 0x" << hex << bor_header;
throw JException(ss.str(), __FILE__, __LINE__);
throw JExceptionDataFormat(ss.str(), __FILE__, __LINE__);
}

// Loop over crates
Expand All @@ -491,7 +502,7 @@ void DEVIOWorkerThread::ParseBORbank(uint32_t* &iptr, uint32_t *iend)
if( (crate_header>>16) != 0x71 ){
stringstream ss;
ss << "Bad BOR crate header: 0x" << hex << (crate_header>>16);
throw JException(ss.str(), __FILE__, __LINE__);
throw JExceptionDataFormat(ss.str(), __FILE__, __LINE__);
}

// Loop over modules
Expand Down Expand Up @@ -542,15 +553,15 @@ void DEVIOWorkerThread::ParseBORbank(uint32_t* &iptr, uint32_t *iend)
stringstream ss;
ss << "Unknown BOR module type: " << modType << " (module_header=0x"<<hex<<module_header<<")";
jerr << ss.str() << endl;
throw JException(ss.str(), __FILE__, __LINE__);
throw JExceptionDataFormat(ss.str(), __FILE__, __LINE__);
}
}

// Check that the bank size and data structure size match.
if( module_len > sizeof_dest ){
stringstream ss;
ss << "BOR module bank size does not match structure! " << module_len << " > " << sizeof_dest << " for modType " << modType;
throw JException(ss.str(), __FILE__, __LINE__);
throw JExceptionDataFormat(ss.str(), __FILE__, __LINE__);
}

// Copy bank data, assuming format is the same
Expand Down Expand Up @@ -588,7 +599,7 @@ void DEVIOWorkerThread::ParseTSscalerBank(uint32_t* &iptr, uint32_t *iend)
if(Nwords != Nwords_expected){
_DBG_ << "TS bank size does not match expected!!" << endl;
_DBG_ << "Found " << Nwords << " words. Expected " << Nwords_expected << endl;

throw JExceptionDataFormat("TS bank size does not match expected", __FILE__, __LINE__);
}else{
// n.b. Get the last event here since if this is a block
// of events, the last should be the actual sync event.
Expand Down Expand Up @@ -693,7 +704,7 @@ void DEVIOWorkerThread::ParseBuiltTriggerBank(uint32_t* &iptr, uint32_t *iend)
if( ((*iptr) & mask) != mask ){
stringstream ss;
ss << "Bad header word in Built Trigger Bank: " << hex << *iptr;
throw JException(ss.str(), __FILE__, __LINE__);
throw JExceptionDataFormat(ss.str(), __FILE__, __LINE__);
}

uint32_t tag = (*iptr)>>16; // 0xFF2X
Expand All @@ -704,7 +715,7 @@ void DEVIOWorkerThread::ParseBuiltTriggerBank(uint32_t* &iptr, uint32_t *iend)
if(Mevents == 0) {
stringstream ss;
ss << "DEVIOWorkerThread::ParseBuiltTriggerBank() called with zero events! "<<endl;
throw JException(ss.str(), __FILE__, __LINE__);
throw JExceptionDataFormat(ss.str(), __FILE__, __LINE__);
}


Expand Down Expand Up @@ -765,7 +776,7 @@ void DEVIOWorkerThread::ParseBuiltTriggerBank(uint32_t* &iptr, uint32_t *iend)
for(uint32_t i=2; i<Nwords_per_event; i++) codarocinfo->misc.push_back(*iptr++);

if(iptr > iend){
throw JException("Bad data format in ParseBuiltTriggerBank!", __FILE__, __LINE__);
throw JExceptionDataFormat("Bad data format in ParseBuiltTriggerBank!", __FILE__, __LINE__);
}
}
}
Expand Down Expand Up @@ -873,6 +884,8 @@ void DEVIOWorkerThread::ParseDataBank(uint32_t* &iptr, uint32_t *iend)
cout.flush(); cerr.flush();
DumpBinary(&iptr[-2], iend, 32, &iptr[-1]);
// }
throw JExceptionDataFormat("Unknown bank type in EVIO", __FILE__, __LINE__);

}

iptr = iend_data_block_bank;
Expand Down Expand Up @@ -965,8 +978,7 @@ void DEVIOWorkerThread::ParseCAEN1190(uint32_t rocid, uint32_t* &iptr, uint32_t
_DBG_ << "CAEN1290TDC parser sees more events than CODA header! (>" << current_parsed_events.size() << ")" << endl;
for( auto p : events_by_event_id) cout << "id=" << p.first << endl;
iptr = iend;
exit(-1); // should we exit, or try and continue??
return;
throw JExceptionDataFormat("CAEN1290TDC parser sees more events than CODA header", __FILE__, __LINE__);
}
pe = *pe_iter++;
events_by_event_id[event_id] = pe;
Expand Down Expand Up @@ -1000,6 +1012,7 @@ void DEVIOWorkerThread::ParseCAEN1190(uint32_t rocid, uint32_t* &iptr, uint32_t
break;
default:
cout << "Unknown datatype: 0x" << hex << type << " full word: "<< *iptr << dec << endl;
throw JExceptionDataFormat("Unknown data type for CAEN1190", __FILE__, __LINE__);
}

iptr++;
Expand Down Expand Up @@ -1047,7 +1060,7 @@ void DEVIOWorkerThread::ParseModuleConfiguration(uint32_t rocid, uint32_t* &iptr
for(uint32_t i=0; i< Nvals; i++){
if( iptr >= iend){
_DBG_ << "DAQ Configuration bank corrupt! slot_mask=0x" << hex << slot_mask << dec << " Nvals="<< Nvals << endl;
exit(-1);
throw JExceptionDataFormat("Corrupt DAQ config. bank", __FILE__, __LINE__);
}

daq_param_type ptype = (daq_param_type)((*iptr)>>16);
Expand Down Expand Up @@ -1123,7 +1136,7 @@ void DEVIOWorkerThread::ParseModuleConfiguration(uint32_t rocid, uint32_t* &iptr

default:
_DBG_ << "Unknown module type: 0x" << hex << (ptype>>8) << endl;
exit(-1);
throw JExceptionDataFormat("Unknown module type in configuration bank", __FILE__, __LINE__);
}


Expand Down Expand Up @@ -1191,6 +1204,7 @@ void DEVIOWorkerThread::ParseJLabModuleData(uint32_t rocid, uint32_t* &iptr, uin
while(iptr<iend && ((*iptr) & 0xF8000000) != 0x88000000) iptr++; // Skip to JLab block trailer
iptr++; // advance past JLab block trailer
while(iptr<iend && *iptr == 0xF8000000) iptr++; // skip filler words after block trailer
throw JExceptionDataFormat("Unknown JLab module type", __FILE__, __LINE__);
break;
}
}
Expand Down Expand Up @@ -1383,7 +1397,7 @@ void DEVIOWorkerThread::Parsef250Bank(uint32_t rocid, uint32_t* &iptr, uint32_t
break;
default:
if(VERBOSE>7) cout << " FADC250 unknown data type ("<<data_type<<")"<<" (0x"<<hex<<*iptr<<dec<<")"<<endl;
break;
throw JExceptionDataFormat("Unexpected word type in fADC125 block!", __FILE__, __LINE__);
}
}

Expand Down Expand Up @@ -1738,6 +1752,10 @@ void DEVIOWorkerThread::Parsef125Bank(uint32_t rocid, uint32_t* &iptr, uint32_t
case 15: // Filler (non-data) word
if(VERBOSE>7) cout << " FADC125 ignored data type: " << data_type <<endl;
break;
default:
if(VERBOSE>7) cout << " FADC125 unknown data type ("<<data_type<<")"<<" (0x"<<hex<<*iptr<<dec<<")"<<endl;
throw JExceptionDataFormat("Unexpected word type in fADC125 block!", __FILE__, __LINE__);

}
}

Expand Down Expand Up @@ -1907,7 +1925,7 @@ void DEVIOWorkerThread::ParseF1TDCBank(uint32_t rocid, uint32_t* &iptr, uint32_t
cerr<<endl;
if(iiptr > (iptr+4)) break;
}
throw JException("Unexpected word type in F1TDC block!", __FILE__, __LINE__);
throw JExceptionDataFormat("Unexpected word type in F1TDC block!", __FILE__, __LINE__);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/programs/Analysis/hd_ana/hd_ana.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int main(int narg, char *argv[])
// Run though all events, calling our event processor's methods
app.Run(NULL, 1);

if( app.GetExitCode() ) cerr << "Exit code: " << app.GetExitCode() << endl;
return app.GetExitCode();
}

Expand Down
1 change: 1 addition & 0 deletions src/programs/Analysis/hd_root/hd_root.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int main(int narg, char *argv[])

delete myproc;

if( app.GetExitCode() ) cerr << "Exit code: " << app.GetExitCode() << endl;
return app.GetExitCode();
}

Expand Down

0 comments on commit 83864c3

Please sign in to comment.