[537] | 1 | #include "machdefs.h"
|
---|
| 2 |
|
---|
| 3 | //---- System et stdc++ include files
|
---|
| 4 | #include <stdio.h>
|
---|
| 5 | #include <stdlib.h>
|
---|
| 6 | #include <math.h>
|
---|
| 7 | #include <ctype.h>
|
---|
| 8 | #include <string.h>
|
---|
| 9 | #include <iostream>
|
---|
| 10 | #include <fstream>
|
---|
| 11 | #include <complex>
|
---|
| 12 |
|
---|
| 13 | #include <typeinfo>
|
---|
| 14 | #include <string>
|
---|
| 15 | #include <vector>
|
---|
| 16 | #include <map>
|
---|
| 17 | #include <functional>
|
---|
| 18 | #include <list>
|
---|
| 19 |
|
---|
| 20 | //---- Sophya include files
|
---|
| 21 | #include "sopnamsp.h"
|
---|
| 22 | #include "basetools.h"
|
---|
| 23 | #include "systools.h"
|
---|
| 24 | #include "sutils.h"
|
---|
| 25 | #include "ntools.h"
|
---|
| 26 | #include "array.h"
|
---|
| 27 | #include "histats.h"
|
---|
| 28 |
|
---|
| 29 | //---- Spiapp include files
|
---|
| 30 | #include "nobjmgr.h"
|
---|
| 31 | #include "servnobjm.h"
|
---|
| 32 |
|
---|
| 33 | //---- Include files from additionnal modules
|
---|
| 34 |
|
---|
| 35 | //---- function to compare bits on double
|
---|
| 36 | int_8 BitCmp64(double v,int_8 flg)
|
---|
| 37 | {return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;}
|
---|
| 38 |
|
---|
| 39 | //---- function for Adding and displaying Objects
|
---|
| 40 | void Keep_Object(AnyDataObj & obj, string const & nom)
|
---|
| 41 | {
|
---|
| 42 | string name = nom;
|
---|
| 43 | NamedObjMgr om;
|
---|
| 44 | if (om.GetObj(name))
|
---|
| 45 | cerr << "KeepObj()/Warning Already kept object " << endl;
|
---|
| 46 | else om.AddObj(obj, name);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | void Display_Object(AnyDataObj & obj, string const & opt, string const & nom)
|
---|
| 50 | {
|
---|
| 51 | string name = nom;
|
---|
| 52 | NamedObjMgr om;
|
---|
| 53 | if (!om.GetObj(name))
|
---|
| 54 | om.AddObj(obj, name);
|
---|
| 55 | om.DisplayObj(name, opt);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | //---- function for getting and setting ObjectManager variables
|
---|
| 59 | void Set_ObjMgrVar(MuTyV v, string const & nom)
|
---|
| 60 | {
|
---|
| 61 | NamedObjMgr om;
|
---|
| 62 | om.SetVar(nom, (string)v);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | MuTyV Get_ObjMgrVar(const char * nom)
|
---|
| 66 | {
|
---|
| 67 | string name = nom; NamedObjMgr om;
|
---|
| 68 | MuTyV v = om.GetVar(name);
|
---|
| 69 | return v;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | //---- Macro for Objects and variables saving
|
---|
| 73 | #define KeepObj(obj) Keep_Object(obj, #obj)
|
---|
| 74 | #define GetOMVar(var) Get_ObjMgrVar( #var )
|
---|
| 75 | #define SetOMVar(var) Set_ObjMgrVar(var, #var )
|
---|
| 76 |
|
---|
| 77 | //---- Macro Displaying objects and command execution
|
---|
| 78 | #define DispObj(obj, att) Display_Object(obj, att, #obj);
|
---|
| 79 |
|
---|
| 80 | #define ExecCmd(cmd) srvo.ExecuteCommand(cmd);
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | //-------------------------------------------------//
|
---|
| 85 | //----------------- User Functions ----------------//
|
---|
| 86 | //-------------------------------------------------//
|
---|
| 87 |
|
---|
| 88 | extern "C" {
|
---|
| 89 | int doreduc( vector<string>& args );
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | int doreduc( vector<string>& args )
|
---|
| 93 | {
|
---|
| 94 | // Some definitions to help using spiapp;
|
---|
| 95 | NamedObjMgr omg;
|
---|
| 96 | Services2NObjMgr& srvo = *omg.GetServiceObj();
|
---|
| 97 |
|
---|
| 98 | //-------------- Object List --------------
|
---|
| 99 | //Number of objects = 2
|
---|
| 100 | string ___nomobj;
|
---|
| 101 |
|
---|
[556] | 102 | ___nomobj = "specv0";
|
---|
| 103 | TVector< r_4 > * ___specv0 = dynamic_cast< TVector< r_4 > * >(omg.GetObj(___nomobj));
|
---|
| 104 | if(___specv0==NULL) throw NullPtrError("CxxExecutor::PutObject: Non existing object specv0... please update file");
|
---|
| 105 | TVector< r_4 > & specv0 = (*___specv0);
|
---|
[537] | 106 |
|
---|
[556] | 107 | ___nomobj = "specv1";
|
---|
| 108 | TVector< r_4 > * ___specv1 = dynamic_cast< TVector< r_4 > * >(omg.GetObj(___nomobj));
|
---|
| 109 | if(___specv1==NULL) throw NullPtrError("CxxExecutor::PutObject: Non existing object specv1... please update file");
|
---|
| 110 | TVector< r_4 > & specv1 = (*___specv1);
|
---|
[537] | 111 |
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | //--------------------------------------------//
|
---|
| 115 | //----------------- User Code ----------------//
|
---|
| 116 | //--------------------------------------------//
|
---|
| 117 |
|
---|
| 118 | sa_size_t NUMBER_OF_CHANNELS = 2;
|
---|
| 119 | sa_size_t NUMBER_OF_FREQ = 8192;
|
---|
| 120 | TMatrix<r_4> specMtxInPut(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
[556] | 121 | specMtxInPut.Row(0)=specv0;
|
---|
| 122 | specMtxInPut.Row(1)=specv1;
|
---|
[537] | 123 |
|
---|
| 124 | //JEC 22/9/11 Mean & Sigma in 32-bins size START
|
---|
| 125 | sa_size_t nSliceFreq = 32; //TODO: put as an input parameter option ?
|
---|
| 126 | sa_size_t deltaFreq = NUMBER_OF_FREQ/nSliceFreq;
|
---|
| 127 | //JEC 22/9/11 Mean & Sigma in 32-bins size END
|
---|
| 128 |
|
---|
| 129 | TMatrix<r_4> reducedMeanDiffOnOff(NUMBER_OF_CHANNELS,nSliceFreq); //init 0 by default
|
---|
| 130 | TMatrix<r_4> reducedSigmaDiffOnOff(NUMBER_OF_CHANNELS,nSliceFreq); //init 0 by default
|
---|
| 131 | for (sa_size_t iSlice=0; iSlice<nSliceFreq; iSlice++){
|
---|
| 132 | sa_size_t freqLow= iSlice*deltaFreq;
|
---|
| 133 | sa_size_t freqHigh= freqLow + deltaFreq -1;
|
---|
| 134 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh){
|
---|
| 135 | TVector<r_4> reducedRow;
|
---|
| 136 | reducedRow = specMtxInPut.SubMatrix(Range(iCh),Range(freqLow,freqHigh)).CompactAllDimensions();
|
---|
| 137 | double mean;
|
---|
| 138 | double sigma;
|
---|
| 139 | MeanSigma(reducedRow,mean,sigma);
|
---|
| 140 | reducedMeanDiffOnOff(iCh,iSlice) = mean;
|
---|
| 141 | reducedSigmaDiffOnOff(iCh,iSlice) = sigma;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | KeepObj(reducedMeanDiffOnOff);
|
---|
| 145 | KeepObj(reducedSigmaDiffOnOff);
|
---|
| 146 |
|
---|
| 147 | return 0;
|
---|
| 148 | }
|
---|