forked from ecmwf/fdb
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ecmwf#24 from ecmwf/feature/archive-callback
Feature/archive callback
- Loading branch information
Showing
15 changed files
with
147 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* (C) Copyright 1996- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* In applying this licence, ECMWF does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an intergovernmental organisation nor | ||
* does it submit to any jurisdiction. | ||
*/ | ||
|
||
/* | ||
* This software was developed as part of the EC H2020 funded project NextGenIO | ||
* (Project ID: 671951) www.nextgenio.eu | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "fdb5/database/Key.h" | ||
#include "fdb5/database/FieldLocation.h" | ||
|
||
namespace fdb5 { | ||
|
||
using ArchiveCallback = std::function<void(const Key&, const FieldLocation&)>; | ||
|
||
static const ArchiveCallback CALLBACK_NOOP = [](const Key&, const FieldLocation&) {}; | ||
|
||
} // namespace fdb5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ list( APPEND api_tests | |
select | ||
dist | ||
fdb_c | ||
archive_callback | ||
) | ||
|
||
foreach( _test ${api_tests} ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "eckit/testing/Test.h" | ||
#include "fdb5/api/FDB.h" | ||
|
||
namespace fdb5::test { | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
CASE("Archive callback") { | ||
FDB fdb; | ||
|
||
std::string data_str = "Raining cats and dogs"; | ||
const void* data = static_cast<const void *>(data_str.c_str()); | ||
size_t length = data_str.size(); | ||
|
||
Key key; | ||
key.set("class","od"); | ||
key.set("expver","xxxx"); | ||
key.set("type","fc"); | ||
key.set("stream","oper"); | ||
key.set("date","20101010"); | ||
key.set("time","0000"); | ||
key.set("domain","g"); | ||
key.set("levtype","sfc"); | ||
key.set("param","130"); | ||
|
||
std::map<fdb5::Key, eckit::URI> map; | ||
std::vector<Key> keys; | ||
|
||
fdb.registerCallback([&map] (const fdb5::Key& key, const fdb5::FieldLocation& location) { | ||
map[key] = location.fullUri(); | ||
}); | ||
|
||
key.set("step","1"); | ||
keys.push_back(key); | ||
fdb.archive(key, data, length); | ||
|
||
key.set("date","20111213"); | ||
keys.push_back(key); | ||
fdb.archive(key, data, length); | ||
|
||
key.set("type","pf"); | ||
keys.push_back(key); | ||
fdb.archive(key, data, length); | ||
|
||
fdb.flush(); | ||
|
||
EXPECT(map.size() == 3); | ||
|
||
// for (const auto& [key, uri] : map) { | ||
// std::cout << key << " -> " << uri << std::endl; | ||
// } | ||
|
||
for (const auto& [key, uri] : map) { | ||
bool found = false; | ||
for (const auto& originalKey : keys) { | ||
if (key == originalKey){ | ||
found = true; | ||
break; | ||
} | ||
} | ||
EXPECT(found); | ||
} | ||
|
||
} | ||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
} // namespace fdb5::test | ||
|
||
int main(int argc, char** argv) { | ||
|
||
eckit::Log::info() << ::getenv("FDB_HOME") << std::endl; | ||
|
||
return ::eckit::testing::run_tests(argc, argv); | ||
} |