Public Member Functions | Private Attributes | List of all members
OutputDB Class Reference

Public Member Functions

 OutputDB (std::string sample, const Config &config)
 
 ~OutputDB ()
 
void Put (std::string &serializeKey, std::string &serializeString)
 

Private Attributes

leveldb::DB * fLevelDB
 
leveldb::WriteOptions fWriteOptions
 
MDB_env * mdb_env
 
MDB_dbi mdb_dbi
 
MDB_val mdb_key
 
MDB_val mdb_data
 
MDB_txn * mdb_txn
 

Detailed Description

Definition at line 134 of file cvnCreateDB.cc.

Constructor & Destructor Documentation

OutputDB::OutputDB ( std::string  sample,
const Config config 
)

Definition at line 152 of file cvnCreateDB.cc.

152  :
153  fLevelDB(0), mdb_env(0), mdb_txn(0) {
154 
155  std::string outputDir;
156  if (sample=="test")
157  outputDir=config.fTestOutputDir;
158  else
159  outputDir=config.fTrainOutputDir;
160 
161  if (config.fOutputFormat=="LevelDB"){
162  leveldb::Options fileOptions;
163  fileOptions.error_if_exists = config.fErrorIfExists;
164  fileOptions.create_if_missing = config.fCreateIfMissing;
165  fileOptions.write_buffer_size = config.fWriteBufferSize;
166 
167  fWriteOptions.sync = config.fWriteSync;
168 
169  if(!leveldb::DB::Open(fileOptions, outputDir, &fLevelDB).ok()) {
170  std::cout << "Problem opening the database: "
171  << outputDir << std::endl;
172  exit(1);
173  }
174  }
175 
176  else if (config.fOutputFormat=="LMDB") {
177  mkdir(outputDir.c_str(),0777);
178  mdb_env_create(&mdb_env);
179  mdb_env_set_mapsize(mdb_env, 10737418240);
180  mdb_env_open(mdb_env, outputDir.c_str(), 0, 0777);
181  mdb_txn_begin(mdb_env, NULL, 0, &mdb_txn);
182  mdb_dbi_open(mdb_txn,NULL, 0, &mdb_dbi);
183  }
184 
185  else {
186  std::cout << "Unrecognized output format " << config.fOutputFormat << std::endl;
187  exit(1);
188  }
189 
190 }
MDB_dbi mdb_dbi
Definition: cvnCreateDB.cc:146
def mkdir(path, mode=0o777)
std::string string
Definition: nybbler.cc:12
MDB_txn * mdb_txn
Definition: cvnCreateDB.cc:148
MDB_env * mdb_env
Definition: cvnCreateDB.cc:145
static Config * config
Definition: config.cpp:1054
leveldb::DB * fLevelDB
Definition: cvnCreateDB.cc:142
leveldb::WriteOptions fWriteOptions
Definition: cvnCreateDB.cc:143
QTextStream & endl(QTextStream &s)
OutputDB::~OutputDB ( )

Definition at line 192 of file cvnCreateDB.cc.

192  {
193  if (mdb_txn) mdb_txn_commit(mdb_txn);
194 }
MDB_txn * mdb_txn
Definition: cvnCreateDB.cc:148

Member Function Documentation

void OutputDB::Put ( std::string serializeKey,
std::string serializeString 
)

Definition at line 196 of file cvnCreateDB.cc.

196  {
197  if (fLevelDB) {
198  fLevelDB->Put(fWriteOptions, serializeKey, serializeString);
199  } //end if LevelDB
200  else {//it must be LMDB
201  mdb_data.mv_size=serializeString.size();
202  mdb_data.mv_data=reinterpret_cast<void*>(&serializeString[0]);
203  mdb_key.mv_size=serializeKey.size();
204  mdb_key.mv_data=reinterpret_cast<void*>(&serializeKey[0]);
205  if ( mdb_put(mdb_txn,mdb_dbi,&mdb_key,&mdb_data,0)!= MDB_SUCCESS){
206  std::cout<< "ERROR: Events not loaded correctly" <<std::endl;
207  }//end if put fails
208  }//end if LMDB
209 }//end OutputDB::Put
MDB_dbi mdb_dbi
Definition: cvnCreateDB.cc:146
MDB_val mdb_data
Definition: cvnCreateDB.cc:147
MDB_val mdb_key
Definition: cvnCreateDB.cc:147
MDB_txn * mdb_txn
Definition: cvnCreateDB.cc:148
leveldb::DB * fLevelDB
Definition: cvnCreateDB.cc:142
leveldb::WriteOptions fWriteOptions
Definition: cvnCreateDB.cc:143
QTextStream & endl(QTextStream &s)

Member Data Documentation

leveldb::DB* OutputDB::fLevelDB
private

Definition at line 142 of file cvnCreateDB.cc.

leveldb::WriteOptions OutputDB::fWriteOptions
private

Definition at line 143 of file cvnCreateDB.cc.

MDB_val OutputDB::mdb_data
private

Definition at line 147 of file cvnCreateDB.cc.

MDB_dbi OutputDB::mdb_dbi
private

Definition at line 146 of file cvnCreateDB.cc.

MDB_env* OutputDB::mdb_env
private

Definition at line 145 of file cvnCreateDB.cc.

MDB_val OutputDB::mdb_key
private

Definition at line 147 of file cvnCreateDB.cc.

MDB_txn* OutputDB::mdb_txn
private

Definition at line 148 of file cvnCreateDB.cc.


The documentation for this class was generated from the following file: