DedxCurSvc Class Reference

#include <DedxCurSvc.h>

Inheritance diagram for DedxCurSvc:

IDedxCurSvc List of all members.

Public Member Functions

 DedxCurSvc (const std::string &name, ISvcLocator *svcloc)
 ~DedxCurSvc ()
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvUnknown)
virtual StatusCode initialize ()
virtual StatusCode finalize ()
void handle (const Incident &)
void getDedxCurveInfo ()
const double getCurve (int i)
const double getSigma (int i)
const int getCurveSize ()
const int getSigmaSize ()

Static Public Member Functions

static const InterfaceID & interfaceID ()

Private Attributes

double m_curve [50]
double m_sigma [50]
int m_curve_size
int m_sigma_size
std::string m_bossRelease
std::string m_calParVer
std::string m_sftver
std::string m_dbStatus
std::string m_type
MYSQLconn
IDataProviderSvc * m_eventSvc
IDatabaseSvcm_dbsvc
int m_runFromMax
int m_runToMin

Detailed Description

Definition at line 16 of file DedxCurSvc.h.


Constructor & Destructor Documentation

DedxCurSvc::DedxCurSvc ( const std::string name,
ISvcLocator *  svcloc 
)

Definition at line 32 of file DedxCurSvc.cxx.

References m_bossRelease, m_calParVer, m_dbStatus, m_sftver, and m_type.

00032                                                                    : Service(name, svcloc) {
00033 declareProperty("BossRelease",m_bossRelease="default");
00034 declareProperty("BossVer",m_sftver="default");
00035 declareProperty("ParVer",m_calParVer="default");
00036 declareProperty("DbStatus",m_dbStatus="OK");
00037 declareProperty("Type",m_type="default");
00038 }

DedxCurSvc::~DedxCurSvc (  ) 

Definition at line 98 of file DedxCurSvc.cxx.

00098                        {
00099 }


Member Function Documentation

StatusCode DedxCurSvc::finalize (  )  [virtual]

Definition at line 91 of file DedxCurSvc.cxx.

References Bes_Common::INFO, and msgSvc().

00091                                   {
00092   MsgStream log(msgSvc(), name());
00093   log << MSG::INFO << name() << ": End of Run" << endreq;
00094   return StatusCode::SUCCESS;
00095 }

const double DedxCurSvc::getCurve ( int  i  )  [inline, virtual]

Implements IDedxCurSvc.

Definition at line 31 of file DedxCurSvc.h.

References m_curve.

00031 {return m_curve[i];}

const int DedxCurSvc::getCurveSize (  )  [inline, virtual]

Implements IDedxCurSvc.

Definition at line 33 of file DedxCurSvc.h.

References m_curve_size.

00033 {return m_curve_size;}

void DedxCurSvc::getDedxCurveInfo (  ) 

Definition at line 117 of file DedxCurSvc.cxx.

References EvtCyclic3::c_str(), calibUtil::ERROR, Bes_Common::FATAL, DatabaseRecord::GetString(), genRecEmupikp::i, Bes_Common::INFO, m_bossRelease, m_calParVer, m_curve, m_curve_size, m_dbStatus, m_dbsvc, m_eventSvc, m_runFromMax, m_runToMin, m_sftver, m_sigma, m_sigma_size, m_type, IDatabaseSvc::query(), and deljobs::string.

Referenced by handle().

