1 #include "otsdaq/MessageFacility/MessageFacility.h"
9 #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
10 #include "otsdaq/ConfigurationInterface/ConfigurationManagerRW.h"
18 #define TRACE_NAME "SaveJSON_Document"
36 void SaveJSON_Document(
int argc,
char* argv[])
39 if(getenv(
"SERVICE_DATA_PATH") == NULL)
40 setenv(
"SERVICE_DATA_PATH",
41 (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData").c_str(),
44 __COUT__ <<
"=================================================\n";
45 __COUT__ <<
"=================================================\n";
46 __COUT__ <<
"=================================================\n";
47 __COUT__ <<
"\nSaving Trigger Document!" << std::endl;
50 <<
"\n\nusage: Two arguments:\n\t <path_to_source_JSON> <document_name_to_save>"
54 __COUT__ <<
"argc = " << argc << std::endl;
55 for(
int i = 0; i < argc; i++)
56 __COUT__ <<
"argv[" << i <<
"] = " << argv[i] << std::endl;
60 __COUT__ <<
"Error! Must provide 2 parameters.\n\n" << std::endl;
92 __COUT__ <<
"Saving document..." << std::endl;
96 std::FILE* fp = std::fopen(argv[1],
"rb");
99 __COUT__ <<
"\n\nERROR! Could not open file at " << argv[1]
100 <<
". Error: " << errno <<
" - " << strerror(errno) << __E__;
104 std::fseek(fp, 0, SEEK_END);
105 json.resize(std::ftell(fp));
107 std::fread(&json[0], 1, json.size(), fp);
110 std::string artad_db_uri = __ENV__(
"ARTDAQ_DATABASE_URI");
111 __COUT__ << artad_db_uri << __E__;
112 if(!artad_db_uri.size())
114 __COUT__ <<
"ERROR! ARTDAQ_DATABASE_URI not set." << __E__;
118 std::pair<std::string, TableVersion> savedDoc =
119 theInterface_->saveCustomJSON(json, argv[2]);
120 __COUT__ <<
"Done with JSON doc save as '" << savedDoc.first <<
"-v"
121 << savedDoc.second <<
"'" << __E__;
125 int main(
int argc,
char* argv[])
127 if(getenv(
"OTSDAQ_LOG_FHICL") == NULL)
128 setenv(
"OTSDAQ_LOG_FHICL",
129 (std::string(__ENV__(
"USER_DATA")) +
130 "/MessageFacilityConfigurations/MessageFacilityWithCout.fcl")
134 if(getenv(
"OTSDAQ_LOG_ROOT") == NULL)
136 "OTSDAQ_LOG_ROOT", (std::string(__ENV__(
"USER_DATA")) +
"/Logs").c_str(), 1);
139 SaveJSON_Document(argc, argv);