#ifndef VEGA_VSignal #define VEGA_VSignal //#if !defined(__CINT__) || defined(__MAKECINT__) #include "VGenericSignal.h" #include "VSignalManager.h" #include "Frv.h" //#endif #if !defined(__CINT__) // Specialized helper functions for initialization, comparaison, copy template FrVect* VSignalBuild(char* name, int nData, double dx, char* unitX="", char* unitY="", T_type dummy=0) {return 0;} template int VSignalTypeCompare(int type, T_type dummy=0) {return 0;} template FrVect* VSignalCopyTo(FrVect* vect, T_type dummy=0) {return 0;} #endif //#if defined(__CINT__) //class VSignal{}; //#endif template class VSignal : public VGenericSignal { private: T_type* mVectData; // pointer to vector data // That should be all ! avoid putting too many data to be able to // pass VSignal objects instead of pointers to functions and methods public: VSignal() { // VSignal constructor mVect = 0; mVectData = 0; // mPlot = 0; printf("VSignal default constructor\n"); } VSignal(VFrVectObject* frvo) { // VSignal constructor printf ("operator = for VFrVectObject\n"); FrVect* vect = frvo->Release(); delete frvo; Adopt(vect); } VSignal(const VSignal& v) { // VSignal copy constructor FrVect* vect0; if (!gSignalManager) gSignalManager = new VSignalManager(); if (mVect) gSignalManager->Shrink(mVect); if (v.GetFrVect() != 0) { if (!VSignalTypeCompare(v.GetFrVect()->type)) { vect0 = VSignalCopyTo(v.GetFrVect()); } else vect0 = v.GetFrVect();; gSignalManager->Grow(vect0); mVect = vect0; mVectData = (T_type*)(mVect->data); // mPlot = 0; } else { mVect = 0; mVectData = 0; } printf("VSignal copy constructor from vector 0x%x\n",(unsigned int)mVect); } VSignal(char* name, int nData, double dx, char* unitX="", char* unitY="") { // VSignal constructor mVect = VSignalBuild(name,nData,dx,unitX,unitY); if (!mVect) { mVectData = 0; printf("Type not allowed \n"); } else { mVectData = (T_type*)(mVect->data); if (!gSignalManager) gSignalManager = new VSignalManager(); gSignalManager->Grow(mVect); printf("VSignal constructor from vector double\n"); } // mPlot = 0; } virtual ~VSignal() { // VSignal destructor if (mVect && gSignalManager) gSignalManager->Shrink(mVect); printf("VSignal destructor\n"); } void Adopt(FrVect* vect) { FrVect* vect0; if (!gSignalManager) gSignalManager = new VSignalManager(); if (mVect) gSignalManager->Shrink(mVect); if (vect) { if (!VSignalTypeCompare(vect->type)) { vect0 = VSignalCopyTo(vect); } else vect0=vect; gSignalManager->Grow(vect0); mVect = vect0; mVectData = (T_type*)(mVect->data); // mPlot = 0; } else { mVect = 0; mVectData = 0; } printf("adopt vector 0x%x\n",(unsigned int)mVect); } inline FrVect* GetFrVect() const {return mVect;} inline int GetLength() {if (mVect) return mVect->nx[0]; return 0;} #if FR_VERS<6000 inline double GetTimeD() {return (double)(mVect->GTimeS + 1.e-9*mVect->GTimeN);} #else inline double GetTimeD() {return mVect->GTime;} #endif inline T_type& operator [] (int index){return mVectData[index];} inline VSignal& operator = (VSignal& v) { printf ("operator = called for VSignal\n"); Adopt(v.GetFrVect()); return *this; } inline VSignal operator+ (VSignal& v) { VSignal vout; FrVect* vect; if(mVect==NULL || v.GetFrVect()==NULL){ printf("ERROR in in operator + -> Vector inside the object is NULL \n\n"); return vout; } // strcpy(output_name, v.GetFrVect()->name); // strcat(output_name, "_<+>_"); // strcat(output_name, mVect->name); if(mVect->nData!=v.GetFrVect()->nData){ printf("ERROR in operator + --> Different size vectors %ld %ld\n\n", mVect->nData,v.GetFrVect()->nData); return vout; } vect=FrvAdd(mVect,v.GetFrVect(),NULL,v.GetFrVect()->name); #if FR_VERS<6000 vect->GTimeS=(v.GetFrVect())->GTimeS; vect->GTimeN=(v.GetFrVect())->GTimeN; #else vect->GTime=(v.GetFrVect())->GTime; #endif vout.Adopt(vect); return vout; } inline VSignal& operator= (VFrVectObject* frvo) { printf ("operator = for VFrVectObject\n"); FrVect* vect = frvo->Release(); delete frvo; Adopt(vect); return *this; } inline VSignal& operator= (FrVect* vect) { printf ("operator = not recommended for raw FrVect\n"); return *this; } ClassDefT(VSignal,0) // Signal view/manipulation }; ClassImpT(VSignal,T_type) #endif