iocontext.cpp 3.39 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2017-2020, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "iocontext.h"
#include "impl/environment.h"

#include <sstream>
#include <iostream>

namespace OpenZGY {
#if 0
}
#endif

namespace
{
  std::string _redact(const std::string& s)
  {
    return s.size() < 20 ? s : s.substr(0,4) + "..." + s.substr(s.size()-4);
  }
}

/**
 * The class needs at least one virtual member to make dynamic_cast work.
 */
IOContext::~IOContext()
{
}

/** \cond SSTORE */

SeismicStoreIOContext::SeismicStoreIOContext()
{
  using InternalZGY::Environment;

  // TODO-Low: No longer recognize the deprecated $HACK_SAUTH_TEST_TOKEN.

  // Temporarily accept both $OPENZGY_TOKEN and $HACK_SAUTH_TEST_TOKEN as the
  // credentials to use. Warn if the latter is set.
  // Remove this check and the calls to it after a suitable grace period.
  std::string oldtoken = Environment::getStringEnv("HACK_SAUTH_TEST_TOKEN");
  std::string newtoken = Environment::getStringEnv("OPENZGY_TOKEN");

  if (oldtoken != "") {
    if (newtoken.empty()) {
      std::cerr << "WARNING: $HACK_SAUTH_TEST_TOKEN is deprecated. Please use $OPENZGY_TOKEN instead.\n";
      newtoken = oldtoken;
    }
    else if (oldtoken != newtoken)
      std::cerr << "WARNING: $HACK_SAUTH_TEST_TOKEN is deprecated. Ignored in favor of $OPENZGY_TOKEN.\n";
    else
      std::cerr << "NOTE: $HACK_SAUTH_TEST_TOKEN and $OPENZGY_TOKEN are both set.\n";
  }

  sdurl(Environment::getStringEnv("OPENZGY_SDURL"));
  sdapikey(Environment::getStringEnv("OPENZGY_SDAPIKEY"));
  sdtoken(newtoken, "");
  maxsize(Environment::getNumericEnv("OPENZGY_MAXSIZE_MB", 64));
  maxhole(Environment::getNumericEnv("OPENZGY_MAXHOLE_MB", 2));
  aligned(Environment::getNumericEnv("OPENZGY_ALIGNED_MB", 0));
  segsize(Environment::getNumericEnv("OPENZGY_SEGSIZE_MB", 1024));
73
  segsplit(Environment::getNumericEnv("OPENZGY_SEGSPLIT", 8));
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  threads(Environment::getNumericEnv("OPENZGY_NUMTHREADS", 1));
  legaltag(Environment::getStringEnv("OPENZGY_LEGALTAG"));
  writeid(Environment::getStringEnv("OPENZGY_WRITEID"));
  seismicmeta(Environment::getStringEnv("OPENZGY_SEISMICMETA"));
}

std::string
SeismicStoreIOContext::toString() const
{
  std::stringstream ss;
  ss << "SD context:\n"
     << "  sdurl:    \"" << _sdurl << "\"\n"
     << "  sdapikey: \"" << _redact(_sdapikey) << "\"\n"
     << "  sdtoken:  \"" << _redact(_sdtoken) << "\" [" << _sdtokentype << "]" << "\n"
     << "  maxsize:  " << _maxsize / (1024*1024) << " MB\n"
     << "  maxhole:  " << _maxhole / (1024*1024) << " MB\n"
     << "  aligned:  " << _aligned / (1024*1024) << " MB\n"
     << "  segsize:  " << _segsize / (1024*1024) << " MB\n"
92
     << "  segsplit: " << _segsplit << "\n"
93
94
95
96
97
98
99
100
101
102
     << "  threads:  " << _threads << "\n"
     << "  legaltag: \"" << _legaltag << "\"\n"
     << "  writeid:  \"" << _writeid << "\"\n"
     << "  seismeta: \"" << _seismicmeta << "\"\n";
  return ss.str();
}

/** \endcond */

} // namespace