/** Method calculates averaged polar coordinates of the detector's group (which may consist of one detector) *@param det -- reference to the Mantid Detector *@param Observer -- sample position or the centre of the polar system of coordinates to calculate detector's parameters. *@param Detector -- return Detector class containing averaged polar coordinates of the detector or detector's group in spherical coordinate system with centre at Observer */ void FindDetectorsPar::calcDetPar(const Geometry::IDetector &det, const Kernel::V3D &Observer, DetParameters &Detector) { // get number of basic detectors within the composit detector size_t nDetectors = det.nDets(); // define summator AvrgDetector detSum; // do we want spherical or linear box sizes? detSum.setUseSpherical(!m_SizesAreLinear); if (nDetectors == 1) { detSum.addDetInfo(det, Observer); } else { // access contributing detectors; auto detGroup = dynamic_cast<const Geometry::DetectorGroup *>(&det); if (!detGroup) { g_log.error() << "calc_cylDetPar: can not downcast IDetector_sptr to " "detector group for det->ID: " << det.getID() << '\n'; throw(std::bad_cast()); } for (const auto &det : detGroup->getDetectors()) { detSum.addDetInfo(*det, Observer); } } // calculate averages and return the detector parameters detSum.returnAvrgDetPar(Detector); }
TEST(DetectorSpectrumMapDataTest, read_detector_spectrum_map_detectors) { extern std::string testDataPath; auto detSpecMap = DetectorSpectrumMapData(testDataPath + "spectrum_gastubes_01.dat"); EXPECT_EQ(245768, detSpecMap.getNumberOfEntries()); auto detectors = detSpecMap.getDetectors(); EXPECT_EQ(1, detectors[0]); EXPECT_EQ(1100000, detectors[8]); EXPECT_EQ(4523511, detectors[245767]); }
std::vector<Geometry::IDetector_const_sptr> SpectrumInfo::getDetectorVector(const size_t index) const { const auto &det = getDetector(index); const auto &ndet = det.nDets(); if (ndet > 1) { const auto group = dynamic_cast<const Geometry::DetectorGroup *>(&det); return group->getDetectors(); } else { size_t thread = static_cast<size_t>(PARALLEL_THREAD_NUMBER); return {m_lastDetector[thread]}; } }
void CNetwork::readInputFile() { // open the TRAF file FILE *file_trf = NULL; if (file_trf = fopen(m_traf_input_file, "r")) { sprintf(out_buf, "Opened file: \"%s\".", m_traf_input_file); OutputString(out_buf, strlen(out_buf), SIM_COLOR_RGB, RTE_MESSAGE_RGB); // parse the time periods processTimePeriods(file_trf); rewind(file_trf); // create the node list getNodes(file_trf); rewind(file_trf); // create the link list getLinks(file_trf); rewind(file_trf); // find the opposing link for each link, if one exists int up = 0; int down = 0; CLink *link = NULL; POSITION pos = m_link_list.GetHeadPosition(); while (pos != NULL) { link = m_link_list.GetNext(pos); up = link->getOpposingNodeId(); down = link->m_dn_node->getId(); CLink *opposing = NULL; opposing = findLink(up, down); link->setOpposingLink(opposing); } // create the lanes on each link createLanes(file_trf); rewind(file_trf); // NOTE: create here the signal timings for the nodes to be controlled by the algorithm, if you want // create the detectors that exist in the TRAF file getDetectors(file_trf); // close the stream fclose(file_trf); } }
TEST(DetectorSpectrumMapDataTest, create_message_buffer) { extern std::string testDataPath; auto detSpecMap = DetectorSpectrumMapData(testDataPath + "spectrum_gastubes_01.dat"); std::string rawbuf; EXPECT_NO_THROW(detSpecMap.getBufferPointer(rawbuf)); auto receivedMapData = DetectorSpectrumMapData(); EXPECT_NO_THROW(receivedMapData.decodeMessage( reinterpret_cast<const uint8_t *>(rawbuf.c_str()))); EXPECT_EQ(245768, receivedMapData.getNumberOfEntries()); auto detectors = receivedMapData.getDetectors(); EXPECT_EQ(1, detectors[0]); EXPECT_EQ(1100000, detectors[8]); EXPECT_EQ(4523511, detectors[245767]); auto spectra = receivedMapData.getSpectra(); EXPECT_EQ(1, spectra[0]); EXPECT_EQ(9, spectra[8]); EXPECT_EQ(245768, spectra[245767]); }