PbScCalibrationData.C

Go to the documentation of this file.
00001  
00002 //#############################################################################
00003 // E.Kistenev         6/10/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 "PbScSector.h" 
00014 #include "PbScSuperModule.h"
00015 
00016 using std::cerr;
00017 using std::cout;
00018 using std::endl;
00019 
00020 //____________________________________________________________________
00021 PbScCalibrationData::PbScCalibrationData() 
00022 { 
00023         Status    = kFALSE;
00024 //  Read list of files with calibration data accuired in 902 
00025   FILE * fp = 0; 
00026   int     dummy, supn; 
00027   char    filename[80]; 
00028   char *  file = new char[100];
00029   char * var = getenv("EMCAL_DATA_PBSC");
00030 
00031   if ( !var ) 
00032     {
00033       cerr << "<EMCAL-FATAL> PbScCalibrationData::PbScCalibrationData : "
00034            << "Environment variable EMCAL_DATA_PBSC not set !"
00035            << "Exit likely to happen soon."
00036            << endl;
00037       return;
00038     }
00039 
00040   sprintf(file,"%s/Cal_902/PbScSMCalibrationList",var);
00041   if( (fp =fopen(file,"r")) != 0 ) { 
00042     while(fscanf(fp,"%d,%d,%d",&dummy,&supn,&dummy)!=EOF){ 
00043                         char c;
00044       while( (c = fgetc(fp)) != '\n'){;} 
00045       fgets(filename,80,fp); 
00046       fName[supn-1]=new char[strlen(filename)+1];
00047       filename[strlen(filename)-1]='\0'; 
00048       strcpy(fName[supn-1],filename);
00049                         //      cout<<fName[supn-1]<<endl;
00050     } 
00051                 delete [] file;
00052   } else {
00053     cout << "Cannot open file : " << file << endl;
00054     return;
00055   }    
00056   fclose (fp); 
00057   PbScSMList=new int[108];
00058   int SMList[108]  = { 
00059     49,54,42,43,53,41,38,46,37,51,47,50,26,30,44,45,52,48, 
00060     34,27,67,68,60,21,63,71,55,65,70,28,74,77,82,72,79,57, 
00061     23,22,19,20,24,35,69,66,56,61,29,33,36,58,59,62,64,31, 
00062     86,78,84,25,76,88,87,75,81,83,94,98,109,73,90,80,85,32, 
00063     8,13,10,4,5,17,18,9,11,7,14,3,39,40,15,12,16,6, 
00064     108,105,107,89,104,100,101,95,93,97,91,1,102,106,92,103,96,99 
00065   }; 
00066   for(int i=0;i<108;i++)        PbScSMList[i]=SMList[i];
00067         Status  = kTRUE;
00068 } 
00069 
00070 //____________________________________________________________________
00071 PbScCalibrationData::~PbScCalibrationData() 
00072 { 
00073   for(int i=0;i<109; i++) delete [] fName[i];
00074   delete [] PbScSMList;
00075 }; 
00076  
00077 //____________________________________________________________________
00078 int PbScCalibrationData::getSMNumber(int SMId) 
00079 {
00080         for(int i=0;i<108; i++){ if(SMId==PbScSMList[i])return i; }
00081         return -1;
00082 }
00083  
00084 //____________________________________________________________________
00085 void  PbScCalibrationData::LoadPMTDataBase(char * fName)
00086 {
00087         FILE *  fp;
00088   char *  file = new char[100];
00089         float   Line[100];
00090         EmcStaticData * gData = EmcStaticData::buildEmcStaticData();
00091   sprintf(file,"%sCal_902/%s",getenv("EMCAL_DATA_PBSC"),fName) ;
00092         cout<<file<<endl;
00093         int linesRead=0;
00094         if( (fp =fopen(file,"r")) != 0 ) { 
00095                 while(fscanf(fp,"%f",&Line[0])!=EOF){
00096                         //                      cout<<"Next Line "<<endl;
00097                         for(int i =1; i<PMTWordsPerTower+7; i++) fscanf(fp,"%f ",&Line[i]); 
00098                         linesRead++;
00099                         // cout<<linesRead<<" "<<Line[0]<<" "<<Line[1]<<endl;
00100                         // check if this is an installed PMT
00101                         int SMId         = static_cast<int>(Line[0]);
00102                         int Twr          = static_cast<int>(Line[1]-1);
00103                         int SMNumber     = this->getSMNumber(SMId);
00104                         int SectorNumber = SMNumber/18;
00105                         SMNumber         = SMNumber%18;
00106                         //      cout<<"Out to load "<<linesRead<<" "<<SMId<<" "<<SMNumber<<" "<<SectorNumber<<" Tower "<<Twr<<endl;
00107                         // check if this sector exists
00108                         if(EmcSector * sData = gData->getSector(SectorNumber)){
00109                                 // Sector exists - find supermodule pointer
00110                                 EmcSuperModule * smData = sData->getSuperModule(SMNumber);
00111                                 ((PbScSuperModule *) smData)->LoadDataBase902(Twr, Line);
00112                         }                       
00113                 }
00114                 fclose(fp);
00115                 delete [] file;
00116                 return;
00117         } else {
00118                 cout<<"File "<<file<<" not found. PMT data-base is missing"<<endl;
00119         }
00120 }
00121