From 761872388ef655fe255ff1f95962c9ed5ad6009b Mon Sep 17 00:00:00 2001
From: Mikhail Mineev <Mikhail.Mineev@cern.ch>
Date: Fri, 26 Jul 2024 16:51:19 +0200
Subject: [PATCH] corrected error in TagMetaDto

---
 doc/crest_example_fs.cxx     | 53 +++++++++++---------------
 doc/crest_example_server.cxx | 74 ++++++++++++++++++++++++++++++++++++
 src/CrestModel.cxx           |  2 +-
 test/CrestApiFs_test.cxx     | 38 +++++++++---------
 test/CrestApi_test.cxx       | 40 +++++++++----------
 5 files changed, 137 insertions(+), 70 deletions(-)

diff --git a/doc/crest_example_fs.cxx b/doc/crest_example_fs.cxx
index 57ac252..c3ff3d3 100644
--- a/doc/crest_example_fs.cxx
+++ b/doc/crest_example_fs.cxx
@@ -145,50 +145,42 @@ void testFindTag_FS(const std::string &tagname)
 // Tag Meta Info Method Tests for file storage
 //===================================================
 
-void testCreateTagMeta_FS(const std::string &tagname)
-{
+void testCreateTagMeta_FS(const std::string &tagname) {
   std::cout << std::endl
             << "test: createTagMeta FS" << std::endl;
 
+  // CrestClient myCrestClient = CrestClient(SURL,false);
   CrestFsClient myCrestClient = CrestFsClient(true, "/tmp/crest");
 
-  nlohmann::json channel = {{"0", "ATLAS_PREFERRED"}};
-
-  std::cout << std::endl
-            << "channel = " << std::endl
-            << channel.dump(4) << std::endl;
+  /*
+  {"chansize":6,\"colsize\":3,"description":"{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}","tagInfo":"{\"channel_list\" : [{\"583008256\":\"\"},{\"583073792\":\"\"},{\"583139328\":\"\"},{\"583204864\":\"\"},{\"583270400\":\"\"},{\"583335936\":\"\"}],\"node_description\":\"<timeStamp>time</timeStamp><addrHeader><address_header service_type=\\"71\\" clid=\\"1238547719\\"/></addrHeader><typeName>CondAttrListCollection</typeName>\",\"payload_spec\":\"ModuleId:UInt32,ErrorCode:UInt32,json:Blob64k\"}","tagName":"JfexModuleSettings-RUN3-MCDEFAULT-TEST"}
+  */
 
-  nlohmann::json chanList = nlohmann::json::array({channel});
+  PayloadSpecDto spec;
+  spec.add("ModuleId","UInt32");
+  spec.add("ErrorCode","UInt32");
+  spec.add("json","Blob64k");
 
-  nlohmann::json tagInfo =
-      {
-          {"channel_list", chanList},
-          {"node_description", "description of the node"},
-          {"payload_spec", "stave:Int32, eta:Int32, mag:Float, base:Float, free:Float"}};
+  std::string description = "<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>";
+  TagInfoDto taginfo(description);
+  taginfo.setPayloadSpec(spec);
 
-  std::cout << std::endl
-            << "TagInfo = " << std::endl
-            << tagInfo.dump(4) << std::endl;
+  ChannelSetDto chanset;
+  chanset.add("583008256","");
+  chanset.add("583204864","");
 
-  std::cout << std::endl
-            << "TagInfo = " << std::endl
-            << tagInfo.dump() << std::endl;
+  taginfo.setChannel(chanset);
 
-  nlohmann::json js =
-      {
-          {"tagName", tagname},
-          {"description", "none"},
-          {"chansize", 1},
-          {"colsize", 6},
-          {"tagInfo", tagInfo.dump()},
-          {"insertionTime", "2020-12-04"}};
+  std::string tag_description = "{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}";
+  TagMetaDto metainfo(tagname,tag_description,taginfo);
 
-  TagMetaDto dto = TagMetaDto();
-  dto = dto.from_json(js);
+  nlohmann::json metainfo_js = metainfo.to_json();
+  
+  std::cout << "tag meta info = " << std::endl << metainfo_js.dump(4) << std::endl; 
 
   try
   {
-    myCrestClient.createTagMeta(dto);
+    myCrestClient.createTagMeta(metainfo);
     std::cout << std::endl
               << "test: createTagMeta FS (success)" << std::endl;
   }
@@ -200,6 +192,7 @@ void testCreateTagMeta_FS(const std::string &tagname)
   }
 }
 
+
 void testFindTagMeta_FS(const std::string &tagname)
 {
   std::cout << std::endl
diff --git a/doc/crest_example_server.cxx b/doc/crest_example_server.cxx
index 6594602..0ecd132 100644
--- a/doc/crest_example_server.cxx
+++ b/doc/crest_example_server.cxx
@@ -439,6 +439,80 @@ void testGetSize(const std::string& tagname) {
   }
 }
 