00117                                  {
00118   MsgStream log(messageService(), name());
00119   SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
00120   int  run = eventHeader->runNumber();
00121   if(run<0){
00122     log << MSG::INFO << "This data is the MC sample with the Run Number: " << run << endreq;
00123     if(m_type=="Sim"){
00124       run=-run;
00125       log << MSG::INFO << "Reverse the sign of Run Number" << endreq;
00126     }
00127   }
00128   //  unsigned long *lengths;
00129   MYSQL_RES *res_set;
00130   MYSQL_ROW row;
00131   char stmt1[400];
00132 
00133   std::string sftver;
00134   
00135   if(m_sftver == "default" && m_bossRelease == "default")
00136   {
00137     log << MSG::FATAL << " BossRelease and BossVer for DedxCurve not set!" << endreq;
00138     exit(1);
00139   }
00140 
00141   if( (run<m_runFromMax || run>m_runToMin) ) 
00142   { 
00143     if(m_sftver == "default")
00144     {
00145       sprintf(stmt1,"select RunFrom, RunTo, SftVer, ParVer from CalVtxLumVer where BossRelease = '%s' and RunFrom <= %d and RunTo >= %d and DataType = 'DedxCurve'", m_bossRelease.c_str(), run, run);
00146       std::cout<<stmt1<<std::endl;
00147       DatabaseRecordVector rest;
00148       int row_no = m_dbsvc->query("offlinedb",stmt1,rest);
00149       if(row_no==0) {
00150         log << MSG::FATAL << "can not find result for DedxCur with: " << stmt1 << endreq;
00151         exit(1);
00152       }
00153       if(row_no>1) {
00154         log << MSG::FATAL << "find more than 1 results for DedxCur with: " << stmt1 << endreq;
00155         exit(1);
00156       }
00157       DatabaseRecord* recordst = rest[0];
00158       sftver = recordst->GetString("SftVer");
00159       m_calParVer = recordst->GetString("ParVer");
00160       m_runFromMax = atoi((recordst->GetString("RunFrom")).c_str());
00161       m_runToMin = atoi((recordst->GetString("RunTo")).c_str());
00162       log << MSG::INFO << "get from CalVtxLumVer, m_runFromMax: "<< m_runFromMax << " m_runToMin: "<<m_runToMin<< endreq;
00163     }
00164     else
00165       sftver = m_sftver;
00166   
00167     if(m_calParVer!="default")
00168       sprintf(stmt1,"select RunFrom, RunTo, DedxCurvePar,DedxSigmaPar from DedxCurvePar where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and DedxCurveParVer = %s and Status='%s'",sftver.c_str(),run,run,m_calParVer.c_str(), m_dbStatus.c_str());
00169     else
00170       sprintf(stmt1,"select RunFrom, RunTo, DedxCurvePar,DedxSigmaPar from DedxCurvePar where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and Status='%s' order by DedxCurveParVer desc",sftver.c_str(),run,run, m_dbStatus.c_str());
00171     std::cout<<stmt1<<std::endl; 
00172     
00173     DatabaseRecordVector res;
00174     int row_no  = m_dbsvc->query("offlinedb", stmt1, res);
00175     if(row_no==0){
00176      log << MSG::FATAL << "can not find result for DedxCur with: "<< stmt1 << endreq;
00177      exit(1);
00178     }
00179     if(row_no>1){
00180       log << MSG::FATAL << "find more than 1 results for DedxCur with: "<< stmt1 << endreq;
00181       exit(1);
00182     }
00183     
00184     DatabaseRecord* records = res[0];
00185     int runFrom = atoi((records->GetString("RunFrom")).c_str());
00186     int runTo = atoi((records->GetString("RunTo")).c_str());
00187     if(m_sftver=="default")
00188     {
00189       m_runFromMax = runFrom>m_runFromMax? runFrom:m_runFromMax;
00190       m_runToMin = runTo<m_runToMin? runTo:m_runToMin;
00191     }
00192     else
00193     {
00194       m_runFromMax = runFrom;
00195       m_runToMin = runTo;
00196     }
00197     log << MSG::INFO << "get from DedxCurvePar runFrom: "<< runFrom << " runTo: "<<runTo<< endreq;
00198     log << MSG::INFO << "m_runFromMax: "<< m_runFromMax << " m_runToMin: "<<m_runToMin<< endreq;
00199 
00200     TBuffer *buf1 = new TBufferFile(TBuffer::kRead);
00201     buf1->SetBuffer((*records)["DedxCurvePar"],327680,kFALSE);
00202     TBuffer *buf2 = new TBufferFile(TBuffer::kRead);
00203     buf2->SetBuffer((*records)["DedxSigmaPar"],327680,kFALSE);
00204     
00205     
00206     TTree* curvetree = new TTree(); 
00207     curvetree->Streamer(*buf1); 
00208     
00209     TTree* sigmatree = new TTree(); 
00210     sigmatree->Streamer(*buf2);
00211     
00212     double curve[50];
00213     double sigma[50];
00214     int SigmaSize;
00215     int CurveSize;
00216     curvetree -> SetBranchAddress("curve", curve);
00217     curvetree -> SetBranchAddress("CurveSize", &CurveSize);
00218     sigmatree -> SetBranchAddress("sigma", sigma);
00219     sigmatree -> SetBranchAddress("SigmaSize", &SigmaSize);
00220     
00221     Int_t nentries_curve = (Int_t)curvetree ->GetEntries();
00222     Int_t nentries_sigma = (Int_t)sigmatree ->GetEntries();
00223     curvetree -> GetEntry(0);
00224     if(CurveSize>50){
00225       log << MSG::ERROR<<"CurveSize larger than designed number"<<endreq;
00226       exit(1);}  
00227     for(int i=0; i<CurveSize;i++){
00228         m_curve[i]=curve[i];
00229        }
00230     
00231     sigmatree-> GetEntry(0);
00232     if(SigmaSize>50){
00233       log << MSG::ERROR<<"SigmaSize larger than designed number"<<endreq;
00234       exit(1);}
00235     for(int i=0; i<SigmaSize;i++){
00236         m_sigma[i]=sigma[i];}
00237       m_curve_size=CurveSize;
00238       m_sigma_size=SigmaSize;
00239      delete curvetree;
00240      delete sigmatree;
00241   }
00242    return;
00243 }

const double DedxCurSvc::getSigma ( int  i  )  [inline, virtual]

Implements IDedxCurSvc.

Definition at line 32 of file DedxCurSvc.h.

References m_sigma.

00032 {return m_sigma[i];}

const int DedxCurSvc::getSigmaSize (  )  [inline, virtual]

Implements IDedxCurSvc.

Definition at line 34 of file DedxCurSvc.h.

References m_sigma_size.

00034 {return m_sigma_size;}

void DedxCurSvc::handle ( const Incident &   ) 

