GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoDBExport.h
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 
35 #ifndef __GoDBExport_h
36 #define __GoDBExport_h
37 
38 #include "vtkMySQLDatabase.h"
39 #include <vector>
40 
41 #include "QGoIOConfigure.h"
42 
48 class QGOIO_EXPORT GoDBExport
49 {
50 public:
51 
52  GoDBExport(std::string iServerName, std::string iLogin,
53  std::string iPassword, int iImagingSessionID,
54  std::string iFilename);
55  virtual ~GoDBExport();
56 
63  void ExportContours();
64 
72  void ExportMeshes();
73 
74 private:
75 
76  vtkMySQLDatabase *m_DatabaseConnector;
77  std::string m_ServerName;
78  std::string m_Password;
79  std::string m_Login;
81  std::fstream m_outfile;
82  std::string m_NameDocXml;
83 
84  std::vector< std::string > m_VectorContourIDs;
85  std::vector< std::string > m_VectorMeshIDs;
86  std::vector< std::string > m_VectorTrackIDs;
87  std::vector< std::string > m_VectorLineageIDs;
88  std::vector< std::string > m_VectorChannelIDs;
89 
96  std::vector< std::pair< std::string, std::string > > GetImagingSessionInfoFromDB();
97 
105  std::pair< std::string, std::string > GetOneInfoFromDBForImgSession(
106  std::string iNameInfo);
107 
111  void WriteGeneraleInfo();
112 
121  template< typename T >
122  void WriteTableInfoFromDB(std::string iField, std::string iValue)
123  {
124  T TableRow;
125 
126  std::vector< std::string > ListTableIDs = ListSpecificValuesForOneColumn(
127  this->m_DatabaseConnector, TableRow.GetTableName(),
128  TableRow.GetTableIDName(), iField, iValue);
129  std::vector< std::string >::iterator iter = ListTableIDs.begin();
130  while ( iter != ListTableIDs.end() )
131  {
132  std::vector< std::pair< std::string, std::string > > EntityInfo =
133  this->GetOneEntityInfoFromDB(*iter, TableRow);
134  this->WriteOnTheOutputFile(TableRow.GetTableName(), EntityInfo);
135  iter++;
136  }
137  }
138 
145  template< typename T >
146  void WriteTableInfoFromDB(std::vector< std::string > iListIDs)
147  {
148  T TableRow;
149 
150  if ( iListIDs.empty() )
151  {
152  this->WriteNumberOfEntities(TableRow.GetTableName(), 0);
153  return;
154  }
155  this->WriteNumberOfEntities( TableRow.GetTableName(), iListIDs.size() );
156  std::vector< std::string >::iterator iter = iListIDs.begin();
157  while ( iter != iListIDs.end() )
158  {
159  std::vector< std::pair< std::string, std::string > > EntityInfo =
160  this->GetOneEntityInfoFromDB(*iter, TableRow);
161  this->WriteOnTheOutputFile(TableRow.GetTableName(), EntityInfo);
162  iter++;
163  }
164  }
165 
174  template< typename T >
175  std::vector< std::pair< std::string, std::string > >
176  GetOneEntityInfoFromDB(std::string iEntityID, T iTableRow)
177  {
178  std::vector< std::pair< std::string, std::string > > oEntityInfo =
179  std::vector< std::pair< std::string, std::string > >();
180  iTableRow.SetValuesForSpecificID(atoi( iEntityID.c_str() ),
181  this->m_DatabaseConnector);
182  std::vector< std::string > FieldNames = iTableRow.GetVectorColumnNames();
183  std::vector< std::string >::iterator iter = FieldNames.begin();
184  while ( iter != FieldNames.end() )
185  {
186  std::pair< std::string, std::string > FieldInfo;
187  FieldInfo.first = *iter;
188  FieldInfo.second = iTableRow.GetMapValue(*iter);
189  oEntityInfo.push_back(FieldInfo);
190  iter++;
191  }
192  return oEntityInfo;
193  }
194 
204  void GetVectorsTableNamesTracesIDsAndFields(
205  std::vector< std::string > & ioVectorTableNames,
206  std::vector< std::vector< std::string > > & ioVectorTracesIDs,
207  std::vector< std::string > & ioVectorFields,
208  bool IncludeChannelIDs = false);
209 
214  void WriteCellTypeAndSubCellTypeInfoFromDatabase();
215 
220  void WriteContoursInfoFromDatabase();
221 
226  void WriteTracksInfoFromDatabase();
227 
232  void WriteMeshesInfoFromDatabase();
233 
238  void WriteLineagesInfoFromDatabase();
239 
244  void WriteChannelsInfoFromDatabase();
245 
250  void WriteIntensityInfoFromDatabase();
251 
256  void UpdateVectorContourIDsForExportContours();
257 
263  void UpdateVectorMeshIDsForExportContours();
264 
269  void UpdateVectorContourIDsForExportMeshes();
270 
276  void UpdateVectorMeshIDsForExportMeshes();
277 
282  void UpdateVectorChannelIDsForExportMeshes();
283 
289  void UpdateVectorTrackIDsToExportInfo();
290 
296  void UpdateVectorLineageIDsToExportInfo();
297 
302  void UpdateAllVectorTracesIDsToExportContours();
303 
308  void UpdateAllVectorTracesIDsToExportMeshes();
309 
314  void WriteTheColorsInfoFromDatabase();
315 
321  void WriteCoordinatesInfoFromDatabase();
322 
328  std::string GetNameWithBrackets(std::string iName);
329 
335  std::string GetNameWithSlashBrackets(std::string iName);
336 
343  void WriteOnTheOutputFile(std::string iNameOfEntity,
344  std::vector< std::pair< std::string, std::string > > iInfoToWrite);
345 
351  void WriteNumberOfEntities(std::string iNameOfEntity, size_t iNumber);
352 
356  void AddTabulation();
357 
361  void OpenDBConnection();
362 
366  void CloseDBConnection();
367 };
368 #endif
std::vector< std::string > m_VectorLineageIDs
Definition: GoDBExport.h:87
std::string m_Password
Definition: GoDBExport.h:78
std::vector< std::pair< std::string, std::string > > GetOneEntityInfoFromDB(std::string iEntityID, T iTableRow)
get the info with their names for an entity from the database and put them in a vector of pair of str...
Definition: GoDBExport.h:176
std::string m_Login
Definition: GoDBExport.h:79
std::vector< std::string > m_VectorMeshIDs
Definition: GoDBExport.h:85
std::string m_NameDocXml
Definition: GoDBExport.h:82
std::vector< std::string > m_VectorContourIDs
Definition: GoDBExport.h:84
void WriteTableInfoFromDB(std::vector< std::string > iListIDs)
get the info from the database for all the entities from a table which IDs are in iListIDs and write ...
Definition: GoDBExport.h:146
void WriteTableInfoFromDB(std::string iField, std::string iValue)
get the info from the database for all the entities from a table or with a limitation defined with fi...
Definition: GoDBExport.h:122
std::string m_ServerName
Definition: GoDBExport.h:77
export the data from the database into a textfile
Definition: GoDBExport.h:48
std::vector< std::string > ListSpecificValuesForOneColumn(vtkMySQLDatabase *iDatabaseConnector, const std::string &TableName, const std::string &ColumnName, const std::string &field, const std::string &value, bool ExcludeZero)
SELECT ColumnName FROM TableName WHERE field = value and ColumnName <> 0 (if excludezero) ...
vtkMySQLDatabase * m_DatabaseConnector
Definition: GoDBExport.h:76
int m_ImagingSessionID
Definition: GoDBExport.h:80
std::vector< std::string > m_VectorTrackIDs
Definition: GoDBExport.h:86
std::vector< std::string > m_VectorChannelIDs
Definition: GoDBExport.h:88
std::fstream m_outfile
Definition: GoDBExport.h:81