16 template <
class DetCardPolicy>
21 return (m_reg.event_reg.eventMode(status) != 0) ?
true :
false;
29 template <
class DetCardPolicy>
34 os <<
"This is a " << DetCardPolicy::card_type <<
" DETECTOR card with " << m_memsize / (1024*1024)
35 <<
" MB memory" << std::endl;
36 os <<
"Mode is " << (m_mode & ModeNeutronData ?
"neutron" :
"sample environment") << std::endl;
37 os <<
"Highest DAE2 spectrum used = " << m_highspec << std::endl;
38 getNTimeChannels(&value, status);
39 os << value <<
" time channels" << std::endl;
40 if (m_hardware_periods)
42 os <<
"HARDWARE periods: number of DAQ periods = " << m_nperiods << std::endl;
43 getCurrentHardwarePeriod(&value, status);
44 os <<
"Current DAQ period number = " << value << std::endl;
45 readRegister16As32(DCPERSIZE0, DCPERSIZE1, &value, status);
46 os <<
"Current DAQ period size (words) = " << value << std::endl;
50 os <<
"SOFTWARE periods: number of periods = " << m_nperiods << std::endl;
52 getTotalCounts(&value, status);
53 os <<
"Total counts register = " << value << std::endl;
56 printVetoStatus(os,
false, status);
60 os <<
"Veto logging not supported" << std::endl;
64 getFrameSyncDelay(&value, status);
65 os <<
"Delayed Frame synch = " << value << std::endl;
72 printRegister(
"Next Frame Marker Register", DCNXFRMR, os);
73 printRegister(
"Next Memory Write Register", DCNXMEMWR, os);
74 printRegister(
"Number of Memory Wraps Register", DCNMEMWR, os);
75 printRegister(
"Last Read Register", DCADDLRR, os);
76 printRegister(
"Event Mode Register", DCEVNTMD, os,
true);
81 template <
class DetCardPolicy>
85 getDIMVetos(&temp16, status);
86 readDIMVetoOccurredFlag(&value16, status);
87 for(
int i=0; i<16; i++)
89 bool enabled = ((temp16 & (1 << i)) != 0);
90 bool triggered = ((value16 & (1 << i)) != 0);
91 if (!triggered_only || (enabled && triggered))
93 os <<
"Detector card " << m_position <<
" Veto for Dim" << i <<
94 " is " << (enabled ?
"ENABLED" :
"DISABLED") <<
95 (triggered ?
" OCCURRED" :
" CLEAR") << std::endl;
98 printVetoStatus(FrameOverflowVeto, os, triggered_only, status);
99 printVetoStatus(MemoryFullVeto, os, triggered_only, status);
100 printVetoStatus(FIFOLateVeto, os, triggered_only, status);
104 template <
class DetCardPolicy>
107 bool enabled = isVetoEnabled(veto, status);
108 bool triggered = hasVetoOccurred(veto, status);
109 if (!triggered_only || (enabled && triggered))
111 os <<
"Detector card " << m_position <<
" " << getVetoName(veto) << (enabled ?
" ENABLED, " :
" DISABLED ") << (triggered ?
"OCCURRED" :
"CLEAR") << std::endl;
116 template <
class DetCardPolicy>
120 os <<
"DAE2 -> DAE1 spec map" << std::endl;
121 for(i=0; i<= m_highspec; i++)
123 if (m_dae2specmap[i] != NOSPECTRUM)
125 os << i <<
" -> " << m_dae2specmap[i] << std::endl;
128 os <<
"DAE1 -> DAE2 spec map" << std::endl;
129 for(i=0; i<DAESPECMAX; i++)
131 if (m_dae1specmap[i] != NOSPECTRUM)
133 os << i <<
" -> " << m_dae1specmap[i] << std::endl;
138 template <
class DetCardPolicy>
143 readPOSLUTMemory(0, m_poslut, DCPOSLUTSIZE, status);
144 os <<
"*** DUMP OF POSLUT ***\n";
145 for(i=0; i<DCPOSLUTSIZE; i++)
148 os << val << ((i+1) % 20 == 0 ?
'\n' :
' ');
150 os <<
"*** DUMP DONE ***\n";
154 template <
class DetCardPolicy>
162 getFrameSyncDelay(&value, status);
163 os <<
"Delayed frame sync = " << value << std::endl;
165 getNTimeChannels(&ntc, status);
166 os << ntc <<
" time channels - first few boundaries in clock pulses\n";
172 getTimeChannels(tcb, ntc, status);
173 for(i=start; i<end; i++)
176 os << tcb[i] << ( ((i+1) % 10) ?
" " :
"\n");
182 template <
class DetCardPolicy>
186 return readDescriptorTimeBinLimitRegister(value, status);
189 template <
class DetCardPolicy>
193 return readTCGTimeBinLimitRegister(ntc, status);
196 template <
class DetCardPolicy>
199 writeDescriptorTimeBinLimitRegister(ntc+1, status);
200 return writeTCGTimeBinLimitRegister(ntc, status);
203 template <
class DetCardPolicy>
207 int spec = findDAE1Spectrum(dae1_spec, status);
208 if (spec != NOSPECTRUM)
210 if (isEventMode(status))
212 memset(buffer, 0, nbuffer *
sizeof(
isisU32_t));
216 getSpectrumSize(&nchan, status);
219 status.
addInfoVa(
FAC_DETCARD,
"Card %d reading DAE1 spectrum %d truncated (%d > %d)", position(), dae1_spec, nchan, nbuffer);
221 return readHistogramMemory(4*spec*nchan, buffer, nbuffer , status);
225 memset(buffer, 0,
sizeof(
isisU32_t) * nbuffer);
231 template <
class DetCardPolicy>
234 std::ostringstream message;
236 int dae1_spec, i, j, n;
237 if (isEventMode(status))
243 if (spec_start + nspec >= DAESPECMAX)
248 std::vector<int> dae2_spec;
249 dae2_spec.reserve(nspec);
250 for(i = 0; i < nspec; ++i)
252 dae1_spec = i + spec_start;
253 if (m_dae1specmap[dae1_spec] != NOSPECTRUM)
255 dae2_spec.push_back(m_dae1specmap[dae1_spec]);
259 dae2_spec.push_back(NOSPECTRUM);
262 std::vector<int> consec_points, consec_sizes;
264 getSpectrumSize(&nchan, status);
265 for(i=0; i<consec_points.size(); ++i)
267 j = consec_points[i];
269 int d2spec = dae2_spec[j];
270 dae1_spec = m_dae2specmap[d2spec];
271 int effective_period = dae1_spec / m_dae1persize;
272 int offset = spec_to_crpt_offset[dae1_spec % m_dae1persize] + (period + effective_period) * persize;
273 if ( (offset + n * nchan) > nbuffer )
275 message <<
"DetectorCard: too small buffer " << nbuffer <<
" for reading DAE1 spectrum " << dae1_spec <<
" period " << period <<
" from card " << position() <<
"\n";
277 else if (readHistogramMemory(4*nchan*(d2spec + period*m_dae2persize), buffer + offset, n*nchan, status) !=
ISISVME::Success)
279 message <<
"DetectorCard: error reading DAE1 spectrum " << dae1_spec <<
" from card " << position() <<
"\n";
282 if (message.str().size() > 0)
292 template <
class DetCardPolicy>
295 std::ostringstream message;
298 int dae1_spec, i, j, n;
299 if (isEventMode(status))
304 std::vector<int> consec_points, consec_sizes;
305 findConsecutive(m_dae2specmap, NOSPECTRUM, consec_points, consec_sizes);
306 getSpectrumSize(&nchan, status);
307 for(i=0; i<consec_points.size(); ++i)
309 j = consec_points[i];
311 dae1_spec = m_dae2specmap[j];
325 int period = j / m_dae2persize;
326 int offset = spec_to_crpt_offset[dae1_spec % m_dae1persize] + period * persize;
332 if ( (offset + n * nchan) > nbuffer )
334 message <<
"DetectorCard: too small buffer " << nbuffer <<
" for reading " << n <<
" DAE1 spectra starting at " << dae1_spec <<
" period " << period <<
" on card " << position() <<
"\n";
336 else if (readHistogramMemory(4*j*nchan, buffer + offset, n*nchan, status) !=
ISISVME::Success)
338 message <<
"DetectorCard: error reading " << n <<
" DAE1 spectra starting at " << dae1_spec <<
" on card " << position() <<
"\n";
343 for(i=0; i<=m_highspec; i++)
345 dae1_spec = m_dae2specmap[i];
346 if (dae1_spec != NOSPECTRUM)
348 if ( (dae1_spec+1)*nchan > nbuffer )
358 if (readHistogramMemory(4*i*nchan, buffer + dae1_spec*nchan, nchan, status) !=
ISISVME::Success)
360 message <<
"DetectorCard: error reading DAE1 spectrum " << dae1_spec <<
" from card " << position() <<
"; retrying\n";
370 if (message.str().size() > 0)
378 template <
class DetCardPolicy>
382 if (isEventMode(status))
384 memset(buffer, 0, nbuffer *
sizeof(
isisU32_t));
388 getSpectrumSize(&nchan, status);
391 status.
addInfoVa(
FAC_DETCARD,
"Card %d reading DAE2 spectrum %d truncated (%d > %d)", position(), spec, nchan, nbuffer);
393 return readHistogramMemory(4*spec*nchan, buffer, nbuffer , status);
396 template <
class DetCardPolicy>
399 setNTimeChannels(ntc, status);
400 return writeTCGLUTMemory(0, tcb, ntc+1, status);
403 template <
class DetCardPolicy>
406 return readTCGLUTMemory(0, tcb, ntc+1, status);
411 template <
class DetCardPolicy>
414 int i, j, dae1_highest = -1;
416 if (isEventMode(status))
421 getSpectrumSize(&nchan, status);
422 for(i=0; i<=m_highspec; i++)
424 j = m_dae2specmap[i];
439 if (j > dae1_highest)
444 addmap[j].
card = m_position;
448 addmap[j].
len = nchan;
451 return dae1_highest + 1;
454 template <
class DetCardPolicy>
457 std::ostringstream message;
458 int modn_min=1000000, modn_max=-1, mpos_min=1000000, mpos_max=-1;
460 readPOSLUTMemory(0, m_poslut, DCPOSLUTSIZE, status);
466 for(i=0; i<DAESPECMAX; i++)
468 m_dae1specmap[i] = NOSPECTRUM;
469 m_dae2specmap[i] = NOSPECTRUM;
471 m_dae1specmap[0] = 0;
472 m_dae2specmap[0] = 0;
473 for(i=0; i<DCDIMMAX; i++)
475 for(j=0; j<DCPOSMAX; j++)
477 s = m_poslut[DCPOSMAX*i + j];
507 if (m_highspec >= DAESPECMAX)
509 m_highspec = DAESPECMAX;
512 message <<
"Highest DAE2 spectrum: " << m_highspec <<
"\n";
513 message <<
"Number of position: " << np <<
"\n";
514 message <<
"MPOS: " << mpos_min <<
" to " << mpos_max <<
"\n";
515 message <<
"MODN: " << modn_min <<
" to " << modn_max <<
"\n";
520 template <
class DetCardPolicy>
522 int npos[],
int spec[],
int spec_step[],
523 int nblocks,
int nperiods,
int dae1persize,
DAEstatus& status)
525 std::ostringstream message;
529 m_dae1persize = dae1persize;
530 m_nperiods = nperiods;
531 memset(m_poslut, 0, DCPOSLUTSIZE *
sizeof(
isisU32_t));
532 for(i=0; i<DAESPECMAX; i++)
534 m_dae1specmap[i] = NOSPECTRUM;
535 m_dae2specmap[i] = NOSPECTRUM;
537 m_dae1specmap[0] = 0;
538 m_dae2specmap[0] = 0;
539 for(i=0; i<nblocks; i++)
541 if (cards[i] != m_position)
546 for(j=0; j<npos[i]; j++)
548 m_poslut[DCPOSMAX * dims[i] + pos_start[i] + j] = s;
549 m_dae1specmap[s] = s;
550 m_dae2specmap[s] = s;
559 m_dae2persize = m_highspec + 1;
560 message <<
"Card: " << m_position <<
" DAE2 Highest: " << m_highspec <<
"NPOS: " << np << std::endl;
561 if (m_highspec > DAESPECMAX)
564 "Detector Card %d has too many spectra: %d",
565 m_position, m_highspec);
568 return writePOSLUTMemory(0, m_poslut, DCPOSLUTSIZE, status);
571 template <
class DetCardPolicy>
573 int mpos[],
int spec[],
int ndet,
574 int nperiods,
int dae1persize,
DAEstatus& status)
576 std::ostringstream message_i, message_e, message_w;
577 int i, j, s, dae1min, dae1max, npos, ngap;
579 int modn_min=1000000, modn_max=-1, mpos_min=1000000, mpos_max=-1;
581 memset(m_poslut, 0, DCPOSLUTSIZE *
sizeof(
isisU32_t));
582 m_dae1persize = dae1persize;
583 m_nperiods = nperiods;
584 if (ndet > DAESPECMAX)
589 if (m_mode & ModeSEData)
591 return programDAE1POSLUTDataDae(status);
593 for(i=0; i<DAESPECMAX; i++)
595 m_dae1specmap[i] = NOSPECTRUM;
596 m_dae2specmap[i] = NOSPECTRUM;
598 m_dae1specmap[0] = 0;
599 m_dae2specmap[0] = 0;
605 for(i=0; i<ndet; i++)
607 if (crat[i] == m_position)
612 m_dae1specmap[spec[i]] = SPECTRUM_PLACEHOLDER;
614 if (spec[i] > dae1max)
618 if (spec[i] < dae1min)
627 for(i=dae1min; i<=dae1max; i++)
629 if (m_dae1specmap[i] == SPECTRUM_PLACEHOLDER)
631 m_dae1specmap[i] = ++m_highspec;
632 m_dae2specmap[m_highspec] = i;
639 if (m_highspec > DCMAXSPECPOSLUT)
644 m_dae2persize = m_highspec + 1;
647 message_i <<
"There is a gap of total size " << ngap <<
" in the DAE1 spectra on the card" << std::endl;
650 if (m_dae2persize * m_nperiods >= DAESPECMAX)
653 "Detector Card %d has too many spectra * periods: %d > %d",
654 m_position, m_dae2persize * m_nperiods, DAESPECMAX);
657 if (m_nperiods * m_dae1persize + m_highspec >= DAESPECMAX)
660 "Detector Card %d has too many spectra * periods: %d > %d",
661 m_position, m_dae1persize * m_nperiods + m_highspec, DAESPECMAX);
664 for(i=0; i<m_dae2persize; i++)
666 s = m_dae2specmap[i];
669 for(j=1; j<m_nperiods; j++)
671 m_dae2specmap[i + j * m_dae2persize] = s + j * m_dae1persize;
672 m_dae1specmap[s + j * m_dae1persize] = i + j * m_dae2persize;
676 m_highspec = m_nperiods * m_dae2persize - 1;
678 for(i=0; i<ndet; i++)
680 if (crat[i] == m_position)
683 if (mpos[i] < mpos_min)
687 if (modn[i] < modn_min)
691 if (mpos[i] > mpos_max)
695 if (modn[i] > modn_max)
699 j = m_dae1specmap[spec[i]];
702 m_poslut[DCPOSMAX * modn[i] + mpos[i]] = j;
706 message_e <<
"DetectorCard: Error in mapping for dae1 spectrum " << spec[i] <<
" -> dae2 spectrum " << j << std::endl;
712 message_i <<
"Card: " << m_position <<
" DAE2 Highest: " << m_highspec
713 <<
" DAE1 low: " << dae1min <<
" DAE1 high: " << dae1max
714 <<
" NPOS: " << npos << std::endl;
715 message_i <<
"MPOS: " << mpos_min <<
" to " << mpos_max << std::endl;
716 message_i <<
"MODN: " << modn_min <<
" to " << modn_max << std::endl;
720 message_w <<
"*** Detector Card " << m_position <<
" not used" << std::endl;
721 m_dae1specmap[0] = NOSPECTRUM;
722 m_dae2specmap[0] = NOSPECTRUM;
724 if (message_i.str().size() > 0)
728 if (message_w.str().size() > 0)
732 if (message_e.str().length() > 0)
738 getSpectrumSize(&nchan, status);
739 mem_needed = 4 * m_nperiods * m_dae2persize * nchan;
740 if (isEventMode(status))
742 status.
addInfoVa(
FAC_DETCARD,
"Card %d using event mode - equivalent card histogram memory needed would be %d MBytes",
743 position(), mem_needed / (1024 * 1024));
745 else if (mem_needed > m_memsize)
748 "Detector Card %d has too little memory: %d < %d bytes",
749 m_position, m_memsize, mem_needed);
754 position(), mem_needed, m_memsize);
756 return writePOSLUTMemory(0, m_poslut, DCPOSLUTSIZE, status);
761 template <
class DetCardPolicy>
768 if ( (m_memsize == 0) || ((start + 4 * len) <= m_memsize) )
770 stat = readMemory(start + DCMEMSTART, buffer, len, props, status);
779 std::ostringstream message;
780 message <<
"readHistogramMemory: not enough memory on card for address range 0x" << std::hex << start <<
" to 0x" << start + 4*len << std::dec << std::endl;
786 template <
class DetCardPolicy>
793 std::ostringstream message;
801 stat = readMemory(DCMEMSTART, buffer, len, props, status);
806 message <<
"sumHistogramMemory: ERROR" << std::endl;
824 status.
addInfoVa(
FAC_DAE,
"Detector card at position %d has memory sum %u, last non zero location after %d words\n", m_position, sum, max_i);
828 template <
class DetCardPolicy>
832 if ( (m_memsize == 0) || ((start + 4 * len) <= m_memsize) )
834 return writeMemory(start + DCMEMSTART, buffer, len, 0, props, status);
838 std::ostringstream message;
839 message <<
"writeHistogramMemory: not enough memory on card" << std::endl;
845 template <
class DetCardPolicy>
849 setTCGAccessRegister(DCTPOSLUT, status);
851 readMemory(start + DCPOSLUT, buffer, len, props, status);
854 buffer[i] &= DetCardPolicy::DCPOSLUTMASK;
859 template <
class DetCardPolicy>
862 setTCGAccessRegister(DCTPOSLUT, status);
864 return writeMemory(start + DCPOSLUT, buffer, len, (
memory_check ? DCPOSLUTMASK : 0x0), props, status);
867 template <
class DetCardPolicy>
870 setTCGAccessRegister(DCTPOSLUT, status);
872 return zeroMemory<isisU32_t>(start + DCPOSLUT, len, (
memory_check ? DCPOSLUTMASK : 0x0), props, status);
875 template <
class DetCardPolicy>
881 return readMemory(start + DCTCGLUT, buffer, len, props, status);
884 template <
class DetCardPolicy>
889 return writeMemory(start + DCTCGLUT, buffer, len, (
memory_check ? 0xffffffff : 0x0), props, status);
892 template <
class DetCardPolicy>
895 return writeRegister(DCTAC, mask, status);
898 template <
class DetCardPolicy>
901 return setAndClearRegisterBits(DCTAC, mask,
true, status);
904 template <
class DetCardPolicy>
907 return readRegister(DCTAC, value, status);
911 template <
class DetCardPolicy>
914 m_last_address_read = m_memsize - 4;
918 return setTCGAccessRegister(DCTHISCLE, status);
922 return writeRegister(DCRUNMEMCLEAR, 0x1, status);
927 template <
class DetCardPolicy>
933 readTCGAccessRegister(&value, status);
938 readRegister(DCRUNMEMCLEAR, &value, status);
948 readRegister(DCADDLRR, &value, status);
951 if (value != m_last_address_read)
955 writeRegister(DCADDLRR, m_last_address_read, status);
963 template <
class DetCardPolicy>
968 readRegister(DCDESCRX, value, status);
972 setTCGAccessRegister(DCTDESCR, status);
973 readRegister(DCDESCR, value, status);
980 template <
class DetCardPolicy>
985 return writeRegister(DCDESCRX, value, status);
989 setTCGAccessRegister(DCTDESCR, status);
990 return writeRegister(DCDESCR, value, status);
995 template <
class DetCardPolicy>
998 readRegister(DCTCGTBL, value, status);
1004 template <
class DetCardPolicy>
1007 return writeRegister(DCTCGTBL, value, status);
1010 template <
class DetCardPolicy>
1012 m_nperiods(1), m_dae1persize(0), m_dae2persize(0), m_options(0), m_reg(this), m_last_address_read(0),m_wrap_counter(0),
1013 m_dae1specmap(DAESPECMAX),m_dae2specmap(DAESPECMAX),m_mode(ModeNeutronData)
1017 std::ostringstream message;
1023 if (
readRegister(DCPERCNT0, &value, temp_status,
false,
false) == 1)
1025 message <<
"This Card Supports HARDWARE periods" <<
"\n";
1029 if (
readRegister(DCVETOFLAG , &value, temp_status,
false,
false) == 1)
1031 message <<
"This Card Supports VETO logging" <<
"\n";
1035 if (
readRegister(DCFSDEL0, &value, temp_status,
false,
false) == 1)
1037 message <<
"This Card supports delayed frame sync" <<
"\n";
1041 if (
readRegister(DCNXFRMR, &value, temp_status,
false,
false) == 1)
1043 message <<
"This Card supports Event Mode data collection" <<
"\n";
1047 if (
readRegister(DCTOTCNTS, &value, temp_status,
false,
false) == 1)
1049 message <<
"This Card has a total counts register" <<
"\n";
1062 if (specmap_array != NULL)
1079 isisU32_t pattern = 0x01010101, zero = 0x0;
1084 for(j=64; j<65 && !done; j++)
1091 if (temp2 == pattern)
1094 message <<
"The card has " << j <<
"Mb of memory" << std::endl;
1124 template <
class DetCardPolicy>
1128 int i, highspec = 0, offset = 0;
1129 while(!found && (offset < len))
1131 highspec = array[offset+1];
1132 if (array[offset] == m_position)
1138 offset += (highspec + 3);
1146 if (highspec != m_highspec)
1151 for(i=0; i<=m_highspec; i++)
1153 m_dae2specmap[i] = array[i+offset+2];
1160 template <
class DetCardPolicy>
1163 int i, new_offset = offset + m_highspec + 3;
1164 if (new_offset <= len)
1166 array[offset] = m_position;
1167 array[offset+1] = m_highspec;
1168 for(i=0; i<=m_highspec; i++)
1170 array[i+offset+2] = m_dae2specmap[i];
1182 template <
class DetCardPolicy>
1185 std::ostringstream message;
1186 int i, j, dae1_high = 0, dae1_low = 999999;
1188 for(i=0; i<DAESPECMAX; i++)
1190 m_dae1specmap[i] = NOSPECTRUM;
1192 m_dae1specmap[0] = 0;
1193 for(i=1; i<=m_highspec; i++)
1195 j = m_dae2specmap[i];
1196 if (j != NOSPECTRUM)
1206 m_dae1specmap[j] = i;
1217 message <<
"Recreated DAE1 specmap with DAE1 spec range " << dae1_low <<
" to " << dae1_high << std::endl;
1218 if ( (dae1_high - dae1_low + 1) != m_highspec )
1220 message <<
"DAE1 and DAE2 spectra not contiguous" << std::endl;
1226 template <
class DetCardPolicy>
1234 if (m_dae2persize <= 0 || m_dae1persize <= 0)
1239 if (m_dae2persize * nperiod >= DAESPECMAX)
1242 "Detector Card %d has too many spectra * periods: %d > %d",
1243 m_position, m_dae2persize * nperiod, DAESPECMAX);
1246 if (nperiod * m_dae1persize + m_dae2persize >= DAESPECMAX)
1249 "Detector Card %d has too many spectra * periods: %d > %d",
1250 m_position, m_dae1persize * nperiod + m_dae2persize, DAESPECMAX);
1255 getSpectrumSize(&nchan, status);
1258 mem_needed = 4 * nperiod * m_dae2persize * nchan;
1259 if ( !isEventMode(status) && (mem_needed > m_memsize) )
1262 "Detector Card %d has too little memory for %d periods: %d < %d bytes",
1263 m_position, nperiod, m_memsize, mem_needed);
1267 m_nperiods = nperiod;
1269 for(i=m_dae2persize; i<m_dae2specmap.size(); ++i)
1271 m_dae2specmap[i] = NOSPECTRUM;
1273 for(i=m_dae1persize; i<m_dae1specmap.size(); ++i)
1275 m_dae1specmap[i] = NOSPECTRUM;
1277 for(i=0; i<m_dae2persize; ++i)
1279 s = m_dae2specmap[i];
1280 if (s != NOSPECTRUM)
1282 for(j=1; j<m_nperiods; ++j)
1284 m_dae2specmap[i + j * m_dae2persize] = s + j * m_dae1persize;
1285 m_dae1specmap[s + j * m_dae1persize] = i + j * m_dae2persize;
1289 m_highspec = m_nperiods * m_dae2persize - 1;
1298 template <
class DetCardPolicy>
1301 int i, j, s, period_incr;
1302 if (period >= m_nperiods)
1307 if (m_dae2persize == 0)
1314 return setPeriodCounter(period, status);
1318 period_incr = period * m_dae2persize;
1319 for(i=0; i<DCDIMMAX; i++)
1321 for(j=0; j<DCPOSMAX; j++)
1323 s = m_poslut[DCPOSMAX*i + j] % m_dae2persize;
1324 m_poslut[DCPOSMAX*i + j] = s + period_incr;
1325 if (s + period_incr > DCMAXSPECPOSLUT)
1332 return writePOSLUTMemory(0, m_poslut, DCPOSLUTSIZE, status);
1337 template <
class DetCardPolicy>
1343 readRegister(DCVETOENABLE, &value, status);
1354 template <
class DetCardPolicy>
1359 return setRegisterBits(DCVETOENABLE, (
isisU32_t)dim_mask << 16,
true, status);
1367 template <
class DetCardPolicy>
1372 return clearRegisterBits(DCVETOENABLE, 0xffff0000, status);
1380 template <
class DetCardPolicy>
1385 return writeRegister(DCVETOFLAG, 0, status);
1394 template <
class DetCardPolicy>
1400 readRegister(DCVETOFLAG, &v, status);
1411 template <
class DetCardPolicy>
1416 case FrameOverflowVeto:
1418 case MemoryFullVeto:
1427 template <
class DetCardPolicy>
1432 case FrameOverflowVeto:
1433 return "FrameOverflowVeto";
1434 case MemoryFullVeto:
1435 return "MemoryFullVeto";
1437 return "FIFOLateVeto";
1443 template <
class DetCardPolicy>
1446 return setRegisterBits(DCVETOENABLE, getVetoMask(veto),
true, status);
1449 template <
class DetCardPolicy>
1452 return clearRegisterBits(DCVETOENABLE, getVetoMask(veto), status);
1455 template <
class DetCardPolicy>
1458 return registerBitsSet(DCVETOENABLE, getVetoMask(veto), status);
1461 template <
class DetCardPolicy>
1464 return registerBitsSet(DCVETOFLAG, getVetoMask(veto), status);
1467 template <
class DetCardPolicy>
1471 DeleteCriticalSection(&m_critical);
1474 template <
class DetCardPolicy>
1479 return writeRegister32As16(DCPERCNT0, DCPERCNT1, period, status);
1488 template <
class DetCardPolicy>
1493 return writeRegister32As16(DCPERSIZE0, DCPERSIZE1, per_size, status);
1502 template <
class DetCardPolicy>
1507 readRegister16As32(DCPERCNT0, DCPERCNT1, value, status);
1508 if (*value < 0 || *value >= m_nperiods)
1522 template <
class DetCardPolicy>
1528 m_hardware_periods = hardware_periods;
1529 getSpectrumSize(&value, status);
1531 if (single_daq_period)
1533 setPeriodSize(0, status);
1537 setPeriodSize(m_dae2persize * value, status);
1539 setPeriodCounter(0, status);
1543 m_hardware_periods =
false;
1544 if (hardware_periods)
1552 template <
class DetCardPolicy>
1557 return readRegister(DCTOTCNTS, counts, status);
1566 template <
class DetCardPolicy>
1571 return setAndClearTCGAccessRegister(DCTTOTCNTSCLE, status);
1579 template <
class DetCardPolicy>
1584 return readRegister16As32(DCFSDEL0, DCFSDEL1, value, status);
1593 template <
class DetCardPolicy>
1598 return writeRegister32As16(DCFSDEL0, DCFSDEL1, value , status);
1600 else if (value == 0)
1607 "Attempt to set a non-zero frame sync delay on a card without such support");
1617 #define MAKE_TEST_PATTERN(addr) ( ((addr) << 4) + m_position ) // write card ID as botton 4 bits
1619 template <
class DetCardPolicy>
1624 unsigned long i, j, start;
1625 const int bufsize = 100000;
1630 if (start + 4*bufsize < m_memsize)
1636 n = (m_memsize - start) / 4;
1646 else if (1 == pattern)
1652 buffer[i] = pattern;
1655 writeHistogramMemory(start, buffer, n, status);
1662 template <
class DetCardPolicy>
1667 unsigned long i, start, j;
1669 const int bufsize = 100000, max_error = 20;
1672 unsigned long tpattern;
1673 ICPTimer icptimer(
"checkTestPattern(DC)", status);
1676 if (start + 4*bufsize < m_memsize)
1682 n = (m_memsize - start) / 4;
1685 readHistogramMemory(start, buffer, n, status);
1697 if (buffer[i] != tpattern)
1699 if (nerror < max_error)
1711 "There were %d error(s) on card %d (only first %d printed)", nerror, m_position, max_error);
1715 status.
addInfoVa(
FAC_DAE,
"There were no errors on card %d (%d MB checked)", m_position, m_memsize / (1024 * 1024));
1721 template <
class DetCardPolicy>
1726 printVetoStatus(os,
true, status);
1732 template <
class DetCardPolicy>
1735 LOGSTR_DEBUG(
"Setting event collection mode to " << enable);
1740 m_reg.event_reg.eventMode(
true, status);
1741 m_reg.event_reg.enable32bitEvents(status);
1742 m_reg.event_reg.allVetoesInHeader(
false, status);
1743 m_reg.event_reg.storeVetodData(
false, status);
1756 m_reg.event_reg.eventMode(
false, status);
1764 template <
class DetCardPolicy>
1767 if ( !isEventMode(status) )
1772 LOGSTR_DEBUG(
"Updating dae address to " << m_last_address_read);
1773 readRegister(DCNXMEMWR, &last_mem_write, status);
1774 writeRegister(DCADDLRR, m_last_address_read, status);
1775 unsigned bytes_diff = (m_memsize + m_last_address_read - last_mem_write) % m_memsize;
1776 if (bytes_diff < 4096)
1778 LOGSTR_WARNING(
"memory nearly full only " << bytes_diff <<
" free");
1787 template <
class DetCardPolicy>
1791 if ( !isEventMode(status) )
1799 std::string error_message;
1803 readRegister(DCADDLRR, &value32, status);
1804 if (value32 != m_last_address_read)
1806 LOGSTR_WARNING(
"DAE and ICP disagree on last value read - dae " << value32 <<
" icp " << m_last_address_read);
1807 m_last_address_read = value32;
1810 poco_assert(m_last_address_read % 4 == 0);
1811 int start_address = (m_last_address_read + 4) % m_memsize;
1812 uint32_t new_words =
static_cast<uint32_t
>(nNewEventWords(status));
1813 LOGSTR_DEBUG(
"new words in dae " << new_words <<
" starting from address " << start_address);
1817 readRegister(DCNXMEMWR, &value32, status);
1818 if ( (m_memsize + value32 - start_address) % m_memsize >=
sizeof(
DAEEventHeader) )
1821 readHistogramMemoryWrapped(start_address, reinterpret_cast<isisU32_t*>(&temp_head),
DAE_EVENT_HEADER_WORDS, status);
1827 else if (iret != 0x20)
1829 LOGSTR_WARNING(
"No new events, but invalid header present " << error_message)
1838 if (new_words > maxlen)
1840 num_unread = new_words - maxlen;
1847 if (readHistogramMemoryWrapped(start_address, buffer, len, status))
1850 readRegister(DCNMEMWR, &value16, status);
1851 LOGSTR_NOTICE(
"Detector card memory wrapped, count = " << value16);
1852 if (value16 != m_wrap_counter)
1854 LOGSTR_WARNING(
"mismatch in event memory wrap count: dae = " << value16 <<
", icp = " << m_wrap_counter);
1858 m_last_address_read = (m_last_address_read + 4 * len) % m_memsize;
1863 template <
class DetCardPolicy>
1866 poco_assert( start % 4 == 0 );
1867 poco_assert( start < m_memsize );
1868 poco_assert( 4 * len <= m_memsize );
1869 uint32_t end_limit = (start + 4 * len) % m_memsize;
1870 if (end_limit > start)
1872 readHistogramMemory(start, buffer, len, status);
1877 unsigned len1 = (m_memsize - start) / 4;
1878 unsigned len2 = end_limit / 4;
1879 poco_assert(len == len1 + len2);
1880 readHistogramMemory(start, buffer, len1, status);
1881 readHistogramMemory(0, buffer + len1, len2, status);
1888 template <
class DetCardPolicy>
1891 if ( !isEventMode(status) )
1896 readRegister(DCNXFRMR, &next_dae_frame_address, status);
1897 poco_assert(next_dae_frame_address % 4 == 0);
1898 uint32_t num_bytes = (m_memsize + next_dae_frame_address - m_last_address_read - 4) % m_memsize;
1899 poco_assert(num_bytes % 4 == 0);
1905 return num_bytes / 4;
1923 template <
class DetCardPolicy>
1928 uint32_t check_mask = 0x0;
1930 writeRegister(DCTAC, 0xC0000000, status);
1932 zeroMemory<isisU32_t>(DCTCGLUT, DCTCGLUTSIZE, check_mask, props, status);
1936 writeRegister(DCEVNTMD, 0x0, status);
1938 writeRegister(DCDESCRX, 0x0, status);
1939 writeRegister(DCTCGTBL, 0x0, status);
1943 template <
class DetCardPolicy>
1950 if (mode != ModeSEData)
1958 template <
class DetCardPolicy>
1962 for(i=0; i<DAESPECMAX; i++)
1964 m_dae1specmap[i] = NOSPECTRUM;
1965 m_dae2specmap[i] = NOSPECTRUM;
1970 m_dae2persize = m_highspec + 1;
1971 m_highspec = m_nperiods * m_dae2persize - 1;
1974 for(i=0; i < DCPOSLUTSIZE; ++i)
1978 return writePOSLUTMemory(0, m_poslut, DCPOSLUTSIZE, status);
int clearPOSLUTMemory(DAEstatus &status, unsigned long start=0, int len=65536)
uint32_t TransferProps
combination of TransferProp values
int readSpectrum(int spec, isisU32_t *buffer, int nbuffer, DAEstatus &status)
read DAE2 spectrum
int setTCGAccessRegister(isisU32_t mask, DAEstatus &status)
void printSpecmap(std::ostream &os)
std::string checksumAsString(md5checksum_t checksum)
unsigned long m_memsize
histogram memory in bytes
virtual int programDAE1POSLUT(int crat[], int modn[], int mpos[], int spec[], int ndet, int nperiods, int dae1persize, DAEstatus &status)
int setFrameSyncDelay(isisU32_t value, DAEstatus &status)
int clearVetoOccurredFlag(DAEstatus &status)
virtual int getNTimeChannels(isisU32_t *ntc, DAEstatus &status)
int addVa(int facility, int severity, int errtype, const char *format,...)
int readAllDAE1Spectra(isisU32_t *buffer, int nbuffer, const int spec_to_crpt_offset[], int persize, DAEstatus &status)
int saveDAE2SpecmapToArray(int *array, int offset, int len, DAEstatus &status)
int readTCGAccessRegister(isisU32_t *value, DAEstatus &status)
int getCurrentHardwarePeriod(isisU32_t *period, DAEstatus &status)
int getFrameSyncDelay(isisU32_t *value, DAEstatus &status)
void updateDAEEventLastRead(DAEstatus &status)
called when all events returned by getNewEvents() have been safely processed
int clearTotalCountsRegister(DAEstatus &status)
uint32_t getNewEvents(isisU32_t *buffer, uint32_t maxlen, uint64_t &num_unread, bool &run_ended, DAEstatus &status)
virtual int setPeriodType(bool hardware_periods, bool single_daq_period, DAEstatus &status)
int readTCGLUTMemory(unsigned long start, isisU32_t *buffer, int len, DAEstatus &status)
int getTotalCounts(isisU32_t *counts, DAEstatus &status)
CRITICAL_SECTION m_critical
int readTCGTimeBinLimitRegister(isisU32_t *value, DAEstatus &status)
std::vector< int > m_dae1specmap
dae2spec = m_dae1specmap[dae1spec]
int add(DAEstatus &dstatus, bool clear)
int setPeriodSize(int per_size, DAEstatus &status)
void printPOSLUT(std::ostream &os, DAEstatus &status)
int enableDIMVetos(isisU16_t dim_mask, DAEstatus &status)
virtual void printStatus(std::ostream &os, DAEstatus &status)
#define LOGSTR_DEBUG(__arg)
int fillAddmap(Addmap *addmap, int len, DAEstatus &status)
virtual int getTimeChannels(isisU32_t *tcb, int ntc, DAEstatus &status)
int readDIMVetoOccurredFlag(isisU16_t *dim_mask, DAEstatus &status)
#define LOGSTR_NOTICE(__arg)
int m_highspec
highest DAE2 spectrum used
virtual void printStatus(std::ostream &os, DAEstatus &dstatus)
isisU16_t m_wrap_counter
number of times memory wrapped in event mode
int checkTestPattern(unsigned long pattern, DAEstatus &status)
uint32_t getVetoMask(DetectorCardVeto veto)
for use with DAE2DetCardPolicy::DCVETOENABLE and DAE2DetCardPolicy::DCVETOFLAG - see DAEEventHeaderIn...
#define LOGSTR_WARNING(__arg)
int writeHistogramMemory(unsigned long start, isisU32_t *buffer, int len, DAEstatus &status)
virtual int readPOSLUT(DAEstatus &status)
bool isRegisterUsed(const T &address)
registers are either "unsigned" or "unused_t"
virtual int setTimeChannels(isisU32_t *tcb, int ntc, DAEstatus &status)
int clearHistogramMemoryStart(DAEstatus &status)
int writeTCGLUTMemory(unsigned long start, isisU32_t *buffer, int len, DAEstatus &status)
bool hasVetoOccurred(DetectorCardVeto veto, DAEstatus &status)
const char * getVetoName(DetectorCardVeto veto)
int enableVeto(DetectorCardVeto veto, DAEstatus &status)
int printVetoStatus(std::ostream &os, bool triggered_only, DAEstatus &status)
virtual int programDAE1POSLUTDataDae(DAEstatus &status)
int clear(int severity, int direction, bool reset_overall_severity=true)
bool isClearHistogramMemoryComplete(DAEstatus &status)
void printTimeChannels(std::ostream &os, int start=0, int end=-1)
bit assignmments for DAE2DetCardPolicy::DCEVNTMD
isisU32_t sumHistogramMemory(DAEstatus &status)
#define LOGSTR_INFORMATION(__arg)
DetectorCard(int position, ISISVME *vme, int *specmap_array, int specmap_len, DAEstatus &status)
int readRegister(unsigned long address, isisU32_t *value, DAEstatus &status, bool little_endian=false, bool retry=true)
int getDIMVetos(isisU16_t *dim_mask, DAEstatus &status)
dim mask for vetos that are enabled
#define LOGSTR_ERROR(__arg)
int recreateDAE1Specmap(DAEstatus &status)
unsigned char md5checksum_t[16]
bool isVetoEnabled(DetectorCardVeto veto, DAEstatus &status)
int addWarning(int facility, const std::string &text)
int disableDIMVetos(DAEstatus &status)
int addWarningVa(int facility, const char *format,...)
int readHistogramMemory(unsigned long start, isisU32_t *buffer, int len, DAEstatus &status)
isisU32_t m_last_address_read
last memory addess read in event mode
uint64_t nNewEventWords(DAEstatus &status)
determine how many words there are to read that correspond to complete frames of events ...
int md5sumString(const void *buffer, int len, unsigned char *md5sum, DAEstatus &status)
bool readHistogramMemoryWrapped(unsigned long start, isisU32_t *buffer, uint32_t len, DAEstatus &status)
return true is memory wrapped during read
static const int NOSPECTRUM
static const unsigned DAE_EVENT_HEADER_WORDS
int writeDescriptorTimeBinLimitRegister(isisU32_t value, DAEstatus &status)
int readPOSLUTMemory(unsigned long start, isisU32_t *buffer, int len, DAEstatus &status)
int writePOSLUTMemory(unsigned long start, isisU32_t *buffer, int len, DAEstatus &status)
static bool isEndRunHeader(const DAEEventHeader *head, DAEstatus &status)
check whether an event frame header is a special enf of frame header
int fillWithTestPattern(unsigned long pattern, DAEstatus &status)
virtual int resetCardState(DAEstatus &status)
virtual int changePeriod(int period, DAEstatus &status)
int writeTCGTimeBinLimitRegister(isisU32_t value, DAEstatus &status)
int getSpectrumSize(isisU32_t *value, DAEstatus &status)
void setLoggerName(const std::string &logger_name)
static const int SPECTRUM_PLACEHOLDER
int setEventCollectionMode(bool enable, DAEstatus &status)
set up for event or histogram mode
int loadDAE2SpecmapFromArray(int *array, int len, DAEstatus &status)
int disableVeto(DetectorCardVeto veto, DAEstatus &status)
int addInfo(int facility, const std::string &text)
virtual int programPOSLUT(int cards[], int dims[], int pos_start[], int npos[], int spec[], int spec_step[], int nblocks, int nperiods, int dae1persize, DAEstatus &status)
int setPeriodCounter(int period, DAEstatus &status)
int readDAE1Spectrum(int dae1_spec, isisU32_t *buffer, int nbuffer, DAEstatus &status)
isisU32_t * m_poslut
temp workspace for POSLUT programming
int whichVeto(std::ostream &os, DAEstatus &status)
#define MAKE_TEST_PATTERN(addr)
int readDAE1Spectra(isisU32_t *buffer, int nbuffer, const int spec_to_crpt_offset[], int spec_start, int nspec, int period, int persize, DAEstatus &status)
reads into buffer the spectra on this card that are in the range considered
std::vector< int > m_dae2specmap
dae1spec = m_dae2specmap[dae2spec]
virtual int setNTimeChannels(isisU32_t ntc, DAEstatus &status)
int addInfoVa(int facility, const char *format,...)
void setCardMode(DetectorCardMode mode)
void findConsecutive(const std::vector< T > &vec, T invalid_val, std::vector< int > &indexes, std::vector< int > &sizes)
return an array of indices containing the start points of consecutive sequences of numbers ...
int setAndClearTCGAccessRegister(isisU32_t mask, DAEstatus &status)
bool isEventMode(DAEstatus &status)
virtual int changeNumberOfPeriods(int nperiod, DAEstatus &status)
int readDescriptorTimeBinLimitRegister(isisU32_t *value, DAEstatus &status)
static void checkEventHeader(const DAEEventHeader *head)