Definition at line 103 of file DedxCurSvc.cxx.

References Bes_Common::DEBUG, getDedxCurveInfo(), and m_eventSvc.

00103                                           {
00104   MsgStream log( messageService(), name() );
00105   log << MSG::DEBUG << "handle: " << inc.type() << endreq;
00106 
00107   SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
00108   int  run = eventHeader->runNumber();
00109 
00110   if ( inc.type() == "NewRun" ){
00111     log << MSG::DEBUG << "New Run:" << run << endreq;
00112     getDedxCurveInfo();
00113   }
00114 }

StatusCode DedxCurSvc::initialize (  )  [virtual]

Definition at line 51 of file DedxCurSvc.cxx.

References calibUtil::ERROR, Bes_Common::INFO, m_dbsvc, m_eventSvc, m_runFromMax, m_runToMin, and msgSvc().

00051                                     {
00052   
00053   MsgStream log(msgSvc(), name());
00054   log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
00055   
00056   StatusCode sc = Service::initialize();
00057   if ( sc.isFailure() ) return sc;
00058 
00059   IIncidentSvc* incsvc;
00060   sc = service("IncidentSvc", incsvc);
00061   int priority = 100;
00062   if( sc.isSuccess() ){
00063     incsvc -> addListener(this, "NewRun", priority);
00064   }
00065   
00066 
00067    sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
00068   if (sc .isFailure() ) {
00069     log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
00070     return sc;
00071   }
00072 
00073 
00074   sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
00075   if (sc .isFailure() ) {
00076     log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
00077     return sc;
00078   }
00079   
00080   StatusCode scc;
00081   log<<MSG::INFO << "setProperties()" << endreq;
00082   scc = setProperties();
00083  
00084   m_runFromMax=0;
00085   m_runToMin=0;
00086 
00087   return sc;
00088 }  

static const InterfaceID& IDedxCurSvc::interfaceID (  )  [inline, static, inherited]

Definition at line 11 of file IDedxCurSvc.h.

References IID_IDedxCurSvc().

00011 { return IID_IDedxCurSvc; }

StatusCode DedxCurSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvUnknown 
) [virtual]

Definition at line 41 of file DedxCurSvc.cxx.

References IID_IDedxCurSvc().

00041                                                                                    {
00042   
00043   if ( IID_IDedxCurSvc.versionMatch(riid) ) { 
00044     *ppvInterface = static_cast<IDedxCurSvc*> (this); 
00045   } 
00046   else return Service::queryInterface(riid, ppvInterface) ; 
00047   return StatusCode::SUCCESS;
00048 }


Member Data Documentation

MYSQL* DedxCurSvc::conn [private]

Definition at line 48 of file DedxCurSvc.h.

std::string DedxCurSvc::m_bossRelease [private]

Definition at line 42 of file DedxCurSvc.h.

Referenced by DedxCurSvc(), and getDedxCurveInfo().

std::string DedxCurSvc::m_calParVer [private]

Definition at line 43 of file DedxCurSvc.h.

Referenced by DedxCurSvc(), and getDedxCurveInfo().

double DedxCurSvc::m_curve[50] [private]

Definition at line 38 of file DedxCurSvc.h.

Referenced by getCurve(), and getDedxCurveInfo().

int DedxCurSvc::m_curve_size [private]

Definition at line 40 of file DedxCurSvc.h.

Referenced by getCurveSize(), and getDedxCurveInfo().

std::string DedxCurSvc::m_dbStatus [private]

Definition at line 45 of file DedxCurSvc.h.

Referenced by DedxCurSvc(), and getDedxCurveInfo().

IDatabaseSvc* DedxCurSvc::m_dbsvc [private]

Definition at line 50 of file DedxCurSvc.h.

Referenced by getDedxCurveInfo(), and initialize().

IDataProviderSvc* DedxCurSvc::m_eventSvc [private]

Definition at line 49 of file DedxCurSvc.h.

Referenced by getDedxCurveInfo(), handle(), and initialize().

int DedxCurSvc::m_runFromMax [private]

Definition at line 52 of file DedxCurSvc.h.

Referenced by getDedxCurveInfo(), and initialize().

int DedxCurSvc::m_runToMin [private]

Definition at line 53 of file DedxCurSvc.h.

Referenced by getDedxCurveInfo(), and initialize().

std::string DedxCurSvc::m_sftver [private]

Definition at line 44 of file DedxCurSvc.h.

Referenced by DedxCurSvc(), and getDedxCurveInfo().

double DedxCurSvc::m_sigma[50] [private]

Definition at line 39 of file DedxCurSvc.h.

Referenced by getDedxCurveInfo(), and getSigma().

int DedxCurSvc::m_sigma_size [private]

Definition at line 41 of file DedxCurSvc.h.

Referenced by getDedxCurveInfo(), and getSigmaSize().

std::string DedxCurSvc::m_type [private]

Definition at line 46 of file DedxCurSvc.h.

Referenced by DedxCurSvc(), and getDedxCurveInfo().


Generated on Tue Nov 29 23:18:15 2016 for BOSS_7.0.2 by  doxygen 1.4.7