00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CSPadPixCoords/CSPad2x2NDArrReshape.h"
00017
00018
00019
00020
00021 #include <time.h>
00022 #include <sstream>
00023
00024
00025
00026
00027 #include "MsgLogger/MsgLogger.h"
00028 #include "PSEvt/EventId.h"
00029
00030
00031
00032
00033
00034
00035
00036 using namespace CSPadPixCoords;
00037 PSANA_MODULE_FACTORY(CSPad2x2NDArrReshape)
00038
00039 using namespace std;
00040
00041
00042
00043
00044
00045 namespace CSPadPixCoords {
00046
00047
00048
00049
00050
00051 CSPad2x2NDArrReshape::CSPad2x2NDArrReshape (const std::string& name)
00052 : Module(name)
00053 , m_source()
00054 , m_keys_in()
00055 , m_keys_out()
00056 , m_print_bits()
00057 , m_count_evt(0)
00058 , m_count_clb(0)
00059 , m_count_msg(0)
00060 {
00061 m_source = configSrc("source", ":Cspad2x2");
00062 m_keys_in = configStr("keys_in", "");
00063 m_keys_out = configStr("keys_out", "");
00064 m_print_bits = config ("print_bits", 0);
00065
00066 put_keys_in_vectors();
00067
00068
00069 }
00070
00071
00072
00073
00074
00075 CSPad2x2NDArrReshape::~CSPad2x2NDArrReshape ()
00076 {
00077 }
00078
00079
00080
00081
00082 void
00083 CSPad2x2NDArrReshape::printInputParameters()
00084 {
00085 WithMsgLog(name(), info, log) {
00086 log << "\nInput parameters:"
00087 << "\nsource : " << m_source
00088 << "\nkeys_in : " << m_keys_in
00089 << "\nkeys_out : " << m_keys_out
00090 << "\nprint_bits : " << m_print_bits
00091 << "\n";
00092 }
00093 }
00094
00095
00096
00097
00098 void
00099 CSPad2x2NDArrReshape::beginJob(Event& evt, Env& env)
00100 {
00101 if( m_print_bits & 1 ) printInputParameters();
00102 if( m_print_bits & 2 ) print_in_out_keys();
00103 if( m_print_bits & 16) printSizeOfTypes();
00104 }
00105
00106
00107
00108
00109
00110 void
00111 CSPad2x2NDArrReshape::event(Event& evt, Env& env)
00112 {
00113 ++m_count_evt;
00114
00115 procEvent(evt);
00116
00117 if( m_count_clb == 0 ) {
00118 if(procCalib(env)) m_count_clb++;
00119 }
00120 }
00121
00122
00123
00124 void CSPad2x2NDArrReshape::beginRun(Event& evt, Env& env)
00125 {
00126 m_count_clb = 0;
00127 }
00128
00129
00130
00131 void CSPad2x2NDArrReshape::beginCalibCycle(Event& evt, Env& env) {}
00132 void CSPad2x2NDArrReshape::endCalibCycle(Event& evt, Env& env) {}
00133 void CSPad2x2NDArrReshape::endRun(Event& evt, Env& env) {}
00134 void CSPad2x2NDArrReshape::endJob(Event& evt, Env& env) {}
00135
00136
00137
00138 void
00139 CSPad2x2NDArrReshape::put_keys_in_vectors()
00140 {
00141 v_keys_in .reserve(50);
00142 v_keys_out .reserve(50);
00143
00144 std::stringstream ss(m_keys_in);
00145 std::string key_in;
00146 std::string key_out;
00147
00148 if(m_keys_in.empty()) {
00149 MsgLog(name(), warning, "The list of input keys in keys_in is empty. "
00150 << "At lease one input key needs to be specified.");
00151 throw std::runtime_error("Check CSPad2x2NDArrReshape parameters in the configuration file!");
00152 }
00153
00154 if(m_keys_out.empty()) {
00155
00156
00157 do { ss >> key_in;
00158 size_t pos = key_in.find(':');
00159 if( pos != std::string::npos ) key_out = std::string(key_in, 0, pos);
00160 else key_out = key_in + ":2x185x388";
00161
00162
00163
00164
00165
00166 v_keys_in .push_back(key_in);
00167 v_keys_out.push_back(key_out);
00168
00169 } while( ss.good() );
00170
00171 } else {
00172
00173
00174 std::stringstream ss_out(m_keys_out);
00175
00176 do { ss >> key_in; v_keys_in .push_back(key_in); } while( ss.good() );
00177 do { ss_out >> key_out; v_keys_out.push_back(key_out); } while( ss_out.good() );
00178
00179
00180
00181
00182
00183
00184 if(v_keys_in.size() != v_keys_out.size()) {
00185 MsgLog(name(), warning, "The list of output keys: (" << m_keys_out
00186 << ") is not empty, \nbut their number: " << v_keys_out.size()
00187 <<" does not equal to the number: " << v_keys_in.size()
00188 <<" of the input keys: (" << m_keys_in << ").");
00189 throw std::runtime_error("Check CSPad2x2NDArrReshape parameters in the configuration file!");
00190 }
00191 }
00192 }
00193
00194
00195
00196 void
00197 CSPad2x2NDArrReshape::print_in_out_keys()
00198 {
00199 std::vector<std::string>::iterator it_in = v_keys_in.begin();
00200 std::vector<std::string>::iterator it_out = v_keys_out.begin();
00201
00202 std::stringstream ss; ss << "\n List of input/output keys for [185x388x2] -> [2x185x388] conversion:";
00203
00204 for ( ; it_in != v_keys_in.end(); ++it_in, ++it_out)
00205 ss << "\n key_in: " << std::setw(16) << std::left << *it_in
00206 << " key_out: " << std::setw(16) << std::left << *it_out;
00207 ss << '\n';
00208
00209 MsgLog(name(), info, ss.str());
00210 }
00211
00212
00213
00214 bool
00215 CSPad2x2NDArrReshape::procEvent(Event& evt)
00216 {
00217 bool is_found = false;
00218
00219 for(size_t i=0; i<v_keys_out.size(); ++i) {
00220 if ( procEventForType<int16_t> (evt, i) ) { is_found = true; continue; }
00221 if ( procEventForType<float> (evt, i) ) { is_found = true; continue; }
00222 if ( procEventForType<double> (evt, i) ) { is_found = true; continue; }
00223 if ( procEventForType<int> (evt, i) ) { is_found = true; continue; }
00224 }
00225
00226 if(m_print_bits && !is_found && ++m_count_msg < 11) {
00227 MsgLog(name(), info, "ndarray is not available in the eventStore, event:" << m_count_evt
00228 << " source:" << m_source << " keys:" << m_keys_in);
00229 if (m_count_msg == 10) MsgLog(name(), warning, "STOP WARNINGS for source:" << m_source << " keys:" << m_keys_in);
00230 }
00231
00232 return is_found;
00233 }
00234
00235
00236
00237 bool
00238 CSPad2x2NDArrReshape::procCalib(Env& env)
00239 {
00240 bool is_found = false;
00241
00242 for(size_t i=0; i<v_keys_out.size(); ++i) {
00243 if ( procCalibForType<int16_t> (env, i) ) { is_found = true; continue; }
00244 if ( procCalibForType<float> (env, i) ) { is_found = true; continue; }
00245 if ( procCalibForType<double> (env, i) ) { is_found = true; continue; }
00246 if ( procCalibForType<int> (env, i) ) { is_found = true; continue; }
00247 }
00248
00249 if(m_print_bits && !is_found && ++m_count_msg < 11) {
00250 MsgLog(name(), info, "ndarray is not available in the calibStore, event:" << m_count_evt
00251 << " source:" << m_source << " keys:" << m_keys_in);
00252 if (m_count_msg == 10) MsgLog(name(), warning, "STOP WARNINGS for source:" << m_source << " keys:" << m_keys_in);
00253 }
00254
00255 return is_found;
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 }