From 0a14f02489fb25cc11131bc63006fd264952156e Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 12:10:36 +0100
Subject: [PATCH 01/15] Add mappings example

---
 examples/crest-manage-tag-gtag.py | 99 +++++++++++++++++++++++++++++++
 examples/crest-store-lar.py       |  5 +-
 examples/crest-store-tile.py      |  5 +-
 pycrest/api/tag_info_container.py | 17 +++++-
 4 files changed, 119 insertions(+), 7 deletions(-)
 create mode 100644 examples/crest-manage-tag-gtag.py

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
new file mode 100644
index 0000000..90bb1b2
--- /dev/null
+++ b/examples/crest-manage-tag-gtag.py
@@ -0,0 +1,99 @@
+from pycrest.api.crest_api import CrestApi
+from pycrest.api.crest_cond_container import CrestCondContainer
+from pycrest.api.tag_info_container import TagInfoContainer
+from hep.crest.client.model.iov_set_dto import IovSetDto
+from hep.crest.client.model.tag_dto import TagDto
+from hep.crest.client.model.tag_meta_dto import TagMetaDto
+import json
+# Author: Andrea Formica (CERN)
+# Example for Global Tag Coordination.
+#
+# In this snippet we will create some tags with the tag info as a system expert would do.
+# Then we will create a global tag and associate the tags to it.
+# We can easily LOCK and UNLOCK the global tag, but for the moment this has no effect (the CREST server does not support it).
+# We are going to implement the LOCK and UNLOCK features in the CREST server later on.
+
+# create an instance of the API class
+api_instance = CrestApi(host='http://crest.cern.ch/api-v4.0')
+
+# Define tags and metadata
+meta_info = {
+    'Test-LARBadChannelsOflBadChannels-RUN3-00': {
+        'description': 'A Test LAR CREST tag',
+        'time_type': 'time',
+        'tag_info_builder': TagInfoContainer(payload_spec='AnInt:UInt32,ABlob:Blob64k', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>', folder='/LAR/BadChannelsOfl/BadChannels', schema='COOLOFL_LAR')
+    },
+    'Test-TileOfl02CalibCes-RUN3-00': {
+        'description': 'A Test Tile CREST tag',
+        'time_type': 'time',
+        'tag_info_builder': TagInfoContainer(payload_spec='TileCalibBlob:Blob64k', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>', folder='/TILE/OFL02/CALIB/CES', schema='COOLOFL_TILE')
+    },
+    'Test-MuonAlignMDTBarrel-RUN3-00': {
+        'description': 'A Test Muon CREST tag',
+        'time_type': 'time',
+        'tag_info_builder': TagInfoContainer(payload_spec='filedata:String4k,file:String4k,tech:Int32', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>', folder='/MUON/ALIGN/MDT/BARREL', schema='COOLOFL_MUONALIGN')
+    }
+}
+
+def delete_tag(tag_name):
+    # Clean up the existing tag
+    # Remove the tag
+    print('Delete tag %s if exists' % tag_name)
+    try:
+        tag = api_instance.get_tag(name=tag_name)
+        if tag is not None and isinstance(tag, TagDto):
+            tagname = tag.name
+            description = tag.description
+            print(f'Found tag {tagname} - {description} for name {tag_name}: removing it...')
+            api_response = api_instance.remove_tag(name=tagname)
+    except Exception as e:
+        print("Exception when calling CrestApi: %s\n" % e)
+
+def create_crest_tag(tag_name, description, time_type, tag_info_builder):
+    try:
+        # Create a new tag
+        api_response = api_instance.create_tag(name=tag_name, timeType=time_type, description=description)
+        if isinstance(api_response, TagDto):
+            print(f'Created tag {api_response.name}')
+        else:
+            print(f'Error creating tag {tag_name}: {api_response}')
+        # Add tag info
+        ti = tag_info_builder.dump_tag_info()
+        channel_size = tag_info_builder.get_channels_size()
+        column_size = tag_info_builder.get_columns_size()
+        description = tag_info_builder.get_tag_info_description()
+        print(f'Creating tag meta info for {tag_name} with specs: {ti} and channels: {channel_size} and columns: {column_size}')
+        api_response = api_instance.create_tag_meta(name=tag_name, tag_info=ti, chansize=channel_size, colsize=column_size, description=description)
+        if isinstance(api_response, TagMetaDto):
+            print(f'Created tag meta info for {api_response.tag_name}')
+            tag_info = api_response.tag_info
+            dic_info = json.loads(tag_info) 
+            print(f'Tag info has specs: {dic_info["payload_spec"]} and channels: {dic_info["channel_list"]}')
+        else:
+            print(f'Error creating tag meta info for {tag_name}: {api_response}')
+    except Exception as e:
+        print("Exception when calling CrestApi : %s\n" % e)
+
+# Loop over the tags
+for tag, info in meta_info.items():
+    delete_tag(tag)
+    create_crest_tag(tag, info['description'], info['time_type'], info['tag_info_builder'])
+
+# Create a global tag
+global_tag_name = 'Test-GlobalTag-RUN3-00'
+print(f'Create global tag {global_tag_name}')
+try:
+    api_response = api_instance.create_global_tag(name=global_tag_name, description='A Test Global Tag')
+    print(api_response)
+
+    # Associate the tags to the global tag
+    for tag, info in meta_info.items():
+        print(f'Create mapping for tag {tag} to global tag {global_tag_name}')
+        record = 'test_record'
+        label = info['tag_info_builder'].get_folder()
+        api_response = api_instance.create_global_tag_map(globaltagname=global_tag_name, tagname=tag, record=record, label=label)
+    # Query the global tag and mappings
+    api_response = api_instance.find_global_tag_map(name=global_tag_name)
+    print(f'List global tag mappings {api_response}')
+except Exception as e:
+    print("Exception when calling CrestApi to create global tag and mappings: %s\n" % e)
diff --git a/examples/crest-store-lar.py b/examples/crest-store-lar.py
index b9fe419..b82ea86 100644
--- a/examples/crest-store-lar.py
+++ b/examples/crest-store-lar.py
@@ -30,7 +30,7 @@ description = 'A Test LAR CREST tag'
 time_type = 'time'
 # Tag meta information
 destfolder='/LAR/BadChannelsOfl/BadChannels'
-tag_info_builder = TagInfoContainer(payload_spec='ChannelSize:UInt32,StatusWordSize:UInt32,Endianness:UInt32,Version:UInt32,Blob:Blob64k', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>')
+tag_info_builder = TagInfoContainer(payload_spec='ChannelSize:UInt32,StatusWordSize:UInt32,Endianness:UInt32,Version:UInt32,Blob:Blob64k', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>', folder=destfolder, schema='COOLOFL_LAR')
 tag_info_builder.add_channel(channel_id='0', channel_name='LAR-Bad-00')
 tag_info_builder.add_channel(channel_id='1', channel_name='LAR-Bad-01')
 tag_info_builder.add_channel(channel_id='2', channel_name='LAR-Bad-02')
@@ -93,8 +93,9 @@ try:
     ti = tag_info_builder.dump_tag_info()
     channel_size = tag_info_builder.get_channels_size()
     column_size = tag_info_builder.get_columns_size()
+    description = tag_info_builder.get_tag_info_description()
     print(f'Creating tag meta info for {desttag} with specs: {ti} and channels: {channel_size} and columns: {column_size}')
-    api_response = api_instance.create_tag_meta(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size)
+    api_response = api_instance.create_tag_meta(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size, description=description)
     if isinstance(api_response, TagMetaDto):
         print(f'Created tag meta info for {api_response.tag_name}')
         tag_info = api_response.tag_info
diff --git a/examples/crest-store-tile.py b/examples/crest-store-tile.py
index 9d75773..6e42ebc 100644
--- a/examples/crest-store-tile.py
+++ b/examples/crest-store-tile.py
@@ -32,7 +32,7 @@ description = 'A Test Tile CREST tag'
 time_type = 'time'
 # Tag meta information
 destfolder='/TILE/OFL02/CALIB/CES'
-tag_info_builder = TagInfoContainer(payload_spec='TileCalibBlob:Blob64k', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>')
+tag_info_builder = TagInfoContainer(payload_spec='TileCalibBlob:Blob64k', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>', folder=destfolder, schema='COOLOFL_TILE')
 for chan in range(0, 50):
     tag_info_builder.add_channel(channel_id=str(chan), channel_name=f'TileCalib-0{chan}')
 
@@ -79,8 +79,9 @@ try:
     ti = tag_info_builder.dump_tag_info()
     channel_size = tag_info_builder.get_channels_size()
     column_size = tag_info_builder.get_columns_size()
+    description = tag_info_builder.get_tag_info_description()
     print(f'Creating tag meta info for {desttag} with specs: {ti} and channels: {channel_size} and columns: {column_size}')
-    api_response = api_instance.create_tag_meta(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size)
+    api_response = api_instance.create_tag_meta(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size, description=description)
     if isinstance(api_response, TagMetaDto):
         print(f'Created tag meta info for {api_response.tag_name}')
         tag_info = api_response.tag_info
diff --git a/pycrest/api/tag_info_container.py b/pycrest/api/tag_info_container.py
index f17f27f..cc7d27e 100644
--- a/pycrest/api/tag_info_container.py
+++ b/pycrest/api/tag_info_container.py
@@ -8,12 +8,16 @@ import json
 class TagInfoContainer():
     _payload_spec = ''
     _channel_list = [] 
+    _folder = ''
+    _schema = ''
     _node_description = ''
 
-    def __init__(self, payload_spec, node_description):
+    def __init__(self, payload_spec, node_description, _folder, _schema):
         self._payload_spec = payload_spec
         self._node_description = node_description
-        print(f'Payload spec: {self._payload_spec} and node description: {self._node_description}')
+        self._folder = _folder
+        self._schema = _schema
+        print(f'Payload spec: {self._payload_spec}, node description: {self._node_description}, folder: {self._folder}, schema: {self._schema}')
 
     def add_channel(self, channel_id='0', channel_name='none'):
        self._channel_list.append({channel_id: channel_name})
@@ -21,7 +25,11 @@ class TagInfoContainer():
     def get_tag_info(self):
         output = { 'payload_spec': self._payload_spec, 'channel_list': self._channel_list, 'node_description': self._node_description }
         return output
-    
+
+    def get_tag_info_description(self):
+        output = { 'schema': self._schema, 'node_fullpath': self._folder }
+        return output
+
     def get_payload_spec(self):
         return self._payload_spec
     
@@ -34,6 +42,9 @@ class TagInfoContainer():
     def dump_tag_info(self):
         return json.dumps(self.get_tag_info())
     
+    def dump_tag_info_description(self):
+        return json.dumps(self.get_tag_info_description())
+    
     def get_channels_size(self):
         return len(self._channel_list)
     
-- 
GitLab


From c4ca515c41cdb40a54ddb7d054cc428bf318007e Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 12:22:17 +0100
Subject: [PATCH 02/15] Delete the mappings and the gtag

---
 examples/crest-manage-tag-gtag.py | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 90bb1b2..9160d11 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -1,16 +1,15 @@
 from pycrest.api.crest_api import CrestApi
-from pycrest.api.crest_cond_container import CrestCondContainer
 from pycrest.api.tag_info_container import TagInfoContainer
-from hep.crest.client.model.iov_set_dto import IovSetDto
 from hep.crest.client.model.tag_dto import TagDto
 from hep.crest.client.model.tag_meta_dto import TagMetaDto
+from hep.crest.client.model.global_tag_dto import GlobalTagDto
+
 import json
 # Author: Andrea Formica (CERN)
 # Example for Global Tag Coordination.
 #
 # In this snippet we will create some tags with the tag info as a system expert would do.
 # Then we will create a global tag and associate the tags to it.
-# We can easily LOCK and UNLOCK the global tag, but for the moment this has no effect (the CREST server does not support it).
 # We are going to implement the LOCK and UNLOCK features in the CREST server later on.
 
 # create an instance of the API class
@@ -79,8 +78,31 @@ for tag, info in meta_info.items():
     delete_tag(tag)
     create_crest_tag(tag, info['description'], info['time_type'], info['tag_info_builder'])
 
+
 # Create a global tag
 global_tag_name = 'Test-GlobalTag-RUN3-00'
+
+# Delete the global tag and the mappings
+print(f'Delete global tag {global_tag_name} if exists')
+try:
+    gtag = api_instance.get_global_tag(name=global_tag_name)
+    if gtag is not None and isinstance(gtag, GlobalTagDto):
+
+        print(f'Found global tag {gtag.name}, remove it together with all mappings...')
+        api_response = api_instance.find_global_tag_map(name=gtag.name)
+        mappings = api_response.resources
+        for mapping in mappings:
+            print(f'Remove mapping {mapping}')
+            api_response = api_instance.delete_global_tag_map(globaltagname=gtag.name, tagname=mapping.tag_name, label=mapping.label)
+        print(f'Remove global tag {gtag.name}')
+        api_response = api_instance.remove_global_tag(name=gtag.name)
+except Exception as e:
+    print("Exception when calling CrestApi: %s\n" % e)
+
+for tag, info in meta_info.items():
+    delete_tag(tag)
+    create_crest_tag(tag, info['description'], info['time_type'], info['tag_info_builder'])
+
 print(f'Create global tag {global_tag_name}')
 try:
     api_response = api_instance.create_global_tag(name=global_tag_name, description='A Test Global Tag')
-- 
GitLab


From 62f31ae5419662aa84fed0f1a68e3443878204b9 Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 12:24:26 +0100
Subject: [PATCH 03/15] clean up

---
 pycrest/api/tag_info_container.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pycrest/api/tag_info_container.py b/pycrest/api/tag_info_container.py
index cc7d27e..e441362 100644
--- a/pycrest/api/tag_info_container.py
+++ b/pycrest/api/tag_info_container.py
@@ -12,11 +12,11 @@ class TagInfoContainer():
     _schema = ''
     _node_description = ''
 
-    def __init__(self, payload_spec, node_description, _folder, _schema):
+    def __init__(self, payload_spec, node_description, folder, schema):
         self._payload_spec = payload_spec
         self._node_description = node_description
-        self._folder = _folder
-        self._schema = _schema
+        self._folder = folder
+        self._schema = schema
         print(f'Payload spec: {self._payload_spec}, node description: {self._node_description}, folder: {self._folder}, schema: {self._schema}')
 
     def add_channel(self, channel_id='0', channel_name='none'):
-- 
GitLab


From d43102a55fe59f8e63a8001cc65c6f02ae6784b4 Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 12:25:20 +0100
Subject: [PATCH 04/15] clean up

---
 pycrest/api/tag_info_container.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pycrest/api/tag_info_container.py b/pycrest/api/tag_info_container.py
index e441362..056b6a8 100644
--- a/pycrest/api/tag_info_container.py
+++ b/pycrest/api/tag_info_container.py
@@ -50,4 +50,7 @@ class TagInfoContainer():
     
     def get_columns_size(self):
         return len(self._payload_spec.split(','))
+    
+    def get_folder(self):
+        return self._folder
     
\ No newline at end of file
-- 
GitLab


From af289a8fb37df998b891f3a4b99a08d4d7c99de8 Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 12:32:24 +0100
Subject: [PATCH 05/15] clean up

---
 examples/crest-manage-tag-gtag.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 9160d11..722f314 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -45,6 +45,7 @@ def delete_tag(tag_name):
             description = tag.description
             print(f'Found tag {tagname} - {description} for name {tag_name}: removing it...')
             api_response = api_instance.remove_tag(name=tagname)
+            print(f'Response: {api_response}')
     except Exception as e:
         print("Exception when calling CrestApi: %s\n" % e)
 
@@ -62,7 +63,7 @@ def create_crest_tag(tag_name, description, time_type, tag_info_builder):
         column_size = tag_info_builder.get_columns_size()
         description = tag_info_builder.get_tag_info_description()
         print(f'Creating tag meta info for {tag_name} with specs: {ti} and channels: {channel_size} and columns: {column_size}')
-        api_response = api_instance.create_tag_meta(name=tag_name, tag_info=ti, chansize=channel_size, colsize=column_size, description=description)
+        api_response = api_instance.create_tag_meta(name=tag_name, tag_info=ti, chansize=channel_size, colsize=column_size, description=json.dumps(description))
         if isinstance(api_response, TagMetaDto):
             print(f'Created tag meta info for {api_response.tag_name}')
             tag_info = api_response.tag_info
-- 
GitLab


From e2d2993a145694dbb29166f02915d602670f0e4d Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 14:06:47 +0100
Subject: [PATCH 06/15] clean up

---
 examples/crest-manage-tag-gtag.py | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 722f314..16961de 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -74,11 +74,6 @@ def create_crest_tag(tag_name, description, time_type, tag_info_builder):
     except Exception as e:
         print("Exception when calling CrestApi : %s\n" % e)
 
-# Loop over the tags
-for tag, info in meta_info.items():
-    delete_tag(tag)
-    create_crest_tag(tag, info['description'], info['time_type'], info['tag_info_builder'])
-
 
 # Create a global tag
 global_tag_name = 'Test-GlobalTag-RUN3-00'
@@ -100,6 +95,7 @@ try:
 except Exception as e:
     print("Exception when calling CrestApi: %s\n" % e)
 
+# Delete the tags and create them again
 for tag, info in meta_info.items():
     delete_tag(tag)
     create_crest_tag(tag, info['description'], info['time_type'], info['tag_info_builder'])
-- 
GitLab


From 2616fd78f479fd6ceabe5b740799a85d9f943679 Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 14:09:46 +0100
Subject: [PATCH 07/15] clean up

---
 pycrest/api/crest_api.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/pycrest/api/crest_api.py b/pycrest/api/crest_api.py
index 5eb87c1..c58e5ec 100644
--- a/pycrest/api/crest_api.py
+++ b/pycrest/api/crest_api.py
@@ -403,6 +403,21 @@ class CrestApi():
             print("Exception when calling TagsApi->list_tags in get_tag: %s\n" % e)
             return HTTPResponse(status_code=e.status, reason=e.reason, code=e.status, message=e.body)
 
+    def get_global_tag(self, name='none'):
+        """
+        Get global tag
+        """
+        api_instance = globaltags_api.GlobaltagsApi(self._api_client)
+        try:
+            api_response = api_instance.find_global_tag(name=name)
+            if api_response['size'] == 1:
+                return api_response['resources'][0]
+            else:
+                return None
+        except ApiException as e:
+            print("Exception when calling GlobaltagsApi->list_global_tags in get_global_tag: %s\n" % e)
+            return HTTPResponse(status_code=e.status, reason=e.reason, code=e.status, message=e.body)
+
 
     def get_size(self, tagname):
         """
-- 
GitLab


From 877f48e134a8bbda46fdac4fd6421bb62f4a92e2 Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 14:12:00 +0100
Subject: [PATCH 08/15] clean up

---
 examples/crest-manage-tag-gtag.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 16961de..3a09f01 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -83,13 +83,12 @@ print(f'Delete global tag {global_tag_name} if exists')
 try:
     gtag = api_instance.get_global_tag(name=global_tag_name)
     if gtag is not None and isinstance(gtag, GlobalTagDto):
-
         print(f'Found global tag {gtag.name}, remove it together with all mappings...')
         api_response = api_instance.find_global_tag_map(name=gtag.name)
         mappings = api_response.resources
         for mapping in mappings:
             print(f'Remove mapping {mapping}')
-            api_response = api_instance.delete_global_tag_map(globaltagname=gtag.name, tagname=mapping.tag_name, label=mapping.label)
+            api_response = api_instance.delete_global_tag_map(globaltagname=gtag.globalTagName, tagname=mapping.tagName, label=mapping.label)
         print(f'Remove global tag {gtag.name}')
         api_response = api_instance.remove_global_tag(name=gtag.name)
 except Exception as e:
-- 
GitLab


From db57892ff32ea5f3ed18eb4b6984e5460f88f78b Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 14:15:02 +0100
Subject: [PATCH 09/15] clean up

---
 examples/crest-manage-tag-gtag.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 3a09f01..4fbb905 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -3,6 +3,7 @@ from pycrest.api.tag_info_container import TagInfoContainer
 from hep.crest.client.model.tag_dto import TagDto
 from hep.crest.client.model.tag_meta_dto import TagMetaDto
 from hep.crest.client.model.global_tag_dto import GlobalTagDto
+from hep.crest.client.model.global_tag_map_dto import GlobalTagMapDto
 
 import json
 # Author: Andrea Formica (CERN)
@@ -87,8 +88,9 @@ try:
         api_response = api_instance.find_global_tag_map(name=gtag.name)
         mappings = api_response.resources
         for mapping in mappings:
-            print(f'Remove mapping {mapping}')
-            api_response = api_instance.delete_global_tag_map(globaltagname=gtag.globalTagName, tagname=mapping.tagName, label=mapping.label)
+            if isinstance(mapping, GlobalTagMapDto):
+                print(f'Remove mapping {mapping}')
+                api_response = api_instance.delete_global_tag_map(globaltagname=gtag.name, tagname=mapping.tag_name, label=mapping.label)
         print(f'Remove global tag {gtag.name}')
         api_response = api_instance.remove_global_tag(name=gtag.name)
 except Exception as e:
-- 
GitLab


From 3d36c9f87f16b236848da5c524c2baeec02073d3 Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 14:18:56 +0100
Subject: [PATCH 10/15] clean up

---
 examples/crest-manage-tag-gtag.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 4fbb905..9c69dbc 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -88,6 +88,7 @@ try:
         api_response = api_instance.find_global_tag_map(name=gtag.name)
         mappings = api_response.resources
         for mapping in mappings:
+            print(f'Found mapping {mapping}')
             if isinstance(mapping, GlobalTagMapDto):
                 print(f'Remove mapping {mapping}')
                 api_response = api_instance.delete_global_tag_map(globaltagname=gtag.name, tagname=mapping.tag_name, label=mapping.label)
-- 
GitLab


From 822ae7e97990d9eaa730aa0dfb1a32c2b631f3b3 Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 14:20:10 +0100
Subject: [PATCH 11/15] clean up

---
 examples/crest-manage-tag-gtag.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 9c69dbc..2457078 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -43,8 +43,7 @@ def delete_tag(tag_name):
         tag = api_instance.get_tag(name=tag_name)
         if tag is not None and isinstance(tag, TagDto):
             tagname = tag.name
-            description = tag.description
-            print(f'Found tag {tagname} - {description} for name {tag_name}: removing it...')
+            print(f'Found tag {tag} : removing it...')
             api_response = api_instance.remove_tag(name=tagname)
             print(f'Response: {api_response}')
     except Exception as e:
-- 
GitLab


From 3210c787b9d40c29296e6cbbedc2cf132d033aaa Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 14:37:49 +0100
Subject: [PATCH 12/15] clean up

---
 examples/crest-manage-tag-gtag.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 2457078..f9346e1 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -4,6 +4,7 @@ from hep.crest.client.model.tag_dto import TagDto
 from hep.crest.client.model.tag_meta_dto import TagMetaDto
 from hep.crest.client.model.global_tag_dto import GlobalTagDto
 from hep.crest.client.model.global_tag_map_dto import GlobalTagMapDto
+from hep.crest.client.model.global_tag_map_set_dto import GlobalTagMapSetDto
 
 import json
 # Author: Andrea Formica (CERN)
@@ -115,5 +116,8 @@ try:
     # Query the global tag and mappings
     api_response = api_instance.find_global_tag_map(name=global_tag_name)
     print(f'List global tag mappings {api_response}')
+    if isinstance(api_response, GlobalTagMapSetDto):
+        mappings = (GlobalTagMapSetDto)(api_response)
+        print(f'Found mappings {mappings}')
 except Exception as e:
     print("Exception when calling CrestApi to create global tag and mappings: %s\n" % e)
-- 
GitLab


From d46c3fb4c234983ded4e92b959c1529f25eb4ace Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 15:13:58 +0100
Subject: [PATCH 13/15] clean up

---
 examples/crest-manage-tag-gtag.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index f9346e1..649e679 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -15,7 +15,7 @@ import json
 # We are going to implement the LOCK and UNLOCK features in the CREST server later on.
 
 # create an instance of the API class
-api_instance = CrestApi(host='http://crest.cern.ch/api-v4.0')
+api_instance = CrestApi(host='http://crest-underrtow.web.cern.ch/api-v4.0')
 
 # Define tags and metadata
 meta_info = {
-- 
GitLab


From 055284d424f6113c89ac2604ec2485aa34133b16 Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 15:14:49 +0100
Subject: [PATCH 14/15] clean up

---
 examples/crest-manage-tag-gtag.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/crest-manage-tag-gtag.py b/examples/crest-manage-tag-gtag.py
index 649e679..d449762 100644
--- a/examples/crest-manage-tag-gtag.py
+++ b/examples/crest-manage-tag-gtag.py
@@ -15,7 +15,7 @@ import json
 # We are going to implement the LOCK and UNLOCK features in the CREST server later on.
 
 # create an instance of the API class
-api_instance = CrestApi(host='http://crest-underrtow.web.cern.ch/api-v4.0')
+api_instance = CrestApi(host='http://crest-undertow-api.web.cern.ch/api-v4.0')
 
 # Define tags and metadata
 meta_info = {
-- 
GitLab


From c84e3a49dd813a1d75f83075558baf9d1e56b1df Mon Sep 17 00:00:00 2001
From: formica <andrea.formica@cern.ch>
Date: Mon, 5 Feb 2024 15:24:13 +0100
Subject: [PATCH 15/15] clean up

---
 README.md          | 11 +++++++----
 examples/README.md | 14 +++++++++++++-
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index cea3a31..db38b46 100644
--- a/README.md
+++ b/README.md
@@ -93,11 +93,14 @@ $HOME/.local/bin/pycrest get iovList -n test_MvG5
 In the `examples` sub directory you can find scripts showing the usage of the `CrestApi` module from an existing application in python. 
 Just run the example to verify that all the installation is ok.
 ```shell
-python ./examples/create_tag_store_data.py
+python ./examples/crest-store.py
 ```
-This script will create a fake temporary tag, add and retrieve some IOV and Payload, then finally remove the tag.
-Other scripts which are useful are the `cool-command.py` and `crest-store.py/crest-read.py`. 
-Those are documented [here](./examples/README.md), and they can be used to make comparaison on some simple usage between COOL and CREST.
+A similar file is used to read data: `./examples/crest-read.py`.
+This script will create a fake temporary tag, add and retrieve some IOV and Payload. 
+We try to keep a similar script working with the COOL API (`cool-command.py`) in order to help experts in changing their scripts for CREST. 
+This is work in progress, we need to find the best way to present analogies and differences with the experts.
+
+The examples are documented [here](./examples/README.md).
 
 ## CREST servers
 We try to keep 2 server instances which access the same database:
diff --git a/examples/README.md b/examples/README.md
index 0a66899..9399bf4 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -32,4 +32,16 @@ When you re-run the script the tag that has been stored previously is removed.
 In order to check the data you have been reading you can use:
 ```shell
 python crest-read.py
-```
\ No newline at end of file
+```
+
+# Example inspired from specific systems
+This section is under development. We intend to proceed with some system experts in order to provide instructions useful to them.
+## Tile
+The scripts `crest-store-tile.py` and `crest-read-tile.py` contains example which are taken from present TILE folder in COOL.
+
+## LAR
+The scripts `crest-store-lar.py` and `crest-read-lar.py` contains example which are taken from present LAR folder in COOL.
+
+## Global tag coordination
+The script `crest-manage-tag-gtag.py` contains an example to create a global_tag, some tags, and then associate the global_tag to the tags.
+The script also remove everything already existing if it finds them in the CREST DB.
\ No newline at end of file
-- 
GitLab