EmcStaticData.C

Go to the documentation of this file.
00001 //$Id: EmcStaticData.C,v 1.4 2002/01/11 11:59:09 aphecetc Exp $ 
00002 //#############################################################################
00003 // E.Kistenev         03/01/99 
00004 // send comments to kistenev@bnl.gov 
00005 //#############################################################################
00006 
00007 #include <iostream> 
00008 #include <cstdio>
00009 #include <cstdlib>
00010 
00011 #include "EmcStaticData.h" 
00012 #include "PbScCalibrationData.h"
00013 #include "PbGlCalibrationData.h"
00014 #include "EmcSector.h"
00015 #include "PbScSector.h"
00016 #include "PbGlSector.h"
00017 #include "emcException.h"
00018 
00019 EmcStaticData * EmcStaticData::single       = 0 ;
00020 int             EmcStaticData::access_count = 0 ;
00021 
00022 //____________________________________________________________________
00023 EmcStaticData::EmcStaticData()
00024 {
00025 }
00026 
00027 EmcStaticData::~EmcStaticData()
00028 {
00029 }
00030 
00031 //____________________________________________________________________
00032 EmcStaticData * EmcStaticData::buildEmcStaticData() 
00033 { 
00034   if(single==0) { 
00035     single   = new EmcStaticData(); 
00036     single->PbScData = 0 ;
00037     single->PbGlData = 0 ;
00038     // we build SM static data if, and only if, we
00039     // have some environment variables set.
00040     // FIXME: should we also test the emcDataManager::GetSourceDir()
00041     // here ?
00042     char* pbsc = getenv("EMCAL_DATA_PBSC") ;
00043     if (pbsc) {
00044       single->PbScData = new PbScCalibrationData(); 
00045     }
00046     char* pbgl = getenv("EMCAL_DATA_PBGL") ;
00047     if (pbgl) {
00048       single->PbGlData = new PbGlCalibrationData();
00049     }
00050     single->Sectors.resize(8) ;
00051     for(int iS = 0; iS<8; iS++) single->Sectors[iS] = 0;
00052   } 
00053   access_count ++; 
00054   return single; 
00055 }; 
00056  
00057 //____________________________________________________________________
00058 int EmcStaticData::deleteEmcStaticData() 
00059 { 
00060   //  It would be appropriate to check access_count - decrease it by one 
00061   //  and decide if singleton must be deleted on the basis of result - but -
00062   //  how can we make sure that anyone who cared to ask for the pointer also
00063   //  delets the object associated to that pointer- for that reason
00064   //  access counter is returned and you are free to use it to judge your
00065   //  programming style 
00066   access_count--;
00067   if(single){
00068     if(access_count<=0){
00069       for (int i=0; i<7; i++) {
00070         delete single->Sectors[i];
00071       } 
00072       single->Sectors.resize(8);
00073       if(single->PbScData) delete single->PbScData; 
00074       if(single->PbGlData) delete single->PbGlData; 
00075       delete single;
00076       single = 0;
00077     }
00078   }
00079   return access_count;
00080 }; 
00081  
00082 //____________________________________________________________________
00083 void 
00084 EmcStaticData::buildEmcSector(const char * sectorName, PHTimeStamp* ts) 
00085   //try 
00086 { 
00087   // This method is critical. If it fails, initial calibration
00088   // will _not_ be available, and thus, no meaningfull calibration
00089   // can be expected...
00090 
00091   int SectorNumber = EmcIndexer::EmcSectorNumber(sectorName);
00092 
00093   delete single->Sectors[SectorNumber] ; 
00094   single->Sectors[SectorNumber] = 0 ;
00095 
00096   EmcSector* sector ;
00097 
00098   if(SectorNumber==6 || SectorNumber==7) { 
00099       sector = new PbGlSector(SectorNumber,ts); 
00100   } else { 
00101       sector = new PbScSector(SectorNumber,ts); 
00102   } 
00103   if (sector->IsOK()) {
00104     single->Sectors[SectorNumber] = sector ;
00105     single->Sectors[SectorNumber]->setSectorId(sectorName) ;
00106   }
00107   else {
00108     delete sector ;
00109     single->Sectors[SectorNumber] = 0 ;
00110     throw emcException("EmcStaticData::buildEmcSector : Sector not built. Calibration will be nonsense !!!") ;
00111   }
00112 } 
00113 //catch (...) { throw; }
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126