Mysql Class Reference

#include <Mysql.hh>

Collaboration diagram for Mysql:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Mysql ()
 ~Mysql ()
bool executeQuery (std::string query)
MYSQL_RES * executeSelect (std::string sql)
ui32 addReconstructionSoftware (std::string svnVersion, std::string comments=" ")
ui32 addMergeSoftware (std::string svnVersion, std::string comments=" ")
ui32 getReconstructionSoftwareId (std::string svnVersion)
ui32 getMergeSoftwareId (std::string svnVersion)
ui32 addRebuildFile (ui32 reconstructionSoftwareId, std::string path, std::string name, bool reconstructionStatus, ui32 eventNumber, ui32 hitNumber, bool fileExist, std::string comments)
ui32 addMergeFile (ui32 mergeSoftwareId, std::string path, std::string name, bool mergeStatus, ui32 eventNumber, ui32 hitNumber, bool fileExist, std::string comments)
ui32 getRebuildFile (std::string filePath, std::string fileName)
ui32 getMergeFile (std::string filePath, std::string fileName)
ui32 getRawFileId (std::string filePath, std::string fileName)
ui32 getRunIdFromRawFile (std::string filePath, std::string fileName)
ui32 getRunIdFromRawFile (ui32 rawFileId)
ui32 getRunIdFromRebuildFile (std::string filePath, std::string fileName)
ui32 getRunIdFromRebuildFile (ui32 rebuildFileId)
ui32 getRunIdFromMergeFile (std::string filePath, std::string fileName)
ui32 getRunIdFromMergeFile (ui32 mergeFileId)
bool connectRebuildAndRawFile (ui32 rawId, ui32 rebuildId)
bool connectMergeAndRebuildFile (ui32 rebuildId, ui32 mergeId)
ui32 updateRunProcessInfo (i32 runId, float offsetX, float offsetY, float pressure, float temperature, ui32 deltaTMax)
ui32 getARunInfo (ui32 runId, std::string clause)
ui32 getARunChamberInfo (ui32 runId, ui16 chamberId, std::string clause)
float getRunOffsetX (ui32 runId)
float getRunOffsetY (ui32 runId)
float getRunPressure (ui32 runId)
float getRunTemperature (ui32 runId)
ui32 getRunDeltaTMax (ui32 runId)
ui32 addRunChamberProcessInfo (ui32 runId, ui16 chamberId, float xmean, float ymean, float inefficiency, float nHitMean, ui32 deltaTMax)
float getRunChamberXMean (ui32 runId, ui16 chamberId)
float getRunChamberYMean (ui32 runId, ui16 chamberId)
float getRunChamberInefficiency (ui32 runId, ui16 chamberId)
float getRunChamberNHitMean (ui32 runId, ui16 chamberId)
ui32 getRunChamberDeltaTMax (ui32 runId, ui16 chamberId)
const std::vector< std::string > & getMergedFilesByTimestamp (std::string startTS, std::string endTS)

Private Member Functions

void init ()
void connect ()
void close ()

Private Attributes

MYSQL * conn

Detailed Description

Definition at line 24 of file Mysql.hh.


Constructor & Destructor Documentation

Mysql::Mysql (  ) 

Definition at line 10 of file Mysql.cpp.

00011 {
00012  this->init(); 
00013 }

Mysql::~Mysql (  ) 

Definition at line 16 of file Mysql.cpp.

00017 {
00018   this->close();
00019 }


Member Function Documentation

bool Mysql::executeQuery ( std::string  query  ) 

Referenced by addRunChamberProcessInfo().

MYSQL_RES* Mysql::executeSelect ( std::string  sql  ) 

Referenced by connectMergeAndRebuildFile(), connectRebuildAndRawFile(), getRunIdFromMergeFile(), getRunIdFromRawFile(), getRunIdFromRebuildFile(), main(), and updateRunProcessInfo().

ui32 Mysql::addReconstructionSoftware ( std::string  svnVersion,
std::string  comments = " " 
)

Referenced by main().

ui32 Mysql::addMergeSoftware ( std::string  svnVersion,
std::string  comments = " " 
)

Referenced by main().

ui32 Mysql::getReconstructionSoftwareId ( std::string  svnVersion  ) 

Referenced by main().

ui32 Mysql::getMergeSoftwareId ( std::string  svnVersion  ) 

ui32 Mysql::addRebuildFile ( ui32  reconstructionSoftwareId,
std::string  path,
std::string  name,
bool  reconstructionStatus,
ui32  eventNumber,
ui32  hitNumber,
bool  fileExist,
std::string  comments 
)

Referenced by main().

ui32 Mysql::addMergeFile ( ui32  mergeSoftwareId,
std::string  path,
std::string  name,
bool  mergeStatus,
ui32  eventNumber,
ui32  hitNumber,
bool  fileExist,
std::string  comments 
)

Referenced by main().

ui32 Mysql::getRebuildFile ( std::string  filePath,
std::string  fileName 
)

Referenced by getRunIdFromRebuildFile(), and main().

ui32 Mysql::getMergeFile ( std::string  filePath,
std::string  fileName 
)

ui32 Mysql::getRawFileId ( std::string  filePath,
std::string  fileName 
)

Referenced by main().

ui32 Mysql::getRunIdFromRawFile ( std::string  filePath,
std::string  fileName 
)

Referenced by main().

ui32 Mysql::getRunIdFromRawFile ( ui32  rawFileId  ) 

Definition at line 685 of file Mysql.cpp.

00686   {
00687   string sRawFileId ;
00688 
00689   stringstream out;
00690   out << rawFileId;
00691   sRawFileId = out.str();
00692 
00693   string sql = "SELECT  `RUN_ID` FROM  `RAW_FILE` WHERE  `RAWFILE_ID` =  \""+sRawFileId+"\"";
00694   MYSQL_RES* result = this->executeSelect(sql);
00695 
00696 
00697   if ( result != NULL )
00698   {
00699     MYSQL_ROW row = mysql_fetch_row(result);
00700     if ( row != NULL )
00701     {
00702       return atoi(row[0]);
00703     }
00704     else
00705     {
00706        throw MicroException("No run for this raw file");
00707     }
00708   }
00709   return UNDEFINED_ID;
00710  }

ui32 Mysql::getRunIdFromRebuildFile ( std::string  filePath,
std::string  fileName 
)

Definition at line 713 of file Mysql.cpp.

Referenced by main().

00714   {
00715     ui32 rebuildFileId = this->getRebuildFile(filePath,fileName);
00716     return getRunIdFromRebuildFile(rebuildFileId);
00717   }

ui32 Mysql::getRunIdFromRebuildFile ( ui32  rebuildFileId  ) 

Definition at line 719 of file Mysql.cpp.

00720   {
00721     string sRebuildFileId ;
00722 
00723     stringstream out;
00724     out << rebuildFileId;
00725     sRebuildFileId = out.str();
00726 
00727     string sql = "SELECT `RUN_ID` FROM `RAW_FILE` WHERE `REBUILDFILE_ID` = \""+sRebuildFileId+"\"";
00728 
00729     MYSQL_RES* result = this->executeSelect(sql);
00730 
00731     if ( result != NULL )
00732     {
00733       MYSQL_ROW row = mysql_fetch_row(result);
00734       if ( row != NULL )
00735       {
00736         return atoi(row[0]);
00737       }
00738       else
00739       {
00740          throw MicroException("No run for this raw file");
00741       }
00742     }
00743     return UNDEFINED_ID;
00744   }

ui32 Mysql::getRunIdFromMergeFile ( std::string  filePath,
std::string  fileName 
)

Referenced by main().

ui32 Mysql::getRunIdFromMergeFile ( ui32  mergeFileId  ) 

Definition at line 754 of file Mysql.cpp.

00755   {
00756     string sMergeFileId ;
00757 
00758     stringstream out;
00759     out << mergeFileId;
00760     sMergeFileId = out.str();
00761 
00762     string sql = "SELECT `RUN_ID` FROM  `RAW_FILE` WHERE  `REBUILDFILE_ID` IN ( SELECT  `REBUILDFILE_ID` FROM  `REBUILD_FILE` WHERE  `MERGEFILE_ID` ="+sMergeFileId+")" ;
00763 
00764     MYSQL_RES* result = this->executeSelect(sql);
00765 
00766     if ( result != NULL )
00767     {
00768       MYSQL_ROW row = mysql_fetch_row(result);
00769       if ( row != NULL )
00770       {
00771         return atoi(row[0]);
00772       }
00773       else
00774       {
00775          throw MicroException("No run for this raw file");
00776       }
00777     }
00778     return UNDEFINED_ID;
00779   }

bool Mysql::connectRebuildAndRawFile ( ui32  rawId,
ui32  rebuildId 
)

Definition at line 471 of file Mysql.cpp.

Referenced by main().

00472 {
00473 
00474   string sRawId, sRebuildId;
00475 
00476   stringstream out;
00477   out << rawId;
00478   sRawId = out.str();
00479 
00480   out.str("");
00481   out << rebuildId;
00482   sRebuildId = out.str();
00483   
00484   string sql = "UPDATE  `microbookeeping`.`RAW_FILE` SET  `REBUILDFILE_ID` =  '"+sRebuildId+"' WHERE  `RAW_FILE`.`RAWFILE_ID` ="+sRawId+";" ;
00485 
00486   MYSQL_RES* result = this->executeSelect(sql);
00487 
00488   return true;
00489 
00490 }

bool Mysql::connectMergeAndRebuildFile ( ui32  rebuildId,
ui32  mergeId 
)

Definition at line 493 of file Mysql.cpp.

Referenced by main().

00494 {
00495 
00496   string sRebuildId, sMergeId;
00497 
00498   stringstream out;
00499   out << mergeId;
00500   sMergeId = out.str();
00501 
00502   out.str("");
00503   out << rebuildId;
00504   sRebuildId = out.str();
00505 
00506   string sql = "UPDATE  `microbookeeping`.`REBUILD_FILE` SET  `MERGEFILE_ID` =  '"+sMergeId+"' WHERE  `REBUILD_FILE`.`REBUILDFILE_ID` ="+sRebuildId+";" ;
00507 
00508   MYSQL_RES* result = this->executeSelect(sql);
00509 
00510   return true;
00511 
00512 }

ui32 Mysql::updateRunProcessInfo ( i32  runId,
float  offsetX,
float  offsetY,
float  pressure,
float  temperature,
ui32  deltaTMax 
)

Definition at line 215 of file Mysql.cpp.

Referenced by main().

00217 {
00218 
00219   string sRunId, sOffsetX, sOffsetY, sPressure, sTemperature, sDeltaTMax;
00220 
00221   stringstream out;
00222   out << runId;
00223   sRunId = out.str();
00224 
00225   out.str("");
00226   out << offsetX;
00227   sOffsetX = out.str();
00228 
00229   out.str("");
00230   out << offsetY;
00231   sOffsetY = out.str();
00232 
00233   out.str("");
00234   out << pressure;
00235   sPressure = out.str();
00236 
00237   out.str("");
00238   out << temperature;
00239   sTemperature = out.str();
00240 
00241   out.str("");
00242   out << deltaTMax;
00243   sDeltaTMax = out.str();
00244 
00245     string sql = "UPDATE  `microbookeeping`.`RUN` SET  `OFFSETX` =  '"+sOffsetX+"', `OFFSETY` =  '"+sOffsetY+"', `DELTATMAX` =  '"+sDeltaTMax+"', `PRESSURE` =  '"+sPressure+"', `TEMPERATURE` =  '"+sTemperature+"' WHERE  `RUN`.`RUN_ID` ="+sRunId; 
00246   MYSQL_RES* result = this->executeSelect(sql);
00247 
00248   return true;
00249   
00250 }

ui32 Mysql::getARunInfo ( ui32  runId,
std::string  clause 
)

Referenced by getRunDeltaTMax(), getRunOffsetX(), getRunOffsetY(), getRunPressure(), and getRunTemperature().

ui32 Mysql::getARunChamberInfo ( ui32  runId,
ui16  chamberId,
std::string  clause 
)

Referenced by getRunChamberDeltaTMax(), getRunChamberInefficiency(), getRunChamberNHitMean(), getRunChamberXMean(), and getRunChamberYMean().

float Mysql::getRunOffsetX ( ui32  runId  ) 

Definition at line 557 of file Mysql.cpp.

Referenced by main(), and selectAndCopyEvent().

00558 {
00559   return this->getARunInfo(  runId,"OFFSETX");
00560 }

float Mysql::getRunOffsetY ( ui32  runId  ) 

Definition at line 562 of file Mysql.cpp.

Referenced by main(), and selectAndCopyEvent().

00563 {
00564   return this->getARunInfo(  runId,"OFFSETY");
00565 }

float Mysql::getRunPressure ( ui32  runId  ) 

Definition at line 572 of file Mysql.cpp.

Referenced by main().

00573 {
00574   return this->getARunInfo(  runId,"PRESSURE");
00575 }

float Mysql::getRunTemperature ( ui32  runId  ) 

Definition at line 577 of file Mysql.cpp.

Referenced by main().

00578 {
00579   return this->getARunInfo(  runId,"TEMPERATURE");
00580 }

ui32 Mysql::getRunDeltaTMax ( ui32  runId  ) 

Definition at line 567 of file Mysql.cpp.

Referenced by main().

00568 {
00569   return this->getARunInfo(  runId,"DELTATMAX");
00570 }

ui32 Mysql::addRunChamberProcessInfo ( ui32  runId,
ui16  chamberId,
float  xmean,
float  ymean,
float  inefficiency,
float  nHitMean,
ui32  deltaTMax 
)

Definition at line 149 of file Mysql.cpp.

Referenced by main().

