8 #define DET_MEM_LEN (32*1024*1024) // 128Mb
11 template <
class DetCardPolicy>
14 template <
class DetCardPolicy>
39 addMapping(
ISISVME::TransferIORegisterSpace, DCTAC, 1, &
m_tcgAccessRegister,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
41 addMapping(
ISISVME::TransferIORegisterSpace, DCTCGTBL, 1, &
m_tcgTimeBinLimitRegister,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
43 addMapping(
ISISVME::TransferLUTSpace, DCTCGLUT, DCTCGLUTSIZE,
m_tcglutMemory,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
44 addMapping(
ISISVME::TransferIORegisterSpace, DCDESCR, 1, &
m_descriptorTimeBinLimitRegister,
"",
true,
true, tcg_access, DCTDESCR,
false,
false, fault_mode);
45 addMapping(
ISISVME::TransferIORegisterSpace, DCDESCRX, 1, &
m_descriptorTimeBinLimitRegister,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
46 addMapping(
ISISVME::TransferLUTSpace, DCPOSLUT, DCPOSLUTSIZE,
m_poslutMemory,
"",
true,
true, tcg_access, DCTPOSLUT,
false,
false, fault_mode);
47 addMapping(
ISISVME::TransferIORegisterSpace, DCVETOENABLE, 1, &
m_vetoEnableRegister,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
48 addMapping(
ISISVME::TransferIORegisterSpace, DCVETOFLAG, 1, &
m_vetoFlagRegister,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
49 addMapping(
ISISVME::TransferIORegisterSpace, DCPERSIZE0, 1, &
m_periodSizeLow,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
50 addMapping(
ISISVME::TransferIORegisterSpace, DCPERSIZE1, 1, &
m_periodSizeHigh,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
51 addMapping(
ISISVME::TransferIORegisterSpace, DCPERCNT0, 1, &
m_periodCounterLow,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
52 addMapping(
ISISVME::TransferIORegisterSpace, DCPERCNT1, 1, &
m_periodCounterHigh,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
53 addMapping(
ISISVME::TransferIORegisterSpace, DCTOTCNTS, 1, &
m_totalCounts,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
54 addMapping(
ISISVME::TransferRunMemorySpace, DCMEMSTART,
DET_MEM_LEN,
m_detMemory,
"",
true,
true, NULL, 0,
true,
false, fault_mode);
55 addMapping(
ISISVME::TransferIORegisterSpace, DCFSDEL0, 1, &
m_fsdelay0,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
56 addMapping(
ISISVME::TransferIORegisterSpace, DCFSDEL1, 1, &
m_fsdelay1,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
58 addMapping(
ISISVME::TransferIORegisterSpace, DCEVNTMD, 1, &
m_eventModeReg,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
59 addMapping(
ISISVME::TransferIORegisterSpace, DCNXFRMR, 1, &
m_nextFrameMarker,
"",
true,
false, NULL, 0,
false,
false, fault_mode);
60 addMapping(
ISISVME::TransferIORegisterSpace, DCNXMEMWR, 1, &
m_nextMemoryWrite,
"",
true,
false, NULL, 0,
false,
false, fault_mode);
61 addMapping(
ISISVME::TransferIORegisterSpace, DCNMEMWR, 1, &
m_numMemoryWraps,
"",
true,
false, NULL, 0,
false,
false, fault_mode);
62 addMapping(
ISISVME::TransferIORegisterSpace, DCADDLRR, 1, &
m_lastReadAddr,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
64 addMapping(
ISISVME::TransferIORegisterSpace, DCOPMODE, 1, &
m_dcopmode,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
65 addMapping(
ISISVME::TransferIORegisterSpace, DCMUONSTEP, 1, &
m_dcmuonstep,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
67 addMapping(
ISISVME::TransferIORegisterSpace, DCRUNMEMCLEAR, 1, &
m_runMemoryClear,
"",
true,
true, NULL, 0,
false,
false, fault_mode);
80 template <
class DetCardPolicy>
83 increment2(1, m_periodCounterLow, m_periodCounterHigh);
87 template <
class DetCardPolicy>
90 m_periodCounterLow = m_periodCounterHigh = 0;
94 template <
class DetCardPolicy>
97 os <<
"SIMDetector card at position " << m_position <<
" for " << (m_neutron_data ?
"neutron" :
"sample environment") <<
" data using policy " << DetCardPolicy::det_card_policy_name;
100 template <
class DetCardPolicy>
103 if (m_detMemory != m_shared_detMemory)
105 delete []m_detMemory;
107 delete []m_poslutMemory;
108 delete []m_tcglutMemory;
111 template <
class DetCardPolicy>
114 static bool simspec0 = Poco::Util::Application::instance().config().getBool(
"isisicp.simulation.simulatespec0",
true);
115 static bool simbin0 = Poco::Util::Application::instance().config().getBool(
"isisicp.simulation.simulatebin0",
true);
116 static bool simulate_data = Poco::Util::Application::instance().config().getBool(
"isisicp.simulation.simulatedata",
false);
121 simulateEventMode(delay, simspec0, simbin0);
125 simulateHistogramMode(delay, simspec0, simbin0);
131 template <
class DetCardPolicy>
134 unsigned chan = 0, ntc = m_tcgTimeBinLimitRegister;
135 unsigned tof_pulses =
static_cast<unsigned>(tof * 32.0);
136 for(
unsigned i=0; i<ntc; ++i)
138 if ( (tof_pulses >= m_tcglutMemory[i]) && (tof_pulses < m_tcglutMemory[i+1]) )
146 template <
class DetCardPolicy>
149 isisU32_t period_size = m_periodSizeLow + (m_periodSizeHigh << 16);
150 isisU32_t period = m_periodCounterLow + (m_periodCounterHigh << 16);
155 isisU32_t start_spec = (simspec0 ? 0 : 2);
159 Poco::Thread::sleep(50);
162 if (m_vme->isRunning() && !m_vme->isVetoing())
164 for(
unsigned card_spectrum=start_spec; card_spectrum <= start_spec+4; card_spectrum += 2)
166 offset = card_spectrum * m_descriptorTimeBinLimitRegister + period_size * period;
172 ++(m_detMemory[offset]);
174 for(
unsigned j=10; j<=20; j++)
179 ++(m_detMemory[(getTimeChannelIndex(tof) + offset) % (
unsigned)
DET_MEM_LEN ]);
184 ++(m_detMemory[(getTimeChannelIndex(tof) + offset) % (
unsigned)
DET_MEM_LEN ]);
191 template <
class DetCardPolicy>
195 unsigned char device_id = 30;
196 static uint32_t data_word_val = 10;
197 union { uint32_t u;
unsigned char b[4]; } data_word;
198 data_word_val += 100;
199 data_word.u = data_word_val;
204 ev.
spectrum = (device_id & 0xff) | (0x0 << 8);
206 writeToMemoryWrapped(reinterpret_cast<isisU32_t*>(&ev),
sizeof(ev) /
sizeof(
isisU32_t));
208 for(
int i=0; i<4; ++i)
210 ev.
spectrum = (data_word.b[i] & 0xff) | ((i+1) << 8);
212 writeToMemoryWrapped(reinterpret_cast<isisU32_t*>(&ev),
sizeof(ev) /
sizeof(
isisU32_t));
217 template <
class DetCardPolicy>
220 static bool spreadsimevents = Poco::Util::Application::instance().config().getBool(
"isisicp.simulation.spreadsimevents",
true);
226 unsigned card_spectrum = (spreadsimevents ? m_poslutMemory[i % DCPOSLUTSIZE] : 2);
245 writeToMemoryWrapped(reinterpret_cast<isisU32_t*>(&ev),
sizeof(ev) /
sizeof(
isisU32_t));
250 template <
class DetCardPolicy>
254 static int n_events_sim = Poco::Util::Application::instance().config().getInt(
"isisicp.simulation.neventssim", 5);
255 isisU32_t period = m_periodCounterLow + (m_periodCounterHigh << 16);
257 int proton_incr = (int)( 180.0 * (
double)delay / (1000.0 * 3600.0 * 1.738e-6) ) ;
259 GetSystemTime(&systime);
268 memset(&header, 0 ,
sizeof(header));
281 simulateEventModeDetector(header, simspec0, simbin0);
285 simulateEventModeDataDae(header, simspec0, simbin0);
287 m_nextFrameMarker = m_nextMemoryWrite;
288 LOGSTR_DEBUG(
"Card " << position() <<
" next frame address " << m_nextFrameMarker
289 <<
" next mem " << m_nextMemoryWrite <<
" end sent " << m_end_sent);
295 memset(&header, 0 ,
sizeof(header));
308 LOGSTR_DEBUG(
"Card " << position() <<
" next frame address " << m_nextFrameMarker
309 <<
" next mem " << m_nextMemoryWrite <<
" end sent " << m_end_sent);
313 template <
class DetCardPolicy>
316 int i = 0, nretry = 3;
329 m_detMemory[m_nextMemoryWrite / 4] = data[i];
330 m_nextMemoryWrite += 4;
334 m_nextMemoryWrite = 0;
342 static void det_junk_fill(
void* arg)
347 for(k=1; k<=NSIMDETCARDS; k++)
349 for(i=0; i<(unsigned)dae->m_detMemoryLength; i += 417)
351 pVal = dae->m_detMemory[k] + i % dae->m_detMemoryLength;
352 j = (unsigned)(((
double)rand() / (double)(RAND_MAX+1)) * 1000.0);
359 template <
class DetCardPolicy>
370 m_tcgAccessRegister &= ~DCTHISCLE;
371 m_nextFrameMarker = m_nextMemoryWrite = m_numMemoryWraps = m_lastReadAddr = 0;
373 m_runMemoryClear = 0;
375 if (
isRegisterUsed(DCTAC) && (m_tcgAccessRegister & DCTTOTCNTSCLE) )
382 template <
class DetCardPolicy>
isisU32_t m_tcgAccessRegister
SIMDetectorCard(int position, VMESimulationIface *vme, bool shared, FaultMode fault_mode, bool neutron_data, DAEstatus &status)
virtual ~SIMDetectorCard()
isisU32_t m_periodCounterLow
virtual void printStatus(std::ostream &os)
isisU32_t m_descriptorTimeBinLimitRegister
virtual void simulate(int delay)
isisU32_t * m_poslutMemory
isisU32_t m_numMemoryWraps
virtual void updateCardAfterWrite(DAEstatus &status)
virtual void updateCardAfterRead(DAEstatus &status)
static const int DAEEventHeaderFixedMarker
int addMapping(ISISVME::TransferProps props, isisU32_t address, int n, isisU32_t *var, const char *name, bool readable, bool writable, isisU32_t *access_reg, unsigned access_bit, bool wrap, bool sixteen_bit_access, FaultMode fault_mode)
#define LOGSTR_DEBUG(__arg)
void writeToMemoryWrapped(isisU32_t *data, int len)
isisU32_t m_vetoFlagRegister
#define LOGSTR_WARNING(__arg)
static isisU32_t * m_shared_detMemory
bool isRegisterUsed(const T &address)
registers are either "unsigned" or "unused_t"
static void SystemTimeToDAETime(const SYSTEMTIME &systime, DAEEventHeader::DAETime &daetime)
bit assignmments for DAE2DetCardPolicy::DCEVNTMD
isisU32_t * m_tcglutMemory
#define LOGSTR_INFORMATION(__arg)
isisU32_t m_periodCounterHigh
virtual void simulateEventMode(int delay, bool simspec0, bool simbin0)
isisU32_t m_nextFrameMarker
static const unsigned DAE_EVENT_HEADER_WORDS
isisU32_t m_tcgTimeBinLimitRegister
unsigned getTimeChannelIndex(float tof)
tof in microseconds
isisU32_t m_periodSizeLow
isisU32_t m_nextMemoryWrite
void setLoggerName(const std::string &logger_name)
isisU32_t m_periodSizeHigh
isisU32_t m_runMemoryClear
virtual void simulateEventModeDetector(DAEEventHeader &header, bool simspec0, bool simbin0)
virtual void simulateEventModeDataDae(DAEEventHeader &header, bool simspec0, bool simbin0)
isisU32_t m_vetoEnableRegister
virtual void simulateHistogramMode(int delay, bool simspec0, bool simbin0)