10 #define MIN_COMP_LEN 25
11 static int* makeNewRawData(const isisU32_t* raw_data, int nper_daq,
16 int* new_raw_data =
new int[nsp1*nper_daq*ntc1];
17 for(k=0; k<nper_daq; k++)
23 new_raw_data[i + j*ntc1 + k*ntc1*nsp1] =
24 raw_data[(i+1) + (j+1)*(ntc1+1) + k*(nsp1+1)*(ntc1+1)];
35 const unsigned char* ustr = (
const unsigned char*)str;
36 unsigned char* res =
new unsigned char[len+1];
39 if ( (ustr[i] ==
'\0') || (ustr[i] > 127) || !isprint(ustr[i]) )
55 static const int izero = 0;
56 static const int izero64 = 0;
57 static const float fzero = 0.0;
58 static const double dzero = 0.0;
78 template<
typename T,
int NXTYPE>
80 const char* attr_name,
const T* value,
int len,
bool convert_null)
94 if (NXopendata(fileid, data_name) == NX_OK)
96 NXputattr(fileid, attr_name, (
void*)value, len, NXTYPE);
102 template<
typename T,
int NXTYPE>
104 const char* attr_name, T value,
bool convert_null)
106 return writeAttribute<T,NXTYPE>(fileid, data_name, attr_name, &value, 1, convert_null);
109 template<
typename T,
int NXTYPE>
110 static int writeData(NXhandle fileid,
const char* data_name,
111 const T* value,
const int* dims_array,
int ndims,
bool convert_null,
int compression_type)
115 int dummy_dims_array[1] = { 1 };
116 int* chunk_size =
new int[ndims];
117 for(i=0; i<ndims; i++)
119 len *= dims_array[i];
123 if (convert_null || value != NULL)
127 dims_array = dummy_dims_array;
131 ret = NXmakedata(fileid, data_name, NXTYPE, ndims, (
int*)dims_array);
137 for(i=0; i<ndims; i++)
141 chunk_size[ndims-1] = dims_array[ndims-1];
142 if ( (compression_type != NX_COMP_NONE) && (chunk_size[ndims-1] >
MIN_COMP_LEN) )
144 ret = NXcompmakedata(fileid, data_name, NXTYPE, ndims, (
int*)dims_array, compression_type, chunk_size);
148 ret = NXmakedata(fileid, data_name, NXTYPE, ndims, (
int*)dims_array);
155 NXopendata(fileid, data_name);
156 NXputdata(fileid, (
void*)value);
167 template<
typename T,
int NXTYPE>
169 const T* value,
const int64_t* dims_array,
int ndims,
170 const int64_t* slab_start,
const int64_t* slab_size,
171 const int64_t* dest_start,
int compression_type)
174 int64_t i, j, offset;
175 int64_t dims[10], sizes[10];
178 NXputslab64(fileid, (
void*)(value+slab_start[0]), (int64_t*)dest_start, (int64_t*)slab_size);
182 dims[1] = dest_start[1]; sizes[0] = 1; sizes[1] = slab_size[1];
183 for(i=0; i<slab_size[0]; i++)
185 offset = (i + slab_start[0]) * dims_array[1] + slab_start[1];
186 dims[0] = i + dest_start[0];
187 NXputslab64(fileid, (
void*)(value + offset), dims, sizes);
192 dims[2] = dest_start[2]; sizes[0] = 1; sizes[1] = 1; sizes[2] = slab_size[2];
193 for(i=0; i<slab_size[0]; i++)
195 for(j=0; j<slab_size[1]; j++)
197 offset = (i + slab_start[0]) * (dims_array[1] * dims_array[2]) +
198 (j + slab_start[1]) * dims_array[2] +
200 dims[1] = j + dest_start[1];
201 dims[0] = i + dest_start[0];
202 NXputslab64(fileid, (
void*)(value + offset), dims, sizes);
209 template<
typename T,
int NXTYPE>
211 const T* value,
const int* dims_array,
int ndims,
212 const int* slab_start,
const int* slab_size,
213 const int* dest_start,
int compression_type)
215 std::vector<int64_t> t_dims_array(dims_array, dims_array+ndims);
216 std::vector<int64_t> t_slab_start(slab_start, slab_start+ndims);
217 std::vector<int64_t> t_slab_size(slab_size, slab_size+ndims);
218 std::vector<int64_t> t_dest_start(dest_start, dest_start+ndims);
219 return addSlab<T,NXTYPE>(fileid, value, &(t_dims_array[0]), ndims, &(t_slab_start[0]), &(t_slab_size[0]), &(t_dest_start[0]), compression_type);
222 template<
typename T,
int NXTYPE>
223 static int addSlab(NXhandle fileid,
const char* data_name,
224 const T* value,
const int* dims_array,
int ndims,
225 const int* slab_start,
const int* slab_size,
226 const int* dest_start,
int compression_type)
228 NXopendata(fileid, data_name);
229 addSlab<T,NXTYPE>(fileid, value, dims_array, ndims, slab_start, slab_size, dest_start, compression_type);
238 template<
typename T,
int NXTYPE>
239 static int writeSlab(NXhandle fileid,
const char* data_name,
240 const T* value,
const int* dims_array,
int ndims,
241 const int* slab_start,
const int* slab_size,
bool convert_null,
int compression_type)
243 const int BUFFER_SIZE = 1024 * 1024;
247 int dims[10], sizes[10];
248 int* chunk_size =
new int[ndims];
250 for(i=0; i<ndims; i++)
254 chunk_size[ndims-1] = slab_size[ndims-1];
255 if ( (compression_type != NX_COMP_NONE) && (chunk_size[ndims-1] >
MIN_COMP_LEN) )
257 ret = NXcompmakedata(fileid, data_name, NXTYPE, ndims, (
int*)slab_size, compression_type, chunk_size);
261 ret = NXmakedata(fileid, data_name, NXTYPE, ndims, (
int*)slab_size);
268 NXopendata(fileid, data_name);
271 NXputslab(fileid, (
void*)(value+slab_start[0]), &zero, (
int*)slab_size);
275 dims[1] = 0; sizes[0] = 1; sizes[1] = slab_size[1];
276 for(i=0; i<slab_size[0]; i++)
278 offset = (i + slab_start[0]) * dims_array[1] + slab_start[1];
280 NXputslab(fileid, (
void*)(value + offset), dims, sizes);
285 dims[2] = 0; sizes[0] = 1; sizes[1] = 1; sizes[2] = slab_size[2];
286 for(i=0; i<slab_size[0]; i++)
288 for(j=0; j<slab_size[1]; j++)
290 offset = (i + slab_start[0]) * (dims_array[1] * dims_array[2]) +
291 (j + slab_start[1]) * dims_array[2] +
295 NXputslab(fileid, (
void*)(value + offset), dims, sizes);
311 const int* dims_array,
int ndims,
312 int compression_type,
int spectra_chunk)
314 const int BUFFER_SIZE = 1024 * 1024;
319 int* chunk_size =
new int[ndims];
321 for(i=0; i<ndims; i++)
325 chunk_size[ndims-1] = dims_array[ndims-1];
328 if (dims_array[ndims-2] > spectra_chunk)
330 chunk_size[ndims-2] = spectra_chunk;
334 chunk_size[ndims-2] = dims_array[ndims-2];
337 if ( (compression_type != NX_COMP_NONE) && (chunk_size[ndims-1] >
MIN_COMP_LEN) )
339 ret = NXcompmakedata(fileid, data_name, NXTYPE, ndims, (
int*)dims_array, compression_type, chunk_size);
343 ret = NXmakedata(fileid, data_name, NXTYPE, ndims, (
int*)dims_array);
361 template<
typename T,
int NXTYPE>
363 const T* value,
const int* dims_array,
int ndims,
int dest_start[],
364 const int* slab_start,
const int* slab_size,
const std::vector<int>& slab_list,
365 bool convert_null,
int compression_type,
int spectra_chunk)
369 int dims[10], sizes[10];
370 NXopendata(fileid, data_name);
373 NXputslab(fileid, (
void*)(value+slab_start[0]), &(dest_start[0]), (
int*)slab_size);
377 dims[1] = dest_start[1]; sizes[0] = 1; sizes[1] = slab_size[1];
378 for(i = 0; i < slab_list.size(); ++i)
380 offset = (slab_list[i]) * dims_array[1] + slab_start[1];
381 dims[0] = i + dest_start[0];
382 NXputslab(fileid, (
void*)(value + offset), dims, sizes);
387 dims[2] = dest_start[2]; sizes[0] = 1; sizes[1] = 1; sizes[2] = slab_size[2];
388 for(i=0; i<slab_size[0]; i++)
390 for(j=0; j < slab_list.size(); ++j)
392 offset = (i + slab_start[0]) * (dims_array[1] * dims_array[2]) +
393 (slab_list[j]) * dims_array[2] +
395 dims[1] = j + dest_start[1];
396 dims[0] = i + dest_start[0];
397 NXputslab(fileid, (
void*)(value + offset), dims, sizes);
410 template<
typename T,
int NXTYPE>
412 const T* value,
const int* dims_array,
int ndims,
413 const int* slab_start,
const int* slab_size,
const std::vector<int>& slab_list,
414 bool convert_null,
int compression_type,
int spectra_chunk)
416 int ret = makeDataSlab<NXTYPE>(fileid, data_name, slab_size, ndims, compression_type, spectra_chunk);
421 int start_index[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
422 ret = addSlabList<T,NXTYPE>(fileid, data_name, value, dims_array, ndims, start_index, slab_start,
423 slab_size, slab_list, convert_null, compression_type, spectra_chunk);
428 template<
typename T,
int NXTYPE>
429 static int writeData(NXhandle fileid,
const char* data_name, T value,
bool convert_null,
int compression_type)
432 return writeData<T,NXTYPE>(fileid, data_name, &value, &one, 1, convert_null, compression_type);
435 template<
typename T,
int NXTYPE>
436 static int writeData(NXhandle fileid,
const char* data_name,
const T* value,
int len,
bool convert_null,
int compression_type)
438 return writeData<T,NXTYPE>(fileid, data_name, value, &len, 1, convert_null, compression_type);
441 template<
typename T,
int NXTYPE>
442 static int writeData(NXhandle fileid,
const char* data_name,
const T* value,
int dim1,
int dim2,
bool convert_null,
int compression_type)
444 int dims_array[2] = { dim1, dim2 };
445 return writeData<T,NXTYPE>(fileid, data_name, value, dims_array, 2, convert_null, compression_type);
452 NXMSetError(error_arg, error_func);
456 m_spectra_chunk(8), m_error_func(NULL), m_error_arg(NULL)
459 if (error_func != NULL)
482 the_clone->
clone(*
this);
491 return NXopen(filename, NXACC_RDWR, &
m_fileid);
498 return NXopen(filename, NXACC_CREATE5, &
m_fileid);
502 return NXopen(filename, NXACC_CREATE, &
m_fileid);
507 return NXopen(filename, NXACC_READ, &
m_fileid);
520 if (NXopendata(
m_fileid, name) == NX_OK)
525 else if (NXopengroup(
m_fileid, name, nxclass) == NX_OK)
540 return NXmakenamedlink(
m_fileid, name, &link);
554 int IXNeXusFile::addSlab(
const char* data_name,
const int* value,
const int* dims_array,
int ndims,
const int* slab_start,
const int* slab_size,
const int* dest_start)
556 return ::addSlab<int,NX_INT32>(
m_fileid, data_name, value, dims_array, ndims, slab_start, slab_size, dest_start,
m_compression_type);
559 int IXNeXusFile::addSlab(
const char* data_name,
const unsigned long* value,
const int* dims_array,
int ndims,
const int* slab_start,
const int* slab_size,
const int* dest_start)
561 return ::addSlab<unsigned long,NX_INT32>(
m_fileid, data_name, value, dims_array, ndims, slab_start, slab_size, dest_start,
m_compression_type);
564 int IXNeXusFile::addSlab(
const char* data_name,
const float* value,
const int* dims_array,
int ndims,
const int* slab_start,
const int* slab_size,
const int* dest_start)
566 return ::addSlab<float,NX_FLOAT32>(
m_fileid, data_name, value, dims_array, ndims, slab_start, slab_size, dest_start,
m_compression_type);
569 int IXNeXusFile::addSlab(
const int* value,
const int* dims_array,
int ndims,
const int* slab_start,
const int* slab_size,
const int* dest_start)
574 int IXNeXusFile::addSlab(
const unsigned long* value,
const int* dims_array,
int ndims,
const int* slab_start,
const int* slab_size,
const int* dest_start)
576 return ::addSlab<unsigned long,NX_INT32>(
m_fileid, value, dims_array, ndims, slab_start, slab_size, dest_start,
m_compression_type);
579 int IXNeXusFile::addSlab(
const float* value,
const int* dims_array,
int ndims,
const int* slab_start,
const int* slab_size,
const int* dest_start)
581 return ::addSlab<float,NX_FLOAT32>(
m_fileid, value, dims_array, ndims, slab_start, slab_size, dest_start,
m_compression_type);
584 int IXNeXusFile::addSlab(
const int* value,
const int64_t* dims_array,
int ndims,
const int64_t* slab_start,
const int64_t* slab_size,
const int64_t* dest_start)
589 int IXNeXusFile::addSlab(
const float* value,
const int64_t* dims_array,
int ndims,
const int64_t* slab_start,
const int64_t* slab_size,
const int64_t* dest_start)
591 return ::addSlab<float,NX_FLOAT32>(
m_fileid, value, dims_array, ndims, slab_start, slab_size, dest_start,
m_compression_type);
654 int IXNeXusFile::writeSlab(
const char* data_name,
const int* value,
const int* dims_array,
int ndims,
const int* slab_start,
const int* slab_size)
659 int IXNeXusFile::writeSlabList(
const char* data_name,
const unsigned long* value,
const int* dims_array,
int ndims,
const int* slab_start,
const int* slab_size,
const std::vector<int>& slab_list)
661 return ::writeSlabList<unsigned long,NX_INT32>(
m_fileid, data_name, value, dims_array, ndims, slab_start, slab_size, slab_list,
testOptions(
WriteDummyOnNULL),
m_compression_type,
m_spectra_chunk);
664 int IXNeXusFile::addSlabList(
const char* data_name,
const unsigned long* value,
const int* dims_array,
int ndims,
int dest_start[],
const int* slab_start,
const int* slab_size,
const std::vector<int>& slab_list)
666 return ::addSlabList<unsigned long,NX_INT32>(
m_fileid, data_name, value, dims_array, ndims, dest_start, slab_start, slab_size, slab_list,
testOptions(
WriteDummyOnNULL),
m_compression_type,
m_spectra_chunk);
727 return writeData(data_name, value, strlen(value));
767 return writeAttribute(data_name, attr_name, value, strlen(value));
773 NXmakegroup(
m_fileid, name, (
char*)nxclass);
776 NXopengroup(
m_fileid, name, (
char*)nxclass);
789 static char buffer[256];
790 struct tm *tm_struct;
791 tm_struct = localtime(&time);
794 strftime(buffer,
sizeof(buffer),
"%Y-%m-%dT%H:%M:%S", tm_struct);
798 strncpy(buffer,
"<UNKNOWN>",
sizeof(buffer));
800 buffer[
sizeof(buffer)-1] =
'\0';
805 static int readDeadTimes(
float* deadtimes_array,
int ndet,
const char* file)
808 memset(deadtimes_array, 0, ndet*
sizeof(
float));
810 f.open(file, std::ios::in);
822 while(f.good() && n < ndet)
825 if ((i >= 1) && (i <= ndet))
827 f >> deadtimes_array[i-1];
843 static int readTZero(
float& tzero,
float& tzero_offset,
const char* file)
846 tzero = 0.0f, tzero_offset = 0.1f;
848 f.open(file, std::ios::in);
851 f.ignore(50000,
'\n');
868 int i, j, k, m, n, ngroup, group_type;
870 for(i=0; i<ndet; i++)
875 f.open(file, std::ios::in);
876 f.ignore(50000,
'\n');
879 f.ignore(50000,
'\n');
884 for(i=0; i<ndet; i++)
886 f.ignore(50000,
'\n');
887 f.ignore(50000,
'\n');
891 f.ignore(50000,
'\n');
892 f.ignore(50000,
'\n');
895 f.ignore(50000,
'\n');
897 for(i=1; i <= ngroup; i++)
901 f.ignore(50000,
'\n');
903 f.ignore(50000,
'\n');
907 if ((k >=1) && (k <= ndet))
912 f.ignore(50000,
'\n');
914 else if (group_type == 2)
916 f.ignore(50000,
'\n');
917 for(m=1; m <= 2; m++)
920 f.ignore(50000,
'\n');
924 if ((k >=1) && (k <= ndet))
926 grouping[k-1] = m + 2*(i-1);
929 f.ignore(50000,
'\n');
932 f.ignore(50000,
'\n');
945 static void computeDetectorAverage(
const float* det_vals,
float* spec_vals,
const std::vector<int>* det_lookup,
const std::vector<int>& spec_list)
949 for(i=0; i < spec_list.size(); i++)
952 const std::vector<int>& dvec = det_lookup[spec_list[i]];
956 val += det_vals[dvec[j]];
960 spec_vals[i] = val /
static_cast<float>(n);
964 spec_vals[i] = 9999.0;
971 using namespace NeXus;
972 using namespace NeXus::Stream;
975 int mon_spec, mon_number, mon_tr;
976 for(
int i=0; i<crpt->
nmon; i++)
979 _snprintf(name,
sizeof(name),
"monitor_%d", mon_number);
980 if (crpt->
mdet[i] == 0)
982 dstatus.
addWarningVa(
FAC_DAE,
"Skipping monitor %d - not properly defined in wiring table", mon_number);
992 memcpy(monitor_data + j*ntc, raw_data + offset + 1, ntc *
sizeof(
isisU32_t));
994 int data_size[3] = { crpt->
nper_daq, 1, ntc };
997 nxf >> Group(name,
"NXmonitor");
1001 nxf << Group(name,
"NXmonitor");
1003 ixnf.
writeData(
"monitor_number", mon_number);
1004 ixnf.
writeData(
"data", reinterpret_cast<int*>(monitor_data), data_size, 3);
1007 ixnf.
writeAttribute(
"data",
"axes",
"period_index,spectrum_index,time_of_flight");
1008 ixnf.
makeLink(NULL, tof_links[mon_tr-1]);
1010 ixnf.
writeData(
"spectrum_index", mon_spec);
1013 delete[] monitor_data;
1020 long first_run_number;
1022 char measurement_line[80];
1025 std::stringstream string_str;
1026 std::vector<int> dims(2), slab_start(2), slab_size(2);
1027 dims[0] = NX_UNLIMITED;
1028 dims[1] =
sizeof(measurement_line);
1032 slab_size[1] = dims[1];
1046 string_str <<
"c:\\data\\measurement.nxs";
1047 std::string file(string_str.str());
1048 if (access(file.c_str(), 0) == 0)
1050 nx_mode = NXACC_RDWR;
1054 nx_mode = NXACC_CREATE5;
1056 sprintf(buffer,
"%08d", first_run_number);
1057 string_str <<
"entry_" << buffer;
1060 NeXus::File nf(file, nx_mode);
1061 if (nx_mode != NXACC_RDWR)
1063 nf.makeGroup(
"entry_1",
"NXentry",
true);
1064 nf.makeData(
"measurement_id", NeXus::CHAR, dims);
1065 nf.makeData(
"measurement_subid", NeXus::CHAR, dims);
1066 nf.makeData(
"measurement_type", NeXus::CHAR, dims);
1067 nf.makeData(
"measurement_label", NeXus::CHAR, dims);
1068 nf.makeData(
"sample_id", NeXus::CHAR, dims);
1073 nf.openGroup(
"entry_1",
"NXentry");
1076 strncpy(measurement_line, crpt->
measurement_id,
sizeof(measurement_line));
1077 nf.openData(
"measurement_id");
1078 slab_start[0] += nf.getInfo().dims[0];
1079 if (slab_start[0] < 0) { slab_start[0] = 0; }
1080 nf.putSlab(measurement_line, slab_start, slab_size);
1082 strncpy(measurement_line, label.c_str(),
sizeof(measurement_line));
1083 nf.openData(
"measurement_label"); nf.putSlab(measurement_line, slab_start, slab_size); nf.closeData();
1085 nf.openData(
"measurement_subid"); nf.putSlab(measurement_line, slab_start, slab_size); nf.closeData();
1086 strncpy(measurement_line, crpt->
measurement_type,
sizeof(measurement_line));
1087 nf.openData(
"measurement_type"); nf.putSlab(measurement_line, slab_start, slab_size); nf.closeData();
1088 strncpy(measurement_line, crpt->
sample_id,
sizeof(measurement_line));
1089 nf.openData(
"sample_id"); nf.putSlab(measurement_line, slab_start, slab_size); nf.closeData();
1092 catch(std::exception& ex)
1102 int NeXusWriter::writeISISNeXus(
const char* filename,
bool logs_only,
const ISISCRPT_STRUCT* crpt,
const isisU32_t* raw_data,
isisU32_t raw_data_size,
const ISISRAW* iraw,
const seblock_map_t& blocks,
const std::string& events_nxfile,
const std::string& inst_xml_file,
const std::string& inst_parameter_map_file,
DAEstatus& dstatus)
1104 int ret = writeISISNeXus(events_nxfile.c_str(), logs_only, crpt, raw_data, raw_data_size, iraw, blocks, inst_xml_file, inst_parameter_map_file, dstatus,
true);
1105 rename(events_nxfile.c_str(), filename);
1112 std::ifstream fs(file_name, std::ios::in);
1113 fs.seekg(0, std::ios::end);
1114 file_contents.reserve(fs.tellg());
1115 fs.seekg(0, std::ios::beg);
1116 file_contents.assign( (std::istreambuf_iterator<char>(fs)), std::istreambuf_iterator<char>() );
1120 int NeXusWriter::writeISISNeXus(
const char* filename,
bool logs_only,
const ISISCRPT_STRUCT* crpt,
const isisU32_t* raw_data,
isisU32_t raw_data_size,
const ISISRAW* iraw,
const seblock_map_t& blocks,
const std::string& inst_xml_file,
const std::string& inst_parameter_map_file,
DAEstatus& dstatus,
bool update)
1122 static const char* entry_name =
"raw_data_1";
1123 static const char* source_name =
"source";
1125 if ( Poco::Util::Application::instance().config().getBool(
"isisicp.snseventfile",
false) )
1127 entry_name =
"entry";
1128 source_name =
"SNS";
1133 NXsetcache(64*1024*1024);
1137 if (nx_file.
open(filename, mode, file_type) != NX_OK)
1144 std::string tmp_str;
1159 nx_file.
openGroup(entry_name,
"NXentry");
1168 nx_file.
writeData(
"definition",
"pulsedTD");
1170 nx_file.
writeAttribute(
"definition",
"url",
"http://definition.nexusformat.org/instruments/pulsedTD?version=1.0");
1174 nx_file.
writeData(
"definition",
"TOFRAW");
1176 nx_file.
writeAttribute(
"definition",
"url",
"http://definition.nexusformat.org/instruments/TOFRAW?version=1.0");
1177 nx_file.
writeData(
"definition_local",
"ISISTOFRAW");
1179 nx_file.
writeAttribute(
"definition_local",
"url",
"http://svn.isis.rl.ac.uk/instruments/ISISTOFRAW?version=1.0");
1182 nx_file.
writeData(
"program_name",
"ISISICP.EXE");
1210 nx_file.
writeData(
"experiment_identifier", buffer);
1212 std::string seci_config;
1214 nx_file.
writeData(
"seci_config", seci_config);
1216 long first_run_number;
1219 first_run_number = 0;
1221 std::string measurement_label;
1224 measurement_label =
"";
1229 nx_file.
writeData(
"measurement_first_run", (
int)first_run_number);
1230 nx_file.
writeData(
"measurement_label", measurement_label.c_str());
1251 unsigned long sum = 0;
1253 int* period_sum =
new int[crpt->
nper];
1254 float* period_fsum =
new float[crpt->
nper];
1255 float* total_counts_period =
new float[crpt->
nper_daq];
1259 for(i=crpt->
ntc[0] + 1; i < persize; i++)
1261 period_sum[j] += raw_data[i+j*persize];
1263 sum += period_sum[j];
1264 total_counts_period[j] = (float)period_sum[j] / (
float)1e6;
1271 delete[] total_counts_period;
1273 for(j=0; j<crpt->
nper; j++)
1275 period_sum[j] = crpt->
period[j].good_frames;
1278 for(j=0; j<crpt->
nper; j++)
1280 period_sum[j] = crpt->
period[j].total_frames;
1284 for(j=0; j<crpt->
nper; j++)
1286 period_fsum[j] = crpt->
period[j].good_uamph;
1288 nx_file.
writeData(
"proton_charge", period_fsum, crpt->
nper);
1290 for(j=0; j<crpt->
nper; j++)
1292 period_fsum[j] = crpt->
period[j].total_uamph;
1294 nx_file.
writeData(
"proton_charge_raw", period_fsum, crpt->
nper);
1298 for(j=0; j<crpt->
nper; j++)
1300 if (crpt->
period[j].daq_period >= 0)
1302 period_sum[i++] = crpt->
period[j].good_frames;
1309 sum += period_sum[i];
1322 for(j=0; j<crpt->
nper; j++)
1324 period_sum[j] = crpt->
nperseq;
1327 for(j=0; j<crpt->
nper; j++)
1329 period_sum[j] = crpt->
period[j].requested_frames;
1331 nx_file.
writeData(
"frames_requested", period_sum, crpt->
nper);
1332 for(j=0; j<crpt->
nper; j++)
1334 period_sum[j] = crpt->
period[j].type;
1337 for(j=0; j<crpt->
nper; j++)
1339 period_sum[j] = crpt->
period[j].output;
1342 tmp_str = crpt->
period[0].label;
1343 for(j=1; j<crpt->
nper; j++)
1345 tmp_str.append(
";");
1346 tmp_str.append(crpt->
period[j].label);
1348 nx_file.
writeData(
"labels", tmp_str.c_str());
1349 delete[] period_sum;
1350 delete[] period_fsum;
1354 nx_file.
openGroup(
"instrument",
"NXinstrument");
1363 if ( (strlen(crpt->
instrument_xml_file) > 0) && (access(inst_xml_file.c_str(), 4 ) == 0) )
1367 std::string inst_xml, inst_parameter_map;
1369 readExternalFile(inst_xml_file, inst_xml);
1370 readExternalFile(inst_parameter_map_file, inst_parameter_map);
1374 nx_file.
writeData(
"description",
"Mantid Instrument IDF copied from " + detector_calibration_file);
1376 nx_file.
makeNewGroup(
"instrument_parameter_map",
"NXnote");
1377 nx_file.
writeData(
"data", inst_parameter_map);
1378 nx_file.
writeData(
"type",
"text/plain");
1379 nx_file.
writeData(
"description",
"Mantid Instrument parameters copied from " + detector_calibration_file);
1382 nx_file.
writeData(
"instrument_detector_calibration_file", detector_calibration_file);
1384 catch(
const std::exception& ex)
1386 LOGSTR_ERROR(
"Cannot load instrument XML: " << ex.what());
1394 nx_file.
writeData(
"type",
"Pulsed Muon Source");
1399 nx_file.
writeData(
"type",
"Pulsed Neutron Source");
1429 for(j=0; j<crpt->
ntrg; j++)
1431 sprintf(buffer,
"time_channels_%d", j+1);
1434 nx_file.
openGroup(buffer,
"IXtime_channels");
1439 nx_file.
writeData(
"time_of_flight", &(crpt->
rtcb[j][0]), 1 + crpt->
ntc[j]);
1442 nx_file.
writeAttribute(
"time_of_flight",
"units",
"microsecond");
1443 nx_file.
writeData(
"time_of_flight_raw", &(crpt->
tcb[j][0]), 1 + crpt->
ntc[j]);
1445 nx_file.
writeAttribute(
"time_of_flight_raw",
"frequency",
"32 MHz");
1447 nx_file.
getLink(
"time_of_flight", tof_links[j]);
1448 nx_file.
getLink(
"time_of_flight_raw", tof_raw_links[j]);
1451 std::vector<int> period_no(crpt->
nper_daq);
1457 nx_file.
getLink(
"period_index", period_link);
1460 NXlink counts_link, spec_link;
1462 std::vector<int>* det_lookup =
new std::vector<int>[crpt->
getNumSpectra(
true)];
1463 for(i=0; i<crpt->
ndet; i++)
1465 det_lookup[crpt->
spec[i]].push_back(i);
1468 std::set<int> spec_groups;
1469 for(i=0; i<crpt->
ndet; ++i)
1471 int spec = crpt->
spec[i];
1474 for(i=0; i<crpt->
ntrg; ++i)
1476 spec_groups.insert(i+1);
1478 nx_file.
openGroup(
"instrument",
"NXinstrument");
1481 BOOST_FOREACH(
int group_index, spec_groups)
1487 for(
int k=0; k<crpt->
ntrg; ++k)
1490 std::set<int> spec_set;
1492 for(i=0; i<crpt->
ndet; i++)
1494 int spec = crpt->
spec[i];
1498 spec_set.insert(spec);
1499 det_tr[0] = crpt_tr;
1502 std::vector<int> spec_list;
1503 spec_list.reserve(spec_set.size());
1504 for(std::set<int>::const_iterator it = spec_set.begin(); it != spec_set.end(); ++it)
1506 spec_list.push_back(*it);
1508 if (spec_list.size() > 0)
1510 nx_file.
openGroup(
"instrument",
"NXinstrument");
1511 nx_file.
openGroup(det_name.c_str(),
"NXdetector");
1514 int data_size[3] = { crpt->
nper_daq, spec_list.size(), crpt->
ntc[k] };
1515 nx_file.
makeDataSlab(
"counts", raw_data, data_size, 3);
1516 if ( logs_only && (spec_list.size() > 10) )
1518 spec_list.resize(10);
1520 std::vector<int> spec_offsets(spec_list.size());
1522 std::transform(spec_list.begin(), spec_list.end(), spec_offsets.begin(), std::bind2nd(std::minus<int>(), spec_min));
1523 int count_dims[3] = { 1, crpt->
getNumSpectra(k+1,
true), crpt->
ntc[k] + 1 };
1524 int slab_start[3] = { 0, 0, 1 };
1529 int slab_size[3] = { 1, spec_list.size(), crpt->
ntc[k] };
1532 int dest_start[3] = { i, 0, 0 };
1533 nx_file.
addSlabList(
"counts", raw_data + crpt->
spectrumCRPTOffsetImpl(spec_min, i, raw_data_size), count_dims, 3, dest_start, slab_start, slab_size, spec_offsets);
1537 nx_file.
writeAttribute(
"counts",
"axes",
"period_index,spectrum_index,time_of_flight");
1538 nx_file.
getLink(
"counts", counts_link);
1539 time_counts.
info(
"writeISISNeXus(counts)", dstatus);
1540 nx_file.
writeData(
"spectrum_index", spec_list);
1541 nx_file.
getLink(
"spectrum_index", spec_link);
1550 nx_file.
makeLink(NULL, period_link);
1551 nx_file.
makeLink(NULL, tof_links[det_tr[0] - 1]);
1552 nx_file.
makeLink(NULL, tof_raw_links[det_tr[0] - 1]);
1553 nx_file.
writeData(
"source_detector_distance", crpt->
sdd);
1555 nx_file.
writeData(
"polar_angle", spec_work, spec_list.size());
1558 nx_file.
writeData(
"distance", spec_work, spec_list.size());
1561 nx_file.
writeData(
"delt", spec_work, spec_list.size());
1562 for(i=0; i<crpt->
nuse; i++)
1564 sprintf(buffer,
"user_table%02d", i+1);
1566 nx_file.
writeData(buffer, spec_work, spec_list.size());
1569 nx_file.
writeData(
"azimuthal_angle", spec_work, spec_list.size());
1577 nx_file.
openGroup(det_name.c_str(),
"NXdata");
1583 nx_file.
makeLink(NULL, counts_link);
1584 nx_file.
makeLink(NULL, tof_links[det_tr[0] - 1]);
1586 nx_file.
makeLink(NULL, period_link);
1588 time_detector.
info(
"writeISISNeXus(detector)",dstatus);
1592 delete[] det_lookup;
1594 addMonitors(nx_file, crpt, raw_data, raw_data_size, tof_links, period_link, update, dstatus);
1602 if (Poco::Util::Application::instance().config().getBool(
"isisicp.saveeventsinfile",
true) )
1606 nxwriter.
start(crpt, &nx_file,
false);
1622 for(seblock_map_t::const_iterator it = blocks.begin(); it != blocks.end(); ++it)
1624 if (it->first ==
"ICPEVENT" || it->first ==
"ICPDEBUG")
1630 nx_file.
writeData(
"vi_name", it->second.vi_name);
1631 nx_file.
writeData(
"read_control", it->second.read_control);
1632 nx_file.
writeData(
"set_control", it->second.set_control);
1633 if (it->second.is_real && it->second.fcurrent_value.size() > 0)
1635 nx_file.
writeData(
"value", it->second.fcurrent_value);
1637 nx_file.
writeData(
"value_spread", it->second.fcurrent_spread);
1638 nx_file.
writeAttribute(
"value_spread",
"units", it->second.units);
1639 nx_file.
writeData(
"setpoint", it->second.fsetpoint_value);
1641 nx_file.
writeData(
"setpoint_spread", it->second.fsetpoint_spread);
1642 nx_file.
writeAttribute(
"setpoint_spread",
"units", it->second.units);
1644 else if (it->second.current_value.size() > 0)
1646 nx_file.
writeData(
"value", it->second.current_value);
1648 nx_file.
writeData(
"setpoint", it->second.setpoint_value);
1651 if (it->second.fvalues.size() > 0 || it->second.svalues.size() > 0)
1654 nx_file.
writeData(
"name", it->second.nexus_name);
1655 if (it->second.is_real)
1657 nx_file.
writeData(
"value", it->second.fvalues);
1661 nx_file.
writeData(
"value", it->second.svalues);
1664 nx_file.
writeData(
"time", it->second.time);
1672 time_selogs.
info(
"writeISISNeXus(selogs)", dstatus);
1693 nx_file.
addLog(
"monitor_sum_1", int_vec,
"counts", run_blocks.
time,
"second", crpt->
start_time);
1695 nx_file.
addLog(
"total_counts", int_vec,
"counts", run_blocks.
time,
"second", crpt->
start_time);
1703 seblock_map_t::const_iterator se_it;
1704 se_it = blocks.find(
"ICPEVENT");
1705 if (se_it != blocks.end())
1707 nx_file.
addLog(
"icp_event", se_it->second.svalues,
"", se_it->second.time,
"second", crpt->
start_time);
1709 se_it = blocks.find(
"ICPDEBUG");
1710 if (se_it != blocks.end())
1712 nx_file.
addLog(
"icp_debug", se_it->second.svalues,
"", se_it->second.time,
"second", crpt->
start_time);
1715 time_runlogs.
info(
"writeISISNeXus(runlogs)", dstatus);
1720 nx_file.
writeData(
"HDR", (
const char*)&(iraw->
hdr),
sizeof(iraw->
hdr) /
sizeof(
char));
1722 nx_file.
writeData(
"ADD", (
const int*)&(iraw->
add),
sizeof(iraw->
add) /
sizeof(
int));
1727 nx_file.
writeData(
"USER", (
const char*)&(iraw->
user),
sizeof(iraw->
user) /
sizeof(
char));
1728 nx_file.
writeData(
"IRPB", (
const int*)&(iraw->
rpb),
sizeof(iraw->
rpb) /
sizeof(
int));
1729 nx_file.
writeData(
"RRPB", (
const float*)&(iraw->
rpb),
sizeof(iraw->
rpb) /
sizeof(
float));
1731 nx_file.
writeData(
"CRPB", tmp_chars,
sizeof(iraw->
rpb) /
sizeof(
int),
sizeof(
int));
1735 nx_file.
writeData(
"IVPB", (
const int*)&(iraw->
ivpb),
sizeof(iraw->
ivpb) /
sizeof(
int));
1736 nx_file.
writeData(
"RVPB", (
const float*)&(iraw->
ivpb),
sizeof(iraw->
ivpb) /
sizeof(
float));
1744 nx_file.
writeData(
"SPB", (
const int*)&(iraw->
spb),
sizeof(iraw->
spb) /
sizeof(
int));
1745 nx_file.
writeData(
"ISPB", (
const int*)&(iraw->
spb),
sizeof(iraw->
spb) /
sizeof(
int));
1746 nx_file.
writeData(
"RSPB", (
const float*)&(iraw->
spb),
sizeof(iraw->
spb) /
sizeof(
float));
1748 nx_file.
writeData(
"CSPB", tmp_chars,
sizeof(iraw->
spb) /
sizeof(
int),
sizeof(
int));
1753 nx_file.
writeData(
"DAEP", (
const int*)&(iraw->
daep),
sizeof(iraw->
daep) /
sizeof(
int));
1786 nx_file.
writeData(
"NOTE",
" No notes were made");
1799 for(i=0; i<crpt->
nuse; i++)
1801 sprintf(buffer,
"UT%02d", i+1);
1805 time_vms.
info(
"writeISISNeXus(vms)", dstatus);
1810 time_all.
info(
"writeISISNeXus", dstatus);
1821 if ( (getenv(
"ISISICP_COMPRESSION") != NULL) &&
1822 !strcmp(getenv(
"ISISICP_COMPRESSION"),
"1") )
1827 std::string tmp_str;
1829 float vector[3] = { 1.0, 1.0, 1.0 };
1830 int int_temp[3] = { 1, 1, 1 };
1851 sprintf(buffer,
"%lu", static_cast<unsigned long>(crpt->
duration));
1864 f.
writeData(
"experiment_number", buffer);
1873 f.
writeData(
"magnetic_field_state",
"TF");
1874 f.
writeData(
"magnetic_field_vector", vector, 3);
1875 f.
writeAttribute(
"magnetic_field_vector",
"coordinate_system",
"cartesian");
1886 float* angle_array =
new float[4*crpt->
ndet*crpt->
nper_daq];
1887 memset(angle_array, 0, 4*crpt->
ndet*crpt->
nper_daq*
sizeof(
float));
1891 delete []angle_array;
1892 float* deadtimes_array =
new float[crpt->
ndet*crpt->
nper_daq];
1893 int dead_available =
readDeadTimes(deadtimes_array, crpt->
ndet, Poco::Path(inst_settings_dir,
"dtpar.dat").toString().c_str());
1896 for(j=0; j<crpt->
ndet; j++)
1898 deadtimes_array[i*crpt->
ndet+j] = deadtimes_array[j];
1904 delete []deadtimes_array;
1908 f.
writeData(
"aperture",
"slit settings");
1912 unsigned long sum = 0;
1914 int* period_sum =
new int[crpt->
nper];
1915 float* total_counts_period =
new float[crpt->
nper_daq];
1919 for(i=crpt->
ntc[0] + 1; i < persize; i++)
1921 period_sum[j] += raw_data[i+j*persize];
1923 sum += period_sum[j];
1924 total_counts_period[j] = (float)period_sum[j] / (
float)1e6;
1926 f.
writeData(
"total_counts", (
float)sum / (
float)1e6);
1930 delete[] total_counts_period;
1932 for(j=0; j<crpt->
nper; j++)
1934 period_sum[j] = crpt->
period[j].good_frames;
1937 for(j=0; j<crpt->
nper; j++)
1939 period_sum[j] = crpt->
period[j].total_frames;
1943 for(j=0; j<crpt->
nper; j++)
1945 if (crpt->
period[j].daq_period >= 0)
1947 period_sum[i++] = crpt->
period[j].good_frames;
1954 sum += period_sum[i];
1956 if (crpt->
nper == 1)
1967 for(j=0; j<crpt->
nper; j++)
1969 period_sum[j] = crpt->
period[j].requested_frames;
1971 f.
writeData(
"frames_period_requested", period_sum, crpt->
nper);
1972 for(j=0; j<crpt->
nper; j++)
1974 period_sum[j] = crpt->
period[j].type;
1977 for(j=0; j<crpt->
nper; j++)
1979 period_sum[j] = crpt->
period[j].output;
1982 tmp_str = crpt->
period[0].label;
1983 for(j=1; j<crpt->
nper; j++)
1985 tmp_str.append(
";");
1986 tmp_str.append(crpt->
period[j].label);
1988 f.
writeData(
"period_labels", tmp_str.c_str());
1989 delete[] period_sum;
1994 int count_dims[2] = { crpt->
nsp[0] + 1, crpt->
ntc[0] + 1 };
1995 int slab_dims[2] = { 1, 1 };
1996 int slab_sizes[2] = { crpt->
nsp[0], crpt->
ntc[0] };
1997 float tzero = 0.0, tzero_offset = 0.0;
2000 readTZero(tzero, tzero_offset, Poco::Path(inst_settings_dir,
"basetime_1.uda").toString().c_str());
2004 readTZero(tzero, tzero_offset, Poco::Path(inst_settings_dir,
"basetime_2.uda").toString().c_str());
2017 for(i=0; i < crpt->
ntc[0]; i++)
2019 if ( (tzero*1000.0 >= crpt->
rtcb[0][i]) && (tzero*1000.0 <= crpt->
rtcb[0][i+1]) )
2024 float first_good = tzero + tzero_offset;
2025 int first_good_bin = 0;
2026 for(i=0; i < crpt->
ntc[0]; i++)
2028 if ( (first_good*1000.0 >= crpt->
rtcb[0][i]) && (first_good*1000.0 <= crpt->
rtcb[0][i+1]) )
2030 first_good_bin = i + 1;
2034 crpt->
nsp[0], crpt->
ntc[0]);
2036 delete[] new_raw_data;
2047 f.
writeData(
"resolution", (
int)(1000.0* (crpt->
rtcb[0][1] - crpt->
rtcb[0][0])));
2049 float* time_array =
new float[crpt->
ntc[0]];
2050 for(i=0; i<crpt->
ntc[0]; i++)
2052 time_array[i] = (crpt->
rtcb[0][i+1] + crpt->
rtcb[0][i]) / (2.0 * 1000.0);
2058 for(i=0; i<crpt->
ntc[0]; i++)
2060 time_array[i] -= tzero;
2062 f.
writeData(
"corrected_time", time_array, crpt->
ntc[0]);
2065 delete[] time_array;
2068 std::string file_prefix;
2071 file_prefix =
"long";
2075 file_prefix =
"trans";
2077 Poco::Path search_expr(inst_settings_dir, (file_prefix+
"*.uda").c_str());
2078 std::set<std::string> files_list;
2079 Poco::Glob::glob(search_expr, files_list, Poco::Glob::GLOB_CASELESS);
2080 Poco::RegularExpression re(file_prefix+
"(.*)\\.uda", Poco::RegularExpression::RE_CASELESS);
2081 Poco::RegularExpression::MatchVec matches;
2082 BOOST_FOREACH(
const std::string& file, files_list)
2084 re.match(file, 0, matches);
2085 if (matches.size() == 2)
2087 ngroup =
readGrouping(grouping, crpt->
ndet, Poco::Path(inst_settings_dir,file.c_str()).toString().c_str());
2090 for(j=0; j<crpt->
ndet; j++)
2092 grouping[i*crpt->
ndet+j] = grouping[j];
2095 std::string grouping_name =
"grouping" + file.substr(matches[1].offset, matches[1].length);
2096 std::replace(grouping_name.begin(), grouping_name.end(),
' ',
'_');
2099 if (matches[1].length == 0)
2105 float* alpha_array =
new float[ngroup*ngroup];
2106 for(i=0; i<ngroup*ngroup; i++)
2108 alpha_array[i] = 1.0;
2110 f.
writeData(
"alpha", alpha_array, ngroup*ngroup);
2113 delete[] alpha_array;
2117 std::string log_name;
2119 for(seblock_map_t::const_iterator it = blocks.begin(); it != blocks.end(); ++it)
2121 if (it->first ==
"ICPEVENT")
2123 log_name =
"ICPevent";
2125 else if (strcmp(it->first.c_str(),
"Temp_Sample") == 0)
2127 log_name =
"temperature_log_1";
2131 log_name = it->first;
2134 if (it->second.fvalues.size() > 0 || it->second.svalues.size() > 0)
2138 if (it->second.is_real)
2140 f.
writeAttribute(
"name",
"available", (
int)it->second.fvalues.size());
2141 f.
writeData(
"values", it->second.fvalues);
2145 f.
writeAttribute(
"name",
"available", (
int)it->second.svalues.size());
2146 f.
writeData(
"values", it->second.svalues);
2148 f.
writeAttribute(
"values",
"units", (it->second.units.size() > 0 ? it->second.units.c_str() :
"K") );
2155 time_selogs.
info(
"writeMuonFile(selogs)", dstatus);
2159 std::string block_name;
2160 std::vector<std::string> file_list;
2163 findFiles(
"c:\\data", buffer, file_list);
2164 for(i=0; i<file_list.size(); i++)
2166 j = file_list[i].find_last_of(
"\\");
2167 j = file_list[i].find_first_of(
"_",j);
2168 k = file_list[i].length() - (j + 1) - 4;
2169 block_name = file_list[i].substr(j+1, k);
2170 if (strcmp(block_name.c_str(),
"Temp_Sample") == 0)
2172 strcpy(buffer,
"temperature_log_1");
2176 strcpy(buffer, block_name.c_str());
2178 f.
addLog(buffer, file_list[i].c_str(), block_name.c_str(),
2193 time_all.
info(
"writeMuonFile v1", dstatus);
2194 if (Poco::Util::Application::instance().config().getBool(
"isisicp.muon.nexusv2test",
false))
2196 std::string filename_v2(filename);
2197 filename_v2.append(
"_v2");
2198 writeISISNeXus(filename_v2.c_str(),
false, crpt, raw_data, raw_data_size, NULL, blocks, inst_xml_file, inst_parameter_map_file, dstatus);
2199 time_all.
info(
"writeMuonFile v1+v2", dstatus);
2207 const char* new_sample_name,
DAEstatus& dstatus)
2213 if ( (getenv(
"ISISICP_COMPRESSION") != NULL) &&
2214 !strcmp(getenv(
"ISISICP_COMPRESSION"),
"1") )
2219 int run_number_digits = 8;
2222 std::string sample_name, inst_name, long_title, comment, start_time_iso;
2223 std::string tmp_str;
2224 float magnetic_field, temperature;
2233 f.
readData(
"start_time", start_time_iso);
2234 start_time = f.
unixTime(start_time_iso.c_str());
2235 if (new_comment != NULL)
2237 comment = new_comment;
2246 if (new_sample_name != NULL)
2248 sample_name = new_sample_name;
2255 f.
readData(
"temperature", temperature);
2256 f.
readData(
"magnetic_field", magnetic_field);
2258 if (new_sample_name != NULL)
2260 sprintf(buffer,
"%s T=%f F=%f", sample_name.c_str(), temperature, magnetic_field);
2261 long_title = buffer;
2269 std::string block_name;
2270 std::vector<std::string> file_list;
2271 sprintf(buffer,
"%s%0*d_*.txt", inst_name.c_str(), run_number_digits, run_number);
2273 findFiles(logs_path, buffer, file_list);
2274 for(i=0; i<file_list.size(); i++)
2276 j = file_list[i].find_last_of(
"\\");
2277 j = file_list[i].find_first_of(
"_",j);
2278 k = file_list[i].length() - (j + 1) - 4;
2279 block_name = file_list[i].substr(j+1, k);
2280 if (stricmp(block_name.c_str(),
"ICPEVENT") == 0)
2284 else if (strcmp(block_name.c_str(),
"Temp_Sample") == 0)
2286 strcpy(buffer,
"temperature_log_1");
2290 strcpy(buffer, block_name.c_str());
2292 f.
addLog(buffer, file_list[i].c_str(), block_name.c_str(),
2297 time_all.
info(
"updateMuonFile v1", dstatus);
2307 struct tm tm_struct;
2308 if (strlen(isotime) < 19)
2312 n = sscanf(isotime,
"%d-%d-%dT%d:%d:%d",
2313 &tm_struct.tm_year, &tm_struct.tm_mon, &tm_struct.tm_mday,
2314 &tm_struct.tm_hour, &tm_struct.tm_min, &tm_struct.tm_sec);
2318 n = sscanf(isotime,
"%d-%d-%d %d:%d:%d",
2319 &tm_struct.tm_year, &tm_struct.tm_mon, &tm_struct.tm_mday,
2320 &tm_struct.tm_hour, &tm_struct.tm_min, &tm_struct.tm_sec);
2326 tm_struct.tm_year -= 1900;
2327 tm_struct.tm_mon -= 1;
2328 tm_struct.tm_isdst = -1;
2329 return mktime(&tm_struct);
2335 const char* log_name,
const char* log_units, time_t ref_time)
2337 HANDLE h = INVALID_HANDLE_VALUE;
2339 while((ntries >= 0) && (h == INVALID_HANDLE_VALUE))
2341 h = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
2343 if (h == INVALID_HANDLE_VALUE)
2349 if (h == INVALID_HANDLE_VALUE)
2353 DWORD nbuffer = GetFileSize(h, NULL);
2354 if ( nbuffer == INVALID_FILE_SIZE || nbuffer > (100 * 1000000) )
2359 char* buffer =
new char[nbuffer+1];
2366 if (ReadFile(h, buffer, nbuffer, &nread, NULL) == 0)
2373 buffer[nread] =
'\0';
2374 buffer[nbuffer] =
'\0';
2375 std::string s(buffer);
2376 std::istringstream iss(s);
2378 float *times = 0, *values = 0;
2381 while((
void*)iss != 0)
2384 if ((
void*)iss != 0)
2393 times =
new float[n];
2394 values =
new float[n];
2397 iss.seekg(std::ios::beg);
2399 if (s.length() < 20)
2405 ref_time =
unixTime(s.substr(0,19).c_str());
2408 times[n] = difftime(
unixTime(s.substr(0,19).c_str()), ref_time);
2409 values[n] = atof(s.substr(19,1000).c_str());
2411 while((
void*)iss != 0)
2414 if ((
void*)iss != 0)
2416 if (s.length() > 19)
2418 times[n] = difftime(
unixTime(s.substr(0,19).c_str()), ref_time);
2419 values[n] = atof(s.substr(19,1000).c_str());
2430 makeNewGroup(nxname,
"NXlog");
2443 template<
typename T>
2445 const std::vector<float>& time,
const char* time_units, time_t ref_time)
2447 if (values.size() > 0)
2449 makeNewGroup(nxname,
"NXlog");
2462 int n, rank, dims[20], data_type;
2464 if (NXopendata(m_fileid, data_name) == NX_OK)
2466 NXgetinfo(m_fileid, &rank, dims, &data_type);
2467 if (rank == 1 && data_type == NX_CHAR)
2470 char_data =
new char[n + 1];
2471 NXgetdata(m_fileid, char_data);
2472 char_data[n] =
'\0';
2479 NXclosedata(m_fileid);
2490 int rank, dims[20], data_type;
2491 if (NXopendata(m_fileid, data_name) == NX_OK)
2493 NXgetinfo(m_fileid, &rank, dims, &data_type);
2494 if (rank == 1 && data_type == NX_INT32 && dims[0] == 1)
2496 NXgetdata(m_fileid, &value);
2502 NXclosedata(m_fileid);
2513 int rank, dims[20], data_type;
2514 if (NXopendata(m_fileid, data_name) == NX_OK)
2516 NXgetinfo(m_fileid, &rank, dims, &data_type);
2517 if (rank == 1 && data_type == NX_FLOAT32 && dims[0] == 1)
2519 NXgetdata(m_fileid, &value);
2525 NXclosedata(m_fileid);
2538 char entry_name[100], entry_class[100];
2541 NXinitgroupdir(m_fileid);
2542 while(NXgetnextentry(m_fileid, entry_name, entry_class, &data_type) == NX_OK)
2544 if ( groups_only && ((strlen(entry_class) == 0) || !strcmp(entry_class,
"SDS")) )
2550 entries.push_back(entry_name);
2558 return NXopengroup(m_fileid, group_name, (
char*)group_class);
2569 int dummy_dims_array[1] = { 1 };
2570 int* chunk_size =
new int[ndims];
2571 for(
int i=0; i<ndims; i++)
2573 len *= dims_array[i];
2577 delete []chunk_size;
2578 return NXmakedata(m_fileid, data_name, nxtype, ndims, (
int*)dims_array);
2581 for(
int i=0; i<ndims; i++)
2585 chunk_size[ndims-1] = dims_array[ndims-1];
2586 if ((m_compression_type != NX_COMP_NONE) && (chunk_size[ndims-1] >
MIN_COMP_LEN) )
2588 ret = NXcompmakedata(m_fileid, data_name, nxtype, ndims, (
int*)dims_array, m_compression_type, chunk_size);
2592 ret = NXmakedata(m_fileid, data_name, nxtype, ndims, (
int*)dims_array);
2594 delete []chunk_size;
2600 return NXcompmakedata(m_fileid, data_name, nxtype, ndims, (
int*)dims_array, m_compression_type, (
int*)chunk_size);
2603 template int IXNeXusFile::addLog(
const char* nxname,
const std::vector<uint32_t>& values,
const char* value_units,
2604 const std::vector<float>& time,
const char* time_units, time_t ref_time);
int openGroup(const char *group_name, const char *group_class)
static int addSlabList(NXhandle fileid, const char *data_name, const T *value, const int *dims_array, int ndims, int dest_start[], const int *slab_start, const int *slab_size, const std::vector< int > &slab_list, bool convert_null, int compression_type, int spectra_chunk)
void setErrorReporter(nx_error_t error_func, void *error_arg)
const char * ISOtime(time_t time)
int timr_crpt[ISISCRPT_MAX_DETECTOR]
void start(const ISISCRPT_STRUCT *crpt, IXNeXusFile *file, bool create_empty)
int listEntries(std::list< std::string > &entries, bool groups_only=false)
static int writeSlab(NXhandle fileid, const char *data_name, const T *value, const int *dims_array, int ndims, const int *slab_start, const int *slab_size, bool convert_null, int compression_type)
int getPeriodSize() const
int getNumSpectra(bool include_spectrum_zero=false) const
int code[ISISCRPT_MAX_DETECTOR]
int readData(const char *data_name, std::string &value)
int addVa(int facility, int severity, int errtype, const char *format,...)
int udet[ISISCRPT_MAX_DETECTOR]
static int writeAttribute(NXhandle fileid, const char *data_name, const char *attr_name, const T *value, int len, bool convert_null)
std::vector< int > raw_frames
static int readTZero(float &tzero, float &tzero_offset, const char *file)
std::vector< int64_t > total_counts
int monitorNumberToSpectrum(int monitor_number) const
monitor numbers start at 1, indexes in mdet also start at 1 for historical (i.e fortran and old raw f...
std::vector< float > count_rate
float rtcb[ISISCRPT_MAX_NTRG][ISISCRPT_MAX_TIMECHANB]
int open(const char *filename, int mode, int type=IXNeXusFile::HDF5)
int modn[ISISCRPT_MAX_DETECTOR]
SELOGGER_API int __stdcall se_get_run_status(int run_number, time_t ref_time, RUNBLOCK &blocks)
int clone(const IXNeXusFile &orig)
int makeNewGroup(const char *name, const char *nxclass, bool open_group=true)
#define ISISCRPT_MAX_NTRG
uint32_t spectrumCRPTOffsetImpl(int spec, int daq_period) const
static time_t unixTime(const char *isotime)
int makeData(const char *data_name, int nxtype, const int *dims_array, int ndims)
static const char * veto_names[]
these names will be used in the NeXus data file, so no spaces and lowercase only
int writeSlabList(const char *data_name, const unsigned long *value, const int *dims_array, int ndims, const int *slab_start, const int *slab_size, const std::vector< int > &slab_list)
static int writeData(NXhandle fileid, const char *data_name, const T *value, const int *dims_array, int ndims, bool convert_null, int compression_type)
std::map< std::string, SEBLOCK > seblock_map_t
SECURITY_ATTRIBUTES * defaultNoInheritHandles()
int addLog(const char *nxname, const char *filename, const char *log_name, const char *log_units, time_t ref_time)
int mpos[ISISCRPT_MAX_DETECTOR]
std::vector< float > raw_uamps
std::vector< float > good_uamps
char instrument_xml_file[ISISCRPT_MAX_FNAMELEN]
time_t unixTime(const char *isotime)
const char * detector_format
int compression_block_size
static int ISOtime(time_t time, char *buffer, int len)
static int writeSlabList(NXhandle fileid, const char *data_name, const T *value, const int *dims_array, int ndims, const int *slab_start, const int *slab_size, const std::vector< int > &slab_list, bool convert_null, int compression_type, int spectra_chunk)
int makeDataSlab(const char *data_name, const unsigned long *value, const int *dims_array, int ndims)
SELOGGER_API const char *__stdcall se_get_errmsg()
int makeDataChunked(const char *data_name, int nxtype, const int *dims_array, const int *chunk_array, int ndims)
int addMissingMuonLogs(const char *filename, const char *logs_path, const char *new_comment, const char *new_sample_name, DAEstatus &dstatus)
boost::array< int, ISISCRPT_MAX_NTRG > spec_min
range of spectrum numbers in CRPT time regime
float tthe[ISISCRPT_MAX_DETECTOR]
static void nxErrorFunc(void *arg, char *text)
boost::array< VETO, ISISCRPT_NUM_VETOS > vetos
char institute[ISISCRPT_INSTITUTE_NAME_LEN+1]
static const T * nullValue(const T *, int NXTYPE)
std::vector< float > np_ratio
char temperature_label[256]
std::vector< float > time
float delt[ISISCRPT_MAX_DETECTOR]
int writeSlab(const char *data_name, const int *value, const int *dims_array, int ndims, const int *slab_start, const int *slab_size)
#define ISISCRPT_NUM_VETOS
max number of vetos
int dae_type
time CRPT unloaded (may not be set if program crashed)
int writeAttribute(const std::string &data_name, const std::string &attr_name, const std::string &value)
char long_title[ISISCRPT_TITLE_LEN+1]
char measurement_id[ICP_NAME_LEN]
int findFiles(const char *directory, const char *pattern, std::vector< std::string > &list, bool full_path)
static void computeDetectorAverage(const float *det_vals, float *spec_vals, const std::vector< int > *det_lookup, const std::vector< int > &spec_list)
std::vector< int > period
static char * remove_invalid_chars(const char *str, int len)
void setSpectraChunkSize(int nsp)
SELOGGER_API int __stdcall se_get_measurement_label(const char *measurement_id, std::string &res)
static void readExternalFile(const std::string &file_name, std::string &file_contents)
#define LOGSTR_INFORMATION(__arg)
void(* nx_error_t)(void *arg, char *text)
int tcb[ISISCRPT_MAX_NTRG][ISISCRPT_MAX_TIMECHANB]
int enableOptions(Options options)
#define LOGSTR_ERROR(__arg)
int spec[ISISCRPT_MAX_DETECTOR]
char fname[ISISCRPT_MAX_FNAMELEN]
double info(const char *title, std::ostream &os, bool add_nl=true)
bool isMonitorSpectrum(int spec) const
int spectrumGroup(int spec) const
int addWarningVa(int facility, const char *format,...)
int writeMuonFile(const char *filename, const ISISCRPT_STRUCT *crpt, const isisU32_t *raw_data, isisU32_t raw_data_size, const seblock_map_t &blocks, const Poco::Path &inst_settings_dir, const std::string &inst_xml_file, const std::string &inst_parameter_map_file, DAEstatus &dstatus)
boost::array< int, ISISCRPT_MAX_MONITOR > mdet
static int * makeNewRawData(const isisU32_t *raw_data, int nper_daq, int nsp1, int ntc1)
only used by muons and hence OK for it only to work for one TR
const char * detector_base
char isis_cycle[ISISCRPT_MAX_LVXML_SIZE]
int getLink(const char *name, const char *nxclass, NXlink &link)
int writeISISNeXus(const char *filename, bool logs_only, const ISISCRPT_STRUCT *crpt, const isisU32_t *raw_data, isisU32_t raw_data_size, const ISISRAW *iraw, const seblock_map_t &blocks, const std::string &inst_xml_file, const std::string &inst_parameter_map_file, DAEstatus &dstatus, bool update=false)
SELOGGER_API int __stdcall se_get_seci_config(std::string &seci_config)
static int writeSummaryNeXus(const ISISCRPT_STRUCT *crpt, DAEstatus &dstatus)
std::vector< float > dae_beam_current
int spectrumCRPTTR(int spec) const
static int addSlab(NXhandle fileid, const T *value, const int64_t *dims_array, int ndims, const int64_t *slab_start, const int64_t *slab_size, const int64_t *dest_start, int compression_type)
char inst_abrv[ISISCRPT_INST_ABRV_LEN+1]
char icp_version[ICP_NAME_LEN]
std::vector< int > is_waiting
boost::array< PERIOD, ISISCRPT_MAX_PERIOD > period
int crat[ISISCRPT_MAX_DETECTOR]
SELOGGER_API int __stdcall se_get_measurement_first_run(const char *measurement_id, long &run_number)
std::vector< int > is_running
static int addMonitors(IXNeXusFile &ixnf, const ISISCRPT_STRUCT *crpt, const isisU32_t *raw_data, isisU32_t raw_data_size, NXlink *tof_links, NXlink &period_link, bool update, DAEstatus &dstatus)
static int makeDataSlab(NXhandle fileid, const char *data_name, const int *dims_array, int ndims, int compression_type, int spectra_chunk)
IXNeXusFile(nx_error_t error_func=NULL, void *error_arg=NULL)
static int readDeadTimes(float *deadtimes_array, int ndet, const char *file)
char measurement_type[ICP_NAME_LEN]
boost::array< int, ISISCRPT_MAX_NTRG > ntc
number of time channels per CRPT time regime
char user_name[ISISCRPT_USER_NAME_LEN+1]
bool testOptions(Options options)
char inst_name[ISISCRPT_INST_LEN+1]
void setLoggerName(const std::string &logger_name)
char sample_id[ICP_NAME_LEN]
char sample_orientation[256]
int writeData(const char *data_name, const std::vector< T > &value)
int addSlabList(const char *data_name, const unsigned long *value, const int *dims_array, int ndims, int dest_start[], const int *slab_start, const int *slab_size, const std::vector< int > &slab_list)
char measurement_subid[ICP_NAME_LEN]
void enableCompression(int comp_level=NX_COMP_LZW)
int makeLink(const char *name, const char *nxclass, NXlink &link)
int addSlab(const char *data_name, const int *value, const int *dims_array, int ndims, const int *slab_start, const int *slab_size, const int *dest_start)
char instrument_geometry[5]
SELOGGER_API int __stdcall se_wait_for_async()
float len2[ISISCRPT_MAX_DETECTOR]
float ut[ISISCRPT_MAX_USER *ISISCRPT_MAX_DETECTOR]
static int readGrouping(int *grouping, int ndet, const char *file)
int spectrumNTC(int spec) const
int addInfoVa(int facility, const char *format,...)
std::vector< int > run_status
boost::array< int, ISISCRPT_MAX_NTRG > nsp
number of spectra per CRPT time regime
char script_name[ICP_NAME_LEN]
boost::array< int, ISISCRPT_MAX_DETECTOR > det_group
0 = monitor, else logical det number
std::vector< int > good_frames
std::vector< int64_t > monitor1_sum