| [588] | 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 dorebin( vector<string>& args );
 | 
|---|
 | 90 | }
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 | int dorebin( 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 | 
 | 
|---|
 | 102 | ___nomobj = "invec";
 | 
|---|
 | 103 | TVector< r_8 > * ___invec = dynamic_cast< TVector< r_8 >  * >(omg.GetObj(___nomobj));
 | 
|---|
 | 104 | if(___invec==NULL) throw NullPtrError("CxxExecutor::PutObject: Non existing object invec... please update file");
 | 
|---|
 | 105 | TVector< r_8 > & invec = (*___invec);
 | 
|---|
 | 106 | 
 | 
|---|
 | 107 | 
 | 
|---|
 | 108 | 
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 | //--------------------------------------------//
 | 
|---|
 | 111 | //----------------- User Code ----------------//
 | 
|---|
 | 112 | //--------------------------------------------//
 | 
|---|
 | 113 | 
 | 
|---|
 | 114 |  sa_size_t length=invec.NElts();
 | 
|---|
 | 115 |  sa_size_t packFactor=atoi(args[0].c_str());
 | 
|---|
 | 116 |  sa_size_t redlength=length/packFactor;
 | 
|---|
 | 117 | 
 | 
|---|
 | 118 |  TVector<r_8> outvec(redlength);
 | 
|---|
 | 119 |  for (sa_size_t ibin=0; ibin<redlength; ibin++){
 | 
|---|
 | 120 |    sa_size_t binLow= ibin*packFactor;
 | 
|---|
 | 121 |    sa_size_t binHigh= binLow + packFactor -1;
 | 
|---|
 | 122 |      TVector<r_8> tmp;
 | 
|---|
 | 123 |      tmp = invec.SubVector(Range(binLow,binHigh));
 | 
|---|
 | 124 |      double mean; 
 | 
|---|
 | 125 |      double sigma;
 | 
|---|
 | 126 |      MeanSigma(tmp,mean,sigma);
 | 
|---|
 | 127 |      outvec(ibin)=mean;
 | 
|---|
 | 128 |  }
 | 
|---|
 | 129 |  KeepObj(outvec);
 | 
|---|
 | 130 | 
 | 
|---|
 | 131 | return 0;
 | 
|---|
 | 132 | }
 | 
|---|