35 template <
class DAEPolicy>
42 srand((
unsigned)time(NULL));
46 if (crate_number == 0)
53 bool sharedDetMemory = Poco::Util::Application::instance().config().getBool(
"isisicp.simulation.detcards.shared",
false);
54 std::string card_type = Poco::Util::Application::instance().config().getString(
"isisicp.simulation.detcards.type",
"neutron");
55 int numDetCards = Poco::Util::Application::instance().config().getInt(Poco::format(
"isisicp.simulation.detcards.crate%d.number", crate_number), 0);
56 int numDataDaeDetCards = Poco::Util::Application::instance().config().getInt(Poco::format(
"isisicp.simulation.detcards.crate%d.datadae.number", crate_number), 0);
57 for(i=1; i<=numDetCards; i++)
59 if (card_type ==
"muon")
68 for(i=1; i <= numDataDaeDetCards; i++)
81 template <
class DAEPolicy>
85 for(
int i=0; i<m_env_card_list.size(); ++i)
87 card_ids.push_back(m_env_card_list[i]->position());
89 for(
int i=0; i<m_det_card_list.size(); ++i)
91 card_ids.push_back(m_det_card_list[i]->position());
109 template <
class DAEPolicy>
138 template <
class DAEPolicy>
141 if (m_trigger_func != NULL)
143 return (*m_trigger_func)(m_trigger_func_arg, the_secs, the_ms, trig_id);
151 template <
class DAEPolicy>
155 m_shutdown_requested =
true;
157 for(i=0; i<m_det_card_list.size(); i++)
159 delete m_det_card_list[i];
160 m_det_card_list[i] = 0;
162 for(i=0; i<m_env_card_list.size(); i++)
164 delete m_env_card_list[i];
165 m_env_card_list[i] = 0;
167 DeleteCriticalSection(&m_critical);
170 template <
class DAEPolicy>
175 for(i=0; i< m_det_card_list.size(); i++)
177 if (m_det_card_list[i]->type() == MySIMDAE2Card::DetCard)
185 template <
class DAEPolicy>
190 for(i=0; i< m_det_card_list.size(); i++)
192 if (m_det_card_list[i]->type() == MySIMDAE2Card::DetCard)
201 template <
class DAEPolicy>
207 template <
class DAEPolicy>
214 template <
class DAEPolicy>
221 template <
class DAEPolicy>
227 template <
class DAEPolicy>
233 template <
class DAEPolicy>
239 template <
class DAEPolicy>
242 return readU16(address, data16, props, status);
245 template <
class DAEPolicy>
251 template <
class DAEPolicy>
254 return readU32(address, data32, props, status);
258 template <
class DAEPolicy>
262 return simulateRead(props, address, data16, nitems, status);
265 template <
class DAEPolicy>
268 return simulateRead(props, address, data32, nitems, status);
270 template <
class DAEPolicy>
275 template <
class DAEPolicy>
281 template <
class DAEPolicy>
284 return simulateWrite(props, address, data16, nitems, status);
287 template <
class DAEPolicy>
290 return simulateWrite(props, address, data32, nitems, status);
293 template <
class DAEPolicy>
299 template <
class DAEPolicy>
306 template <
class DAEPolicy>
313 template <
class DAEPolicy>
318 for(i=0; (i<m_det_card_list.size()) && (stat ==
ISISVME::Error); i++)
320 stat = m_det_card_list[i]->read16(props, address, data16, nitems, status);
323 m_det_card_list[i]->updateCardAfterRead(status);
326 for(i=0; (i<m_env_card_list.size()) && (stat ==
ISISVME::Error); i++)
328 stat = m_env_card_list[i]->read16(props, address, data16, nitems, status);
331 m_env_card_list[i]->updateCardAfterRead(status);
336 std::ostringstream message;
337 message <<
"Simulation error (read16) at " << std::hex << address << std::dec << std::endl;
343 template <
class DAEPolicy>
348 for(i=0; (i<m_det_card_list.size()) && (stat ==
ISISVME::Error); i++)
350 stat = m_det_card_list[i]->write16(props, address, data16, nitems, status);
353 m_det_card_list[i]->updateCardAfterWrite(status);
356 for(i=0; (i<m_env_card_list.size()) && (stat ==
ISISVME::Error); i++)
358 stat = m_env_card_list[i]->write16(props, address, data16, nitems, status);
361 m_env_card_list[i]->updateCardAfterWrite(status);
366 std::ostringstream message;
367 message <<
"Simulation error (write16) at " << std::hex << address << std::dec << std::endl;
383 template <
class DAEPolicy>
387 for(
int i=0; i<m_det_card_list.size(); i++)
389 res |= m_det_card_list[i]->isVetoing();
391 for(
int i=0; i<m_env_card_list.size(); i++)
393 res |= m_env_card_list[i]->isVetoing();
421 template <
class DAEPolicy>
425 for(
int i=0; i<m_env_card_list.size(); i++)
427 if (m_env_card_list[i]->type() == MySIMDAE2Card::EnvCard)
429 res = (
dynamic_cast<MySIMEnvCard*
>(m_env_card_list[i]))->frameNumber();
431 if (m_env_card_list[i]->type() == MySIMDAE2Card::EnvPeriodCard)
439 template <
class DAEPolicy>
443 for(
int i=0; i<m_env_card_list.size(); i++)
445 if (m_env_card_list[i]->type() == MySIMDAE2Card::EnvCard)
447 res &= ((
MySIMEnvCard*)m_env_card_list[i])->isRunning();
449 if (m_env_card_list[i]->type() == MySIMDAE2Card::EnvPeriodCard)
457 template <
class DAEPolicy>
462 for(i=0; (i<m_det_card_list.size()) && (stat ==
ISISVME::Error); i++)
464 stat = m_det_card_list[i]->read32(props, address, data32, nitems, status);
467 m_det_card_list[i]->updateCardAfterRead(status);
470 for(i=0; (i<m_env_card_list.size()) && (stat ==
ISISVME::Error); i++)
472 stat = m_env_card_list[i]->read32(props, address, data32, nitems, status);
475 m_env_card_list[i]->updateCardAfterRead(status);
480 std::ostringstream message;
481 message <<
"Simulation error (read32) at " << std::hex << address << std::dec << std::endl;
487 template <
class DAEPolicy>
490 return simulateRead(props, address, reinterpret_cast<isisU32_t*>(data64), 2 * nitems, status);
494 template <
class DAEPolicy>
499 for(i=0; (i<m_det_card_list.size()) && (stat ==
ISISVME::Error); i++)
501 stat = m_det_card_list[i]->write32(props, address, data32, nitems, status);
504 m_det_card_list[i]->updateCardAfterWrite(status);
507 for(i=0; (i<m_env_card_list.size()) && (stat ==
ISISVME::Error); i++)
509 stat = m_env_card_list[i]->write32(props, address, data32, nitems, status);
512 m_env_card_list[i]->updateCardAfterWrite(status);
517 std::ostringstream message;
518 message <<
"Simulation error (write32) at " << std::hex << address << std::dec << std::endl;
524 template <
class DAEPolicy>
527 return simulateWrite(props, address, reinterpret_cast<isisU32_t*>(data64), 2 * nitems, status);
530 template <
class DAEPolicy>
536 template <
class DAEPolicy>
542 template <
class DAEPolicy>
545 return simulateRead(props, address, data, nitems, status);
548 template <
class DAEPolicy>
551 return simulateRead(props, address, data, nitems, status);
std::vector< MySIMEnvPeriodCard * > m_env_card_list
uint32_t TransferProps
combination of TransferProp values
int writeBlockU16(unsigned long address, isisU16_t *data16, long nitems, TransferProps props, DAEstatus &status)
int readU16(unsigned long address, isisU16_t *data16, TransferProps props, DAEstatus &status)
int writeU32(unsigned long address, isisU32_t data32, TransferProps props, DAEstatus &status)
int readU32noRetry(unsigned long address, isisU32_t *data32, TransferProps props, DAEstatus &dstatus)
int writeU16(unsigned long address, isisU16_t data16, TransferProps props, DAEstatus &status)
int add(DAEstatus &dstatus, bool clear)
static int simulateWrite(SIMDAE2Card< DAECardPolicy > *d2card, ISISVME::TransferProps props, unsigned long address, __type *data, long nitems, DAEstatus &status)
int getCardIds(std::vector< int > &card_ids)
int writeBlockU32(unsigned long address, isisU32_t *data32, long nitems, TransferProps props, DAEstatus &status)
void simulation_routineImpl()
int lockDevice(int timeout, DAEstatus &status)
int resetDetectorCardPeriod()
int readBlockU16(unsigned long address, isisU16_t *data16, long nitems, TransferProps props, DAEstatus &status)
VMESimulation(DAEstatus &status)
static void simulation_routine(void *arg)
int readU32(unsigned long address, isisU32_t *data32, TransferProps props, DAEstatus &status)
virtual int frameNumberImpl()=0
bool resetBus(DAEstatus &status)
int open(const char *device, DAEstatus &status)
int writeBlock(unsigned long address, isisU32_t *data, long nitems, TransferProps props, DAEstatus &status)
static int simulateRead(SIMDAE2Card< DAECardPolicy > *d2card, ISISVME::TransferProps props, unsigned long address, __type *data, long nitems, DAEstatus &status)
SIMEnvPeriodCard< typename DAEPolicy::env_t > MySIMEnvPeriodCard
int incrementDetectorCardPeriod()
int readBlockU32(unsigned long address, isisU32_t *data32, long nitems, TransferProps props, DAEstatus &status)
std::vector< MySIMDetectorCard * > m_det_card_list
int unlockDevice(DAEstatus &status)
int readBlock(unsigned long address, isisU32_t *data, long nitems, TransferProps props, DAEstatus &status)
int scanBus(DAEstatus &status)
int addInfo(int facility, const std::string &text)
CRITICAL_SECTION m_critical
int close(DAEstatus &status)
virtual void simulation_routineImpl()=0
int simulateRead(TransferProps props, unsigned long address, isisU16_t *data16, long nitems, DAEstatus &status)
int addInfoVa(int facility, const char *format,...)
int onTrigger(time_t the_secs, unsigned short the_ms, int trig_id)
int simulateWrite(TransferProps props, unsigned long address, isisU16_t *data16, long nitems, DAEstatus &status)
int openBackplane(const char *device_bp, DAEstatus &status)
static std::vector< VMESimulationIface * > m_sim_vme
int readU16noRetry(unsigned long address, isisU16_t *data16, TransferProps props, DAEstatus &dstatus)