Commit 5a5ef42c authored by LEGEARD Luc's avatar LEGEARD Luc
Browse files

correct UtilVector to report mofification o size and pt vector in case of...

correct UtilVector to report mofification o size and pt vector in case of external vector, add MFMParisFram UnitTest
parent 1452f722
......@@ -20,6 +20,10 @@ class UtilVector_c
int fSize;
int fUsedSize;
bool IsSpaceInstanciedInThisClass;
char ** fPt_ext; // used in case of use of external buffer
int * fSize_ext;
public:
//___________________________________________________________________________________
......@@ -28,6 +32,8 @@ class UtilVector_c
fPtTempo = NULL;
fSize = 0;
fUsedSize = 0;
fPt_ext=NULL;
fSize_ext=NULL;
IsSpaceInstanciedInThisClass= false;
}
//_______________________________________________________________________________
......@@ -36,6 +42,8 @@ class UtilVector_c
fSize = 0;
fPtTempo = NULL;
fPt = NULL;
fPt_ext = NULL;
fSize_ext = NULL;
ReSize(size);
IsSpaceInstanciedInThisClass= true;
Reset();
......@@ -63,23 +71,30 @@ UtilVector_c(char** buff, int* size){
}
//_______________________________________________________________________________
void SetExternalPointers(char** buff, int *size){
void SetExternalPointers(char** buff, int *size){
fUsedSize = *size;
fSize = *size;
fPt_ext = buff ;
fSize_ext = size ;
fPtTempo = NULL;
if(fPt and IsSpaceInstanciedInThisClass) free(fPt);
fPt = *buff;
IsSpaceInstanciedInThisClass= false;
}
//_______________________________________________________________________________
void SetExternalPointers(char* buff, int size){
fUsedSize = size;
fSize = size;
fPtTempo = NULL;
fPt_ext = &buff;
fSize_ext = &size;
if(fPt and IsSpaceInstanciedInThisClass) free(fPt);
fPt = buff;
IsSpaceInstanciedInThisClass= false;
IsSpaceInstanciedInThisClass = false;
}
//_______________________________________________________________________________
......@@ -107,7 +122,9 @@ void ReSize(int size) {
}
//printf( " DEBUG : UtilVector_c:ReSize(%d), oldsize = %d, pt = %lld old pt = %lld \n",size,old,(long long *)fPtTempo,(long long *)fPt);
fPt = fPtTempo;
fSize = size;
if (fPt_ext !=NULL) *fPt_ext = fPtTempo;
fSize = size;
if (fSize_ext !=NULL) *fSize_ext = size;
}
//_______________________________________________________________________________
......
......@@ -243,7 +243,7 @@ ss << testloc ; test = test and testloc;
testloc = ( GetItemSize() == testframe-> GetItemSize());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>5) )
if ((verbose>0) )
cout << display <<" (NbI ItS)" <<endl;
return test;
......
......@@ -94,6 +94,7 @@ void MFMCommonFrame::Init() {
fEventNumber = 0;
fFrameType = 0;
fWantedFrameType =0;
fInitStatDone = false;
}
//_______________________________________________________________________________
void MFMCommonFrame::SetUserDataPointer()
......@@ -709,11 +710,83 @@ int MFMCommonFrame::FillBigBufferFromFile(int fLun, char* vector,
}
return 0;
}
//_______________________________________________________________________________
int MFMCommonFrame::ReadInFile(int *lun, char** vector, int * vectorsize) {
/// Get data from a file, and fill current frame and initialize its attributs and its pointer
/// if size of actual frame is not enough, a new size is reallocated
/// lun : descriptor of file (given by a previous open)
/// vector : pointer on pointer will contain frame . if size isn't big, a new value of pointer
/// vectorsize of this pointer
/// return size of read frame.
static UtilVector_c utilvector (MFM_BLOB_HEADER_SIZE) ;
utilvector.SetExternalPointers(vector,vectorsize);
int size = ReadInFile(lun,&utilvector);
return (size);
}
//_______________________________________________________________________________
int MFMCommonFrame::ReadInFile(int *fLun, char** vector, int * vectorsize) {
int MFMCommonFrame::ReadInFile(int *lun) {
/// Get data from a file, and fill current frame and initialize its attributs and its pointer
/// if size of actual frame is not enough, a new size is reallocated
/// lun : descriptor of file (given by a previous open)
/// vector : pointer on pointer will contain frame . if size isn't big, a new value of pointer
/// vectorsize of this pointer
/// return size of read frame.
static UtilVector_c utilvector(MFM_BLOB_HEADER_SIZE) ;
int size = ReadInFile(lun,&utilvector);
return (size);
}
//_______________________________________________________________________________
int MFMCommonFrame::ReadInFile(int *lun, UtilVector_c* utilvector) {
/// Get data from a file, and fill current frame and initialize its attributs and its pointer
/// if size of actual frame is not enough, a new size is reallocated
/// lun : descriptor of file (given by a previous open)
/// utilvector : vector will contain frame . if size isn't big enough, a resize is done
/// return size of read frame.
int count = 0;
int framesize = 0;
static long long int sumread =0;
int sizetoread = MFM_BLOB_HEADER_SIZE; // =8
count = read(*lun, (void*) (utilvector->GetPointer()), sizetoread);
if (count <= 0) {
cout << endl<<" ** End of read file **\n";
return count;
}
if (count < sizetoread) {
cout << " Error in read file\n";
return count;
}
MFMCommonFrame::SetAttributs(utilvector->GetPointer());
framesize = GetFrameSize();
if (framesize > 1000000000)
fError.TreatError(2, framesize, "Crazy Frame size > 1000000000");
if (utilvector->GetSize() < framesize){
utilvector->ReSize(framesize);
SetAttributs(utilvector->GetPointer());
}
sizetoread = framesize - sizetoread;
count = read(*lun, (void*) ((utilvector->GetPointer()) + MFM_BLOB_HEADER_SIZE), sizetoread);
if (count != sizetoread) {
cout << " Error in read file\n";
}
sumread +=framesize;
//if (sumread> 3000000000)
//cout << " debug read size "<<sumread<<" \n";
return framesize;
}
//_______________________________________________________________________________
int MFMCommonFrame::ReadInFileold(int *lun, char** vector, int * vectorsize) {
/// Get data from a file, and fill current frame and initialize its attributs and its pointer
/// if size of actual frame is not enough, a new size is reallocated
/// fLun : descriptor of file (given by a previous open)
/// lun : descriptor of file (given by a previous open)
/// vector : pointer on pointer will contain frame . if size isn't big, a new value of pointer
/// vectorsize of this pointer
/// return size of read frame.
......@@ -722,7 +795,7 @@ int MFMCommonFrame::ReadInFile(int *fLun, char** vector, int * vectorsize) {
char* vectornew = NULL;
static long long int sumread =0;
int sizetoread = MFM_BLOB_HEADER_SIZE; // =8
count = read(*fLun, (void*) (*vector), sizetoread);
count = read(*lun, (void*) (*vector), sizetoread);
if (count <= 0) {
cout << endl<<" ** End of read file **\n";
return count;
......@@ -748,7 +821,7 @@ int MFMCommonFrame::ReadInFile(int *fLun, char** vector, int * vectorsize) {
}
}
sizetoread = framesize - sizetoread;
count = read(*fLun, (void*) ((*vector) + MFM_BLOB_HEADER_SIZE), sizetoread);
count = read(*lun, (void*) ((*vector) + MFM_BLOB_HEADER_SIZE), sizetoread);
if (count != sizetoread) {
cout << " Error in read file\n";
}
......@@ -757,7 +830,6 @@ int MFMCommonFrame::ReadInFile(int *fLun, char** vector, int * vectorsize) {
//cout << " debug read size "<<sumread<<" \n";
return framesize;
}
//_______________________________________________________________________________________________________________________
void MFMCommonFrame::ExtractInfoFrame(int verbose,int dumpsize,int noframe){
// extract informations Frames and print informations
......@@ -1194,6 +1266,7 @@ void MFMCommonFrame::InitStat() {
fMeanFrameSize = 0;
fNegatifJump = 0;
fNoContiJump = 0;
fInitStatDone = true;
}
//_______________________________________________________________________________
void MFMCommonFrame::IncrementNegativJump() {
......@@ -1205,12 +1278,14 @@ void MFMCommonFrame::IncrementNoContiJump() {
}
//_______________________________________________________________________________
void MFMCommonFrame::FillStat() {
if (fInitStatDone == false )return;
fCountFrame++;
uint32_t framesize = GetFrameSize();
fMeanFrameSize += framesize;
}
//_______________________________________________________________________________
string MFMCommonFrame::GetStat(string info)const {
if (fInitStatDone == false )return (string)"";
string display("");
stringstream ss("");
ss << "Number of " << info << " Frames : " << fCountFrame << endl;
......@@ -1224,6 +1299,7 @@ string MFMCommonFrame::GetStat(string info)const {
}
//_______________________________________________________________________________
void MFMCommonFrame::PrintStat(string info) const{
if (fInitStatDone == false )return ;
cout << (GetStat(info));
}
//_______________________________________________________________________________
......@@ -1337,7 +1413,7 @@ ss << testloc ; test = test and testloc;
testloc = ( GetTimeStampFromCommonFrameData() == testframe->GetTimeStampFromCommonFrameData());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>5))
if ((verbose>0))
cout << display <<" (Si Hs Bl Me En So Un Re En Ts)" <<endl;
return test;
}
......
......@@ -22,6 +22,11 @@
#include "stdlib.h"
#include "MFMFewDefines.h"
#include "CUtilities.h"
#include <typeinfo>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#pragma pack(push, 1)// allow strict alignment
#define MFM_ENDIANNESS_MSK 0x80
#define MFM_BLOBNESS_MSK 0x40
......@@ -100,8 +105,9 @@ bool fFrameIsBigEndian ; ///< Endianness or Frame
uint16_t fFrameType; ///< Frame type
int fWantedFrameType; ///< Wanted Frame type in case of generation of frame ( simulation ). No usage in read frame
int fFrameSize; ///< Frame size
uint64_t fTimeStamp; //<Time Stamp
uint32_t fEventNumber; //<EventNumber
uint64_t fTimeStamp; //< Time Stamp
uint32_t fEventNumber; //< EventNumber
bool fInitStatDone; //< tag for init of statistics
private :
mutable int fIncrement; ///< memory of incrementation in case of dump.
......@@ -181,7 +187,7 @@ MFMCommonFrame(MFMCommonFrame* frame);
virtual void DumpRaw(int dumpsize=0, int increment=256) const;
virtual string GetDumpRaw(int dumpsize=0, int increment=256)const;
virtual void GetDumpRaw(void *point,int dumpsize, int increment,string * mydump = NULL)const;
void DumpData(char mode='d', bool nozero=false) const {cout << GetDumpData( mode, nozero);};
void DumpData(char mode='d', bool nozero=false) const {cout << GetDumpData( mode, nozero);};
virtual string GetDumpData(char mode='d', bool nozero=false) const {string test ="";return test;}; /// Dump decoded data in if frame class avec this method
virtual string GetHeaderDisplay(char* infotext=NULL)const;
void HeaderDisplay(char* infotext=NULL) const ;
......@@ -199,8 +205,10 @@ virtual void FillDataWithRamdomValue(uint64_t timestamp,uint32_t eventnumber){fE
virtual void GenerateAFrameExample(uint64_t timestamp,uint32_t eventnumber);
virtual void WriteRandomFrame(int lun,int nbframe,int verbose,int dumsize,int type);
int ReadInFile(int *fLun,char** vector, int * vectosize);
int ReadInFile(int *lun, char** vector, int * vectosize);
int ReadInFileold(int *lun, char** vector, int * vectosize);
int ReadInFile(int *lun, UtilVector_c* vector);
int ReadInFile(int *lun);
int FillBigBufferFromFile(int fLun,char* vector, unsigned int vectosize,unsigned int *readsize,unsigned int *eventcount);
int ReadInMem(char** vector);
virtual void ExtractInfoFrame(int verbose,int dumpsize,int noframe);
......
......@@ -178,6 +178,7 @@ uint16_t MFMNumExoFrame::GetChecksum()const{
}
//_______________________________________________________________________________
void MFMNumExoFrame::InitStat() {
MFMCommonFrame::InitStat();
int i;
fCountNbEventCard = new long long[NUMEXO_MAX_NUMB_BOARDS];
......@@ -187,15 +188,17 @@ void MFMNumExoFrame::InitStat() {
}
//____________________________________________________________________
void MFMNumExoFrame::FillStat() {
if (fInitStatDone == false )return ;
MFMCommonFrame::FillStat();
uint16_t id;
id = GetBoardId();
fCountNbEventCard[id]++;
if (id >NUMEXO_MAX_NUMB_BOARDS ) cout << " Error MFMNumExoFrame::FillStat() BoardId to big"<<id<<" \n";
else fCountNbEventCard[id]++;
}
//____________________________________________________________________
string MFMNumExoFrame::GetStat(string info) const {
if (fInitStatDone == false )return (string) "" ;
string display("");
stringstream ss("");
ss << MFMCommonFrame::GetStat(info);
......@@ -240,7 +243,7 @@ string MFMNumExoFrame::GetHeaderDisplay(char* infotext) const{
display = ss.str();
ss << MFMCommonFrame::GetHeaderDisplay(infotext) ;
ss << " Channel = " << GetTGCristalId();
ss << " Test Checksum = " << VerifyChecksum();
ss << " Test Checksum = " << VerifyChecksum()<<endl;
display = ss.str();
return display;
}
......@@ -255,7 +258,6 @@ bool test= true;
bool testloc= true;
int i=0;
ss << " Test for "<< MyClassName()<<" :" ;
testframe->MFMNumExoFrame::SetAttributs();
MFMNumExoFrame::SetAttributs();
......@@ -269,7 +271,7 @@ ss << testloc ; test = test and testloc;
testloc = ( GetBoardId() == testframe->GetBoardId());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>5))
if ((verbose>0))
cout << display <<" (Cristal Channel Board)" <<endl;
return test;
}
......
......@@ -136,4 +136,82 @@ bool MFMParisFrame::GetPUR()const{
bool MFMParisFrame::GetOVR()const{
return ((((MFM_paris_frame*) pHeader)->Data.Flags)&0x8)>>3;
}
//_______________________________________________________________________________
bool MFMParisFrame::IsSame(MFMParisFrame* testframe,int verbose){
// test if testframe have same attibut values
string display("");
stringstream ss("");
bool test= true;
bool testloc= true;
int i=0;
ss << " Test for "<< MyClassName()<<" : " ;
testframe->MFMParisFrame::SetAttributs();
MFMParisFrame::SetAttributs();
test= MFMNumExoFrame::IsSame((MFMNumExoFrame*)testframe,verbose);
testloc = ( GetQShort()== testframe->GetQShort());
ss << testloc ; test = test and testloc;
testloc = ( GetQLong() == testframe->GetQLong());
ss << testloc ; test = test and testloc;
testloc = ( GetCfd() == testframe->GetCfd());
ss << testloc ; test = test and testloc;
testloc = ( GetPLL() == testframe->GetPLL());
ss << testloc ; test = test and testloc;
testloc = ( GetPUR() == testframe->GetPUR());
ss << testloc ; test = test and testloc;
testloc = ( GetOVR() == testframe->GetOVR());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>0))
cout << display <<" (QS QL CF PLL PUR OVR)" <<endl;
return test;
}
//_______________________________________________________________________________
bool MFMParisFrame::UnitTest(int verbose){
// Test this class
// this methode generate a frame write it in a tmpfile
// read this frame with a other object frame and after comare the both frame
// return true if OK , false if noOK
int lun; // Logical Unit Number
UtilVector_c* vector = new UtilVector_c(MFM_BLOB_HEADER_SIZE); // min size =8
bool test =true;
char tmpfilename[256];
sprintf ( tmpfilename,"test%s.tmp",MyClassName());
int type = MFM_REA_GENE_FRAME_TYPE;
int dump =0;
if (verbose>9)dump =64;
//generation and write
MFMParisFrame * framewrite = new MFMParisFrame();
lun = open(tmpfilename, (O_RDWR | O_CREAT | O_TRUNC), 0644);
framewrite->WriteRandomFrame(lun,1, 0, 0,MFM_REA_GENE_FRAME_TYPE);
close(lun);
//read
lun = open(tmpfilename, (O_RDONLY));
MFMParisFrame * frameread = new MFMParisFrame();
frameread->ReadInFile(&lun, vector);
//compare
cout << ">--Test begin for "<<frameread->MyClassName()<<"--------"<<endl;
test=framewrite->IsSame(frameread,verbose);
cout << ">--Result for "<<frameread->MyClassName()<<" = "<< test<<endl;
if (verbose >5) {
framewrite->ReadAttributsExtractFrame(verbose,dump, true,0,framewrite->GetPointHeader());
frameread->ReadAttributsExtractFrame(verbose,dump, true,0,frameread->GetPointHeader());
}
//end
delete (framewrite);
delete (frameread);
if(vector) delete(vector);
close(lun);
return test;
}
//_______________________________________________________________________________
//_______________________________________________________________________________
......@@ -41,6 +41,7 @@ class MFMParisFrame:public MFMNumExoFrame
MFMParisFrame(int unitBlock_size, int dataSource,
int frameType, int revision, int frameSize,int headerSize);
virtual ~MFMParisFrame();
char* MyClassName()const{ return (char*)"MFMParisFrame";};
// PARIS
void SetQShort(uint16_t energy);
......@@ -56,14 +57,14 @@ class MFMParisFrame:public MFMNumExoFrame
virtual bool GetPUR() const;
virtual bool GetOVR() const;
const char * GetTypeText()const {return MFM_PARIS_FRAME_TYPE_TXT;}
const char * GetTypeText()const {return MFM_PARIS_FRAME_TYPE_TXT;}
virtual int GetDefinedUnitBlockSize()const {return PARIS_UNIT_BLOCK_SIZE ;};
virtual int GetDefinedHeaderSize()const {return NUMEXO_HEADERFRAMESIZE;};
virtual int GetDefinedFrameSize()const {return PARIS_FRAMESIZE;};
uint16_t GetChecksum()const{ return 0;}
bool IsSame(MFMParisFrame* testframe,int verbose);
bool UnitTest(int verbose);
};
#pragma pack(pop) // free aligment
#endif
......
......@@ -136,6 +136,7 @@ void MFMReaGenericFrame::FillDataWithRamdomValue(uint64_t timestamp,
}
//_______________________________________________________________________________
void MFMReaGenericFrame::InitStat() {
if (fInitStatDone == false )return ;
MFMNumExoFrame::InitStat();
int channel;
for ( channel=0; channel< NUMEXO_NB_CHANNELS ; channel ++){
......@@ -149,6 +150,7 @@ void MFMReaGenericFrame::InitStat() {
}
//_______________________________________________________________________________
void MFMReaGenericFrame::FillStat() {
if (fInitStatDone == false )return ;
MFMNumExoFrame::FillStat();
int channel,board;
uint32_t eventnumber = GetEventNumber();
......@@ -172,7 +174,7 @@ void MFMReaGenericFrame::FillStat() {
}
//_______________________________________________________________________________
string MFMReaGenericFrame::GetStat(string info)const {
if (fInitStatDone == false )return(string)"" ;
string display("");
stringstream ss("");
ss << MFMNumExoFrame::GetStat(info);
......@@ -288,6 +290,7 @@ string MFMReaGenericFrame::GetDumpData(char mode, bool nozero) const {
} else {
ss << " E = "<<GetEnergy()<<" T = "<< GetTime() ;
}
ss << endl;
display = ss.str();
return display;
}
......@@ -301,17 +304,18 @@ bool test= true;
bool testloc= true;
int i=0;
ss << " Test for "<< MyClassName()<<" :" ;
ss << " Test for "<< MyClassName()<<" : " ;
testframe->MFMReaGenericFrame::SetAttributs();
MFMReaGenericFrame::SetAttributs();
test= MFMNumExoFrame::IsSame((MFMNumExoFrame*)testframe,verbose);
testloc = ( GetStatus(0) == testframe->GetStatus(0));
ss << testloc ; test = test and testloc;
testloc = ( GetStatus(1) == testframe->GetStatus(1));
ss << testloc ; test = test and testloc;
testloc = ( GetTypeTns() == testframe->GetTypeTns());
ss << testloc ; test = test and testloc;
testloc = ( GetEnergy() == testframe->GetEnergy());
ss << testloc ; test = test and testloc;
testloc = ( GetTime() == testframe->GetTime());
......@@ -319,9 +323,53 @@ ss << testloc ; test = test and testloc;
testloc = ( GetChecksum()== testframe->GetChecksum());
ss << testloc ; test = test and testloc;
display = ss.str();
if ((verbose>5))
cout << display <<" (St1 St2 Typ Ener Time Check)" <<endl;
if ((verbose>0))
cout << display <<" (St1 St2 Typ Ener Time Check)" <<endl;
return test;
}
//_______________________________________________________________________________
bool MFMReaGenericFrame::UnitTest(int verbose){
// Test this class
// this methode generate a frame write it in a tmpfile
// read this frame with a other object frame and after comare the both frame
// return true if OK , false if noOK
int lun; // Logical Unit Number
UtilVector_c* vector = new UtilVector_c(MFM_BLOB_HEADER_SIZE); // min size =8
bool test =true;
char tmpfilename[256];
sprintf ( tmpfilename,"test%s.tmp",MyClassName());
int type = MFM_REA_GENE_FRAME_TYPE;
int dump =0;
if (verbose>9)dump =64;
//generation and write
MFMReaGenericFrame * framewrite = new MFMReaGenericFrame();
lun = open(tmpfilename, (O_RDWR | O_CREAT | O_TRUNC), 0644);
framewrite->WriteRandomFrame(lun,1, 0, 0,MFM_REA_GENE_FRAME_TYPE);
close(lun);
//read
lun = open(tmpfilename, (O_RDONLY));
MFMReaGenericFrame * frameread = new MFMReaGenericFrame();
frameread->ReadInFile(&lun, vector);
//compare
cout << ">--Test begin for "<<frameread->MyClassName()<<"--------"<<endl;
test=framewrite->IsSame(frameread,verbose);
cout << ">--Result for "<<frameread->MyClassName()<<" = "<< test<<endl;
if (verbose >5) {
framewrite->ReadAttributsExtractFrame(verbose,dump, true,0,framewrite->GetPointHeader());
frameread->ReadAttributsExtractFrame(verbose,dump, true,0,frameread->GetPointHeader());
}
//end
delete (framewrite);
delete (frameread);
if(vector) delete(vector);
close(lun);
return test;
}
//_______________________________________________________________________________
//_______________________________________________________________________________
......@@ -79,6 +79,7 @@ class MFMReaGenericFrame : public MFMNumExoFrame
void SetTabValues();
void ResetTabValues();
bool IsSame(MFMReaGenericFrame* testframe,int verbose);
bool UnitTest(int verbose);
};
#pragma pack(pop) // free aligment
#endif
......@@ -351,6 +351,7 @@ void MFMReaTraceFrame::InitStat() {
}
//_______________________________________________________________________________
void MFMReaTraceFrame::FillStat() {
if (fInitStatDone == false )return;
MFMBasicFrame::FillStat();
uint16_t id;
......@@ -370,7 +371,7 @@ void MFMReaTraceFrame::FillStat() {
}
//_______________________________________________________________________________
string MFMReaTraceFrame::GetStat(string info)const {
if (fInitStatDone == false )return(string)"";
string display("");
stringstream ss("");
ss << MFMBasicFrame::GetStat(info);
......@@ -412,6 +413,84 @@ void MFMReaTraceFrame::ChangeDefinedFrameSize(int size) {
}
//_______________________________________________________________________________
bool MFMReaTraceFrame::IsSame(MFMReaTraceFrame* testframe,int verbose){
// test if testframe have same attibut values
// return true if OK
string display("");
stringstream ss("");
bool test= true;
bool testloc= true;
int i=0;
uint16_t value;
uint16_t valuetest;
ss << " Test for "<< MyClassName()<<" :" ;
testframe->MFMReaTraceFrame::SetAttributs();
MFMReaTraceFrame::SetAttributs();
test= MFMBasicFrame::IsSame((MFMBasicFrame*)testframe,verbose);
int nbitems= testframe->GetNbItems();
testloc = ( GetSetupTrace()== testframe->GetSetupTrace());
ss << testloc ; test = test and testloc;
testloc= true;
for (i =0; i< nbitems; i++){