33 #define off_t n_uint64_t
35 static const off_t block_size = 64;
40 void FieldIO_LIME::load_lfn(LimeReader *reader)
42 off_t nbytes = limeReaderBytes(reader);
46 off_t nbytes_alloc = (nbytes + 1) + (block_size - ((nbytes + 1) % block_size));
48 char *buf = (
char *)malloc(nbytes_alloc);
56 int status = limeReaderReadData(buf, &nbytes, reader);
57 if (status != LIME_SUCCESS) {
73 void FieldIO_LIME::load_data(LimeReader *reader,
Field *v)
77 off_t nbytes = limeReaderBytes(reader);
79 vout.
detailed(
m_vl,
"ildg-binary-data: limeReaderBytes: %lu bytes to read.\n", nbytes);
82 char *buf = (
char *)malloc(nbytes);
88 int status = limeReaderReadData(buf, &nbytes, reader);
89 if (status != LIME_SUCCESS) {
96 byte_swap(buf, word_size, nbytes / word_size);
103 if ((nin_file == 0) || (nex_file == 0)) {
108 const int nvol = v->
nvol();
110 double *p = (
double *)buf;
112 for (
int j = 0; j < nex_file; ++j) {
113 for (
int isite = 0; isite < nvol; ++isite) {
114 for (
int i = 0; i < nin_file; ++i) {
117 v->
set(s, isite, t, *p++);
127 void FieldIO_LIME::process_file(
Field *v,
const std::string filename)
129 FILE *fp = fopen(filename.c_str(),
"r");
136 LimeReader *reader = limeCreateReader(fp);
142 #if USE_ILDG_METADATA
143 ILDG_Format::Params params;
148 int status = limeReaderNextRecord(reader);
149 if (status != LIME_SUCCESS)
break;
151 const char *t = limeReaderType(reader);
153 if (strcmp(t,
"ildg-format") == 0) {
154 #if USE_ILDG_METADATA
155 load_metadata(reader, ¶ms);
156 check_metadata(¶ms);
158 }
else if (strcmp(t,
"ildg-binary-data") == 0) {
159 load_data(reader, v);
160 }
else if (strcmp(t,
"ildg-data-lfn") == 0) {
167 limeDestroyReader(reader);
176 const int nin_field = v.
nin();
177 const int nex_field = v.
nex();
184 vout.
detailed(
m_vl,
"reading gauge configuration from %s", filename.c_str());
186 vtmp.
reset(nin_field, Lvol, nex_field);
188 process_file(&vtmp, filename);
198 void FieldIO_LIME::store_data(LimeWriter *writer,
Field *v,
199 bool mark_begin,
bool mark_end)
205 off_t nbytes =
sizeof(double) * v->
size();
207 LimeRecordHeader *h = limeCreateHeader(
210 const_cast<char *
>(
"ildg-binary-data"), nbytes);
211 limeWriteRecordHeader(h, writer);
212 limeDestroyHeader(h);
214 char *buf = (
char *)malloc(nbytes);
221 const int nin_field = v->
nin();
222 const int nex_field = v->
nex();
227 if ((nin_file == 0) || (nex_file == 0)) {
228 nin_file = nin_field;
229 nex_file = nex_field;
235 double *p = (
double *)buf;
237 for (
int j = 0; j < nex_file; ++j) {
238 for (long_t isite = 0; isite < Lvol; ++isite) {
239 for (
int i = 0; i < nin_file; ++i) {
242 *p++ = v->
cmp(s, isite, t);
250 byte_swap(buf,
sizeof(
double), v->
size());
254 limeWriteRecordData(buf, &nbytes, writer);
263 void FieldIO_LIME::store_lfn(LimeWriter *writer,
const std::string lfn_string)
265 off_t nbytes = lfn_string.size();
267 LimeRecordHeader *h = limeCreateHeader(1 , 1 ,
const_cast<char *
>(
"ildg-data-lfn"), nbytes);
269 limeWriteRecordHeader(h, writer);
270 limeDestroyHeader(h);
273 limeWriteRecordData(
const_cast<char *
>(lfn_string.c_str()), &nbytes, writer);
282 const int nin_field = v.
nin();
283 const int nex_field = v.
nex();
288 if ((nin_file == 0) || (nex_file == 0)) {
289 nin_file = nin_field;
290 nex_file = nex_field;
297 vtmp.
reset(nin_field, Lvol, nex_field);
307 vout.
detailed(
m_vl,
"writing gauge configuration to %s\n", filename.c_str());
309 FILE *fp = fopen(filename.c_str(),
"w");
315 LimeWriter *writer = limeCreateWriter(fp);
324 store_data(writer, &vtmp,
true,
true);
329 limeDestroyWriter(writer);
345 vout.
crucial(
"FieldIO_LIME::read_file unsupported.\n");
352 vout.
crucial(
"FieldIO_LIME::write_file unsupported.\n");