00001 #ifndef CSPADPIXCOORDS_CSPAD2X2NDARRRESHAPE_H
00002 #define CSPADPIXCOORDS_CSPAD2X2NDARRRESHAPE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "psana/Module.h"
00021
00022
00023
00024
00025 #include "CSPadPixCoords/GlobalMethods.h"
00026
00027
00028
00029
00030
00031 #include "PSEvt/Source.h"
00032 #include "psddl_psana/cspad2x2.ddl.h"
00033
00034
00035
00036
00037
00038
00039 using namespace std;
00040
00041 namespace CSPadPixCoords {
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 class CSPad2x2NDArrReshape : public Module {
00077 public:
00078
00079
00080
00081 const static uint32_t NRows2x1 = 185;
00082 const static uint32_t NCols2x1 = 388;
00083 const static uint32_t N2x1 = 2;
00084
00085
00086 CSPad2x2NDArrReshape (const std::string& name) ;
00087
00088
00089 virtual ~CSPad2x2NDArrReshape () ;
00090
00091
00092 virtual void beginJob(Event& evt, Env& env);
00093
00094
00095 virtual void beginRun(Event& evt, Env& env);
00096
00097
00098 virtual void beginCalibCycle(Event& evt, Env& env);
00099
00100
00101
00102 virtual void event(Event& evt, Env& env);
00103
00104
00105 virtual void endCalibCycle(Event& evt, Env& env);
00106
00107
00108 virtual void endRun(Event& evt, Env& env);
00109
00110
00111 virtual void endJob(Event& evt, Env& env);
00112
00113
00114 protected:
00115
00116 void printInputParameters();
00117 bool procEvent(Event& evt);
00118 bool procCalib(Env& env);
00119 void put_keys_in_vectors();
00120 void print_in_out_keys();
00121
00122 private:
00123
00124 Pds::Src m_src;
00125 Source m_source;
00126 std::string m_keys_in;
00127 std::string m_keys_out;
00128 unsigned m_print_bits;
00129 unsigned m_count_evt;
00130 unsigned m_count_clb;
00131 unsigned m_count_msg;
00132
00133 std::vector<std::string> v_keys_in;
00134 std::vector<std::string> v_keys_out;
00135
00136
00137
00138
00139
00140
00141 template <typename T>
00142 ndarray<T,3> reshape(const T* data_in) {
00143
00144
00145 ndarray<T,3> out_ndarr = make_ndarray<T>(N2x1, NRows2x1, NCols2x1);
00146
00147 for(size_t r=0; r<NRows2x1; ++r) {
00148 for(size_t c=0; c<NCols2x1; ++c) {
00149 for(size_t n=0; n<N2x1; ++n) out_ndarr[n][r][c] = *data_in++;
00150 }
00151 }
00152
00153 return out_ndarr;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163 template <typename T>
00164 bool procEventForType (Event& evt, size_t i) {
00165
00166
00167 shared_ptr< ndarray<const T,3> > shp_const = evt.get(m_source, v_keys_in[i], &m_src);
00168 if (shp_const) { save3DArrInEvent<T>(evt, m_src, v_keys_out[i], reshape<T>(shp_const->data())); return true; }
00169
00170
00171
00172 shared_ptr< ndarray<T,3> > shp = evt.get(m_source, v_keys_in[i], &m_src);
00173 if (shp) { save3DArrInEvent<T>(evt, m_src, v_keys_out[i], reshape<T>(shp->data())); return true; }
00174
00175 return false;
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185 template <typename T>
00186 bool procCalibForType (Env& env, size_t i) {
00187
00188
00189 shared_ptr< ndarray<const T,3> > shp_const = env.calibStore().get(m_source, &m_src, v_keys_in[i]);
00190 if (shp_const) { save3DArrayInEnv<T>(env, m_src, v_keys_out[i], reshape<T>(shp_const->data())); return true; }
00191
00192
00193
00194 shared_ptr< ndarray<T,3> > shp = env.calibStore().get(m_source, &m_src, v_keys_in[i]);
00195 if (shp) { save3DArrayInEnv<T>(env, m_src, v_keys_out[i], reshape<T>(shp->data())); return true; }
00196
00197 return false;
00198 }
00199
00200
00201
00202
00203 };
00204
00205 }
00206
00207 #endif // CSPADPIXCOORDS_CSPAD2X2NDARRRESHAPE_H