#ifndef PAMVMCRAWMGR_H #define PAMVMCRAWMGR_H #include "CRC.h" #include #include #include #include #include #include #include "TString.h" using namespace std; typedef vector PamVMCBuffer; typedef vector UCBuffer; typedef vector USBuffer; class PamVMCRawMgr: public TObject { private: static PamVMCRawMgr * frm; UInt_t fCounter; UInt_t fCounterPhys; UInt_t fOBT; const char* fFilename; std::ofstream fFile; UInt_t fLen; UCBuffer fEvtDataPSCU; //event UCBuffer fEvtDataPadding; UInt_t fEvtPadding; //++++++++++// // BUFFER // //++++++++++// PamVMCBuffer* fbuffer; protected: PamVMCRawMgr() { fCounter=fCounterPhys=fOBT=0; fbuffer = new PamVMCBuffer(0); }; public: ~PamVMCRawMgr(){ delete fbuffer; delete fFilename; } static PamVMCRawMgr * Instance(); void CreateOutFile(const char* fname){ fFilename = fname; cout<<"OUTPUT RAWFILE: "<size(); //AddPadding(fEvtPadding,&fEvtDataPadding); UInt_t length = fbuffer->size()+fEvtPadding; // DATA+Padding size; DigitizePSCU(length, 0x10, &fEvtDataPSCU); //cout<<"PADDING "<size()<begin(); while( p!=fbuffer->end() ) { fFile.write(&(*p),sizeof(char)); p++; } fbuffer->clear(); //cleaning MAIN buffer } void FinishRun(){ WriteToFile(); Int_t end = EOF; char t = char(end); fFile.write(&t, sizeof(char)); fFile.close(); } void CopyUCharToBuff (const UCBuffer * b){ UCBuffer::const_iterator p = b->begin(); #ifdef DIG_DEBUG cout<<"size of UChar DATA:"<size()<end() ) { //cout<push_back(char(*p)); p++; } } void CopyUShortToBuff (const USBuffer * b){ USBuffer::const_iterator p = b->begin(); #ifdef DIG_DEBUG cout<<"size of UShort DATA:"<size()<end() ) { Data=(*p); memcpy(tmp,&Data,sizeof(UShort_t)); //cout<push_back(char(tmp[1])); fbuffer->push_back(char(tmp[0])); p++; } } void AddPadding(UInt_t & pad, UCBuffer * b){ Float_t pd0 = (fLen+16)/32.; Float_t pd1 = pd0 - (Float_t)Int_t(pd0); Float_t padfrac = 32. - pd1 * 32.; UInt_t padbytes = (UInt_t)padfrac; b->clear(); if ( padbytes > 0 && padbytes < 32 ){ // // here the padding length // pad = padbytes+32; // // random padding bytes // UShort_t Data; UChar_t tmp[2]; for (Int_t ur=0; ur<16; ur++){ Data=(UShort_t)gRandom->Uniform(0.,RAND_MAX); memcpy(tmp,&Data,sizeof(UShort_t)); //cout<<"DATA"<push_back(tmp[1]); //b->push_back(tmp[0]); }; }; } void DigitizePSCU(UInt_t length, UChar_t type, UCBuffer * b){ // UChar_t buff[16]; // // CPU signature // buff[0] = 0xFA; buff[1] = 0xFE; buff[2] = 0xDE; // // packet type (twice) // buff[3] = type; buff[4] = type; // // counter // fCounter++; while ( fCounter > 16777215 ){ fCounter-=16777215; }; // buff[5] = (UChar_t)(fCounter >> 16); buff[6] = (UChar_t)(fCounter >> 8); buff[7] = (UChar_t)fCounter; // // on board time // ULong64_t obt = fOBT + 30LL; // while ( obt > 4294967295LL ){ obt -= 4294967295LL; }; fOBT = UInt_t(obt); // buff[8] = (UChar_t)(fOBT >> 24); buff[9] = (UChar_t)(fOBT >> 16); buff[10] = (UChar_t)(fOBT >> 8); buff[11] = (UChar_t)fOBT; // // Packet length // fLen = length; // buff[12] = (UChar_t)(fLen >> 16); buff[13] = (UChar_t)(fLen >> 8) ; buff[14] = (UChar_t)fLen; // // CPU header CRC // buff[15] = (BYTE)CM_Compute_CRC16((UINT16)0, (BYTE*)&buff, (UINT32)15); #ifdef DIG_DEBUG cout<<"Digitizer::DigitizePSCU... OK " <clear(); for (Int_t i=0; i<16; i++) b->push_back(buff[i]); } void PrintBinaryUns(unsigned char val){ for(Int_t i =7; i>=0; i--){ if(val & (1<