LCOV - code coverage report
Current view: top level - otsdaq/tools - otsdaq_save_json_document.cc (source / functions) Coverage Total Hit
Test: mu2edaq.info.cleaned Lines: 0.0 % 44 0
Test Date: 2026-07-30 01:56:44 Functions: 0.0 % 2 0

            Line data    Source code
       1              : #include "otsdaq/MessageFacility/MessageFacility.h"
       2              : 
       3              : #include <dirent.h>
       4              : #include <cassert>
       5              : #include <iostream>
       6              : #include <memory>
       7              : #include <string>
       8              : 
       9              : #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
      10              : #include "otsdaq/ConfigurationInterface/ConfigurationManagerRW.h"
      11              : // #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h"
      12              : // #include "artdaq-database/JsonDocument/JSONDocument.h"
      13              : 
      14              : // Shared test utilities
      15              : #include "otsdaq/Macros/TestUtilities.h"
      16              : 
      17              : /// usage:
      18              : /// otsdaq_save_json_document <path_to_source_JSON> <document_name_to_save>
      19              : ///
      20              : ///
      21              : #define TRACE_NAME "SaveJSON_Document"
      22              : 
      23              : // #define __FILENAME__                 (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
      24              : // #define __MF_SUBJECT__               __FILENAME__
      25              : // #define __MF_DECOR__         (__MF_SUBJECT__)
      26              : // #define __SHORTFILE__                (__builtin_strstr(&__FILE__[0], "/srcs/") ? __builtin_strstr(&__FILE__[0], "/srcs/") + 6 : __FILE__)
      27              : // #define __COUT_HDR_L__               "[" << std::dec        << __LINE__ << "]\t"
      28              : // #define __COUT_HDR_FL__      __SHORTFILE__ << " "   << __COUT_HDR_L__
      29              : // #define __COUT_ERR__                 TLOG(TLVL_ERROR)
      30              : // #define __COUT_INFO__                TLOG(TLVL_INFO)
      31              : #undef __COUT__
      32              : #define __COUT__        \
      33              :         std::cout           \
      34              :             << __MF_DECOR__ \
      35              :             << __COUT_HDR_FL__  //TLOG(TLVL_DEBUG) //std::cout << __MF_DECOR__ << __COUT_HDR_FL__
      36              : 
      37              : using namespace ots;
      38              : 
      39            0 : void SaveJSON_Document(int argc, char* argv[])
      40              : {
      41            0 :         __COUT__ << "=================================================\n";
      42            0 :         __COUT__ << "=================================================\n";
      43            0 :         __COUT__ << "=================================================\n";
      44            0 :         __COUT__ << "\nSaving Trigger Document!" << std::endl;
      45              : 
      46            0 :         __COUT__
      47            0 :             << "\n\nusage: Two arguments:\n\t <path_to_source_JSON> <document_name_to_save>"
      48            0 :             << std::endl
      49            0 :             << std::endl;
      50              : 
      51            0 :         __COUT__ << "argc = " << argc << std::endl;
      52            0 :         for(int i = 0; i < argc; i++)
      53            0 :                 __COUT__ << "argv[" << i << "] = " << argv[i] << std::endl;
      54              : 
      55            0 :         if(argc != 3)
      56              :         {
      57            0 :                 __COUT__ << "Error! Must provide 2 parameters.\n\n" << std::endl;
      58            0 :                 return;
      59              :         }
      60              : 
      61              :         //==============================================================================
      62              :         // Define environment variables
      63              :         //      Note: normally these environment variables are set by ots script
      64              : 
      65            0 :         test::util::check_and_make_envs();
      66              : 
      67              :         ////////////////////////////////////////////////////
      68              : 
      69              :         //==============================================================================
      70              :         // get prepared with initial source db
      71              : 
      72              :         // ConfigurationManager instance immediately loads active groups
      73            0 :         __COUT__ << "Saving document..." << std::endl;
      74            0 :         ConfigurationManagerRW  cfgMgrInst("doc_admin");
      75            0 :         ConfigurationManagerRW* cfgMgr = &cfgMgrInst;
      76              : 
      77            0 :         std::FILE* fp = std::fopen(argv[1], "rb");
      78            0 :         if(!fp)
      79              :         {
      80            0 :                 __COUT__ << "\n\nERROR! Could not open file at " << argv[1]
      81            0 :                          << ". Error: " << errno << " - " << strerror(errno) << __E__;
      82            0 :                 return;
      83              :         }
      84            0 :         std::string json;
      85            0 :         std::fseek(fp, 0, SEEK_END);
      86            0 :         json.resize(std::ftell(fp));
      87            0 :         std::rewind(fp);
      88            0 :         std::fread(&json[0], 1, json.size(), fp);
      89            0 :         std::fclose(fp);
      90              : 
      91            0 :         std::string artad_db_uri = __ENV__("ARTDAQ_DATABASE_URI");
      92            0 :         __COUT__ << artad_db_uri << __E__;
      93            0 :         if(!artad_db_uri.size())
      94              :         {
      95            0 :                 __COUT__ << "ERROR! ARTDAQ_DATABASE_URI not set." << __E__;
      96            0 :                 return;
      97              :         }
      98            0 :         ConfigurationInterface* theInterface_ = cfgMgr->getConfigurationInterface();
      99              :         std::pair<std::string, TableVersion> savedDoc =
     100            0 :             theInterface_->saveCustomJSON(json, argv[2]);
     101            0 :         __COUT__ << "Done with JSON doc save as '" << savedDoc.first << "-v"
     102            0 :                  << savedDoc.second << "'" << __E__;
     103            0 :         return;
     104            0 : }  //end SaveJSON_Document()
     105              : 
     106            0 : int main(int argc, char* argv[])
     107              : {
     108            0 :         SaveJSON_Document(argc, argv);
     109            0 :         return 0;
     110              : }
     111              : // BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1