40 LOGF(info,
"Translate: %s -> %s",
src,
dst.fileName());
44 std::filesystem::path(
src).extension());
45 auto dstExtension = std::filesystem::path(
48 if (!
dst.fileName().empty()) {
49 dstExtension = std::filesystem::path(
dst.fileName()).extension();
54 std::chrono::time_point currentTime = std::chrono::high_resolution_clock::now();
55 std::chrono::time_point endTime = std::chrono::high_resolution_clock::now();
57 srcSerializer->fromFile(vEvent,
src);
58 endTime = std::chrono::high_resolution_clock::now();
61 vEvent = vEvent.
limit(limit);
64 currentTime = std::chrono::high_resolution_clock::now();
65 dstSerializer->toFile(vEvent,
dst);
66 endTime = std::chrono::high_resolution_clock::now();
75 const std::string dstFolder = dstFolderLocation.
fileName();
76 std::vector<std::string> supported = {
".json",
".root",
".eve"};
77 auto ext1 = srcFolder.substr(srcFolder.rfind(
'.'));
78 auto ext2 = dstFolder.substr(dstFolder.rfind(
'.'));
80 if (supported.end() == std::find(supported.begin(), supported.end(), ext1)) {
81 LOGF(error,
"source folder should end with source extension: /path-to-folder/.ext1 ");
84 if (supported.end() == std::find(supported.begin(), supported.end(), ext2)) {
85 LOGF(error,
"destination folder should end with destination extension: /path-to-folder/.ext2 ");
88 auto src = srcFolder.substr(0, srcFolder.size() - std::string(ext1).size());
89 auto dst = dstFolder.substr(0, dstFolder.size() - std::string(ext2).size());
92 LOGF(error,
"source folder same as destination folder ");
95 if (!std::filesystem::is_directory(
src)) {
96 LOGF(error,
"source folder do not exist ");
99 if (!std::filesystem::is_directory(
dst)) {
100 LOGF(error,
"destination folder do not exist ");
103 std::vector<std::string> vExt1 = {ext1};
105 std::vector<std::string> vExt2 = {ext2};
109 for (
auto& e : destinationList) {
110 auto match = e.substr(0, e.size() - ext2.size()) + ext1;
111 if (sourceList.end() == std::find(sourceList.begin(), sourceList.end(),
match)) {
112 auto path = std::filesystem::path(
dst +
"" + e);
113 std::filesystem::remove(
path);
118 for (
auto& e : sourceList) {
119 auto match = e.substr(0, e.size() - ext1.size()) + ext2;
120 if (destinationList.end() == std::find(destinationList.begin(), destinationList.end(),
match)) {
123 .port = dstFolderLocation.
port(),
124 .host = dstFolderLocation.
hostName()});
147 struct sigaction sigIntHandler {
150 sigemptyset(&sigIntHandler.sa_mask);
151 sigIntHandler.sa_flags = 0;
153 sigaction(SIGINT, &sigIntHandler,
nullptr);
154 LOGF(info,
"Welcome in O2 event conversion tool");
163 po::options_description desc(
"Allowed options");
164 desc.add_options()(
"help,h",
"produce help message")(
"port", po::value(&port)->default_value(-1),
"port number")(
"host", po::value(&host)->default_value(
"localhost"),
"host name")(
"sources", po::value(&
sources),
"sources")(
"limit,l", po::value(&limit)->default_value(-1),
"limit number of elements")(
"folder,f", po::bool_switch(&folderMode)->default_value(
false),
"convert folders")(
"continuous,c", po::bool_switch(&continuousMode)->default_value(
false),
"continuous folder mode");
166 po::positional_options_description p;
169 po::variables_map vm;
170 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
173 if (vm.count(
"help")) {
174 cout << desc <<
"\n";
178 if (vm.count(
"sources")) {
179 if (vm[
"sources"].as<vector<string>>().
size() != 2) {
180 cout <<
"two positional parameters expected" <<
"\n";
186 locationParams.
port = port;
187 locationParams.
host = host;
193 }
else if (continuousMode) {
195 std::this_thread::sleep_for(2000ms);
204 catch (exception& e) {
205 cerr <<
"error: " << e.what() <<
"\n";
208 cerr <<
"Exception of unknown type!\n";