iocontext.cpp 3.25 KB
Newer Older
1
// Copyright 2017-2021, Schlumberger
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
//
// 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;

  sdurl(Environment::getStringEnv("OPENZGY_SDURL"));
  sdapikey(Environment::getStringEnv("OPENZGY_SDAPIKEY"));
49
  sdtoken(Environment::getStringEnv("OPENZGY_TOKEN"), "");
50
51
52
  maxsize(Environment::getNumericEnv("OPENZGY_MAXSIZE_MB", 64));
  maxhole(Environment::getNumericEnv("OPENZGY_MAXHOLE_MB", 2));
  aligned(Environment::getNumericEnv("OPENZGY_ALIGNED_MB", 0));
53
54
  segsize(Environment::getNumericEnv("OPENZGY_SEGSIZE_MB", 256));
  segsplit(Environment::getNumericEnv("OPENZGY_SEGSPLIT", 8));
55
56
  iothreads(Environment::getNumericEnv("OPENZGY_NUMTHREADS_IO", 1));
  cputhreads(Environment::getNumericEnv("OPENZGY_NUMTHREADS_CPU", 1));
57
58
59
  legaltag(Environment::getStringEnv("OPENZGY_LEGALTAG"));
  writeid(Environment::getStringEnv("OPENZGY_WRITEID"));
  seismicmeta(Environment::getStringEnv("OPENZGY_SEISMICMETA"));
60
61
62
  setRoAfterWrite(Environment::getNumericEnv("OPENZGY_RO_AFTER_WRITE", 0) > 0);
  forceRoBeforeRead(Environment::getNumericEnv("OPENZGY_RO_BEFORE_READ", 0) > 0);
  forceRwBeforeWrite(Environment::getNumericEnv("OPENZGY_RW_BEFORE_WRITE", 0) > 0);
63
64
65
66
67
68
69
70
71
72
73
74
75
76
}

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"
77
     << "  segsplit: " << _segsplit << "\n"
78
     << "  threads:  " << _iothreads << " I/O, " << _cputhreads << " CPU.\n"
79
80
     << "  legaltag: \"" << _legaltag << "\"\n"
     << "  writeid:  \"" << _writeid << "\"\n"
81
82
83
84
85
86
     << "  seismeta: \"" << _seismicmeta << "\"\n"
     << "  romode:   "
     << (_set_ro_after_write? "ro_after_write":" ")
     << (_force_ro_before_read? "ro_before_read":" ")
     << (_force_rw_before_write? "rw_before_write":" ")
     << "\n";
87
88
89
  return ss.str();
}

90
91
92
93
94
95
std::shared_ptr<IOContext>
SeismicStoreIOContext::clone() const
{
  return std::make_shared<SeismicStoreIOContext>(*this);
}

96
97
98
/** \endcond */

} // namespace