00150 {
00151   
00152   string sRunId, sChamberId, sXMean, sYMean, sInefficiency, sNhitMean, sDeltaMax;
00153 
00154   stringstream out;
00155   out << runId;
00156   sRunId = out.str();
00157 
00158   out.str("");
00159   out << chamberId;
00160   sChamberId = out.str();
00161 
00162   out.str("");
00163   out << xmean;
00164   sXMean = out.str();
00165 
00166   out.str("");
00167   out << ymean;
00168   sYMean = out.str();
00169 
00170   out.str("");
00171   out << inefficiency;
00172   sInefficiency = out.str();
00173 
00174   out.str("");
00175   out << nHitMean;
00176   sNhitMean = out.str();
00177 
00178   out.str("");
00179   out << deltaTMax;
00180   sDeltaMax = out.str();
00181 
00182   string sql = "INSERT INTO `microbookeeping`.`RUN_CHAMBER_PROCESS_INFO` (`RC_PR_ID`, `RUN_ID`, `CHAMBER_ID`, `XMEAN`, `YMEAN`, `INEFFICIENCY`, `NHITMEAN`, `DELTATMAX`) VALUES (NULL, '"+sRunId+"', '"+sChamberId+"', '"+sXMean+"', '"+sYMean+"', '"+sInefficiency+"', '"+sNhitMean+"', '"+sDeltaMax+"');";
00183 
00184    return this->executeQuery(sql);
00185 /*
00186   // Verify is already exist
00187   try
00188   {
00189     return getReconstructionSoftwareId(svnVersion);
00190   }
00191 
00192   catch (MicroException e)
00193   {
00194     string sql = "INSERT INTO  `microbookeeping`.`REBUILD_SOFTWARE` ( \
00195                 `RSOFT_ID` , `RSOFT_VERSION` , `RSOFT_COMMENT`) \
00196                 VALUES ( NULL ,  '"+ svnVersion+ "',  ' "+ comments + "');";
00197     if ( this->executeQuery(sql))
00198     {
00199       return getReconstructionSoftwareId(svnVersion);
00200     }
00201   }
00202   return UNDEFINED_ID;
00203 */
00204   
00205 }

float Mysql::getRunChamberXMean ( ui32  runId,
ui16  chamberId 
)

Definition at line 644 of file Mysql.cpp.

Referenced by main().

00645 {
00646   return Mysql::getARunChamberInfo(runId, chamberId,"XMEAN");
00647 }

float Mysql::getRunChamberYMean ( ui32  runId,
ui16  chamberId 
)

Definition at line 649 of file Mysql.cpp.

Referenced by main().

00650 {
00651  return Mysql::getARunChamberInfo(runId, chamberId,"YMEAN");
00652 }

float Mysql::getRunChamberInefficiency ( ui32  runId,
ui16  chamberId 
)

Definition at line 654 of file Mysql.cpp.

Referenced by main().

00655 {
00656   return Mysql::getARunChamberInfo(runId, chamberId,"INEFFICIENCY");
00657 }

float Mysql::getRunChamberNHitMean ( ui32  runId,
ui16  chamberId 
)

Definition at line 659 of file Mysql.cpp.

Referenced by main().

00660 {
00661   return Mysql::getARunChamberInfo(runId, chamberId,"NHITMEAN");
00662 }

ui32 Mysql::getRunChamberDeltaTMax ( ui32  runId,
ui16  chamberId 
)

Definition at line 664 of file Mysql.cpp.

Referenced by main().

00665 {
00666   return Mysql::getARunChamberInfo(runId, chamberId,"DELTATMAX");
00667 }

const std::vector<std::string>& Mysql::getMergedFilesByTimestamp ( std::string  startTS,
std::string  endTS 
)

Referenced by main().

void Mysql::init (  )  [private]

Definition at line 30 of file Mysql.cpp.

Referenced by Mysql().

00031 {
00032   conn = mysql_init(NULL);
00033   this->connect();
00034 }

void Mysql::connect (  )  [private]

Definition at line 37 of file Mysql.cpp.

Referenced by init().

00038 {
00039   mysql_real_connect(conn, "ccmysql.in2p3.fr", "lcdet", "mic2010", "microbookeeping", 0, NULL, 0);
00040 }

void Mysql::close (  )  [private]

Definition at line 43 of file Mysql.cpp.

Referenced by ~Mysql().

00044 {
00045  mysql_close(conn);
00046 }


Member Data Documentation

MYSQL* Mysql::conn [private]

Definition at line 100 of file Mysql.hh.

Referenced by close(), connect(), and init().


The documentation for this class was generated from the following files:
Generated on Mon Jun 11 16:58:59 2012 for MicromegasFramework by  doxygen 1.4.7