diff --git a/daq/FEMProxy.h b/daq/FEMProxy.h index 3401633..2bdede4 100644 --- a/daq/FEMProxy.h +++ b/daq/FEMProxy.h @@ -19,7 +19,7 @@ class FEMProxy : public TRESTDAQSocket { public: FEMProxy(){ } - bool pendingEvent=false; + bool pendingEvent=true; TRestRawDAQMetadata::FECMetadata fecMetadata; //std::atomic_int int cmd_sent=0; diff --git a/daq/TRESTDAQ.h b/daq/TRESTDAQ.h index e712c0a..83ad0c4 100644 --- a/daq/TRESTDAQ.h +++ b/daq/TRESTDAQ.h @@ -27,7 +27,7 @@ class TRESTDAQ { // Pure virtual methods to start, stop and configure the DAQ virtual void configure() = 0; - virtual void startDAQ() = 0; + virtual void startDAQ(bool configure=true) = 0; virtual void stopDAQ() = 0; virtual void initialize() = 0; virtual void startUp(){}; diff --git a/daq/TRESTDAQDCC.cxx b/daq/TRESTDAQDCC.cxx index 87ab1b4..bc8c855 100644 --- a/daq/TRESTDAQDCC.cxx +++ b/daq/TRESTDAQDCC.cxx @@ -90,12 +90,12 @@ void TRESTDAQDCC::configure() { // SendCommand("isobus 0x0F", -1);//Reset event counter, timestamp set eventType to test } -void TRESTDAQDCC::startDAQ() { +void TRESTDAQDCC::startDAQ(bool configure) { if ( acqType == daq_metadata_types::acqTypes::PEDESTAL) { pedestal(); } else { - dataTaking(); + dataTaking(configure); } } @@ -149,14 +149,14 @@ void TRESTDAQDCC::pedestal() { FillTree(restRun, &fSignalEvent); } -void TRESTDAQDCC::dataTaking() { +void TRESTDAQDCC::dataTaking(bool configure) { std::cout << "Starting data taking run" << std::endl; char cmd[200]; SendCommand("fem 0"); // Needed? // if(comp)SendCommand("skipempty 1", -1);//Skip empty frames in compress mode // else SendCommand("skipempty 0", -1);//Save empty frames if not - SendCommand("isobus 0x4F"); // Reset event counter, timestamp for type 11 + if(configure)SendCommand("isobus 0x4F"); // Reset event counter, timestamp for type 11 while ( !abrt && !nextFile && (daqMetadata->GetNEvents() == 0 || event_cnt < daqMetadata->GetNEvents())) { SendCommand("fem 0"); diff --git a/daq/TRESTDAQDCC.h b/daq/TRESTDAQDCC.h index 3f44e12..172d89f 100644 --- a/daq/TRESTDAQDCC.h +++ b/daq/TRESTDAQDCC.h @@ -21,13 +21,13 @@ class TRESTDAQDCC : public TRESTDAQ { TRESTDAQDCC(TRestRun* rR, TRestRawDAQMetadata* dM); void configure() override; - void startDAQ() override; + void startDAQ(bool configure=true) override; void stopDAQ() override; void initialize() override; private: void pedestal(); - void dataTaking(); + void dataTaking(bool configure=true); DCCPacket::packetReply SendCommand(const char* cmd, DCCPacket::packetType type = DCCPacket::packetType::ASCII, size_t nPackets = 0, DCCPacket::packetDataType dataType = DCCPacket::packetDataType::NONE); void waitForTrigger(); diff --git a/daq/TRESTDAQDummy.cxx b/daq/TRESTDAQDummy.cxx index 53913cb..fdf6b7a 100644 --- a/daq/TRESTDAQDummy.cxx +++ b/daq/TRESTDAQDummy.cxx @@ -21,7 +21,7 @@ void TRESTDAQDummy::initialize() {} void TRESTDAQDummy::configure() { std::cout << "Configuring readout" << std::endl; } -void TRESTDAQDummy::startDAQ() { +void TRESTDAQDummy::startDAQ(bool configure) { std::srand(static_cast(std::time(nullptr))); while ( !abrt && !nextFile && (daqMetadata->GetNEvents() == 0 || event_cnt < daqMetadata->GetNEvents() ) ) { diff --git a/daq/TRESTDAQDummy.h b/daq/TRESTDAQDummy.h index b8ceb8e..7980531 100644 --- a/daq/TRESTDAQDummy.h +++ b/daq/TRESTDAQDummy.h @@ -17,7 +17,7 @@ class TRESTDAQDummy : public TRESTDAQ { TRESTDAQDummy(TRestRun* rR, TRestRawDAQMetadata* dM); void configure() override; - void startDAQ() override; + void startDAQ(bool configure=true) override; void stopDAQ() override; void initialize() override; }; diff --git a/daq/TRESTDAQFEMINOS.cxx b/daq/TRESTDAQFEMINOS.cxx index e1fe8c6..184252a 100644 --- a/daq/TRESTDAQFEMINOS.cxx +++ b/daq/TRESTDAQFEMINOS.cxx @@ -12,6 +12,7 @@ Author: JuanAn Garcia 18/08/2021 std::atomic TRESTDAQFEMINOS::stopReceiver(false); +std::atomic TRESTDAQFEMINOS::isPed(false); TRESTDAQFEMINOS::TRESTDAQFEMINOS(TRestRun* rR, TRestRawDAQMetadata* dM) : TRESTDAQ(rR, dM) { initialize(); } @@ -41,6 +42,7 @@ void TRESTDAQFEMINOS::initialize() { } //Start receive and event builder threads + stopReceiver=false; receiveThread = std::thread( TRESTDAQFEMINOS::ReceiveThread, &FEMArray); eventBuilderThread = std::thread( TRESTDAQFEMINOS::EventBuilderThread, &FEMArray, restRun, &fSignalEvent); } @@ -154,7 +156,7 @@ void TRESTDAQFEMINOS::configure() { } } -void TRESTDAQFEMINOS::startDAQ() { +void TRESTDAQFEMINOS::startDAQ(bool configure) { auto rT = daq_metadata_types::acqTypes_map.find(std::string(daqMetadata->GetAcquisitionType())); if (rT == daq_metadata_types::acqTypes_map.end()) { std::cout << "Unknown acquisition type " << daqMetadata->GetAcquisitionType() << " skipping" << std::endl; @@ -166,7 +168,7 @@ void TRESTDAQFEMINOS::startDAQ() { if (rT->second == daq_metadata_types::acqTypes::PEDESTAL) { pedestal(); } else { - dataTaking(); + dataTaking(configure); } } @@ -234,67 +236,68 @@ void TRESTDAQFEMINOS::pedestal() { BroadcastCommand("serve_target 1",FEMArray); } -void TRESTDAQFEMINOS::dataTaking() { +void TRESTDAQFEMINOS::dataTaking(bool configure) { std::cout << "Starting data taking run" << std::endl; //BroadcastCommand("daq 0x000000 F",FEMArray,false); - BroadcastCommand("daq 0xFFFFFF F",FEMArray); - BroadcastCommand("sca enable 0",FEMArray); - std::this_thread::sleep_for(std::chrono::seconds(1)); - BroadcastCommand("serve_target 0",FEMArray); - std::this_thread::sleep_for(std::chrono::seconds(4)); - //Readout settings - BroadcastCommand("modify_hit_reg 0",FEMArray); - BroadcastCommand("emit_hit_cnt 1",FEMArray); - BroadcastCommand("emit_empty_ch 0",FEMArray); - BroadcastCommand("emit_lst_cell_rd 1",FEMArray); - BroadcastCommand("keep_rst 1",FEMArray); - BroadcastCommand("skip_rst 0",FEMArray); - //AGET settings - if(compressMode == daq_metadata_types::compressModeTypes::ALLCHANNELS || compressMode == daq_metadata_types::compressModeTypes::ZEROSUPPRESSION){ - BroadcastCommand("aget * mode 0x1",FEMArray);//Mode: 0x0: hit/selected channels 0x1:all channels - } else if(compressMode == daq_metadata_types::compressModeTypes::TRIGGEREDCHANNELS){ - BroadcastCommand("aget * mode 0x0",FEMArray);//Mode: 0x0: hit/selected channels 0x1:all channels - } - BroadcastCommand("aget * tst_digout 1",FEMArray);//?? + if(configure){ + BroadcastCommand("daq 0xFFFFFF F",FEMArray); + BroadcastCommand("sca enable 0",FEMArray); + std::this_thread::sleep_for(std::chrono::seconds(1)); + BroadcastCommand("serve_target 0",FEMArray); + std::this_thread::sleep_for(std::chrono::seconds(4)); + //Readout settings + BroadcastCommand("modify_hit_reg 0",FEMArray); + BroadcastCommand("emit_hit_cnt 1",FEMArray); + BroadcastCommand("emit_empty_ch 0",FEMArray); + BroadcastCommand("emit_lst_cell_rd 1",FEMArray); + BroadcastCommand("keep_rst 1",FEMArray); + BroadcastCommand("skip_rst 0",FEMArray); + //AGET settings + if(compressMode == daq_metadata_types::compressModeTypes::ALLCHANNELS || compressMode == daq_metadata_types::compressModeTypes::ZEROSUPPRESSION){ + BroadcastCommand("aget * mode 0x1",FEMArray);//Mode: 0x0: hit/selected channels 0x1:all channels + } else if(compressMode == daq_metadata_types::compressModeTypes::TRIGGEREDCHANNELS){ + BroadcastCommand("aget * mode 0x0",FEMArray);//Mode: 0x0: hit/selected channels 0x1:all channels + } + BroadcastCommand("aget * tst_digout 1",FEMArray);//?? - BroadcastCommand("subtract_ped 1",FEMArray); - - if(compressMode == daq_metadata_types::compressModeTypes::ZEROSUPPRESSION){ - BroadcastCommand("zero_suppress 1",FEMArray); - BroadcastCommand("zs_pre_post 8 4",FEMArray); - } else { - BroadcastCommand("zero_suppress 0",FEMArray); - BroadcastCommand("zs_pre_post 8 4",FEMArray); - } - - //Event generator - BroadcastCommand("clr tstamp",FEMArray); - BroadcastCommand("clr evnct",FEMArray); - BroadcastCommand("event_limit 0x0",FEMArray);//Infinite - if (triggerType == daq_metadata_types::triggerTypes::INTERNAL){ - BroadcastCommand("trig_rate 1 50",FEMArray); - BroadcastCommand("trig_enable 0x1",FEMArray); - } else if (triggerType == daq_metadata_types::triggerTypes::TCM) { - BroadcastCommand("trig_enable 0x8",FEMArray);//tcm??? - } else if (triggerType == daq_metadata_types::triggerTypes::AUTO) { - BroadcastCommand("trig_enable 0x0",FEMArray); + BroadcastCommand("subtract_ped 1",FEMArray); + + if(compressMode == daq_metadata_types::compressModeTypes::ZEROSUPPRESSION){ + BroadcastCommand("zero_suppress 1",FEMArray); + BroadcastCommand("zs_pre_post 8 4",FEMArray); + } else { + BroadcastCommand("zero_suppress 0",FEMArray); + BroadcastCommand("zs_pre_post 8 4",FEMArray); } - for (auto &FEM : FEMArray){ - char cmd[200]; - for(int a=0;a *FEMA ) { } else { std::unique_lock lock_mem(FEM.mutex_mem); //const std::deque frame (&buf_rcv[1], &buf_rcv[size -1]); - FEM.buffer.insert(FEM.buffer.end(), &buf_rcv[1], &buf_rcv[size -1]); + FEM.buffer.insert(FEM.buffer.end(), &buf_rcv[1], &buf_rcv[size]); int bufferSize = FEM.buffer.size(); lock_mem.unlock(); if (verboseLevel >= TRestStringOutput::REST_Verbose_Level::REST_Debug) @@ -446,49 +450,55 @@ void TRESTDAQFEMINOS::ReceiveThread( std::vector *FEMA ) { } void TRESTDAQFEMINOS::EventBuilderThread(std::vector *FEMA, TRestRun *rR, TRestRawSignalEvent* sEvent){ + sEvent->Initialize(); - sEvent->Initialize(); - - uint32_t ev_count; - uint64_t ts; - - bool newEvent = false; - bool pendingEvent = false; + uint32_t ev_count=0; + uint64_t ts=0; - while (!stopReceiver ){ + bool newEvent = true; + bool emptyBuffer = true; + do { + emptyBuffer=true; for (auto &FEM : *FEMA){ std::unique_lock lock(FEM.mutex_mem); - if(!FEM.buffer.empty()){//Do nothing - if(FEM.pendingEvent){//Wait till we reach end of event for all the FEMINOS + emptyBuffer &= FEM.buffer.empty(); + if(!FEM.buffer.empty()){ + if(FEM.pendingEvent){//Wait till we reach end of event for all the ARC FEM.pendingEvent = !FEMINOSPacket::GetNextEvent( FEM.buffer, sEvent, ts, ev_count); - } else if( !FEM.pendingEvent && !pendingEvent) { - FEM.pendingEvent = !FEMINOSPacket::GetNextEvent( FEM.buffer, sEvent, ts, ev_count); - newEvent=true; } } lock.unlock(); } - pendingEvent=false; - + newEvent = true; for (const auto &FEM : *FEMA){ - //std::unique_lock lock(FEM.mutex_mem); - if(FEM.pendingEvent)pendingEvent=true;//Check if the event is pending - //lock.unlock(); + newEvent &= !FEM.pendingEvent;//Check if the event is pending } - if(newEvent && !pendingEvent){//Save Event if closed + if(newEvent){//Save Event if closed if(rR){ sEvent->SetID(ev_count); sEvent->SetTime( rR->GetStartTimestamp() + (double) ts * 2E-8 ); FillTree(rR, sEvent); sEvent->Initialize(); - newEvent = false; if(event_cnt%100 == 0)std::cout<<"Events "<SetID(ev_count); + sEvent->SetTime( rR->GetStartTimestamp() + (double) ts * 2E-8 ); + FillTree(rR, sEvent); + sEvent->Initialize(); } } - } } diff --git a/daq/TRESTDAQFEMINOS.h b/daq/TRESTDAQFEMINOS.h index 9820438..12e0b0d 100644 --- a/daq/TRESTDAQFEMINOS.h +++ b/daq/TRESTDAQFEMINOS.h @@ -24,7 +24,7 @@ class TRESTDAQFEMINOS : public TRESTDAQ { TRESTDAQFEMINOS(TRestRun* rR, TRestRawDAQMetadata* dM); void configure() override; - void startDAQ() override; + void startDAQ(bool configure=true) override; void stopDAQ() override; void initialize() override; void startUp() override; @@ -34,12 +34,11 @@ class TRESTDAQFEMINOS : public TRESTDAQ { static void EventBuilderThread(std::vector *FEMA, TRestRun *rR, TRestRawSignalEvent* sEvent); static void waitForCmd(FEMProxy &FEM); static std::atomic stopReceiver; - - inline static std::mutex mutex; + static std::atomic isPed; private: void pedestal(); - void dataTaking(); + void dataTaking(bool configure=true); void BroadcastCommand(const char* cmd, std::vector &FEMA, bool wait=true); void SendCommand(const char* cmd, FEMProxy &FEM, bool wait=true); diff --git a/daq/TRESTDAQManager.cxx b/daq/TRESTDAQManager.cxx index a0eb0fe..6458949 100644 --- a/daq/TRESTDAQManager.cxx +++ b/daq/TRESTDAQManager.cxx @@ -53,7 +53,7 @@ void TRESTDAQManager::startUp() { TRestRawDAQMetadata daqMetadata(sM->cfgFile); - sM->status = 1; + sM->status = 2; DetachSharedMemory(&sM); try{ @@ -186,9 +186,9 @@ void TRESTDAQManager::dataTaking() { if(daq){ if(parentRunNumber == 0){ daq->configure(); - std::cout << "Electronics configured, starting data taking run type " << std::endl; + std::cout << "Electronics configured, starting data taking run type "<startDAQ(); // Should wait till completion or stopped + daq->startDAQ(parentRunNumber == 0); // Should wait till completion or stopped daq->stopDAQ(); } } catch(const TRESTDAQException& e) { @@ -302,6 +302,7 @@ void TRESTDAQManager::InitializeSharedMemory(sharedMemoryStruct* sM) { sprintf(sM->cfgFile, "none"); sprintf(sM->runTag, "none"); sprintf(sM->runName, "none"); + sprintf(sM->runType, "none"); sM->startDAQ = 0; sM->startUp = 0; sM->status = 0; diff --git a/restDAQManager.cxx b/restDAQManager.cxx index efa9027..a5aeb0f 100644 --- a/restDAQManager.cxx +++ b/restDAQManager.cxx @@ -17,6 +17,7 @@ void help() { std::cout << " --e : Exit manager" << std::endl; std::cout << " --s : Stop run (if ongoing)" << std::endl; std::cout << " --c : Set configFile (single run)" << std::endl; + std::cout << " --u : Start up electronics (FEMINOS or ARC)" << std::endl; std::cout << " --h : Print this help" << std::endl; std::cout << "If no arguments are provided it starts at infinite loop which is controller via shared memory" << std::endl; }