9 #include <framework/logging/Logger.h>
10 #include <framework/core/FileCatalog.h>
11 #include <framework/dataobjects/FileMetaData.h>
17 #include <boost/program_options.hpp>
24 namespace prog = boost::program_options;
26 int main(
int argc,
char* argv[])
30 std::vector<std::string> dataDescriptions;
32 prog::options_description options(
"Options");
34 (
"help,h",
"print all available options")
35 (
"file", prog::value<string>(&fileName),
"file name")
36 (
"lfn,l", prog::value<string>(&lfn),
"logical file name")
37 (
"description,d", prog::value<std::vector<std::string>>(&dataDescriptions),
38 "data description to set of the form key=value. If the argument does not contain an equal sign it's interpeted as a key to delete from the dataDescriptions")
41 prog::positional_options_description posOptDesc;
42 posOptDesc.add(
"file", -1);
44 prog::variables_map varMap;
45 prog::store(prog::command_line_parser(argc, argv).
46 options(options).positional(posOptDesc).run(), varMap);
50 if (varMap.count(
"help")) {
51 cout <<
"Usage: " << argv[0] <<
" [OPTIONS] [FILE]\n";
52 cout <<
"Add/edit LFN in given file or modify the data description stored in the file, also update file catalog.\n\n";
53 cout << options << endl;
58 if (!varMap.count(
"file")) {
59 B2ERROR(
"The filename is missing.");
62 if (!varMap.count(
"lfn") && !varMap.count(
"description")) {
63 B2ERROR(
"Neither lfn nor data descriptions to be modified, nothing to do");
68 gErrorIgnoreLevel = kError;
69 TFile* file = TFile::Open(fileName.c_str(),
"UPDATE");
70 if (!file || !file->IsOpen()) {
71 B2ERROR(
"Failed to open the file " << fileName);
77 auto* tree =
dynamic_cast<TTree*
>(file->Get(
"persistent"));
78 TTree* newTree =
nullptr;
80 fileMetaData =
dynamic_cast<FileMetaData*
>(file->Get(
"FileMetaData"));
82 B2WARNING(
"Failed to get persistent tree in the file " << fileName);
83 tree =
new TTree(
"persistent",
"persistent");
85 tree->Branch(
"FileMetaData", &fileMetaData);
89 tree->SetBranchAddress(
"FileMetaData", &fileMetaData);
90 newTree = tree->CloneTree(0);
95 B2ERROR(
"Failed to load FileMetaData from file " << fileName);
100 const std::string oldLFN = fileMetaData->
getLfn();
103 if (varMap.count(
"lfn")) fileMetaData->
setLfn(lfn);
104 if (!dataDescriptions.empty()) {
105 for (
const auto& keyvalue : dataDescriptions) {
106 size_t pos = keyvalue.find(
'=');
107 if (pos == std::string::npos) {
111 const std::string key = keyvalue.substr(0, pos);
112 const std::string value = keyvalue.substr(pos + 1);
119 newTree->Write(newTree->GetName(), TObject::kWriteDelete);
121 fileMetaData->Write(
"FileMetaData");
128 std::string oldPFN = oldLFN;
130 if (FileCatalog::Instance().getMetaData(oldPFN, localMetaData)) {
131 localMetaData = *fileMetaData;
132 FileCatalog::Instance().registerFile(fileName, localMetaData, oldLFN);
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.