11 #include "GaudiKernel/FileIncident.h"
20 static const char*
const fmt_oid =
"[OID=%08lX%08lX-%016llX]";
21 static const char*
const fmt_aux =
"[AUX=%08lX]";
25 stringBefore(std::string &
s,
char sc){
27 if (
n!=std::string::npos)
s.resize(
n);
34 const std::string&
name,
44 m_incidentSvc(
"IncidentSvc",
name) {
55 return(StatusCode::FAILURE);
60 return(StatusCode::FAILURE);
62 return(StatusCode::SUCCESS);
74 return(StatusCode::FAILURE);
87 m_file =
new H5::H5File(
"test.h5", H5F_ACC_TRUNC );
90 m_file =
new H5::H5File(
"test.h5", H5F_ACC_RDONLY );
94 return(StatusCode::SUCCESS);
103 StatusCode AthenaHDFStreamTool::putEvent(
long,
const void* , std::size_t,
unsigned int)
const {
105 return(StatusCode::FAILURE);
111 const std::string dh_entry =
"POOLContainer(DataHeader)_entry";
114 FileIncident endFileIncident(
name(),
"EndInputFile",
"HDF:test.h5");
117 return(StatusCode::RECOVERABLE);
121 H5::DataSpace filespace =
dataset.getSpace();
122 const hsize_t mem_size[1] = {2};
123 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
124 H5::DataSpace memspace(1, mem_size);
125 long long unsigned int ds_data[2] = {0, 0};
126 dataset.read(ds_data, H5::PredType::NATIVE_ULLONG, memspace, filespace);
127 std::size_t nbytes = ds_data[1] - ds_data[0];
128 m_token =
"[DB=00000000-0000-0000-0000-000000000000][CNT=POOLContainer(DataHeader)][CLID=4DDBD295-EFCE-472A-9EC8-15CD35A9EB8D][TECH=00000401]";
138 return(StatusCode::SUCCESS);
146 FileIncident beginFileIncident(
name(),
"BeginInputFile",
"HDF:test.h5");
149 return(StatusCode::SUCCESS);
154 if (nbytes == 0 ||
m_token.empty()) {
155 return(StatusCode::SUCCESS);
157 ATH_MSG_INFO(
"AthenaHDFStreamTool::putObject: source = " <<
source <<
", nbytes = " << nbytes);
159 if (
m_token.find(
"[CONT=") != std::string::npos)
m_token.replace(
m_token.find(
"[CONT="), 6,
"[CNT=");
161 stringBefore(ds_name,
']');
162 while (ds_name.find(
"/") != std::string::npos) { ds_name = ds_name.replace(ds_name.find(
"/"), 1,
"_"); }
168 long long unsigned int positionCount = 0;
169 if (
m_token.find(
"[CLID=") == std::string::npos) {
173 sprintf(
text, fmt_aux, nbytes);
177 positionCount =
offset[0];
178 const hsize_t ds_size[1] = {
offset[0] + 15};
180 H5::DataSpace filespace =
dataset.getSpace();
181 const hsize_t mem_size[1] = {15};
182 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
183 H5::DataSpace memspace(1, mem_size);
184 dataset.write(
text, H5::PredType::NATIVE_CHAR, memspace, filespace);
188 if (!
m_group->exists(ds_name)) {
189 const hsize_t maxdim[1] = {H5S_UNLIMITED};
190 const hsize_t ds_size[1] = {nbytes};
191 H5::DataSpace filespace(1, ds_size, maxdim);
192 H5::DSetCreatPropList ds_prop;
193 hsize_t chunkdim[1] = {nbytes};
198 }
else if (nbytes < 16 * 512) {
199 chunkdim[0] = 4 * 4096;
201 chunkdim[0] = (
int(nbytes / 4096) + 1) * 4096;
204 ds_prop.setChunk(1, chunkdim);
205 char fill_val[1] = {0};
206 ds_prop.setFillValue(H5::PredType::NATIVE_CHAR, fill_val);
207 H5::DataSet
dataset =
m_group->createDataSet(ds_name, H5::PredType::NATIVE_CHAR, filespace, ds_prop);
212 positionCount =
offset[0];
213 const hsize_t ds_size[1] = {
offset[0] + nbytes};
215 H5::DataSpace filespace =
dataset.getSpace();
216 const hsize_t mem_size[1] = {nbytes};
217 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
218 H5::DataSpace memspace(1, mem_size);
219 dataset.write(
source, H5::PredType::NATIVE_CHAR, memspace, filespace);
221 if (
m_token.find(
"[OID=") == std::string::npos) {
223 sprintf(
text, fmt_oid, 0
ul, nbytes, positionCount);
228 std::size_t firstU, firstL;
229 long long unsigned int second;
230 ::sscanf(
m_token.substr(
m_token.find(
"[OID="), 40).c_str(), fmt_oid, &firstU, &firstL, &
second);
234 firstL = positionCount + nbytes -
second;
235 sprintf(
text, fmt_oid, firstU, firstL,
second);
240 std::string entry_name = ds_name.substr(ds_name.find(
'(') + 1);
241 stringBefore(entry_name,
')');
243 if (entry_name ==
"DataHeader" || entry_name ==
"DataHeaderForm") {
244 auto dh_entry = ds_name +
"_entry";
245 if (!
m_group->exists(dh_entry)) {
246 const hsize_t maxdim[1] = {H5S_UNLIMITED};
247 const hsize_t ds_size[1] = {2};
248 H5::DataSpace filespace(1, ds_size, maxdim);
249 H5::DSetCreatPropList ds_prop;
250 const hsize_t chunkdim[1] = {512};
251 ds_prop.setChunk(1, chunkdim);
252 char fill_val[1] = {0};
253 ds_prop.setFillValue(H5::PredType::NATIVE_ULLONG, fill_val);
254 H5::DataSet
dataset =
m_group->createDataSet(dh_entry, H5::PredType::NATIVE_ULLONG, filespace, ds_prop);
255 long long unsigned int ds_data[2] = {positionCount, positionCount + nbytes};
256 dataset.write(ds_data, H5::PredType::NATIVE_ULLONG);
260 const hsize_t ds_size[1] = {
offset[0] + 1};
262 H5::DataSpace filespace =
dataset.getSpace();
263 const hsize_t mem_size[1] = {1};
264 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
265 H5::DataSpace memspace(1, mem_size);
266 long long unsigned int ds_data[1] = {positionCount + nbytes};
267 dataset.write(ds_data, H5::PredType::NATIVE_ULLONG, memspace, filespace);
269 if (entry_name ==
"DataHeader") {
270 auto dh_form_entry = ds_name +
"_form_entry";
271 if (!
m_group->exists(dh_form_entry)) {
272 const hsize_t maxdim[1] = {H5S_UNLIMITED};
273 const hsize_t ds_size[1] = {1};
274 H5::DataSpace filespace(1, ds_size, maxdim);
275 H5::DSetCreatPropList ds_prop;
276 const hsize_t chunkdim[1] = {512};
277 ds_prop.setChunk(1, chunkdim);
278 char fill_val[1] = {0};
279 ds_prop.setFillValue(H5::PredType::NATIVE_ULLONG, fill_val);
280 H5::DataSet
dataset =
m_group->createDataSet(dh_form_entry, H5::PredType::NATIVE_ULLONG, filespace, ds_prop);
281 long long unsigned int ds_data[1] = {0};
282 dataset.write(ds_data, H5::PredType::NATIVE_ULLONG);
286 const hsize_t ds_size[1] = {
offset[0] + 1};
288 H5::DataSpace filespace =
dataset.getSpace();
289 const hsize_t mem_size[1] = {1};
290 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
291 H5::DataSpace memspace(1, mem_size);
292 auto dh_form_entry_name = ds_name.substr(0, ds_name.find(
'(')) +
"Form(DataHeaderForm)_entry";
293 H5::DataSet dh_form_dataset =
m_group->openDataSet(dh_form_entry_name);
294 long long unsigned int ds_data[1] = {dh_form_dataset.getInMemDataSize()/8 - 1};
295 dataset.write(ds_data, H5::PredType::NATIVE_ULLONG, memspace, filespace);
298 if (entry_name ==
"DataHeaderForm") {
299 auto dh_entry_name = ds_name.substr(0, ds_name.find(
'(') - 4) +
"(DataHeader)_form_entry";
301 const hsize_t
offset[1] = {
dataset.getInMemDataSize()/8 - 1};
302 H5::DataSpace filespace =
dataset.getSpace();
303 const hsize_t mem_size[1] = {1};
304 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
305 H5::DataSpace memspace(1, mem_size);
306 H5::DataSet dh_form_dataset =
m_group->openDataSet(ds_name +
"_entry");
307 long long unsigned int ds_data[1] = {dh_form_dataset.getInMemDataSize()/8 - 1};
308 dataset.write(ds_data, H5::PredType::NATIVE_ULLONG, memspace, filespace);
311 return(StatusCode::SUCCESS);
317 return(StatusCode::SUCCESS);
321 std::string clid_name =
m_token.substr(
m_token.find(
"[CLID=") + 6);
322 stringBefore(clid_name,
']');
324 stringBefore(ds_name,
']');
325 if (ds_name.empty()) {
326 return(StatusCode::SUCCESS);
328 while (ds_name.find(
'/') != std::string::npos) { ds_name = ds_name.replace(ds_name.find(
'/'), 1,
"_"); }
331 auto n = oid_name.find(
']') + 1;
333 std::size_t firstU, firstL;
334 long long unsigned int second;
335 ::sscanf(oid_name.c_str(), fmt_oid, &firstU, &firstL, &
second);
337 std::size_t aux_size = 0;
347 return(StatusCode::SUCCESS);
349 return(StatusCode::FAILURE);
352 std::string entry_name = ds_name.substr(ds_name.find(
'(') + 1);
353 stringBefore(entry_name,
')');
355 if (entry_name ==
"DataHeader") {
356 if (clid_name ==
"7BE56CEF-C866-4BEE-9348-A5F34B5F1DAD") {
357 ds_name.replace(ds_name.find(
"(DataHeader)"), 12,
"Form(DataHeaderForm)");
359 }
else if (clid_name ==
"00000000-0000-0000-0000-000000000000") {
363 m_token.replace(
m_token.find(
"[CLID="), 43,
"[CLID=4DDBD295-EFCE-472A-9EC8-15CD35A9EB8D]");
368 return(StatusCode::SUCCESS);
373 auto dh_entry = ds_name +
"_entry";
376 return(StatusCode::FAILURE);
379 H5::DataSpace filespace =
dataset.getSpace();
380 const hsize_t mem_size[1] = {2};
381 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
382 H5::DataSpace memspace(1, mem_size);
383 long long unsigned int ds_data[2] = {0, 0};
384 dataset.read(ds_data, H5::PredType::NATIVE_ULLONG, memspace, filespace);
385 firstL = ds_data[1] - ds_data[0];
389 if (!
m_group->exists(ds_name)) {
390 return(StatusCode::FAILURE);
394 return(StatusCode::FAILURE);
397 H5::DataSpace filespace =
dataset.getSpace();
398 const hsize_t mem_size[1] = {firstL};
399 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
400 H5::DataSpace memspace(1, mem_size);
406 ::sscanf(
m_read_data + firstL - 15, fmt_aux, &nbytes);
411 return(StatusCode::SUCCESS);
416 std::size_t firstU, firstL;
417 long long unsigned int second;
418 ::sscanf(
m_token.substr(
m_token.find(
"[OID="), 40).c_str(), fmt_oid, &firstU, &firstL, &
second);
420 stringBefore(ds_name,
']');
421 while (ds_name.find(
'/') != std::string::npos) { ds_name = ds_name.replace(ds_name.find(
'/'), 1,
"_"); }
423 if (firstU > 0 || ds_name.substr(ds_name.length() - 5, 4) ==
"Aux.") {
424 if (firstU == 0) firstU = firstL;
426 sprintf(
text, fmt_aux, firstU);
430 const hsize_t ds_size[1] = {
offset[0] + 15};
432 H5::DataSpace filespace =
dataset.getSpace();
433 const hsize_t mem_size[1] = {15};
434 filespace.selectHyperslab(H5S_SELECT_SET, mem_size,
offset);
435 H5::DataSpace memspace(1, mem_size);
436 dataset.write(
text, H5::PredType::NATIVE_CHAR, memspace, filespace);
439 sprintf(
text, fmt_oid, firstU, firstL,
second);
444 std::string entry_name = ds_name.substr(ds_name.find(
'(') + 1);
445 stringBefore(entry_name,
')');
446 if (entry_name ==
"DataHeaderForm") {
449 *tokenString =
m_token.c_str();
450 return(StatusCode::SUCCESS);
459 return(StatusCode::SUCCESS);