35 static char buffer[256];
37 if (getenv(
"SHORTNAME") != NULL)
39 strncpy(buffer, getenv(
"SHORTNAME"),
sizeof(buffer));
42 strncpy(buffer, inst_name,
sizeof(buffer));
118 if (getenv(
"ISISICP_MIN_TCBWIDTH") != NULL)
120 tcb_minwidth =
static_cast<float>(atof(getenv(
"ISISICP_MIN_TCBWIDTH")));
130 while( (n < output_size) && (input[n] !=
'\0') )
132 output[n] = input[n];
135 for(i=n; i<output_size; i++)
146 va_start(args, format);
147 n = vsnprintf(output, output_size, format, args);
151 for(i=n; i<output_size; i++)
161 int spaceTrimCopy(
char* output,
int output_size,
const char* input,
int input_size)
165 while( (n > 0) && (input[n-1] ==
' ') )
169 if (n >= output_size)
173 strncpy(output, input, n);
182 memset(ctemp,
' ',
sizeof(ctemp));
192 if (!strcmp(item_name,
"HDR"))
194 strncpy(&(ctemp[0]), this->
inst_abrv, 3);
196 strncpy(&(ctemp[8]), this->
user_name, 20);
202 if (ctemp[i] ==
'\0')
211 if (!strcmp(item_name,
"CRPB"))
216 if (ctemp[i] ==
'\0')
235 std::string sitem_name;
236 std::string tmp_item;
241 sitem_name = item_name;
242 n = sitem_name.find(
'_');
243 if (n != std::string::npos)
245 spec_no = atol(item_name+n+1);
246 tmp_item = sitem_name.substr(0,n);
247 return getIntItem(tmp_item.c_str(), &spec_no, 1, &lVal, status);
252 return getIntItem(item_name, &spec_no, 0, &lVal, status);
260 std::string sitem_name;
261 std::string tmp_item;
262 const int* pVal = NULL;
267 if (!strcmp(item_name,
int_items[i].name))
269 for(j=0; j < (nspec == 0 ? 1 : nspec); j++)
280 tmp_item = item_name;
304 for(j=0; j<nspec; j++)
308 for(i=0; i<this->
ndet; i++)
310 if (this->
spec[i] == spec_array[j])
318 lVal[j] = lVal[j] / n;
327 std::string sitem_name;
328 std::string tmp_item;
329 const float* pVal = NULL;
336 for(j=0; j < (nspec == 0 ? 1 : nspec); j++)
347 tmp_item = item_name;
371 for(j=0; j<nspec; j++)
375 for(i=0; i<this->
ndet; i++)
377 if (this->
spec[i] == spec_array[j])
379 dblVal[j] += pVal[i];
385 dblVal[j] = dblVal[j] / (double)n;
395 std::string sitem_name;
396 std::string tmp_item;
400 sitem_name = item_name;
401 n = sitem_name.find(
'_');
402 if (n == std::string::npos)
405 return getRealItem(item_name, &spec_no, 0, &dblVal, status);
409 spec_no = atol(item_name+n+1);
410 tmp_item = sitem_name.substr(0,n);
411 return getRealItem(tmp_item.c_str(), &spec_no, 1, &dblVal, status);
418 if ( !strcmp(item_name,
"SPECTRUMT0") )
421 for(
int i=0; i<nspec; ++i)
423 ntc = std::max(ntc, this->
spectrumNTC(spec_array[i]));
425 dims_array[0] = ntc + 1;
434 int spec_from, spec_to;
439 if ( !strncmp(item_name,
"CNT", 3) && (strlen(item_name) >= 5) && (item_name[4] ==
'[') )
441 long tr = atol(item_name + 3);
447 dims_array[0] = spec_to - spec_from + 1;
448 dims_array[1] = (this->
ntc[tr-1] + 1);
452 if ( !strncmp(item_name,
"CNT", 3) )
454 long tr = atol(item_name + 3);
456 dims_array[1] = (this->
ntc[tr-1] + 1);
460 if ( !strcmp(item_name,
"SPECTRUMT0") )
463 for(
int i=0; i<this->
ntrg; ++i)
465 ntc = std::max(ntc, this->ntc[i]);
467 dims_array[0] = ntc + 1;
471 if ( !strncmp(item_name,
"TCB", 3) && (strlen(item_name) > 3) )
473 long tr = atol(item_name + 3);
474 dims_array[0] = this->
ntc[tr-1] + 1;
478 if (!strncmp(item_name,
"SPECTRUM_", 9) || !strcmp(item_name,
"SPECTRUM"))
485 if (!strcmp(item_name,
"IRPB"))
492 if (!strcmp(item_name,
"DAEP"))
524 if ( (!strncmp(item_name,
"RSPECTRUM_", 10)) ||
525 (!strncmp(item_name,
"RSPECERR_", 9)) ||
526 (!strcmp(item_name,
"RSPECTRUM")) ||
527 (!strcmp(item_name,
"RSPECERR")) )
533 if ( !strncmp(item_name,
"RTCB_", 5) )
539 if ( !strncmp(item_name,
"RTCB", 4) )
541 long tr = atol(item_name+4);
542 dims_array[0] = this->
ntc[tr-1] + 1;
546 if ( !strncmp(item_name,
"TIM", 3) )
548 long tr = atol(item_name+3);
549 dims_array[0] = this->
ntc[tr-1] + 1;
554 if (!strcmp(item_name,
"RRPB"))
589 int spec_from, spec_to;
590 std::string sitem_name = item_name;
592 if ( !strncmp(item_name,
"CNT", 3) && (strlen(item_name) >= 5) && (item_name[4] ==
'[') )
594 long tr = atol(item_name + 3);
600 n = (this->
ntc[tr-1] + 1) * (spec_to - spec_from + 1);
604 larray[i] = raw_data[i + offset];
608 if ( !strncmp(item_name,
"CNT", 3) )
610 long tr = atol(item_name + 3);
612 for(j=0; j<this->
nper; ++j)
614 uint32_t offset = this->
trCRPTOffset(tr, j, raw_data_size);
619 larray[i+n*j] = raw_data[i+offset];
624 memset(larray+n*j, 0, n *
sizeof(
long));
629 if ( !strncmp(item_name,
"TCB", 3) )
632 for(k=0; k<nspec; k++)
636 for(i=0; i<ntc+1; i++)
638 larray[i + offset] = this->
tcb[tr-1][i];
644 if (!strcmp(item_name,
"SPECTRUMT0"))
646 int k = 0, ntcmax = 0;
647 for(j=0; j<nspec; j++)
649 ntcmax = std::max(ntcmax, this->
spectrumNTC(spec_array[j]));
651 for(j=0; j<nspec; j++)
655 for(i=0; i < ntc+1; i++)
657 larray[i + k] = raw_data[offset+i];
663 if (!strcmp(item_name,
"SPECTRUM"))
666 for(j=0; j<nspec; j++)
672 larray[i + k] = raw_data[offset+1+i];
679 if (!strcmp(item_name,
"IRPB"))
681 memset(larray, 0, 32 * nspec *
sizeof(
int));
682 for(k=0; k<nspec; k++)
694 if (!strcmp(item_name,
"DAEP"))
696 memset(larray, 0, 64 * nspec *
sizeof(
int));
697 for(k=0; k<nspec; k++)
701 larray[1 + n] = larray[0 + n] * (this->
nsp[0] + 1) * (this->
ntc[0] + 1) * this->
nper_daq;
717 larray[29 + n] = this->
ntrg;
718 for(i=0; i<this->
ntrg; i++)
742 for(k=0; k<nspec; k++)
759 std::string sitem_name, tmp_item;
760 sitem_name = item_name;
761 n = sitem_name.find(
'_');
762 if (n != std::string::npos)
764 spec_no = atol(item_name+n+1);
765 tmp_item = sitem_name.substr(0,n);
766 return getIntArrayItem(raw_data, raw_data_size, tmp_item.c_str(), &spec_no, 1, larray, status);
771 return getIntArrayItem(raw_data, raw_data_size, item_name, &spec_no, 1, larray, status);
777 return getRealArrayItemHelper<double>(raw_data, raw_data_size, item_name, darray, status);
782 return getRealArrayItemHelper<float>(raw_data, raw_data_size, item_name, farray, status);
787 return getRealArrayItemHelper<double>(raw_data, raw_data_size, item_name, spec_array, nspec, darray, status);
792 return getRealArrayItemHelper<float>(raw_data, raw_data_size, item_name, spec_array, nspec, farray, status);
795 template <
typename T>
800 std::string sitem_name, tmp_item;
801 sitem_name = item_name;
802 n = sitem_name.find(
'_');
803 if (n != std::string::npos)
805 spec_no = atol(item_name+n+1);
806 tmp_item = sitem_name.substr(0,n);
807 return getRealArrayItemHelper<T>(raw_data, raw_data_size, tmp_item.c_str(), &spec_no, 1, darray, status);
812 return getRealArrayItemHelper<T>(raw_data, raw_data_size, item_name, &spec_no, 1, darray, status);
816 template <
typename T>
821 std::string sitem_name = item_name;
823 if ( !strncmp(item_name,
"RTCB", 4) || !strncmp(item_name,
"TIM", 3) )
826 for(k=0; k<nspec; k++)
830 for(i=0; i<ntc+1; i++)
832 darray[i + n] = this->
rtcb[tr-1][i];
838 if (!strcmp(item_name,
"RSPECTRUM"))
841 for(k=0; k<nspec; k++)
848 darray[i + n] = raw_data[offset+1+i] / (this->
rtcb[tr-1][i+1] - this->
rtcb[tr-1][i]);
854 if (!strcmp(item_name,
"RSPECERR"))
857 for(k=0; k<nspec; k++)
864 darray[i + n] =
static_cast<T
>(sqrt((
double)raw_data[offset+1+i]) / (this->
rtcb[tr-1][i+1] - this->
rtcb[tr-1][i]));
871 if (!strcmp(item_name,
"RRPB"))
873 memset(darray, 0, 32 * nspec *
sizeof(
float));
874 for(k=0; k<nspec; k++)
895 for(k=0; k<nspec; k++)
911 size_t n = sitem_name.find(
'_');
912 if (n != std::string::npos)
914 num = atol(sitem_name.c_str()+n+1);
920 split_item.
item = sitem_name.substr(0,n);
929 for(
int i=0; i<
ntrg; ++i)
933 if (include_spectrum_zero)
944 if (tr >= 1 && tr <=
ntrg)
960 for(
int i=0; i<
ntrg; ++i)
970 for(
int i=0; i < this->
ntrg; ++i)
972 for(
int j=0; j < this->
ntrg; ++j)
974 for(
int k=0; k < 1 + this->
ntc[j]; ++k)
987 int simp_chan = this->
tcb_map[to_tr-1][from_tr-1][from_chan];
988 const float* to_rtcb = this->
rtcb[to_tr-1];
989 int ntc = this->ntc[to_tr-1];
995 while(i >= 1 && i < ntc)
997 if (to_rtcb[i] <= tof_val)
1002 if (to_rtcb[i-1] > tof_val)
1021 const float* from_rtcb = this->
rtcb[from_tr-1];
1022 const float* to_rtcb = this->
rtcb[to_tr-1];
1025 float tof_val = (from_rtcb[from_chan-1] + from_rtcb[from_chan]) / 2.0;
1026 int ntc = this->ntc[to_tr-1];
1027 int to_chan = ( std::upper_bound(to_rtcb, to_rtcb + ntc, tof_val) - to_rtcb );
1028 if ( to_chan == ntc )
1051 const float* from_rtcb = this->
rtcb[from_tr-1];
1052 const float* to_rtcb = this->
rtcb[to_tr-1];
1053 float ran = (float)rand() / (float)(RAND_MAX+1);
1054 float tof_val = from_rtcb[from_chan-1] + ran * (from_rtcb[from_chan] - from_rtcb[from_chan-1]);
1055 int ntc = this->ntc[to_tr-1];
1056 int to_chan =
channelLookup(from_chan, from_tr, to_tr, tof_val);
1061 if ( to_chan == ntc )
1071 if (strncmp(comp_name.c_str(),
"NDX", 3) == 0)
#define NULL_TERMINATE(__array)
null terminate a char[n] static array
int getIntArrayItem(const isisU32_t *raw_data, int raw_data_size, const char *item_name, long *larray, DAEstatus &status) const
uint32_t trCRPTOffset(int tr, int daq_period, int raw_data_size) const
int timr_crpt[ISISCRPT_MAX_DETECTOR]
int getNumSpectra(bool include_spectrum_zero=false) const
float rtcb[ISISCRPT_MAX_NTRG][ISISCRPT_MAX_TIMECHANB]
int tcb_map[ISISCRPT_MAX_NTRG][ISISCRPT_MAX_NTRG][ISISCRPT_MAX_TIMECHANB]
int setDAESpecificParameters()
static int vmstime(char *timbuf, int len, time_t time_value)
uint32_t spectrumCRPTOffsetImpl(int spec, int daq_period) const
int getRealArrayItemHelper(const isisU32_t *raw_data, int raw_data_size, const char *item_name, T *darray, DAEstatus &status) const
char rcsid[ISISCRPT_MAX_RCSID+1]
#define ISISCRPT_VERSION
increment ISISCRPT_VERSION for any ISISCRPT_STRUCT changes that might not be detected by a change of ...
int getCharItem(const char *item_name, std::string &cvalue, DAEstatus &status) const
static char_item char_items[]
int spaceTrimCopy(char *output, int output_size, const char *input, int input_size)
static const char * getInstAbrv(const char *inst_name)
static const char * inst_abrv_mappings[][2]
int spacePadCopyVa(char *output, int output_size, const char *format,...)
int timr_dae[ISISCRPT_MAX_DETECTOR]
int persize
size of a period in 32bit words
int channelLookup(int from_chan, int from_tr, int to_tr, float tof_val) const
static real_item real_items[]
static int_array_item int_array_items[]
int getRealItem(const char *item_name, double &dblVal, DAEstatus &status) const
int dae_type
time CRPT unloaded (may not be set if program crashed)
char long_title[ISISCRPT_TITLE_LEN+1]
int tcb[ISISCRPT_MAX_NTRG][ISISCRPT_MAX_TIMECHANB]
static int_item int_items[]
isisU32_t update_good_ppp_high
isisU32_t update_total_ppp_high
boost::array< int, ISISCRPT_MAX_NTRG > tcb_trdelay
int spec[ISISCRPT_MAX_DETECTOR]
static const char * crpt_rcsid
Poco::SingletonHolder< ICPClock > g_icp_clock
int getRealArrayItemSize(const char *item_name, int *dims_array, int &ndims, DAEstatus &status) const
int getRealArrayItem(const isisU32_t *raw_data, int raw_data_size, const char *item_name, double *darray, DAEstatus &status) const
int spectrumCRPTTR(int spec) const
isisU32_t update_good_ppp_low
char inst_abrv[ISISCRPT_INST_ABRV_LEN+1]
int timr_file[ISISCRPT_MAX_DETECTOR]
boost::array< int, ISISCRPT_MAX_NTRG > ntc
number of time channels per CRPT time regime
char user_name[ISISCRPT_USER_NAME_LEN+1]
int simpleChannelRebin(int from_chan, int from_tr, int to_tr) const
char inst_name[ISISCRPT_INST_LEN+1]
void getParameters(LONGLONG &perf_counter, LONGLONG &proc_freq, FILETIME &filetime)
static void splitItemName(const std::string &sitem_name, SplitItem &split_item)
#define VMS_RUN_MASK
need to wrap VMS run numbers to fit into 5 digits
void setInstName(const std::string &comp_name)
isisU32_t update_total_ppp_low
int parseSpectraRange(const std::string &spec_range, int &spec_from, int &spec_to)
int getHighestSpectrumNumber() const
int randomisedChannelRebin(int from_chan, int from_tr, int to_tr) const
int getIntItem(const char *item_name, long &lVal, DAEstatus &status) const
int spectrumNTC(int spec) const
int getIntArrayItemSize(const char *item_name, int *dims_array, int &ndims, DAEstatus &status) const
struct ISISCRPT_STRUCT::@9 icp_clock
static real_array_item real_array_items[]
boost::array< int, ISISCRPT_MAX_NTRG > nsp
number of spectra per CRPT time regime
int spacePadCopy(char *output, const char *input, int output_size)