8 static bool simulate_vme = (getenv(
"SIMULATE_VME") != 0 ?
true :
false);
14 void __stdcall
DAE_DEVICE(
short& tempchan,
int& simulate);
15 void __stdcall
DAESET(
short& zaachan,
int crat[],
int daep[],
16 int dat1[],
int modn[],
int mpos[],
int& ndet,
int& nper,
17 int& ntrg,
int pmap[],
int& nfpp,
int& pre1,
int spec[],
18 int tcb1[],
int timr[],
int ntcftr[],
int nosftr[],
int& vaxmax,
19 int& status,
int& daebegerror,
int& logstatus,
int& delay,
20 int& synch,
int vetoes[],
int& cper,
int& save_permax,
21 int save_tpoffset[],
int& datamode,
int& tables_only);
24 void __stdcall
DAERESUME(
short& zaachan,
int& cper,
int& save_permax,
25 int& save_tpoffset,
int& status);
26 void __stdcall
DAEEND(
isisU32_t dat1[],
int daep[],
int ntcftr[],
int nosftr[],
34 int read_crpt_c(
int **start,
int& section,
int& size);
42 int __stdcall
DAECP(
int code);
44 int set_dae_streams(std::ostringstream* pOut, std::ostringstream* pInf, std::ostringstream* pWarn,
45 std::ostringstream* pErr, std::ostringstream* pDbg);
51 OUTPUT_MESSAGE(*
dae_pErr,
"WIO error" << std::endl);
57 OUTPUT_MESSAGE(*
dae_pErr,
"WIOD error" << std::endl);
63 return RIO(bus_addr, word, device);
68 OUTPUT_MESSAGE(*
dae_pErr,
"read_crpt_c error" << std::endl);
77 if ( getenv(
"ISISVME_DEVICE") != NULL )
79 dae->
open(getenv(
"ISISVME_DEVICE"));
83 dae->
open(
"VXI0::MEMACC");
91 OUTPUT_MESSAGE(*
dae_pErr,
"wmem error" << std::endl);
97 OUTPUT_MESSAGE(*
dae_pErr,
"wmemd error" << std::endl);
111 if ( ((
unsigned long)word %
sizeof(
isisU32_t)) == 0 )
118 OUTPUT_MESSAGE(*
dae_pErr,
"RMEMD error - address not 32bit aligned" << std::endl);
133 OUTPUT_MESSAGE(*
dae_pErr,
"RMEMVI: illegal word length " << wrd_len << std::endl);
144 dae->getGoodFramesLower(word);
148 dae->getGoodFramesUpper(word);
152 dae->getRawFramesLower(word);
156 dae->getRawFramesUpper(word);
164 dae->getRawPPPMiddle(word);
176 dae->getGoodPPPMiddle(word);
184 OUTPUT_MESSAGE(*
dae_pErr,
"RIO: unknown address " << bus_addr << std::endl);
193 OUTPUT_MESSAGE(*
dae_pErr,
"riod error" << std::endl);
197 void __stdcall
DAESET(
short& zaachan,
int crat[],
int daep[],
int dat1[],
198 int modn[],
int mpos[],
int& ndet,
int& nper,
199 int& ntrg,
int pmap[],
int& nfpp,
int& pre1,
int spec[],
200 int tcb1[],
int timr[],
int ntcftr[],
int nosftr[],
int& vaxmax,
201 int& status,
int& daebegerror,
int& logstatus,
int& delay,
202 int& synch,
int vetoes[],
int& cper,
int& save_permax,
203 int save_tpoffset[],
int& datamode,
int& tables_only)
210 OUTPUT_MESSAGE(*
dae_pInf,
"Entering VME DAEBEG" << std::endl);
213 OUTPUT_MESSAGE(*
dae_pErr,
"Error - no DAE assigned" << std::endl);
219 if (ndet > 13*64*1024)
221 OUTPUT_MESSAGE(*
dae_pErr,
"Too many detectors" << std::endl);
225 int ic, maxcrate = 0;
226 for(i=0; i<ndet; i++)
228 if (crat[i] > maxcrate)
237 for(j=0; j<ndet; j++)
242 if (trcn[ic] != timr[j])
244 OUTPUT_MESSAGE(*
dae_pErr,
"Time regime problem" << std::endl);
254 for(i=0; i<maxcrate; i++)
258 OUTPUT_MESSAGE(*
dae_pInf,
"Warning: Time regime " << trcn[i] <<
" for crate " << i << std::endl);
262 if (datamode == 1 && trcn[i] > 1)
264 OUTPUT_MESSAGE(*
dae_pErr,
"Time regime > 1 for crate " << i << std::endl);
270 for(i=0; i<ntrg; i++)
272 permax += (ntcftr[i]+1) * (nosftr[i]+1);
274 save_permax = permax;
276 if (len * daep[0] > daep[1])
278 OUTPUT_MESSAGE(*
dae_pErr,
"Not enough DAE memory" << std::endl);
284 OUTPUT_MESSAGE(*
dae_pErr,
"Not enough CRPT memory" << std::endl);
288 OUTPUT_MESSAGE(*
dae_pInf,
"DAE memory = " << (len * daep[0]) / (1024 * 1024) <<
" Mb" << std::endl);
289 OUTPUT_MESSAGE(*
dae_pInf,
"NPER = " << nper << std::endl);
292 if (tables_only == 0)
298 OUTPUT_MESSAGE(*
dae_pInf,
"TABLES ONLY - memory not zerod" << std::endl);
302 OUTPUT_MESSAGE(*
dae_pInf,
"Programming Time channels" << std::endl);
304 unsigned long * new_tcb1 =
new unsigned long[ntcftr[0]+1];
305 int pulse_generator = 0;
306 if (getenv(
"PULSE_GENERATOR") != 0)
308 pulse_generator = atol(getenv(
"PULSE_GENERATOR"));
311 if (pulse_generator == 1)
313 frame_delay = ((tcb1[0] * pre1) / 32);
314 OUTPUT_MESSAGE(*
dae_pInf,
"PULSE_GENERATOR: frame delay = " << 4 * delay + frame_delay <<
" us" << std::endl);
315 for(i=0; i <= ntcftr[0]; i++)
318 new_tcb1[i] = tcb1[i] * pre1 - frame_delay * 32;
319 if ( (new_tcb1[i] & 0xff000000) != 0 )
321 OUTPUT_MESSAGE(*
dae_pWarn,
"Warning: TCG value larger than 24 bits" << std::endl);
327 OUTPUT_MESSAGE(*
dae_pInf,
"Frame sync delay = " << delay * 4 <<
" us" << std::endl);
328 for(i=0; i <= ntcftr[0]; i++)
333 new_tcb1[i] = tcb1[i] * pre1 - 7;
334 if ( (new_tcb1[i] & 0xff000000) != 0 )
336 OUTPUT_MESSAGE(*
dae_pWarn,
"Warning: TCG value larger than 24 bits" << std::endl);
340 OUTPUT_MESSAGE(*
dae_pInf,
"setting " << ntcftr[0] <<
" time channels from " << (
double)new_tcb1[0] / 32.0 <<
" to " << (
double)new_tcb1[ntcftr[0]] / 32.0 <<
" us" << std::endl);
344 OUTPUT_MESSAGE(*
dae_pInf,
"Programming POSLUT" << std::endl);
349 OUTPUT_MESSAGE(*
dae_pInf,
"Setting vetos" << std::endl);
352 OUTPUT_MESSAGE(*
dae_pInf ,
"Starting run" << std::endl);
353 if (tables_only == 0)
362 OUTPUT_MESSAGE(*
dae_pInf,
"Leaving VME DAEBEG" << std::endl);
367 OUTPUT_MESSAGE(*
dae_pInf ,
"Entering VME DAEPAUSE" << std::endl);
375 OUTPUT_MESSAGE(*
dae_pInf ,
"Leaving VME DAEPAUSE" << std::endl);
379 void __stdcall
DAERESUME(
short& zaachan,
int& cper,
int& save_permax,
int& save_tpoffset,
int& status)
381 OUTPUT_MESSAGE(*
dae_pInf ,
"Entering VME DAERESUME" << std::endl);
385 OUTPUT_MESSAGE(*
dae_pInf ,
"Leaving VME DAERESUME" << std::endl);
395 OUTPUT_MESSAGE(*
dae_pInf ,
"Entering VME DAEEND" << std::endl);
400 for(i=0; i<ntrg; i++)
402 *
dae_pInf <<
"Time regime " << i+1 <<
" NTC " << ntcftr[i] <<
" NOS " << nosftr[i] << std::endl;
403 permax += (ntcftr[i] + 1) * (nosftr[i] + 1);
405 int len = permax * nper;
406 *
dae_pInf << nper <<
" periods of size " << permax <<
" words" << std::endl;
414 *
dae_pInf <<
"Trying readHistogramMemory() " << (double)s.wSecond + (
double)s.wMilliseconds/1000.0 << std::endl;
417 *
dae_pInf <<
"Done readHistogramMemory() " << (double)s.wSecond + (
double)s.wMilliseconds/1000.0 << std::endl;
419 std::cerr <<
"Checking for differences ..." << std::endl;
420 for(i=0; i< len; i++)
422 if (temp_buffer[i] != dat1[i])
430 std::cerr <<
"they differ";
432 std::cerr << std::endl;
434 delete[] temp_buffer;
436 OUTPUT_MESSAGE(*
dae_pInf ,
"Leaving VME DAEEND" << std::endl);
441 OUTPUT_MESSAGE(*
dae_pErr ,
"error - called VME DAECP" << std::endl);
447 OUTPUT_MESSAGE(*
dae_pErr ,
"error - called VME read_crpt_array_c" << std::endl);
int __stdcall RIOD(isis32_t &bus_addr, isisU16_t *word, isis32_t &nwrds, isis16_t &device)
void __stdcall DAESET(short &zaachan, int crat[], int daep[], int dat1[], int modn[], int mpos[], int &ndet, int &nper, int &ntrg, int pmap[], int &nfpp, int &pre1, int spec[], int tcb1[], int timr[], int ntcftr[], int nosftr[], int &vaxmax, int &status, int &daebegerror, int &logstatus, int &delay, int &synch, int vetoes[], int &cper, int &save_permax, int save_tpoffset[], int &datamode, int &tables_only)
int setDAE1Vetos(int vetos[], int n, DAEstatus &status)
int getGoodPPPLower(isisU32_t *value, DAEstatus &status)
static std::ostringstream * dae_pOut
int __stdcall RMEM(isis32_t &bus_addr, isisU16_t *word, isisU16_t &device)
void __stdcall DAERESUME(short &zaachan, int &cper, int &save_permax, int &save_tpoffset, int &status)
int stopRun(StopRunMode mode, DAEstatus &status)
int getGoodPPPUpper(isisU32_t *value, DAEstatus &status)
int read_crpt_array_c(int start, int length, int section[])
int __stdcall WIOD(isis32_t &bus_addr, isisU16_t *word, isis32_t &nwrds, isis16_t &device)
static std::ostringstream * dae_pWarn
isis32_t open(const char *dae_name, DAEstatus &status)
int clearHistogramMemory(DAEstatus &status)
int open_dae_cds(const char *name)
int getRawPPPLower(isisU32_t *value, DAEstatus &status)
int read_crpt_c(int **start, int §ion, int &size)
int __stdcall RMEMVI(isis32_t &bus_addr, isisU32_t *buffer, isisU32_t &length, isis16_t &device, isis32_t &wrd_len)
static std::ostringstream * dae_pErr
static std::ostringstream * dae_pInf
int resetRunController(DAEstatus &status)
int setTimeChannels(int crat, isisU32_t *tcb, int ntc, DAEstatus &status)
int set_dae_streams(std::ostringstream *pOut, std::ostringstream *pInf, std::ostringstream *pWarn, std::ostringstream *pErr, std::ostringstream *pDbg)
static std::ostringstream * dae_pDbg
int startRun(bool clear_counters, int run_number, time_t &start_time, DAEstatus &status)
int getRawFrames(isisU32_t *value, DAEstatus &status)
int __stdcall DAECP(int code)
int __stdcall WIO(isis32_t &bus_addr, isisU16_t *word, isis16_t &device)
int __stdcall RMEMD(isis32_t &bus_addr, isisU16_t *word, isis32_t &nwrds, isisU16_t &device)
int changePeriod(int period, int daq_period, DAEstatus &status)
void __stdcall DAE_DEVICE(short &tempchan, int &simulate)
int getRawPPPUpper(isisU32_t *value, DAEstatus &status)
int setFrameSync(FrameSync fs, int muon_pulse, DAEstatus &status)
int __stdcall RIO(isis32_t &bus_addr, isisU16_t *word, isis16_t &device)
int programDAE1POSLUT(int crat[], int maxcrate, int modn[], int mpos[], int spec[], int ndet, int nper_daq, DAEstatus &status)
int readHistogramMemory(unsigned long start, isisU32_t *buffer, int len, DAEstatus &status)
int setFrameSyncDelay(isisU32_t delay, DAEstatus &status)
int rio_c(long bus_addr, isisU16_t *word, short device)
int __stdcall WMEM(isis32_t &bus_addr, isisU16_t *word, isisU16_t &device)
void __stdcall DAEEND(isisU32_t dat1[], int daep[], int ntcftr[], int nosftr[], int &nper, int &ntrg, short &zaachan, isisU32_t &igfc, isisU32_t &irfc, int &status)
void __stdcall DAEPAUSE(short &zaachan, isisU32_t &igfc, isisU32_t &irfc, int &status)
int __stdcall WMEMD(isis32_t &bus_addr, isisU16_t *word, isis32_t &nwrds, isisU16_t &device)
int getGoodFrames(isisU32_t *value, DAEstatus &status)