7 os <<
"This is a MUON DECTECTOR card" << std::endl;
25 if (ntc >= DCPOSLUTSIZE)
28 "too many time channels %d", ntc);
34 "invalid tcb start - must be 0 not %f ns", tcb[0] / 2.0);
37 int clock_pulses = tcb[1] - tcb[0];
38 if ( (tcb[ntc] - tcb[ntc-1]) != clock_pulses )
41 "The final time bin boundary %f ns must be a multiple of the step size %f ns", tcb[ntc]/2.0, clock_pulses/2.0);
44 for(
int i=0; i<ntc; ++i)
46 if ((tcb[i+1] - tcb[i]) != clock_pulses)
49 "invalid tcb step for bin %d - must be equally spaced and found %f ns(!= %f)", i, (tcb[i+1] - tcb[i])/2.0, clock_pulses/2.0);
53 if (ntc * clock_pulses != 65536)
56 "The time window must be 32768 ns - %f ns is not allowed", ntc * clock_pulses / 2.0);
61 for(
int i=0; i < DCPOSLUTSIZE; ++i)
78 if ( (value % 2) != 0 )
106 "invalid tcb step - %d clock pulses is not a power of 2", clock_pulses);
109 if (clock_pulses > 32)
112 "invalid tcb step %f - max tcb step is 16ns", clock_pulses / 2.0);
115 return (clock_pulses == 1 ? 0 : clock_pulses / 2);
122 return (step_size == 0 ? 1 : 2 * step_size);
139 int* chan_count =
new int[ntc+2];
140 memset(chan_count, 0, (ntc+2)*
sizeof(
int));
144 while( (i < DCPOSLUTSIZE) && !done )
147 if (time_to <= tcb[0])
160 while( (i < DCPOSLUTSIZE) && (j < ntc) )
163 if (time_to <= tcb[j+1])
174 if (i == DCPOSLUTSIZE)
177 "Final TCB too big: ntc = %d (> %d), final tcb = %d", ntc, DCPOSLUTSIZE, tcb[ntc]);
180 while(i < DCPOSLUTSIZE)
183 ++(chan_count[ntc+1]);
187 chan_count[0], chan_count[ntc+1]);
198 for(
int i=0; i<ntc+1; ++i)
200 tcb[i] = i * clock_pulses;
214 memset(tcb, 0, (ntc+1)*
sizeof(
isisU32_t));
215 int time_from, time_to;
216 int i, j = 0, max_ntc = 0;
217 int* chan_count =
new int[ntc];
218 memset(chan_count, 0, ntc*
sizeof(
int));
220 while(i < DCPOSLUTSIZE)
225 if ((j < 0) || (j > ntc ))
228 "Invalid TCB bin %d", j);
231 max_ntc = (j > max_ntc ? j : max_ntc);
259 std::ostringstream message;
264 for(i=0; i<DAESPECMAX; i++)
288 message <<
"Highest DAE2 spectrum: " <<
m_highspec <<
"\n";
297 int npos[],
int spec[],
int spec_step[],
298 int nblocks,
int nperiods,
int dae1persize,
DAEstatus& status)
301 "Invalid poslut bin %d", 1);
313 int mpos[],
int spec[],
int ndet,
314 int nperiods,
int dae1persize,
DAEstatus& status)
316 std::ostringstream message_i, message_e, message_w;
317 int i, j, s, dae1min, dae1max, npos, ngap;
319 int modn_min=1000000, modn_max=-1, mpos_min=1000000, mpos_max=-1;
323 for(i=0; i<DAESPECMAX; i++)
335 for(i=0; i<ndet; i++)
341 if (spec[i] > dae1max)
345 if (spec[i] < dae1min)
352 for(i=dae1min; i<=dae1max; i++)
361 message_i <<
"There is a gap of total size " << ngap <<
" in the DAE1 spectra on the card" << std::endl;
370 for(i=0; i<ndet; i++)
375 if (mpos[i] < mpos_min)
379 if (modn[i] < modn_min)
383 if (mpos[i] > mpos_max)
387 if (modn[i] > modn_max)
401 message_e <<
"Error in calculateSpectrum" << std::endl;
406 message_e <<
"Error in spectrum mapping" << std::endl;
427 <<
" DAE1 low: " << dae1min <<
" DAE1 high: " << dae1max
428 <<
" NPOS: " << npos <<
"\n";
429 message_i <<
"MPOS: " << mpos_min <<
" to " << mpos_max <<
"\n";
430 message_i <<
"MODN: " << modn_min <<
" to " << modn_max <<
"\n";
434 message_w <<
"*** Detector Card " <<
m_position <<
" not used" << std::endl;
442 mem_needed = 4 *
m_nperiods * m_dae2persize * nchan;
446 "Detector Card %d has too little memory: %d < %d bytes",
455 :
DetectorCard(position, vme, specmap_array, specmap_len, status)
457 std::ostringstream message;
461 message <<
"Creating Muon Detector Card" <<
"\n";
512 "Detector Card %d has invalid spectrum %d",
m_position, dae2_spec);
536 "Detector Card %d has invalid modn %d",
m_position, modn);
542 "Detector Card %d has invalid modn %d",
m_position, modn);
548 "Detector Card %d has invalid mpos %d",
m_position, mpos);
unsigned long m_memsize
histogram memory in bytes
int addVa(int facility, int severity, int errtype, const char *format,...)
int calculateModuleAndPosition(int dae2_spec, int &modn, int &mpos, DAEstatus &status)
int getNTimeChannels(isisU32_t *ntc, DAEstatus &status)
int getTimeChannels32(isisU32_t *tcb, int ntc, DAEstatus &status)
int setTimeChannels32(isisU32_t *tcb, int ntc, DAEstatus &status)
int setRegisterBits(unsigned long address, isisU32_t mask, bool preserve, DAEstatus &status, bool little_endian=false)
std::vector< int > m_dae1specmap
dae2spec = m_dae1specmap[dae1spec]
int add(DAEstatus &dstatus, bool clear)
virtual void printStatus(std::ostream &os, DAEstatus &status)
int m_nperiods
number of software/DAQ periods
int m_highspec
highest DAE2 spectrum used
int writeRegister(unsigned long address, isisU32_t value, DAEstatus &status, bool little_endian=false)
int m_dae1persize
number of dae1 spectra in a period
#define LOGSTR_INFORMATION(__arg)
int readRegister(unsigned long address, isisU32_t *value, DAEstatus &status, bool little_endian=false, bool retry=true)
virtual int resetCardState(DAEstatus &status)
This emulates Kelvin Gascoyne's Clear.
int addDebugVa(int facility, const char *format,...)
int m_dae2persize
number of spectra in a dae2 period
static const int NOSPECTRUM
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 changePeriod(int period, 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)
int m_detector_inputs_per_card
int readPOSLUT(DAEstatus &status)
int getSpectrumSize(isisU32_t *value, DAEstatus &status)
void setLoggerName(const std::string &logger_name)
int clockPulsesToMuonStepSize(int clock_pulses, DAEstatus &status)
int programDAE1POSLUT(int crat[], int modn[], int mpos[], int spec[], int ndet, int nperiods, int dae1persize, DAEstatus &status)
int muonStepSizeToClockPulses(int step_size, DAEstatus &status)
static const int SPECTRUM_PLACEHOLDER
bool isPowerOf2(int value)
is value expressable as 2^n for some integer n
int addInfo(int facility, const std::string &text)
void printStatus(std::ostream &os, DAEstatus &status)
int setPeriodCounter(int period, DAEstatus &status)
int setTimeChannels(isisU32_t *tcb, int ntc, DAEstatus &status)
set of ntc+1 time channel boundaries in clock pulses (one pulse = 0.5ns)
isisU32_t * m_poslut
temp workspace for POSLUT programming
std::vector< int > m_dae2specmap
dae1spec = m_dae2specmap[dae2spec]
virtual int setNTimeChannels(isisU32_t ntc, DAEstatus &status)
int getTimeChannels(isisU32_t *tcb, int ntc, DAEstatus &status)
int m_dim_step
are dims numbered 0,1,2,3... or 0,2,4,6... etc.
int calculateSpectrum(int &dae2_spec, int modn, int mpos, DAEstatus &status)
int m_num_dims
totoal number of dims, not the highest dim number
MuonDetectorCard(int position, ISISVME *vme, int *specmap_array, int specmap_len, DAEstatus &status)