LCOV - code coverage report
Current view: top level - src/access - StoreSerialization.cpp (source / functions) Hit Total Coverage
Test: ad_map_access Lines: 76 85 89.4 %
Date: 2022-10-04 09:48:07 Functions: 7 7 100.0 %
Branches: 100 168 59.5 %

           Branch data     Line data    Source code
       1                 :            : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
       2                 :            : //
       3                 :            : // Copyright (C) 2018-2021 Intel Corporation
       4                 :            : //
       5                 :            : // SPDX-License-Identifier: MIT
       6                 :            : //
       7                 :            : // ----------------- END LICENSE BLOCK -----------------------------------
       8                 :            : 
       9                 :            : #include "GeometryStore.hpp"
      10                 :            : #include "ad/map/access/Factory.hpp"
      11                 :            : #include "ad/map/access/Logging.hpp"
      12                 :            : #include "ad/map/access/Operation.hpp"
      13                 :            : #include "ad/map/access/Store.hpp"
      14                 :            : #include "ad/map/lane/LaneOperation.hpp"
      15                 :            : #include "ad/map/serialize/SerializeGeneratedTypes.hpp"
      16                 :            : 
      17                 :            : #include <algorithm>
      18                 :            : #include <string>
      19                 :            : 
      20                 :            : namespace ad {
      21                 :            : namespace map {
      22                 :            : namespace access {
      23                 :            : 
      24                 :         12 : bool Store::save(serialize::ISerializer &serializer,
      25                 :            :                  bool use_magic,
      26                 :            :                  bool use_embedded_geometry,
      27                 :            :                  bool use_geometry_store)
      28                 :            : {
      29         [ +  + ]:         12 :   if (serializer.isStoring())
      30                 :            :   {
      31                 :         11 :     use_magic_ = use_magic;
      32                 :         11 :     use_embedded_geometry_ = use_embedded_geometry;
      33                 :         11 :     use_geometry_store_ = use_geometry_store;
      34                 :         11 :     return serialize(serializer);
      35                 :            :   }
      36                 :            :   else
      37                 :            :   {
      38         [ +  - ]:          1 :     access::getLogger()->error("Cannot save to read-only serializer.");
      39                 :            :   }
      40                 :          1 :   return false;
      41                 :            : }
      42                 :            : 
      43                 :        157 : bool Store::load(serialize::ISerializer &serializer)
      44                 :            : {
      45                 :        157 :   bool ok = false;
      46         [ +  + ]:        157 :   if (!serializer.isStoring())
      47                 :            :   {
      48                 :        156 :     ok = serialize(serializer);
      49                 :            :   }
      50                 :            :   else
      51                 :            :   {
      52         [ +  - ]:          1 :     access::getLogger()->error("Cannot load from to write-only serializer.");
      53                 :            :   }
      54                 :        157 :   return ok;
      55                 :            : }
      56                 :            : 
      57                 :            : ////////////////////////////////
      58                 :            : // ISerializeable implementation
      59                 :            : 
      60                 :         30 : bool Store::isValid() const
      61                 :            : {
      62         [ +  + ]:         30 :   if (!access::isValid(meta_data_, false))
      63                 :            :   {
      64                 :          1 :     return false;
      65                 :            :   }
      66         [ +  + ]:         78 :   for (auto id_and_lane : lane_map_)
      67                 :            :   {
      68                 :         49 :     const lane::LaneId &lane_id = id_and_lane.first;
      69                 :         49 :     const lane::Lane::Ptr &lane = id_and_lane.second;
      70   [ +  -  +  -  :         49 :     if (!lane::isValid(lane_id, false) || !lane || !lane::isValid(*lane, false))
          +  -  +  -  -  
                +  -  + ]
      71                 :            :     {
      72                 :          0 :       return false;
      73                 :            :     }
      74                 :            :   }
      75   [ +  +  +  - ]:         58 :   for (auto partition_id_and_ids : part_lane_map_)
      76                 :            :   {
      77                 :         29 :     const lane::LaneIdList &lane_ids = partition_id_and_ids.second;
      78         [ +  + ]:         78 :     for (auto lane_id : lane_ids)
      79                 :            :     {
      80   [ +  -  -  + ]:         49 :       if (lane_map_.find(lane_id) == lane_map_.end())
      81                 :            :       {
      82                 :          0 :         return false;
      83                 :            :       }
      84                 :            :     }
      85                 :            :   }
      86   [ +  +  +  - ]:         41 :   for (auto partition_id_and_ids : part_landmark_map_)
      87                 :            :   {
      88                 :         12 :     const landmark::LandmarkIdList &landmark_ids = partition_id_and_ids.second;
      89         [ +  + ]:         24 :     for (auto landmark_id : landmark_ids)
      90                 :            :     {
      91   [ +  -  -  + ]:         12 :       if (landmark_map_.find(landmark_id) == landmark_map_.end())
      92                 :            :       {
      93                 :          0 :         return false;
      94                 :            :       }
      95                 :            :     }
      96                 :            :   }
      97                 :         29 :   return true;
      98                 :            : }
      99                 :            : 
     100                 :        167 : bool Store::serialize(serialize::ISerializer &serializer)
     101                 :            : {
     102                 :        167 :   bool old_magic = serializer.setUseMagic(true);
     103                 :        167 :   bool old_use_embedded_points = serializer.setUseEmbeddedPoints(true);
     104                 :            : 
     105   [ +  -  +  -  :        334 :   bool ok = serializer.serialize(serialize::SerializeableMagic::Store) && serializer.serialize(use_magic_)
                   +  - ]
     106   [ +  -  +  -  :        334 :     && serializer.serialize(use_embedded_geometry_) && serializer.serialize(use_geometry_store_);
          +  -  +  -  +  
                      - ]
     107                 :            : 
     108                 :            :   /*Todo the two lines below will be deleted after the map are generated again without use_zfp_*/
     109                 :        167 :   bool use_zfp_ = false;
     110   [ +  -  +  -  :        167 :   ok = ok && serializer.serialize(use_zfp_);
                   +  - ]
     111                 :            : 
     112                 :        167 :   serializer.setUseMagic(use_magic_);
     113                 :        167 :   serializer.setUseEmbeddedPoints(use_embedded_geometry_);
     114   [ +  -  +  -  :        167 :   ok = ok && doSerialize(serializer, meta_data_);
                   +  - ]
     115   [ +  -  +  -  :        167 :   ok = ok && serializer.serializeObjectPtrMap(lane_map_);
                   +  + ]
     116   [ +  +  +  -  :        167 :   ok = ok && serializer.serializeObjectPtrMap(landmark_map_);
                   +  - ]
     117         [ +  + ]:        167 :   if (ok)
     118                 :            :   {
     119         [ +  - ]:        166 :     ok = serializer.serializeObjectVecMap(part_lane_map_);
     120         [ +  - ]:        166 :     ok = serializer.serializeObjectVecMap(part_landmark_map_);
     121                 :            :   }
     122         [ +  + ]:        167 :   if (ok) // Todo will delete this after preparing new map without connector
     123                 :            :   {
     124         [ +  + ]:        166 :     if (serializer.isStoring())
     125                 :            :     {
     126   [ +  -  +  -  :         11 :       ok = serializer.serializeEmptyObjectVec() && serializer.serializeEmptyObjectVec();
             +  -  +  - ]
     127                 :            :     }
     128                 :            :     else
     129                 :            :     {
     130   [ +  -  +  -  :        155 :       ok = serializer.serializeEmptyObjectVec() && serializer.serializeEmptyObjectVec();
             +  -  +  - ]
     131                 :            :     }
     132                 :            :   }
     133         [ +  + ]:        167 :   if (ok)
     134                 :            :   {
     135         [ +  + ]:        166 :     if (use_geometry_store_)
     136                 :            :     {
     137         [ +  - ]:          8 :       GeometryStore gs;
     138         [ +  + ]:          4 :       if (serializer.isStoring())
     139                 :            :       {
     140         [ +  - ]:          2 :         ok = storeGeometry(gs);
     141                 :            :       }
     142         [ +  - ]:          4 :       if (ok)
     143                 :            :       {
     144         [ +  - ]:          4 :         ok = gs.serialize(serializer);
     145   [ +  -  +  +  :          4 :         if (ok && !serializer.isStoring())
                   +  + ]
     146                 :            :         {
     147         [ +  + ]:          2 :           if (use_embedded_geometry_)
     148                 :            :           {
     149         [ +  - ]:          1 :             ok = checkGeometry(gs);
     150                 :            :           }
     151                 :            :           else
     152                 :            :           {
     153         [ +  - ]:          1 :             ok = restoreGeometry(gs);
     154                 :            :           }
     155                 :            :         }
     156                 :            :       }
     157                 :            :     }
     158                 :            :   }
     159                 :        167 :   serializer.setUseMagic(old_magic);
     160                 :        167 :   serializer.setUseEmbeddedPoints(old_use_embedded_points);
     161                 :        167 :   return ok;
     162                 :            : }
     163                 :            : 
     164                 :          2 : bool Store::storeGeometry(GeometryStore &gs)
     165                 :            : {
     166         [ +  + ]:        602 :   for (auto lane : lane_map_)
     167                 :            :   {
     168   [ +  -  -  + ]:        600 :     if (!gs.store(lane.second))
     169                 :            :     {
     170   [ #  #  #  # ]:          0 :       access::getLogger()->error("Store geometry failed for lane {}", lane.first);
     171                 :          0 :       return false;
     172                 :            :     }
     173                 :            :   }
     174                 :          2 :   return true;
     175                 :            : }
     176                 :            : 
     177                 :          1 : bool Store::restoreGeometry(const GeometryStore &gs)
     178                 :            : {
     179         [ +  + ]:        301 :   for (auto lane : lane_map_)
     180                 :            :   {
     181   [ +  -  -  + ]:        300 :     if (!gs.restore(lane.second))
     182                 :            :     {
     183   [ #  #  #  # ]:          0 :       access::getLogger()->error("Restore geometry failed for lane {}", lane.first);
     184                 :          0 :       return false;
     185                 :            :     }
     186                 :            :   }
     187                 :          1 :   return true;
     188                 :            : }
     189                 :            : 
     190                 :          1 : bool Store::checkGeometry(const GeometryStore &gs)
     191                 :            : {
     192         [ +  + ]:        301 :   for (auto lane : lane_map_)
     193                 :            :   {
     194   [ +  -  -  + ]:        300 :     if (!gs.check(lane.second))
     195                 :            :     {
     196   [ #  #  #  # ]:          0 :       access::getLogger()->error("Redundant geometry check failed!");
     197                 :          0 :       return false;
     198                 :            :     }
     199                 :            :   }
     200         [ +  - ]:          1 :   access::getLogger()->info("Redundant geometry check ok.");
     201                 :          1 :   return true;
     202                 :            : }
     203                 :            : 
     204                 :            : } // namespace access
     205                 :            : } // namespace map
     206                 :            : } // namespace ad

Generated by: LCOV version 1.14