void TimepixProducer::Event(i16 *timepixdata, u32 size) { //static unsigned char *serialdatablock; eudaq::RawDataEvent ev("Timepix",GetRunNumber(), GetIncreaseEventNumber() ); unsigned char *serialdatablock = new unsigned char[2*size]; for (unsigned i=0; i < size ; i ++) { serialdatablock[2*i] = (timepixdata[i] & 0xFF00) >> 8 ; serialdatablock[2*i + 1] = timepixdata[i] & 0xFF ; } ev.AddBlock( pixelmanCtrl->m_ModuleID.getInt(), serialdatablock , 2*size); // bool acqact = pixelmanCtrl->getAcquisitionActive(); // Sleep(100); // bool acqact2 = pixelmanCtrl->getAcquisitionActive(); for (int i=0; i < 3; i++) { try { SendEvent(ev); break; } catch(...) { if (i < 2) { EUDAQ_WARN("Device "+eudaq::to_string(pixelmanCtrl->m_ModuleID.getInt()) + ": " + eudaq::to_string(i) + ". Could not send event " + eudaq::to_string( ev.GetEventNumber() ) + ". Retrying..."); } // Sleep to wait for possible network problems to resolve Sleep(500); } if (i==2) { EUDAQ_ERROR("Device "+eudaq::to_string(pixelmanCtrl->m_ModuleID.getInt()) + ": " "Finally failed to send event " + eudaq::to_string( ev.GetEventNumber() )); EUDAQ_WARN("Device "+eudaq::to_string(pixelmanCtrl->m_ModuleID.getInt()) + ": " "Sending empty error event " + eudaq::to_string( ev.GetEventNumber() )); eudaq::RawDataEvent emptyEv("Timepix",GetRunNumber(),ev.GetEventNumber() ); try { SendEvent(ev); break; } catch(...) { EUDAQ_ERROR("Device "+eudaq::to_string(pixelmanCtrl->m_ModuleID.getInt()) + ": " + "Even sending the empty event failed, sorry"); } } } delete[] serialdatablock; }
void TimepixProducer::OnStopRun() { pixelmanCtrl->m_commHistRunCtrl.AddString(_T("End Of Run.")); if ( GetRunStatusFlag() == TimepixProducer::RUN_STOPPED ) { // give a warning to eudaq and do nothing EUDAQ_WARN("StopRun requested when run not active"); SetStatus(eudaq::Status::LVL_WARN, "StopRun requested when run not active"); } else { // send STOP_RUN command to the daq thread PushCommand( STOP_RUN ); // wait for the daq thread to lower the run active flag while ( GetRunStatusFlag() == RUN_ACTIVE ) { Sleep(1); } //EUDAQ_DEBUG("Sending EORE"); Sleep(1000); SendEvent(eudaq::RawDataEvent::EORE(_T("Timepix"),GetRunNumber(), GetEventNumber())); //std::cout << "Stop Run" << std::endl; //MessageBox(NULL, "End Of Run", "Message from Runcontrol",NULL); EUDAQ_INFO("Run Stopped"); SetStatus(eudaq::Status::LVL_OK, "Run Stopped"); } }
void KVINDRAOnlineDataAnalyser::HandleCommands(TString& ordre, TSocket* theSocket) { // Gestion des ordres // Returns kTRUE if command was understood & executed // Returns kFALSE if command unknown // // STOP will stop the analysis (calls EndRun() and EndAnalysis()) // CLEAR RAZ de tous les spectres // // DUMP=yes start dumping fired data parameters // DUMP=no stop dumping fired data parameters // // SAVE=toto.root will save all histograms in '${ANALYSIS_RESULTS}/toto.root' (does not stop analysis) // SAVE=/home/toto.root will save all histograms in '/home/toto.root' (does not stop analysis) // SAVE will save all histograms in '${ANALYSIS_RESULTS}/[class name]_Run[run number]_[date].root' (does not stop analysis) KVString com(ordre.Data()); com.Begin("="); ordre = com.Next(); ordre.ToUpper(); if (ordre == "STOP") { // arrete l'analyse, en appelant EndRun() et EndAnalysis() fGoEventLoop = kFALSE; theSocket->Send("ok"); return; } else if (ordre == "SAVE") { TString tmp_fil = com.Next(); TString fil; bool send_name = kFALSE; if (tmp_fil.Contains("/")) fil = tmp_fil; else if (tmp_fil == "") { TDatime save_time; save_time.Set(); TString date = save_time.AsString(); date.ReplaceAll(" ", "_"); fil = Form("${ANALYSIS_RESULTS}/%s_Run%d_%s.root", GetName(), GetRunNumber(), date.Data()); send_name = kTRUE; } else fil = Form("${ANALYSIS_RESULTS}/%s", tmp_fil.Data()); SaveSpectra(fil.Data()); if (send_name) theSocket->Send(fil.Data()); else theSocket->Send("ok"); return; } else if (ordre == "CLEAR") { ClearAllHistos(); theSocket->Send("ok"); return; } else if (ordre == "DUMP") { TString tmp_fil = com.Next(); tmp_fil.ToLower(); if (tmp_fil == "yes")fDumpEvents = kTRUE; else if (tmp_fil == "no")fDumpEvents = kFALSE; else { theSocket->Send("unknown command"); return; } theSocket->Send("ok"); return; } theSocket->Send("unknown command"); }
void VMEReader::NewRun() const { if (!fOnSocket) return; Client::Send(SocketMessage(NEW_RUN)); std::ostringstream os; os << "New run detected: " << GetRunNumber(); Client::Send(Exception(__PRETTY_FUNCTION__, os.str(), JustWarning)); }
void OnlineGUI::ObtainRunNumber() { // Utility to obtain the runnumber through a helper macro // "GetRunNumber.C" runNumber = GetRunNumber(); #ifdef DEBUG cout << "Runnumber from file: " << runNumber << endl; #endif }
void KVINDRAOnlineDataAnalyser::preInitRun() { Info("InitRun", "Traitement du run %d", GetRunNumber()); fSpectraDB = ((KVGRUNetClientGanilReader*)fRunFile)->GetSpectraServer(); TString path("$(HOME)/.kvonlineanalysisrc"); gSystem->ExpandPathName(path); TEnv env(path.Data()); env.SetValue(Form("%s.%s.SpectraDB.port", ClassName(), gSystem->HostName()), ((KVGRUNetClientGanilReader*)fRunFile)->GetSpectraServerPort()); env.SaveLevel(kEnvLocal); addallhistostoserver(&fHistoList, fHistoList.GetName()); events = 0; }
void VMEReader::ReadXML(const char* filename) { tinyxml2::XMLDocument doc; doc.LoadFile(filename); if (doc.Error()) { std::ostringstream os; os << "Error while trying to parse the configuration file" << "\n\t" << "Code: " << doc.ErrorID() << "\n\t" << "Dump of error:" << "\n" << doc.GetErrorStr1(); throw Exception(__PRETTY_FUNCTION__, os.str(), Fatal); } if (tinyxml2::XMLElement* fpga=doc.FirstChildElement("triggering")) { if (const char* mode=fpga->Attribute("mode")) { std::ostringstream os; os << "Triggering mode: "; if (!strcmp(mode,"continuous_storage")) { fGlobalAcqMode = ContinuousStorage; os << "Continuous storage (manual)"; } if (!strcmp(mode,"trigger_start")) { fGlobalAcqMode = TriggerStart; os << "Continuous storage (trigger on start)"; } if (!strcmp(mode,"trigger_matching")) { fGlobalAcqMode = TriggerMatching; os << "Trigger matching"; } if (fOnSocket) Client::Send(Exception(__PRETTY_FUNCTION__, os.str(), Info)); } } if (tinyxml2::XMLElement* fpga=doc.FirstChildElement("fpga")) { if (const char* address=fpga->Attribute("address")) { unsigned long addr = static_cast<unsigned long>(strtol(address, NULL, 0)); if (!addr) throw Exception(__PRETTY_FUNCTION__, "Failed to parse FPGA's base address", Fatal); try { try { AddFPGAUnit(addr); } catch (Exception& e) { if (fOnSocket) Client::Send(e); } VME::FPGAUnitV1495Control control = fFPGA->GetControl(); if (tinyxml2::XMLElement* clock=fpga->FirstChildElement("clock")) { if (tinyxml2::XMLElement* source=clock->FirstChildElement("source")) { if (!strcmp(source->GetText(),"internal")) control.SetClockSource(VME::FPGAUnitV1495Control::InternalClock); if (!strcmp(source->GetText(),"external")) control.SetClockSource(VME::FPGAUnitV1495Control::ExternalClock); } if (tinyxml2::XMLElement* period=clock->FirstChildElement("period")) { fFPGA->SetInternalClockPeriod(atoi(period->GetText())); } } if (tinyxml2::XMLElement* trig=fpga->FirstChildElement("trigger")) { if (tinyxml2::XMLElement* source=trig->FirstChildElement("source")) { if (!strcmp(source->GetText(),"internal")) control.SetTriggerSource(VME::FPGAUnitV1495Control::InternalTrigger); if (!strcmp(source->GetText(),"external")) control.SetTriggerSource(VME::FPGAUnitV1495Control::ExternalTrigger); } if (tinyxml2::XMLElement* period=trig->FirstChildElement("period")) { fFPGA->SetInternalTriggerPeriod(atoi(period->GetText())); } } if (tinyxml2::XMLElement* sig=fpga->FirstChildElement("signal")) { if (tinyxml2::XMLElement* source=sig->FirstChildElement("source")) { if (!strcmp(source->GetText(),"internal")) for (unsigned int i=0; i<2; i++) control.SetSignalSource(i, VME::FPGAUnitV1495Control::InternalSignal); if (!strcmp(source->GetText(),"external")) for (unsigned int i=0; i<2; i++) control.SetSignalSource(i, VME::FPGAUnitV1495Control::ExternalSignal); } if (tinyxml2::XMLElement* poi=sig->FirstChildElement("poi")) { fFPGA->SetOutputPulserPOI(atoi(poi->GetText())); } } if (tinyxml2::XMLElement* vth=fpga->FirstChildElement("threshold")) { if (tinyxml2::XMLElement* tdc0=vth->FirstChildElement("tdc0")) { fFPGA->SetThresholdVoltage(atoi(tdc0->GetText()), 0); } if (tinyxml2::XMLElement* tdc1=vth->FirstChildElement("tdc1")) { fFPGA->SetThresholdVoltage(atoi(tdc1->GetText()), 1); } if (tinyxml2::XMLElement* tdc2=vth->FirstChildElement("tdc2")) { fFPGA->SetThresholdVoltage(atoi(tdc2->GetText()), 2); } if (tinyxml2::XMLElement* tdc3=vth->FirstChildElement("tdc3")) { fFPGA->SetThresholdVoltage(atoi(tdc3->GetText()), 3); } } switch (fGlobalAcqMode) { case ContinuousStorage: case TriggerStart: control.SetTriggeringMode(VME::FPGAUnitV1495Control::ContinuousStorage); break; case TriggerMatching: control.SetTriggeringMode(VME::FPGAUnitV1495Control::TriggerMatching); break; } fFPGA->SetControl(control); } catch (Exception& e) { e.Dump(); if (fOnSocket) Client::Send(e); throw e; } } else throw Exception(__PRETTY_FUNCTION__, "Failed to extract FPGA's base address", Fatal); } unsigned int tdc_id = 0; for (tinyxml2::XMLElement* atdc=doc.FirstChildElement("tdc"); atdc!=NULL; atdc=atdc->NextSiblingElement("tdc"), tdc_id++) { if (const char* address=atdc->Attribute("address")) { unsigned long addr = static_cast<unsigned long>(strtol(address, NULL, 0)); if (!addr) throw Exception(__PRETTY_FUNCTION__, "Failed to parse TDC's base address", Fatal); try { try { AddTDC(addr); } catch (Exception& e) { if (fOnSocket) Client::Send(e); } VME::TDCV1x90* tdc = GetTDC(addr); uint16_t poi_group1 = 0xffff, poi_group2 = 0xffff; std::string detector_name = "unknown"; switch (fGlobalAcqMode) { case ContinuousStorage: case TriggerStart: tdc->SetAcquisitionMode(VME::CONT_STORAGE); break; case TriggerMatching: tdc->SetAcquisitionMode(VME::TRIG_MATCH); break; } //std::cout << triggering_mode << " --> " << tdc->GetAcquisitionMode() << std::endl; if (tinyxml2::XMLElement* verb=atdc->FirstChildElement("verbosity")) { tdc->SetVerboseLevel(atoi(verb->GetText())); } if (tinyxml2::XMLElement* det=atdc->FirstChildElement("detector")) { detector_name = det->GetText(); } if (tinyxml2::XMLElement* det=atdc->FirstChildElement("det_mode")) { if (!strcmp(det->GetText(),"trailead")) tdc->SetDetectionMode(VME::TRAILEAD); if (!strcmp(det->GetText(),"leading")) tdc->SetDetectionMode(VME::OLEADING); if (!strcmp(det->GetText(),"trailing")) tdc->SetDetectionMode(VME::OTRAILING); if (!strcmp(det->GetText(),"pair")) tdc->SetDetectionMode(VME::PAIR); } if (tinyxml2::XMLElement* dll=atdc->FirstChildElement("dll")) { if (!strcmp(dll->GetText(),"Direct_Low_Resolution")) tdc->SetDLLClock(VME::TDCV1x90::DLL_Direct_LowRes); if (!strcmp(dll->GetText(),"PLL_Low_Resolution")) tdc->SetDLLClock(VME::TDCV1x90::DLL_PLL_LowRes); if (!strcmp(dll->GetText(),"PLL_Medium_Resolution")) tdc->SetDLLClock(VME::TDCV1x90::DLL_PLL_MedRes); if (!strcmp(dll->GetText(),"PLL_High_Resolution")) tdc->SetDLLClock(VME::TDCV1x90::DLL_PLL_HighRes); } if (tinyxml2::XMLElement* poi=atdc->FirstChildElement("poi")) { if (tinyxml2::XMLElement* g0=poi->FirstChildElement("group0")) { poi_group1 = atoi(g0->GetText()); } if (tinyxml2::XMLElement* g1=poi->FirstChildElement("group1")) { poi_group2 = atoi(g1->GetText()); } } tdc->SetPoI(poi_group1, poi_group2); if (atdc->FirstChildElement("ettt")) { tdc->SetETTT(); } if (tinyxml2::XMLElement* wind=atdc->FirstChildElement("trigger_window")) { if (tinyxml2::XMLElement* width=wind->FirstChildElement("width")) { tdc->SetWindowWidth(atoi(width->GetText())); } if (tinyxml2::XMLElement* offset=wind->FirstChildElement("offset")) { tdc->SetWindowOffset(atoi(offset->GetText())); } } OnlineDBHandler().SetTDCConditions(tdc_id, addr, tdc->GetAcquisitionMode(), tdc->GetDetectionMode(), detector_name); } catch (Exception& e) { throw e; } } } for (tinyxml2::XMLElement* acfd=doc.FirstChildElement("cfd"); acfd!=NULL; acfd=acfd->NextSiblingElement("cfd")) { if (const char* address=acfd->Attribute("address")) { unsigned long addr = static_cast<unsigned long>(strtol(address, NULL, 0)); if (!addr) throw Exception(__PRETTY_FUNCTION__, "Failed to parse CFD's base address", Fatal); try { try { AddCFD(addr); } catch (Exception& e) { if (fOnSocket) Client::Send(e); } VME::CFDV812* cfd = GetCFD(addr); if (tinyxml2::XMLElement* poi=acfd->FirstChildElement("poi")) { cfd->SetPOI(atoi(poi->GetText())); } if (tinyxml2::XMLElement* ow=acfd->FirstChildElement("output_width")) { if (tinyxml2::XMLElement* g0=ow->FirstChildElement("group0")) { cfd->SetOutputWidth(0, atoi(g0->GetText())); } if (tinyxml2::XMLElement* g1=ow->FirstChildElement("group1")) { cfd->SetOutputWidth(1, atoi(g1->GetText())); } } if (tinyxml2::XMLElement* dt=acfd->FirstChildElement("dead_time")) { if (tinyxml2::XMLElement* g0=dt->FirstChildElement("group0")) { cfd->SetDeadTime(0, atoi(g0->GetText())); } if (tinyxml2::XMLElement* g1=dt->FirstChildElement("group1")) { cfd->SetDeadTime(1, atoi(g1->GetText())); } } if (tinyxml2::XMLElement* thr=acfd->FirstChildElement("threshold")) { for (tinyxml2::XMLElement* ch=thr->FirstChildElement("channel"); ch!=NULL; ch=ch->NextSiblingElement("channel")) { cfd->SetThreshold(atoi(ch->Attribute("id")), atoi(ch->GetText())); std::cout << "Threshold for channel " << atoi(ch->Attribute("id")) << " set to " << ch->GetText() << std::endl; } } } catch (Exception& e) { throw e; } } } std::cout << "Global acquisition mode: " << fGlobalAcqMode << std::endl; unsigned int run = GetRunNumber(); std::ifstream source(filename, std::ios::binary); std::stringstream out_name; out_name << std::getenv("PPS_PATH") << "/config/config_run" << run << ".xml"; std::ofstream dest(out_name.str().c_str(), std::ios::binary); dest << source.rdbuf(); if (fOnSocket) Client::Send(Exception(__PRETTY_FUNCTION__, "Ready to release veto!", Info)); //doc.Print(); }