+//===================================================
+// Tag Meta Info Method Tests 
+//===================================================
+
+void testCreateTagMeta(const std::string &tagname) {
+  std::cout << std::endl
+            << "test: createTagMeta" << std::endl;
+
+  CrestClient myCrestClient = CrestClient(SURL,false);
+
+  /*
+  {"chansize":6,\"colsize\":3,"description":"{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}","tagInfo":"{\"channel_list\" : [{\"583008256\":\"\"},{\"583073792\":\"\"},{\"583139328\":\"\"},{\"583204864\":\"\"},{\"583270400\":\"\"},{\"583335936\":\"\"}],\"node_description\":\"<timeStamp>time</timeStamp><addrHeader><address_header service_type=\\"71\\" clid=\\"1238547719\\"/></addrHeader><typeName>CondAttrListCollection</typeName>\",\"payload_spec\":\"ModuleId:UInt32,ErrorCode:UInt32,json:Blob64k\"}","tagName":"JfexModuleSettings-RUN3-MCDEFAULT-TEST"}
+  */
+
+  PayloadSpecDto spec;
+  spec.add("ModuleId","UInt32");
+  spec.add("ErrorCode","UInt32");
+  spec.add("json","Blob64k");
+
+  std::string description = "<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>";
+  TagInfoDto taginfo(description);
+  taginfo.setPayloadSpec(spec);
+
+  ChannelSetDto chanset;
+  chanset.add("583008256","");
+  chanset.add("583204864","");
+
+  taginfo.setChannel(chanset);
+
+  std::string tag_description = "{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}";
+  TagMetaDto metainfo(tagname,tag_description,taginfo);
+
+  nlohmann::json metainfo_js = metainfo.to_json();
+  
+  std::cout << "tag meta info = " << std::endl << metainfo_js.dump(4) << std::endl; 
+
+  try
+  {
+    myCrestClient.createTagMeta(metainfo);
+    std::cout << std::endl
+              << "test: createTagMeta (success)" << std::endl;
+  }
+  catch (const std::exception &e)
+  {
+    std::cout << std::endl
+              << "test: createTagMeta (failed)" << std::endl;
+    std::cerr << e.what() << std::endl;
+  }
+}
+
+
+void testFindTagMeta(const std::string &tagname)
+{
+  std::cout << std::endl
+            << "test: findTagMeta " << std::endl;
+
+  CrestClient myCrestClient = CrestClient(SURL,false);
+
+  try
+  {
+    TagMetaDto dto = myCrestClient.findTagMeta(tagname);
+    std::cout << std::endl
+              << "test: findTagMeta (result) =" << std::endl
+              << dto.to_json().dump(4) << std::endl;
+  }
+  catch (const std::exception &e)
+  {
+    std::cout << std::endl
+              << "test: findTagMeta (failed)" << std::endl;
+    std::cerr << e.what() << std::endl;
+  }
+}
+
+
 int main(int argc, char* argv[]) {
   if (argc == 2) {
     SURL = argv[1];
diff --git a/src/CrestModel.cxx b/src/CrestModel.cxx
index bc30a3b..05e30d8 100644
--- a/src/CrestModel.cxx
+++ b/src/CrestModel.cxx
@@ -404,7 +404,7 @@
        tagMeta["description"]=description;
        tagMeta["chansize"]=tagInfo.getChannelSize();
        tagMeta["colsize"]=tagInfo.getColumnSize();
-       tagMeta["tagInfo"]=tagInfo.to_json();
+       tagMeta["tagInfo"]=tagInfo.to_json().dump();
        if(insertionTime.has_value())
          tagMeta["insertionTime"]=insertionTime.value();
        return tagMeta;
diff --git a/test/CrestApiFs_test.cxx b/test/CrestApiFs_test.cxx
index 9ef76f7..423b2a4 100644
--- a/test/CrestApiFs_test.cxx
+++ b/test/CrestApiFs_test.cxx
@@ -103,33 +103,33 @@ BOOST_AUTO_TEST_SUITE(CrestApiFsTest)
     BOOST_TEST(res);
   }
 
+
   BOOST_AUTO_TEST_CASE(tag_meta_test){
 
     std::cout << std::endl << "2) Tag meta info test" << std::endl;   
 
-    nlohmann::json channel = {{"0", "ATLAS_PREFERRED"}};
-    nlohmann::json chanList = nlohmann::json::array({channel});
+    /*
+    {"chansize":6,\"colsize\":3,"description":"{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}","tagInfo":"{\"channel_list\" : [{\"583008256\":\"\"},{\"583073792\":\"\"},{\"583139328\":\"\"},{\"583204864\":\"\"},{\"583270400\":\"\"},{\"583335936\":\"\"}],\"node_description\":\"<timeStamp>time</timeStamp><addrHeader><address_header service_type=\\"71\\" clid=\\"1238547719\\"/></addrHeader><typeName>CondAttrListCollection</typeName>\",\"payload_spec\":\"ModuleId:UInt32,ErrorCode:UInt32,json:Blob64k\"}","tagName":"JfexModuleSettings-RUN3-MCDEFAULT-TEST"}
+    */
 
-    nlohmann::json tagInfo =
-      {
-          {"channel_list", chanList},
-          {"node_description", "description of the node"},
-          {"payload_spec", "stave:Int32, eta:Int32, mag:Float, base:Float, free:Float"}};
+    PayloadSpecDto spec;
+    spec.add("ModuleId","UInt32");
+    spec.add("ErrorCode","UInt32");
+    spec.add("json","Blob64k");
 
-    nlohmann::json js =
-      {
-          {"tagName", tagname},
-          {"description", "none"},
-          {"chansize", 1},
-          {"colsize", 6},
-          {"tagInfo", tagInfo.dump()},
-          {"insertionTime", "2020-12-04"}};
+    std::string description = "<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>";
+    TagInfoDto taginfo(description);
+    taginfo.setPayloadSpec(spec);
 
-    std::cout << "tag meta (" << tagname << ") =" << std::endl
-              << js.dump(4) << std::endl;
+    ChannelSetDto chanset;
+    chanset.add("583008256","");
+    chanset.add("583204864","");
 
-    TagMetaDto dto = TagMetaDto();
-    dto = dto.from_json(js);
+    taginfo.setChannel(chanset);
+
+    std::string tag_description = "{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}";
+    TagMetaDto dto(tagname,tag_description,taginfo);
+    nlohmann::json js = dto.to_json();
 
     try
     {
diff --git a/test/CrestApi_test.cxx b/test/CrestApi_test.cxx
index 8254124..fa7bd51 100644
--- a/test/CrestApi_test.cxx
+++ b/test/CrestApi_test.cxx
@@ -100,34 +100,33 @@ BOOST_AUTO_TEST_SUITE(CrestApiTest)
     BOOST_TEST(res);
   }
 
+
   BOOST_AUTO_TEST_CASE(tag_meta_test){
 
     std::cout << std::endl << "2) Tag meta info test" << std::endl;   
 
-    nlohmann::json channel = {{"0", "ATLAS_PREFERRED"}};
-    nlohmann::json chanList = nlohmann::json::array({channel});
+    /*
+    {"chansize":6,\"colsize\":3,"description":"{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}","tagInfo":"{\"channel_list\" : [{\"583008256\":\"\"},{\"583073792\":\"\"},{\"583139328\":\"\"},{\"583204864\":\"\"},{\"583270400\":\"\"},{\"583335936\":\"\"}],\"node_description\":\"<timeStamp>time</timeStamp><addrHeader><address_header service_type=\\"71\\" clid=\\"1238547719\\"/></addrHeader><typeName>CondAttrListCollection</typeName>\",\"payload_spec\":\"ModuleId:UInt32,ErrorCode:UInt32,json:Blob64k\"}","tagName":"JfexModuleSettings-RUN3-MCDEFAULT-TEST"}
+    */
 
-    nlohmann::json tagInfo =
-      {
-          {"channel_list", chanList},
-          {"node_description", "description of the node"},
-          {"payload_spec", "stave:Int32, eta:Int32, mag:Float, base:Float, free:Float"}};
+    PayloadSpecDto spec;
+    spec.add("ModuleId","UInt32");
+    spec.add("ErrorCode","UInt32");
+    spec.add("json","Blob64k");
 
-    nlohmann::json js =
-      {
-          {"tagName", tagname},
-          {"description", "none"},
-          {"chansize", 1},
-          {"colsize", 6},
-          {"tagInfo", tagInfo.dump()},
-          {"insertionTime", "2018-12-06T11:18:35.641+0000"}
-      };
+    std::string description = "<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>";
+    TagInfoDto taginfo(description);
+    taginfo.setPayloadSpec(spec);
 
-    std::cout << "tag meta (" << tagname << ") =" << std::endl
-              << js.dump(4) << std::endl;
+    ChannelSetDto chanset;
+    chanset.add("583008256","");
+    chanset.add("583204864","");
 
-    TagMetaDto dto = TagMetaDto();
-    dto = dto.from_json(js);
+    taginfo.setChannel(chanset);
+
+    std::string tag_description = "{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}";
+    TagMetaDto dto(tagname,tag_description,taginfo);
+    nlohmann::json js = dto.to_json();
 
     try
     {
@@ -178,6 +177,7 @@ BOOST_AUTO_TEST_SUITE(CrestApiTest)
     BOOST_TEST(res);
   }
 
+
   BOOST_AUTO_TEST_CASE(global_tag_test){
 
     std::cout << std::endl << "3) Global Tag test" << std::endl;    
-- 
GitLab