00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CSPadPixCoords/CSPadNDArrProducer.h"
00017
00018
00019
00020
00021 #include <time.h>
00022
00023
00024
00025
00026 #include "MsgLogger/MsgLogger.h"
00027 #include "PSEvt/EventId.h"
00028
00029
00030
00031
00032
00033
00034
00035 using namespace CSPadPixCoords;
00036 PSANA_MODULE_FACTORY(CSPadNDArrProducer)
00037
00038 using namespace std;
00039
00040
00041
00042
00043
00044 namespace CSPadPixCoords {
00045
00046
00047
00048
00049
00050 CSPadNDArrProducer::CSPadNDArrProducer (const std::string& name)
00051 : Module(name)
00052 , m_source()
00053 , m_inkey()
00054 , m_outkey()
00055 , m_outtype()
00056 , m_is_fullsize()
00057 , m_is_2darray()
00058 , m_print_bits()
00059 , m_count(0)
00060 {
00061
00062 m_source = configSrc("source", ":Cspad.0");
00063 m_inkey = configStr("inkey", "");
00064 m_outkey = configStr("outkey", "cspad_ndarr");
00065 m_outtype = configStr("outtype", "float");
00066 m_is_fullsize = config ("is_fullsize", false);
00067 m_is_2darray = config ("is_2darray", false);
00068 m_print_bits = config ("print_bits", 0);
00069
00070 checkTypeImplementation();
00071 m_config = new CONFIG ( m_source );
00072 }
00073
00074
00075
00076
00077
00078 CSPadNDArrProducer::~CSPadNDArrProducer ()
00079 {
00080 }
00081
00082
00083
00084
00085 void
00086 CSPadNDArrProducer::printInputParameters()
00087 {
00088 WithMsgLog(name(), info, log) {
00089 log << "\nInput parameters:"
00090 << "\nsource : " << m_source
00091 << "\ninkey : " << m_inkey
00092 << "\noutkey : " << m_outkey
00093 << "\nouttype : " << m_outtype
00094 << "\ndtype : " << m_dtype
00095 << "\nis_fullsize : " << m_is_fullsize
00096 << "\nis_2darray : " << m_is_2darray
00097 << "\nprint_bits : " << m_print_bits
00098 << "\n";
00099 }
00100 }
00101
00102
00103
00104
00105 void
00106 CSPadNDArrProducer::beginJob(Event& evt, Env& env)
00107 {
00108 if( m_print_bits & 1 ) printInputParameters();
00109 if( m_print_bits & 16) printSizeOfTypes();
00110 }
00111
00112
00113
00114
00115
00116 void
00117 CSPadNDArrProducer::event(Event& evt, Env& env)
00118 {
00119 ++m_count;
00120
00121 if( ! m_config -> isSet() ) m_config -> setCSPadConfigPars(evt, env);
00122 if( m_count==1 && m_print_bits & 2 ) m_config -> printCSPadConfigPars();
00123
00124 struct timespec start, stop;
00125 int status = clock_gettime( CLOCK_REALTIME, &start );
00126
00127 procEvent(evt, env);
00128
00129 if( m_print_bits & 4 ) {
00130 status = clock_gettime( CLOCK_REALTIME, &stop );
00131 cout << " Time to produce cspad ndarray is "
00132 << stop.tv_sec - start.tv_sec + 1e-9*(stop.tv_nsec - start.tv_nsec)
00133 << " sec" << endl;
00134 }
00135 }
00136
00137
00138
00139 void CSPadNDArrProducer::beginRun(Event& evt, Env& env) {}
00140 void CSPadNDArrProducer::beginCalibCycle(Event& evt, Env& env) {}
00141 void CSPadNDArrProducer::endCalibCycle(Event& evt, Env& env) {}
00142 void CSPadNDArrProducer::endRun(Event& evt, Env& env) {}
00143 void CSPadNDArrProducer::endJob(Event& evt, Env& env) {}
00144
00145
00146
00147 void
00148 CSPadNDArrProducer::procEvent(Event& evt, Env& env)
00149 {
00150
00151 if ( m_dtype == FLOAT and procEventForOutputType<float> (evt) ) return;
00152 if ( m_dtype == DOUBLE and procEventForOutputType<double> (evt) ) return;
00153 if ( m_dtype == INT and procEventForOutputType<int> (evt) ) return;
00154 if ( m_dtype == INT16 and procEventForOutputType<int16_t> (evt) ) return;
00155 }
00156
00157
00158
00159 void
00160 CSPadNDArrProducer::checkTypeImplementation()
00161 {
00162 if ( m_outtype == "float" ) { m_dtype = FLOAT; return; }
00163 if ( m_outtype == "double" ) { m_dtype = DOUBLE; return; }
00164 if ( m_outtype == "int" ) { m_dtype = INT; return; }
00165 if ( m_outtype == "int16" ) { m_dtype = INT16; return; }
00166 if ( m_outtype == "int16_t" ) { m_dtype = INT16; return; }
00167
00168 const std::string msg = "The requested data type: " + m_outtype + " is not implemented";
00169 MsgLog(name(), warning, msg );
00170 throw std::runtime_error(msg);
00171 }
00172
00173
00174
00175 }