Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

MJDatabaseCloverDetector.cc

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------//
00002 //bb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nu//
00003 //                                                                           //
00004 //                         MAJORANA Simulation                               //
00005 //                                                                           //
00006 //      This code implementation is the intellectual property of the         //
00007 //      MAJORANA Collaboration. It is based on Geant4, an intellectual       //
00008 //      property of the RD44 GEANT4 collaboration.                           //
00009 //                                                                           //
00010 //                        *********************                              //
00011 //                                                                           //
00012 //    Neither the authors of this software system, nor their employing       //
00013 //    institutes, nor the agencies providing financial support for this      //
00014 //    work  make  any representation or  warranty, express or implied,       //
00015 //    regarding this software system or assume any liability for its use.    //
00016 //    By copying, distributing or modifying the Program (or any work based   //
00017 //    on on the Program) you indicate your acceptance of this statement,     //
00018 //    and all its terms.                                                     //
00019 //                                                                           //
00020 //bb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nu//
00021 //---------------------------------------------------------------------------//
00022 //                                                          
00023 // $Id: MJDatabaseCloverDetector.cc,v 1.2 2004/11/09 13:42:39 xliu Exp $ 
00024 //      
00025 // CLASS IMPLEMENTATION:  MJDatabaseCloverDetector.cc
00026 //
00027 //---------------------------------------------------------------------------//
00033 // 
00034 //---------------------------------------------------------------------------//
00045 //---------------------------------------------------------------------------//
00046 //
00047 
00048 #include "io/MJLogger.hh"
00049 #include "database/MJDatabase.hh"
00050 #include "database/MJDatabasePsqlImpl.hh"
00051 #include "database/MJDatabaseUtil.hh"
00052 static void
00053 exit_nicely(PGconn *conn)
00054 {
00055         PQfinish(conn);
00056         exit(1);
00057 }
00058 //---------------------------------------------------------------------------//
00059 
00060 #include "database/MJDatabaseCloverDetector.hh"      //Present MJ Class Headers 
00061 
00062 //---------------------------------------------------------------------------//
00063 
00064 MJDatabaseCloverDetector::MJDatabaseCloverDetector()
00065 {
00066 
00067 }
00068 
00069 MJDatabaseCloverDetector::MJDatabaseCloverDetector(string serialNo)
00070   :fSerialNo( serialNo )
00071 {
00072   //construct material here
00073 }
00074 MJDatabaseCloverDetector::MJDatabaseCloverDetector(const MJDatabaseCloverDetector & other)
00075 {
00076 
00077 }
00078 MJDatabaseCloverDetector::~MJDatabaseCloverDetector()
00079 {
00080 }
00081 MJDatabaseCloverDetector* 
00082 MJDatabaseCloverDetector::createDetector(PGresult *res, PGconn * conn)
00083 {
00084   MJDatabaseUtil dbutil;
00085   for (int i = 0; i < PQntuples(res); i++)
00086     {
00087       fSerialNo = PQgetvalue(res, i, 0);
00088       fSpacerWidth =dbutil.c_Float(PQgetvalue(res, i, 1));
00089       string spacerMat = PQgetvalue(res, i, 2);
00090       fSpacerBGModel = PQgetvalue(res, i, 3);
00091       fOpVoltage =dbutil.c_Float( PQgetvalue(res, i, 4));
00092       fCryoEndGap = dbutil.c_Float(PQgetvalue(res, i, 5));
00093       fCryoThinWallThickness = dbutil.c_Float(PQgetvalue(res, i, 6));
00094       fCryoThinWallLength = dbutil.c_Float(PQgetvalue(res, i, 7));
00095       fCryoThickWallThickness = dbutil.c_Float(PQgetvalue(res, i, 8));
00096       fCryoLength = dbutil.c_Float(PQgetvalue(res, i, 9));
00097       fCryoWidth = dbutil.c_Float(PQgetvalue(res, i, 10));
00098       fCryoCornerRadius = dbutil.c_Float(PQgetvalue(res, i, 11));
00099       string cryoMat = PQgetvalue(res, i, 12);
00100       fCryoBGModel = PQgetvalue(res, i, 13);
00101       fColdplateThickness =dbutil.c_Float(PQgetvalue(res, i, 14));
00102       fColdplateGap =dbutil.c_Float( PQgetvalue(res, i, 15));
00103       string coldPMat = PQgetvalue(res, i, 16);
00104       fColdplateBGModel = PQgetvalue(res, i, 17);
00105 
00106       //create the material objects
00107       fSpacerMaterial = *(MJDatabase::GetMaterial(spacerMat));
00108       fCryoMaterial = *(MJDatabase::GetMaterial(cryoMat));
00109       fColdplateMaterial = *(MJDatabase::GetMaterial(coldPMat));
00110 
00111       int len, num;
00112       //get Pl resolution at different energies
00113       len = PQgetlength(res,i, 18);
00114       float * ener ;
00115       if( len > 0) dbutil.fillArray(ener, PQgetvalue(res, i, 18));
00116       len = PQgetlength(res,i, 19);
00117       float * resol;
00118       if( len > 0)  dbutil.fillArray(resol, PQgetvalue(res, i, 19));
00119       //create the vector of resolutions
00120       num =dbutil.c_Int(PQgetvalue(res, i, 18)+2*sizeof(int));  
00121       for (int j=0; j< num; j++){
00122         fResPl.push_back(DetectorRes(ener[j], resol[j]));
00123       }
00124      //get Pm resolution at different energies 
00125       len = PQgetlength(res,i, 20);
00126       if( len > 0)  dbutil.fillArray(ener, PQgetvalue(res, i, 20));
00127       len = PQgetlength(res,i, 21);
00128       if( len > 0)  dbutil.fillArray(resol, PQgetvalue(res, i, 21));
00129       //create the vector of resolutions
00130       num =dbutil.c_Int(PQgetvalue(res, i, 20)+2*sizeof(int));  
00131       for (int j=0; j< num; j++){
00132         fResPm.push_back(DetectorRes(ener[j], resol[j]));
00133       }
00134      //get Pr resolution at different energies
00135       len = PQgetlength(res,i, 22);
00136       if( len > 0)  dbutil.fillArray(ener, PQgetvalue(res, i, 22));
00137       len = PQgetlength(res,i, 23);
00138       if( len > 0)  dbutil.fillArray(resol, PQgetvalue(res, i, 23));
00139       //create the vector of resolutions
00140       num =dbutil.c_Int(PQgetvalue(res, i, 22)+2*sizeof(int));  
00141       for (int j=0; j< num; j++){
00142         fResPr.push_back(DetectorRes(ener[j], resol[j]));
00143       }
00144       //get the parts
00145       getParts(conn);
00146     }
00147   return this;
00148 }
00149 void
00150 MJDatabaseCloverDetector::getParts(PGconn * conn){
00151   PGresult *res;
00152   string cmd = "DECLARE Aportal CURSOR FOR select * from CloverPart_tot" ;
00153   cmd += " where parentid = '" + fSerialNo + "'";
00154   res = PQexec(conn,  cmd.c_str());
00155   if (PQresultStatus(res) != PGRES_COMMAND_OK)
00156     {
00157       MJLog(error) << "DECLARE CURSOR failed: " << PQerrorMessage(conn) << endlog;
00158       PQclear(res);
00159       exit_nicely(conn);
00160     }
00161   PQclear(res);
00162   res = PQexec(conn, "FETCH ALL in Aportal");
00163 
00164   //check to see if we found the object in database
00165   if( PQntuples(res) == 0 ) {
00166     MJLog(error) << "Could not find " << fSerialNo << " in the database " << endlog;
00167     return ;
00168   }
00169 
00170   for (int i = 0; i < PQntuples(res); i++){
00171     fCrystalSerialNo[i] = PQgetvalue(res,i,0);
00172     fCrystals.push_back(*(MJDatabase::GetCloverCrystal(fCrystalSerialNo[i])));
00173   }
00174 }
00175 ostream & operator << (ostream& os, MJDatabaseCloverDetector& det)
00176 {
00177   os << '\n'
00178      <<"****** Clover Detector: " << det.GetDetectorSerialNo() << '\n'
00179      <<"Cryo material      : " << det.GetCryoMaterialName() << '\n'
00180      <<"Coldplate material : " << det.GetColdplateMaterialName() << '\n'
00181      <<"Spacer material    : " << det.GetSpacerMaterialName() << '\n'
00182      <<"Crystal serial no. : { " ;
00183   for (int i=0; i<4; i++)
00184     os << det.fCrystalSerialNo[i] << " ";
00185   os << "}" << '\n';
00186 
00187   return os;
00188 
00189 }

Generated on Mon Nov 29 16:58:49 2004 for Majorana Simulation by  doxygen 1.3.9.1