diff --git a/.gitignore b/.gitignore index 0acd3a7..396b2aa 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,7 @@ *.pcm *.cxx +*.bin + test FSUDAQ diff --git a/DataClass.h b/ClassData.h similarity index 100% rename from DataClass.h rename to ClassData.h diff --git a/DigitizerClass.cpp b/ClassDigitizer.cpp similarity index 80% rename from DigitizerClass.cpp rename to ClassDigitizer.cpp index 262f685..5912e69 100644 --- a/DigitizerClass.cpp +++ b/ClassDigitizer.cpp @@ -1,4 +1,4 @@ -#include "DigitizerClass.h" +#include "ClassDigitizer.h" Digitizer::Digitizer(){ @@ -21,6 +21,10 @@ Digitizer::Digitizer(){ data = new Data(); + settingFileName = ""; + settingFileExist = false; + settingFile = NULL; + ret = -1; isConnected = false; @@ -35,6 +39,7 @@ Digitizer::~Digitizer(){ CloseDigitizer(); delete data; + ///delete settingFile; /// not needed, settingFile open and close at everytime } void Digitizer::Reset(){ @@ -286,10 +291,14 @@ void Digitizer::WriteRegister(uint32_t address, uint32_t value, int ch ){ uint32_t Digitizer::ReadRegister(uint32_t address, unsigned int ch, string str ){ uint32_t * Data = new uint32_t[NChannel]; - if( ch < 0 ) { - ret = CAEN_DGTZ_ReadRegister(handle, address + 0x7000, Data); + if( address < 0x8000) { + if( ch < 0 ) { + ret = CAEN_DGTZ_ReadRegister(handle, address + 0x7000, Data); + }else{ + ret = CAEN_DGTZ_ReadRegister(handle, address + (ch << 8), Data); + } }else{ - ret = CAEN_DGTZ_ReadRegister(handle, address + (ch << 8), Data); + ret = CAEN_DGTZ_ReadRegister(handle, address, Data); } ErrorMsg("ReadRegister"); if( str != "" ) printf("%s : 0x%x \n", str.c_str(), Data[0]); @@ -428,3 +437,128 @@ int Digitizer::GetChTemperature(int ch){ return temp[0]; } +void Digitizer::OpenSettingBinary(string fileName){ + settingFile = NULL; + this->settingFileName = fileName; + settingFile = fopen(fileName.c_str(), "r+"); + if( settingFile == NULL ){ + printf("cannot open file %s. \n", fileName.c_str()); + }else{ + settingFileExist = true; + } +} + +void Digitizer::CreateAndSaveSettingBinary(string fileName){ + /// for 1 digitizer, 16 channels, needs 0x10XX to 0x1FXX + /// Board setting is 0x8000 --> 0x0000 + /// Saved date YYYYMMDDHH --> 0x0004 + /// Global Trigger Mask 0x810C --> 0x010C + /// Channel mask 0x8120 --> 0x0120 + /// ROM Board version 0xF030 --> 0x0030 + /// Board Form factor 0xF034 --> 0x0034 + /// Board ID Byte 1 0xF038 --> 0x0038 + /// Board ID Byte 0 0xF03C --> 0x003C + /// Board Serial Num Byte1 0xF080 --> 0x0080 + /// Board Serial Num Byte0 0xF084 --> 0x0084 /// serial number = byte0 << 8 + byte1 + /// ROC fireware version is 0x8124 --> 0x0124 + /// Board Info is 0x8140 --> 0x0140 + /// ------------------------------------- + /// for 1 channel is 0x2000 = 8192 byte should be enough for all setting for 1 board + + settingFileName = fileName; + settingFile = fopen(settingFileName.c_str(), "w+"); + unsigned int haha[1] = {0x00000000}; /// 4 bytes + + for(int i = 0; i < 8192/4 ; i++){ + fwrite(haha, sizeof(unsigned int), 1, settingFile); + } + + fseek(settingFile, 0L, SEEK_END); + unsigned int inFileSize = ftell(settingFile); + printf("Created file : %s. file size : %d Byte\n", settingFileName.c_str(), inFileSize); + fclose (settingFile); + settingFileExist = true; + + ///Save board setting + EditByteByRegister(Register::DPP::BoardConfiguration); + EditByteByRegister(Register::DPP::GlobalTriggerMask); + EditByteByRegister(Register::DPP::ChannelEnableMask); + EditByteByRegister(Register::DPP::ROM_BoardVersion); + EditByteByRegister(Register::DPP::ROM_BoardFromFactor); + EditByteByRegister(Register::DPP::ROM_BoardIDByte1); + EditByteByRegister(Register::DPP::ROM_BoardIDByte0); + EditByteByRegister(Register::DPP::ROM_BoardSerialNumByte1); + EditByteByRegister(Register::DPP::ROM_BoardSerialNumByte0); + EditByteByRegister(Register::DPP::ROCFPGAFirmwareRevision); + EditByteByRegister(Register::DPP::BoardInfo); + + ///================ channel settings + for( int ch = 0; ch < NChannel ; ch++){ + + EditByteByRegister(Register::DPP::RecordLength_G, ch); + EditByteByRegister(Register::DPP::InputDynamicRange, ch); + EditByteByRegister(Register::DPP::PreTrigger, ch); + EditByteByRegister(Register::DPP::ChannelDCOffset, ch); + EditByteByRegister(Register::DPP::NumberEventsPerAggregate_G, ch); + EditByteByRegister(Register::DPP::DPPAlgorithmControl, ch); + EditByteByRegister(Register::DPP::AMCFirmwareRevision, ch); + EditByteByRegister(Register::DPP::VetoWidth, ch); + + if( DPPType == 0x8B ) { /// DPP-PHA + EditByteByRegister(Register::DPP::PHA::TriggerThreshold, ch); + EditByteByRegister(Register::DPP::PHA::RCCR2SmoothingFactor, ch); + EditByteByRegister(Register::DPP::PHA::RiseTimeValidationWindow, ch); + EditByteByRegister(Register::DPP::PHA::TriggerHoldOffWidth, ch); + EditByteByRegister(Register::DPP::PHA::InputRiseTime, ch); + EditByteByRegister(Register::DPP::PHA::ShapedTriggerWidth, ch); + + EditByteByRegister(Register::DPP::PHA::TrapezoidRiseTime, ch); + EditByteByRegister(Register::DPP::PHA::TrapezoidFlatTop, ch); + EditByteByRegister(Register::DPP::PHA::DecayTime, ch); + EditByteByRegister(Register::DPP::PHA::PeakingTime, ch); + EditByteByRegister(Register::DPP::PHA::PeakHoldOff, ch); + + EditByteByRegister(Register::DPP::PHA::DPPAlgorithmControl2_G, ch); + EditByteByRegister(Register::DPP::PHA::FineGain, ch); + } + } + +} + +unsigned long Digitizer::ReadSettingBinary(uint32_t filePos, int ch){ + if ( !settingFileExist ) return -1; + + if( filePos >= 0x8000 ) { + filePos = filePos & 0x0FFF; + }else{ + if( ch >= 0 ) { + filePos = filePos + (ch << 8); + }else{ + return -1; + } + } + + settingFile = fopen (settingFileName.c_str(),"r"); + fseek( settingFile, filePos, SEEK_SET); + ///printf(" at pos %lu \n", ftell(settingFile)); + unsigned int lala[1]; + ret = fread( lala, sizeof(unsigned int), 1, settingFile); + ///printf(" data at pos %lu : %x \n", ftell(settingFile), lala[0]); + fclose (settingFile); + return lala[0]; +} + +void Digitizer::EditByte(unsigned int value, uint32_t filePos){ + if ( !settingFileExist ) return ; + if( filePos >= 0x8000 ) filePos = filePos & 0x0FFF; + settingFile = fopen (settingFileName.c_str(),"r+"); + fseek( settingFile, filePos, SEEK_SET); + unsigned int jaja[1] = {value}; + fwrite( jaja, sizeof(unsigned int), 1, settingFile); + ///printf("fwrie ret : %d, %x \n", (int)ret, jaja[0]); + fclose (settingFile); +} + +void Digitizer::EditByteByRegister(uint32_t registerAddress, int ch){ + EditByte( ReadRegister(registerAddress, ch), registerAddress); +} diff --git a/DigitizerClass.h b/ClassDigitizer.h similarity index 88% rename from DigitizerClass.h rename to ClassDigitizer.h index 62e8791..aa95db4 100644 --- a/DigitizerClass.h +++ b/ClassDigitizer.h @@ -13,29 +13,11 @@ #include "CAENDigitizerType.h" #include "macro.h" -#include "DataClass.h" +#include "ClassData.h" #include "RegisterAddress.h" - using namespace std; -/** -struct DigitizerChannelSetting { - - /// PDS - unsigned int cfdSetting; - unsigned int chargeZeroSuppThreshold; - unsigned int shortGateWidth; - unsigned int longGateWidth; - unsigned int gateOffset; - unsigned int fixedBaseline; - unsigned int triggerLatency; - unsigned int thresholdPSDCut; - unsigned int pureGapThreshold; - unsigned int earlyBaselineFreeze; - -};*/ - //################################################################ class Digitizer{ @@ -85,7 +67,14 @@ class Digitizer{ ///================ ACQ control void StopACQ(); void StartACQ(); - + + ///================ Setting + void OpenSettingBinary(string fileName); + void CreateAndSaveSettingBinary(string fileName); + void EditByte(unsigned int value, uint32_t filePos); + void EditByteByRegister(uint32_t registerAddress, int ch = -1); + unsigned long ReadSettingBinary(uint32_t filePos, int ch = -1); + protected: ///---- fixed parameter @@ -108,10 +97,16 @@ class Digitizer{ Data * data; + ///------- other parameters int ret; /// return value, refer to CAEN_DGTZ_ErrorCode bool isConnected; + /// ------- setting + string settingFileName; + FILE * settingFile; + bool settingFileExist; + ///========== virtual int ProgramBoard(); void ErrorMsg(string header = ""); diff --git a/DigitizerPHA.h b/DigitizerPHA.h index dc4ce9a..9ac1ca9 100644 --- a/DigitizerPHA.h +++ b/DigitizerPHA.h @@ -1,7 +1,7 @@ #ifndef DIGITIZER_PHA_H #define DIGITIZER_PHA_H -#include "DigitizerClass.h" +#include "ClassDigitizer.h" class DigitizerPHA : public Digitizer { diff --git a/DigitizerPSD.h b/DigitizerPSD.h index b22809a..b6a6bae 100644 --- a/DigitizerPSD.h +++ b/DigitizerPSD.h @@ -1,7 +1,7 @@ #ifndef DIGITIZER_PSD_H #define DIGITIZER_PSD_H -#include "DigitizerClass.h" +#include "ClassDigitizer.h" class DigitizerPSD : public Digitizer { public: diff --git a/Makefile b/Makefile index 6c5fff0..b39f199 100755 --- a/Makefile +++ b/Makefile @@ -11,8 +11,7 @@ CAENLIBS = -lCAENDigitizer ROOTLIBS = `root-config --cflags --glibs` -#OBJS = DataClass.o DigitizerClass.o DigitizerPHA.o DigitizerPSD.o FSUDAQ.o -OBJS = DigitizerClass.o DigitizerPHA.o DigitizerPSD.o FSUDAQ.o +OBJS = ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o FSUDAQ.o ######################################################################### @@ -22,21 +21,21 @@ clean : /bin/rm -f $(OBJS) test FSUDAQ FSUDAQDict.cxx *.pcm -#DataClass.o : DataClass.h macro.h -# $(CC) $(COPTS) -c DataClass.h -o DataClass.o +#ClassData.o : ClassData.h macro.h +# $(CC) $(COPTS) -c ClassData.h -o ClassData.o -DigitizerClass.o : DigitizerClass.cpp DigitizerClass.h RegisterAddress.h macro.h DataClass.h - $(CC) $(COPTS) -c DigitizerClass.cpp +ClassDigitizer.o : ClassDigitizer.cpp ClassDigitizer.h RegisterAddress.h macro.h ClassData.h + $(CC) $(COPTS) -c ClassDigitizer.cpp -DigitizerPHA.o : DigitizerPHA.cpp DigitizerPHA.h DigitizerClass.o +DigitizerPHA.o : DigitizerPHA.cpp DigitizerPHA.h ClassDigitizer.o $(CC) $(COPTS) -c DigitizerPHA.cpp -DigitizerPSD.o : DigitizerPSD.cpp DigitizerPSD.h DigitizerClass.o +DigitizerPSD.o : DigitizerPSD.cpp DigitizerPSD.h ClassDigitizer.o $(CC) $(COPTS) -c DigitizerPSD.cpp -test : test.cpp DigitizerClass.o DigitizerPHA.o DigitizerPSD.o +test : test.cpp ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o @echo "--------- making test" - $(CC) $(COPTS) -o test test.cpp DigitizerClass.o DigitizerPHA.o DigitizerPSD.o $(CAENLIBS) + $(CC) $(COPTS) -o test test.cpp ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o $(CAENLIBS) FSUDAQDict.cxx : FSUDAQ.h FSUDAQLinkDef.h @@ -46,7 +45,7 @@ FSUDAQDict.cxx : FSUDAQ.h FSUDAQLinkDef.h FSUDAQ.o : FSUDAQ.h FSUDAQ.cpp FSUDAQDict.cxx @echo "----------- creating FSUDAQ.o" - $(CC) $(COPTS) -c FSUDAQ.cpp DigitizerClass.cpp DigitizerPHA.cpp DigitizerPSD.cpp $(ROOTLIBS) + $(CC) $(COPTS) -c FSUDAQ.cpp ClassDigitizer.cpp DigitizerPHA.cpp DigitizerPSD.cpp $(ROOTLIBS) FSUDAQ : FSUDAQDict.cxx $(OBJS) @echo "----------- creating FSUDAQ" @@ -55,6 +54,6 @@ FSUDAQ : FSUDAQDict.cxx $(OBJS) #CutsCreator: $(OBJS3) src/CutsCreator.c # g++ -std=c++17 -pthread src/CutsCreator.c -o CutsCreator $(ROOTLIBS) -#BoxScore : src/BoxScore.c Class/DigitizerClass.h Class/FileIO.h Class/GenericPlane.h Class/HelioTarget.h Class/IsoDetect.h Class/HelioArray.h Class/MCPClass.h +#BoxScore : src/BoxScore.c Class/ClassDigitizer.h Class/FileIO.h Class/GenericPlane.h Class/HelioTarget.h Class/IsoDetect.h Class/HelioArray.h Class/MCPClass.h # g++ -std=c++17 -pthread src/BoxScore.c -o BoxScore $(DEPLIBS) $(ROOTLIBS) diff --git a/RegisterAddress.h b/RegisterAddress.h index dab1927..8572279 100644 --- a/RegisterAddress.h +++ b/RegisterAddress.h @@ -71,8 +71,8 @@ namespace Register { static uint32_t InputDynamicRange = 0x1028; /// R/W static uint32_t NumberEventsPerAggregate_G = 0x1034; /// R/W static uint32_t PreTrigger = 0x1038; /// R/W - static uint32_t TriggerThreshold = 0x106C; /// R/W - static uint32_t TriggerHoldOffWidth = 0x1074; /// R/W + ///static uint32_t TriggerThreshold = 0x106C; /// R/W + ///static uint32_t TriggerHoldOffWidth = 0x1074; /// R/W static uint32_t DPPAlgorithmControl = 0x1080; /// R/W static uint32_t ChannelStatus = 0x1088; /// R static uint32_t AMCFirmwareRevision = 0x108C; /// R @@ -97,7 +97,7 @@ namespace Register { static uint32_t EventStored = 0x812C; /// R static uint32_t VoltageLevelModeConfig = 0x8138; /// R/W static uint32_t SoftwareClockSync = 0x813C; /// W - static uint32_t BoardInfo = 0x8140; /// R + static uint32_t BoardInfo = 0x8140; /// R /// [0:7] 0x0E = 725, 0x0B = 730, [8:15] 0x01 = 640 kSample, 0x08 = 5.12 MSample, [16:23] channel number static uint32_t AnalogMonitorMode = 0x8144; /// R/W static uint32_t EventSize = 0x814C; /// R static uint32_t TimeBombDowncounter = 0x8158; /// R @@ -111,7 +111,7 @@ namespace Register { static uint32_t ExtendedVetoDelay = 0x81C4; /// R/W static uint32_t ReadoutControl = 0xEF00; /// R/W static uint32_t ReadoutStatus = 0xEF04; /// R - static uint32_t BoardID = 0xEF08; /// R/W + static uint32_t BoardID = 0xEF08; /// R/W /// Geo address on VME crate static uint32_t MCSTBaseAddressAndControl = 0xEF0C; /// R/W static uint32_t RelocationAddress = 0xEF10; /// R/W static uint32_t InterruptStatusID = 0xEF14; /// R/W @@ -120,7 +120,31 @@ namespace Register { static uint32_t Scratch = 0xEF20; /// R/W static uint32_t SoftwareReset = 0xEF24; /// W static uint32_t SoftwareClear = 0xEF28; /// W - + static uint32_t ConfigurationReload = 0xEF34; /// W + static uint32_t ROMChecksum = 0xF000; /// R + static uint32_t ROMChecksumByte2 = 0xF004; /// R + static uint32_t ROMChecksumByte1 = 0xF008; /// R + static uint32_t ROMChecksumByte0 = 0xF00C; /// R + static uint32_t ROMConstantByte2 = 0xF010; /// R + static uint32_t ROMConstantByte1 = 0xF014; /// R + static uint32_t ROMConstantByte0 = 0xF018; /// R + static uint32_t ROM_C_Code = 0xF01C; /// R + static uint32_t ROM_R_Code = 0xF020; /// R + static uint32_t ROM_IEEE_OUI_Byte2 = 0xF024; /// R + static uint32_t ROM_IEEE_OUI_Byte1 = 0xF028; /// R + static uint32_t ROM_IEEE_OUI_Byte0 = 0xF02C; /// R + static uint32_t ROM_BoardVersion = 0xF030; /// R + static uint32_t ROM_BoardFromFactor = 0xF034; /// R + static uint32_t ROM_BoardIDByte1 = 0xF038; /// R + static uint32_t ROM_BoardIDByte0 = 0xF03C; /// R + static uint32_t ROM_PCB_rev_Byte3 = 0xF040; /// R + static uint32_t ROM_PCB_rev_Byte2 = 0xF044; /// R + static uint32_t ROM_PCB_rev_Byte1 = 0xF048; /// R + static uint32_t ROM_PCB_rev_Byte0 = 0xF04C; /// R + static uint32_t ROM_FlashType = 0xF050; /// R + static uint32_t ROM_BoardSerialNumByte1 = 0xF080; /// R + static uint32_t ROM_BoardSerialNumByte0 = 0xF084; /// R + static uint32_t ROM_VCXO_Type = 0xF088; /// R namespace PHA { static uint32_t DataFlush = 0x103C; /// W not sure diff --git a/test.cpp b/test.cpp index 1c6c354..aea31ae 100644 --- a/test.cpp +++ b/test.cpp @@ -3,15 +3,50 @@ int main(int argc, char* argv[]){ - DigitizerPHA * dig = new DigitizerPHA[2]; + DigitizerPHA * dig = new DigitizerPHA[1]; //DigitizerPSD * psd = new DigitizerPSD(); dig[0].OpenDigitizer(0,0, true); + + dig[0].ReadRegister(Register::DPP::BoardConfiguration, -1, "Board configure"); + dig[0].ReadRegister(Register::DPP::ROM_BoardIDByte0, -1, "Board ID Byte 0"); + dig[0].ReadRegister(Register::DPP::ROM_BoardIDByte1, -1, "Board ID Byte 1"); + dig[0].ReadRegister(Register::DPP::ROM_BoardSerialNumByte0, -1, "Board SN Byte 1"); + dig[0].ReadRegister(Register::DPP::ROM_BoardSerialNumByte1, -1, "Board SN Byte 0"); + dig[0].ReadRegister(Register::DPP::AMCFirmwareRevision, 0, "AMCFirmware"); + dig[0].ReadRegister(Register::DPP::ROCFPGAFirmwareRevision, 0, "ROC FPGA"); + dig[0].ReadRegister(Register::DPP::GlobalTriggerMask, 0, "trigger mask"); + dig[0].ReadRegister(Register::DPP::ChannelEnableMask, 0, "Channel mask"); + + + dig[0].ReadRegister(Register::DPP::PHA::TriggerThreshold, 0, "trigger threshold"); + + + //dig[0].CreateAndSaveSettingBinary("test.bin"); + + dig[0].OpenSettingBinary("test.bin"); + + printf("0x%x \n", (unsigned int)dig[0].ReadSettingBinary(Register::DPP::BoardConfiguration)); + printf("0x%x \n", (unsigned int)dig[0].ReadSettingBinary(Register::DPP::GlobalTriggerMask)); + printf("0x%x \n", (unsigned int)dig[0].ReadSettingBinary(Register::DPP::PHA::TriggerThreshold, 0)); + + + + +/* dig[1].OpenDigitizer(1,0, true); +/* + dig[2].OpenDigitizer(2,0, true); + dig[3].OpenDigitizer(0,1, true); + dig[4].OpenDigitizer(1,1, true); + dig[5].OpenDigitizer(2,1, true); + dig[6].OpenDigitizer(0,2, true); + dig[7].OpenDigitizer(1,2, true); + dig[8].OpenDigitizer(2,2, true); //dig[1].OpenDigitizer(1,0, true); //psd->OpenDigitizer(2,0); - + /* printf("======================= \n"); dig[0].SetRecordLength(3000); @@ -78,7 +113,7 @@ int main(int argc, char* argv[]){ dig[0].SetAcqMode("mixed"); - + */ delete [] dig; //delete psd;