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

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  )  const

Referenced by addRunChamberProcessInfo().

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

Referenced by connectMergeAndRebuildFile(), connectRebuildAndRawFile(), getDetectorIdFromRunId(), getDetectorString(), getRunEnergy(), getRunIdFromDhcalId(), getRunIdFromMergeFile(), getRunIdFromRawFile(), getRunIdFromRebuildFile(), and updateRunProcessInfo().

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

Referenced by main().

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

Referenced by main().

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

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

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

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 
) const

Referenced by main().

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

Referenced by getRunIdFromRebuildFile(), and main().

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

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

Referenced by main().

string Mysql::getRunEnergy ( ui32  runId  )  const

Definition at line 846 of file Mysql.cpp.

Referenced by main().

00847   {
00848   stringstream out;
00849   string sId;
00850   out << runId;
00851   sId = out.str();
00852 
00853 /*
00854 SELECT `BEAM_TYPE_PARTICLE_ENERGY` FROM `BEAM_TYPE` WHERE `BEAM_TYPE_ID` in
00855 (SELECT  `BEAM_TYPE_ID` 
00856 FROM  `RUN` 
00857 WHERE  `RUN_ID` =10687)
00858 */
00859   string sql = "SELECT `BEAM_TYPE_PARTICLE_ENERGY` FROM `BEAM_TYPE` WHERE `BEAM_TYPE_ID` in (SELECT  `BEAM_TYPE_ID` FROM  `RUN` WHERE  `RUN_ID` =" + sId + ")"; 
00860   
00861   MYSQL_RES* result = this->executeSelect(sql);
00862 
00863   if ( result != NULL )
00864   {
00865     MYSQL_ROW row = mysql_fetch_row(result);
00866     if ( row != NULL )
00867     {
00868       return row[0];
00869     }
00870     else
00871     {
00872        throw MicroException("No run with this id");
00873     }
00874   }
00875   throw MicroException("No run with this id");
00876 
00877   }

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

Referenced by main().

ui32 Mysql::getRunIdFromRawFile ( ui32  rawFileId  )  const

Definition at line 684 of file Mysql.cpp.

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

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

Definition at line 712 of file Mysql.cpp.

Referenced by main().

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

ui32 Mysql::getRunIdFromRebuildFile ( ui32  rebuildFileId  )  const

Definition at line 718 of file Mysql.cpp.

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

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

Referenced by main().

ui32 Mysql::getRunIdFromMergeFile ( ui32  mergeFileId  )  const

Definition at line 753 of file Mysql.cpp.

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

ui32 Mysql::getRunIdFromDhcalId ( ui32  dhcalId  )  const

Definition at line 881 of file Mysql.cpp.

00882   {
00883   string sDhcalId ;
00884 
00885   stringstream out;
00886   out << dhcalId;
00887   sDhcalId = out.str();
00888 
00889 /*
00890 SELECT `RUN_ID` FROM `RAW_FILE` WHERE `RAWFILE_NAME` like \"%" + dhcalId  +"%\" "
00891 */
00892   string sql = "SELECT `RUN_ID` FROM  `RUN` WHERE `RUN_NAME` LIKE  '%" +sDhcalId + "%'";
00893   MYSQL_RES* result = this->executeSelect(sql);
00894 
00895 
00896   if ( result != NULL )
00897   {
00898     MYSQL_ROW row = mysql_fetch_row(result);
00899     if ( row != NULL )
00900     {
00901       return atoi(row[0]);
00902     }
00903     else
00904     {
00905        throw MicroException("No run for this dhcalId");
00906     }
00907   }
00908   return UNDEFINED_ID;
00909  }

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

Definition at line 470 of file Mysql.cpp.

Referenced by main().

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

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

Definition at line 492 of file Mysql.cpp.

Referenced by main().

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

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

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 
) const

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

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

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

ui32 Mysql::getDetectorIdFromRunId ( ui32  detectorId  )  const

Definition at line 782 of file Mysql.cpp.

Referenced by getDetectorStringFromRunId().

00783   {
00784     
00785   
00786   stringstream out;
00787   string sRunId;
00788   out << runId;
00789   sRunId = out.str();
00790 
00791   string sql = "SELECT `DETECTOR_ID` FROM `RUN` WHERE `RUN_ID` = " + sRunId ;
00792   MYSQL_RES* result = this->executeSelect(sql);
00793 
00794   if ( result != NULL )
00795   {
00796     MYSQL_ROW row = mysql_fetch_row(result);
00797     if ( row != NULL )
00798     {
00799       return atoi(row[0]);
00800     }
00801     else
00802     {
00803        throw MicroException("No run with this id");
00804     }
00805   }
00806   return UNDEFINED_ID;
00807 }

string Mysql::getDetectorString ( ui32  detectorId  )  const

Definition at line 811 of file Mysql.cpp.

Referenced by getDetectorStringFromRunId().

00812   {
00813   stringstream out;
00814   string sId;
00815   out << detectorId;
00816   sId = out.str();
00817 
00818   string sql = "SELECT  `XML_VALUE` FROM `DETECTOR` WHERE `DETECTOR_ID` =" + sId; 
00819   
00820   MYSQL_RES* result = this->executeSelect(sql);
00821 
00822   if ( result != NULL )
00823   {
00824     MYSQL_ROW row = mysql_fetch_row(result);
00825     if ( row != NULL )
00826     {
00827       return row[0];
00828     }
00829     else
00830     {
00831        throw MicroException("No run with this id");
00832     }
00833   }
00834   throw MicroException("No run with this id");
00835 
00836   }

string Mysql::getDetectorStringFromRunId ( ui32  runId  )  const

Definition at line 839 of file Mysql.cpp.

Referenced by Toolbox::getDetector().

00840   {
00841     ui32 detectorId = getDetectorIdFromRunId(runId) ;
00842     return getDetectorString(detectorId) ;
00843   }

float Mysql::getRunOffsetX ( ui32  runId  )  const

Definition at line 556 of file Mysql.cpp.

Referenced by main(), and selectAndCopyEvent().

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

float Mysql::getRunOffsetY ( ui32  runId  )  const

Definition at line 561 of file Mysql.cpp.

Referenced by main(), and selectAndCopyEvent().

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

float Mysql::getRunPressure ( ui32  runId  )  const

Definition at line 571 of file Mysql.cpp.

Referenced by main().

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

float Mysql::getRunTemperature ( ui32  runId  )  const

Definition at line 576 of file Mysql.cpp.

Referenced by main().

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

ui32 Mysql::getRunDeltaTMax ( ui32  runId  )  const

Definition at line 566 of file Mysql.cpp.

Referenced by main().

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

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

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 
) const

Definition at line 643 of file Mysql.cpp.

Referenced by main().

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

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

Definition at line 648 of file Mysql.cpp.

Referenced by main().

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

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

Definition at line 653 of file Mysql.cpp.

Referenced by main().

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

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

Definition at line 658 of file Mysql.cpp.

Referenced by main().

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

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

Definition at line 663 of file Mysql.cpp.

Referenced by main().

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

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

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 106 of file Mysql.hh.

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


The documentation for this class was generated from the following files:
Generated on Mon Jan 7 13:18:59 2013 for MicromegasFramework by  doxygen 1.4.7