<commit_before>/*

 This macros setup the TPC calibration task AddTaskTPCCalib
 for CPass0.
 - the run number is required to config TPC OCDB

 The following calibration components are added to the AliTPCAnalysisTaskcalib task:
 1. AliTPCcalibCalib - redo reconstruction with current calibration
 2. AliTPCcalibTimeGain - TPC time dependent gain calibration
 3. AliTPCcalibTime - TPC time dependent drift time calibration

*/

// function to set TPC OCDB parameters
void ConfigOCDB(Int_t crun);

Int_t debugLevel=0;
Int_t streamLevel=0;

//_____________________________________________________________________________
AliAnalysisTask  *AddTaskTPCCalib(Int_t runNumber)
{
  //
  // add calibration task
  //
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskTPCCalib", "No analysis manager to connect to.");
    return NULL;
  }

  // check the input handler
  if (!mgr->GetInputEventHandler()) {
    ::Error("AddTaskTPCCalib", "This task requires an input event handler");
    return NULL;
  }

  // set TPC OCDB parameters
  ConfigOCDB(runNumber);

  // setup task TPCCalib
  TString outputFileName=mgr->GetCommonFileName();
  AliTPCAnalysisTaskcalib *task1=new AliTPCAnalysisTaskcalib("CalibObjectsTrain1");
  SetupCalibTaskTrain1(task1);
  mgr->AddTask(task1);
  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
  if (!cinput1) cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
                                      AliAnalysisManager::kInputContainer);
  for (Int_t i=0; i<task1->GetJobs()->GetEntries(); i++) {
    if (task1->GetJobs()->At(i)) {
      AliAnalysisDataContainer* coutput = mgr->CreateContainer(task1->GetJobs()->At(i)->GetName(),
                                                               AliTPCcalibBase::Class(),
                                                               AliAnalysisManager::kOutputContainer,
                                                               "AliESDfriends_v1.root:TPCCalib");
      mgr->ConnectOutput(task1,i,coutput);
    }
  }
  mgr->ConnectInput(task1,0,cinput1);
  //
  // setup task TPCAlign
  AliTPCAnalysisTaskcalib *taskAlign=new AliTPCAnalysisTaskcalib("CalibObjectsTrain1");
  SetupCalibTaskTrainAlign(taskAlign);
  mgr->AddTask(taskAlign);
  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
  if (!cinput1) cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
                                      AliAnalysisManager::kInputContainer);
  for (Int_t i=0; i<taskAlign->GetJobs()->GetEntries(); i++) {
    if (taskAlign->GetJobs()->At(i)) {
      AliAnalysisDataContainer* coutput = mgr->CreateContainer(taskAlign->GetJobs()->At(i)->GetName(),
                                                               AliTPCcalibBase::Class(),
                                                               AliAnalysisManager::kOutputContainer,
                                                               "AliESDfriends_v1.root:TPCAlign");
      mgr->ConnectOutput(taskAlign,i,coutput);
    }
  }
  mgr->ConnectInput(taskAlign,0,cinput1);
  //
  // setup task TPCCluster
  AliTPCAnalysisTaskcalib *taskCluster=new AliTPCAnalysisTaskcalib("CalibObjectsTrain1");
  SetupCalibTaskTrainCluster(taskCluster);
  mgr->AddTask(taskCluster);
  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
  if (!cinput1) cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
                                      AliAnalysisManager::kInputContainer);
  for (Int_t i=0; i<taskCluster->GetJobs()->GetEntries(); i++) {
    if (taskCluster->GetJobs()->At(i)) {
      AliAnalysisDataContainer* coutput = mgr->CreateContainer(taskCluster->GetJobs()->At(i)->GetName(),
                                                               AliTPCcalibBase::Class(),
                                                               AliAnalysisManager::kOutputContainer,
                                                               "AliESDfriends_v1.root:TPCCluster");
      mgr->ConnectOutput(taskCluster,i,coutput);
    }
  }
  mgr->ConnectInput(taskCluster,0,cinput1);
  //

  return task1;
}

//_____________________________________________________________________________
void AddCalibCalib(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  // calibCalib is a prefilter
  // The current OCDB entries transformation are applied on cluster, tracks are refitted
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibCalib *calibCalib = new AliTPCcalibCalib("calibTPC","calibTPC");
  calibCalib->SetDebugLevel(0);
  calibCalib->SetStreamLevel(0);
  calibCalib->SetTriggerMask(-1,-1,kFALSE);        //accept everything
  myTask->AddJob(calibCalib);
}

//_____________________________________________________________________________
void AddCalibTimeGain(TObject* task, Bool_t isCosmic = kFALSE, char * name = "calibTimeGain"){
  //
  //  Responsible: Alexander Kalweit
  //  Description: Time Gain calibration
  //

  // Set run time ranges (time stamps)
  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  if(!entry) {
    ::Error("AddCalibTimeGain","Cannot get AliCDBEntry");
    return;
  }
  const AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());
  if(!grpData) {
    ::Error("AddCalibTimeGain","Cannot get AliGRPObject");
    return;
  }
  time_t sTime = grpData->GetTimeStart();
  time_t eTime = grpData->GetTimeEnd();
  TTimeStamp startRunTime(sTime);
  TTimeStamp stopRunTime(eTime);

  UInt_t year;
  startRunTime.GetDate(kTRUE,0,&year);
  TTimeStamp startTime(year,1,1,0,0,0);
  TTimeStamp stopTime(year,12,31,23,59,59);

  //
  // setup calibration component
  //

  Bool_t useQmax = (grpData->GetBeamType()).Contains("Pb-Pb");

  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibTimeGain *calibTimeGain = new AliTPCcalibTimeGain(name,"calibTimeGain", startTime.GetSec(), stopTime.GetSec(), 10*60);
  calibTimeGain->SetIsCosmic(isCosmic);
  calibTimeGain->SetUseCookAnalytical(kTRUE);
  calibTimeGain->SetUseMax(useQmax);
  calibTimeGain->SetDebugLevel(0);
  calibTimeGain->SetStreamLevel(0);
  calibTimeGain->SetTriggerMask(-1,-1,kTRUE);        //reject laser
  calibTimeGain->SetLowerTrunc(0.02);
  calibTimeGain->SetUpperTrunc(0.6);

  myTask->AddJob(calibTimeGain);

  AliTPCcalibGainMult *calibGainMult = new AliTPCcalibGainMult("calibGainMult","calibGainMult");
  calibGainMult->SetUseMax(useQmax);
  calibGainMult->SetDebugLevel(0);
  calibGainMult->SetStreamLevel(0);
  calibGainMult->SetTriggerMask(-1,-1,kTRUE);        //reject laser
  calibGainMult->SetLowerTrunc(0.02);
  calibGainMult->SetUpperTrunc(0.6);

  myTask->AddJob(calibGainMult);

}

//_____________________________________________________________________________
void AddCalibTime(TObject* task){
  //
  // Responsible: Dag Larsen
  // Description: Time V drift calibration
  //

  // Set run time ranges (time stamps)
  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  if(!entry) {
    ::Error("AddCalibTime","Cannot get AliCDBEntry");
    return;
  }
  const AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());
  if(!grpData) {
    ::Error("AddCalibTime","Cannot get AliGRPObject");
    return;
  }
  time_t sTime = grpData->GetTimeStart();
  time_t eTime = grpData->GetTimeEnd();

  TTimeStamp startRunTime(sTime);
  TTimeStamp stopRunTime(eTime);

  UInt_t year;
  startRunTime.GetDate(kTRUE,0,&year);
  TTimeStamp startTime(year,1,1,0,0,0);
  TTimeStamp stopTime(year,12,31,23,59,59);

  //
  // setup calibration component
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibTime *calibTime = new AliTPCcalibTime("calibTime","calibTime",  startTime.GetSec(), stopTime.GetSec(), 10*60, 2);
  calibTime->SetDebugLevel(0);
  calibTime->SetStreamLevel(0);
  calibTime->SetTriggerMask(-1,-1,kFALSE);        //accept everything

  // max 15000 tracks per event
  calibTime->SetCutTracks(15000);

  myTask->AddJob(calibTime);
}

void AddCalibTracks(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  // Histogram residuals and pulls of the track parameters in bins of track parameters
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCClusterParam * clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();

   AliTPCcalibTracksCuts *cuts = new AliTPCcalibTracksCuts(30, 0.4, 5, 0.13, 0.018);
  //
  AliTPCcalibTracks *calibTracks =  new AliTPCcalibTracks("calibTracks", "Resolution calibration object for tracks", clusterParam, cuts);
  calibTracks->SetDebugLevel(debugLevel);
  calibTracks->SetStreamLevel(streamLevel);
  calibTracks->SetTriggerMask(-1,-1,kTRUE);
  myTask->AddJob(calibTracks);
}

void AddCalibAlign(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibAlign *calibAlign = new AliTPCcalibAlign("alignTPC","Alignment of the TPC sectors");
  calibAlign->SetDebugLevel(debugLevel);
  calibAlign->SetStreamLevel(streamLevel);
  calibAlign->SetTriggerMask(-1,-1,kTRUE);        //accept everything
  myTask->AddJob(calibAlign);
}

void AddCalibAlignInterpolation(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibAlignInterpolation *calibAlign = new AliTPCcalibAlignInterpolation("alignTPCInterpolation","Space point distortion calibration using interpolation",0);
  calibAlign->SetDebugLevel(debugLevel);
  calibAlign->SetStreamLevel(streamLevel);
  calibAlign->SetTriggerMask(-1,-1,kTRUE);        //accept everything
  myTask->AddJob(calibAlign);
}

void AddCalibLaser(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibLaser *calibLaser = new AliTPCcalibLaser("laserTPC","laserTPC");
  calibLaser->SetDebugLevel(debugLevel);
  calibLaser->SetStreamLevel(streamLevel);
  calibLaser->SetTriggerMask(-1,-1,kFALSE);        //accept everything
  myTask->AddJob(calibLaser);
}

void AddCalibCosmic(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  // Histogram residuals and pulls of the track parameters in bins of track parameters
  // Dump cosmic tracks to the tree
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibCosmic *calibCosmic = new AliTPCcalibCosmic("cosmicTPC","cosmicTPC");
  calibCosmic->SetDebugLevel(debugLevel);
  calibCosmic->SetStreamLevel(1);
  calibCosmic->SetTriggerMask(-1,-1,kTRUE);        //accept everything
  myTask->AddJob(calibCosmic);
}

//_____________________________________________________________________________
void SetupCalibTaskTrain1(TObject* task){
  //
  // Setup tasks for calibration train
  //
  AddCalibCalib(task);
  AddCalibTimeGain(task);
  AddCalibTime(task);
  AddCalibAlignInterpolation(task);
}

void SetupCalibTaskTrainAlign(TObject* task){
  //
  // Setup tasks for calibration train
  //
  AddCalibAlign(task);
  AddCalibLaser(task);
  //AddCalibCosmic(task);
}

void SetupCalibTaskTrainCluster(TObject* task){
  //
  // Setup tasks for calibration train
  //
  AddCalibTracks(task);
}

//_____________________________________________________________________________
void ConfigOCDB(Int_t run){
  //
  // Configure TPC OCDB
  //
  printf("SETUP OCBD for TPC\n");
  printf("SETUP OCBD for TPC\n");
  printf("SETUP OCBD for TPC Run =%d\n", run);
  //
  //
  AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
  param->ReadGeoMatrices();
  //
  AliMagF* magF= TGeoGlobalMagField::Instance()->GetField();
  printf("\n\nSET EXB FIELD\t\n\n");
  AliTPCcalibDB::Instance()->SetExBField(magF);
  //
  //
  //
  AliTPCTransform *transform     = AliTPCcalibDB::Instance()->GetTransform() ;
  //
  //AliTPCRecoParam * tpcRecoParam = AliTPCRecoParam::GetCosmicTestParam(kTRUE);
  //
  AliCDBEntry* entry = AliCDBManager::Instance()->Get("TPC/Calib/RecoParam");
  if (!entry){
    ::Error("AddTaskTPCCalib","TPC reco param not available");
    return;
  }
  TObjArray * array = (TObjArray*)entry->GetObject();
  if (!array){
    ::Error("AddTaskTPCCalib","TPC reco param not available");
    return;
  }

  //get the beam type from OCDB to decide which type of reco param we need -
  //high or low flux
  entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
  TString beamType = grpData->GetBeamType();
  if (beamType==AliGRPObject::GetInvalidString()) {
    ::Error("AddTaskTPCCalib","GRP/GRP/Data entry:  missing value for the beam type ! Using UNKNOWN");
    beamType = "UNKNOWN";
  }
  // 0 - Low Flux (pp), 1- High Flux (Pb-Pb)
  Int_t fluxType=0;
  if (beamType.Contains("p-p")) {fluxType=0;}
  if (beamType.Contains("A-A")) {fluxType=1;}
  AliTPCRecoParam * tpcRecoParam = (AliTPCRecoParam*)array->At(fluxType);
  ::Info("AddTaskTPCCalib","Beam type: %s, using fluxType=%i",beamType.Data(),fluxType);
  tpcRecoParam->Print();

  transform->SetCurrentRecoParam(tpcRecoParam);
  tpcRecoParam->SetUseGainCorrectionTime(0);
  tpcRecoParam->SetUseRPHICorrection(kFALSE);
  tpcRecoParam->SetUseTOFCorrection(kFALSE);
  //
  tpcRecoParam->SetUseDriftCorrectionTime(0);
  tpcRecoParam->SetUseDriftCorrectionGY(0);
  //
  tpcRecoParam->SetUseRadialCorrection(kFALSE);
  tpcRecoParam->SetUseQuadrantAlignment(kFALSE);
  //
  tpcRecoParam->SetUseSectorAlignment(kFALSE);
  tpcRecoParam->SetUseFieldCorrection(kFALSE);
  tpcRecoParam->SetUseExBCorrection(kFALSE);
  //
  tpcRecoParam->SetUseMultiplicityCorrectionDedx(kFALSE);
  tpcRecoParam->SetUseAlignmentTime(kFALSE);
  tpcRecoParam->SetUseComposedCorrection(kTRUE);
  //
  tpcRecoParam->SetCorrectionHVandPTMode(1);

  AliTPCcalibDB::Instance()->SetRun(run);
}
<commit_msg>ATO-108 - switch OFF default space point calibration in the CPass0 calibration. This step invalidates standard calibration pass<commit_after>/*

 This macros setup the TPC calibration task AddTaskTPCCalib
 for CPass0.
 - the run number is required to config TPC OCDB

 The following calibration components are added to the AliTPCAnalysisTaskcalib task:
 1. AliTPCcalibCalib - redo reconstruction with current calibration
 2. AliTPCcalibTimeGain - TPC time dependent gain calibration
 3. AliTPCcalibTime - TPC time dependent drift time calibration

*/

// function to set TPC OCDB parameters
void ConfigOCDB(Int_t crun);

Int_t debugLevel=0;
Int_t streamLevel=0;

//_____________________________________________________________________________
AliAnalysisTask  *AddTaskTPCCalib(Int_t runNumber)
{
  //
  // add calibration task
  //
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskTPCCalib", "No analysis manager to connect to.");
    return NULL;
  }

  // check the input handler
  if (!mgr->GetInputEventHandler()) {
    ::Error("AddTaskTPCCalib", "This task requires an input event handler");
    return NULL;
  }

  // set TPC OCDB parameters
  ConfigOCDB(runNumber);

  // setup task TPCCalib
  TString outputFileName=mgr->GetCommonFileName();
  AliTPCAnalysisTaskcalib *task1=new AliTPCAnalysisTaskcalib("CalibObjectsTrain1");
  SetupCalibTaskTrain1(task1);
  mgr->AddTask(task1);
  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
  if (!cinput1) cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
                                      AliAnalysisManager::kInputContainer);
  for (Int_t i=0; i<task1->GetJobs()->GetEntries(); i++) {
    if (task1->GetJobs()->At(i)) {
      AliAnalysisDataContainer* coutput = mgr->CreateContainer(task1->GetJobs()->At(i)->GetName(),
                                                               AliTPCcalibBase::Class(),
                                                               AliAnalysisManager::kOutputContainer,
                                                               "AliESDfriends_v1.root:TPCCalib");
      mgr->ConnectOutput(task1,i,coutput);
    }
  }
  mgr->ConnectInput(task1,0,cinput1);
  //
  // setup task TPCAlign
  AliTPCAnalysisTaskcalib *taskAlign=new AliTPCAnalysisTaskcalib("CalibObjectsTrain1");
  SetupCalibTaskTrainAlign(taskAlign);
  mgr->AddTask(taskAlign);
  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
  if (!cinput1) cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
                                      AliAnalysisManager::kInputContainer);
  for (Int_t i=0; i<taskAlign->GetJobs()->GetEntries(); i++) {
    if (taskAlign->GetJobs()->At(i)) {
      AliAnalysisDataContainer* coutput = mgr->CreateContainer(taskAlign->GetJobs()->At(i)->GetName(),
                                                               AliTPCcalibBase::Class(),
                                                               AliAnalysisManager::kOutputContainer,
                                                               "AliESDfriends_v1.root:TPCAlign");
      mgr->ConnectOutput(taskAlign,i,coutput);
    }
  }
  mgr->ConnectInput(taskAlign,0,cinput1);
  //
  // setup task TPCCluster
  AliTPCAnalysisTaskcalib *taskCluster=new AliTPCAnalysisTaskcalib("CalibObjectsTrain1");
  SetupCalibTaskTrainCluster(taskCluster);
  mgr->AddTask(taskCluster);
  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
  if (!cinput1) cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
                                      AliAnalysisManager::kInputContainer);
  for (Int_t i=0; i<taskCluster->GetJobs()->GetEntries(); i++) {
    if (taskCluster->GetJobs()->At(i)) {
      AliAnalysisDataContainer* coutput = mgr->CreateContainer(taskCluster->GetJobs()->At(i)->GetName(),
                                                               AliTPCcalibBase::Class(),
                                                               AliAnalysisManager::kOutputContainer,
                                                               "AliESDfriends_v1.root:TPCCluster");
      mgr->ConnectOutput(taskCluster,i,coutput);
    }
  }
  mgr->ConnectInput(taskCluster,0,cinput1);
  //

  return task1;
}

//_____________________________________________________________________________
void AddCalibCalib(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  // calibCalib is a prefilter
  // The current OCDB entries transformation are applied on cluster, tracks are refitted
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibCalib *calibCalib = new AliTPCcalibCalib("calibTPC","calibTPC");
  calibCalib->SetDebugLevel(0);
  calibCalib->SetStreamLevel(0);
  calibCalib->SetTriggerMask(-1,-1,kFALSE);        //accept everything
  myTask->AddJob(calibCalib);
}

//_____________________________________________________________________________
void AddCalibTimeGain(TObject* task, Bool_t isCosmic = kFALSE, char * name = "calibTimeGain"){
  //
  //  Responsible: Alexander Kalweit
  //  Description: Time Gain calibration
  //

  // Set run time ranges (time stamps)
  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  if(!entry) {
    ::Error("AddCalibTimeGain","Cannot get AliCDBEntry");
    return;
  }
  const AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());
  if(!grpData) {
    ::Error("AddCalibTimeGain","Cannot get AliGRPObject");
    return;
  }
  time_t sTime = grpData->GetTimeStart();
  time_t eTime = grpData->GetTimeEnd();
  TTimeStamp startRunTime(sTime);
  TTimeStamp stopRunTime(eTime);

  UInt_t year;
  startRunTime.GetDate(kTRUE,0,&year);
  TTimeStamp startTime(year,1,1,0,0,0);
  TTimeStamp stopTime(year,12,31,23,59,59);

  //
  // setup calibration component
  //

  Bool_t useQmax = (grpData->GetBeamType()).Contains("Pb-Pb");

  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibTimeGain *calibTimeGain = new AliTPCcalibTimeGain(name,"calibTimeGain", startTime.GetSec(), stopTime.GetSec(), 10*60);
  calibTimeGain->SetIsCosmic(isCosmic);
  calibTimeGain->SetUseCookAnalytical(kTRUE);
  calibTimeGain->SetUseMax(useQmax);
  calibTimeGain->SetDebugLevel(0);
  calibTimeGain->SetStreamLevel(0);
  calibTimeGain->SetTriggerMask(-1,-1,kTRUE);        //reject laser
  calibTimeGain->SetLowerTrunc(0.02);
  calibTimeGain->SetUpperTrunc(0.6);

  myTask->AddJob(calibTimeGain);

  AliTPCcalibGainMult *calibGainMult = new AliTPCcalibGainMult("calibGainMult","calibGainMult");
  calibGainMult->SetUseMax(useQmax);
  calibGainMult->SetDebugLevel(0);
  calibGainMult->SetStreamLevel(0);
  calibGainMult->SetTriggerMask(-1,-1,kTRUE);        //reject laser
  calibGainMult->SetLowerTrunc(0.02);
  calibGainMult->SetUpperTrunc(0.6);

  myTask->AddJob(calibGainMult);

}

//_____________________________________________________________________________
void AddCalibTime(TObject* task){
  //
  // Responsible: Dag Larsen
  // Description: Time V drift calibration
  //

  // Set run time ranges (time stamps)
  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  if(!entry) {
    ::Error("AddCalibTime","Cannot get AliCDBEntry");
    return;
  }
  const AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());
  if(!grpData) {
    ::Error("AddCalibTime","Cannot get AliGRPObject");
    return;
  }
  time_t sTime = grpData->GetTimeStart();
  time_t eTime = grpData->GetTimeEnd();

  TTimeStamp startRunTime(sTime);
  TTimeStamp stopRunTime(eTime);

  UInt_t year;
  startRunTime.GetDate(kTRUE,0,&year);
  TTimeStamp startTime(year,1,1,0,0,0);
  TTimeStamp stopTime(year,12,31,23,59,59);

  //
  // setup calibration component
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibTime *calibTime = new AliTPCcalibTime("calibTime","calibTime",  startTime.GetSec(), stopTime.GetSec(), 10*60, 2);
  calibTime->SetDebugLevel(0);
  calibTime->SetStreamLevel(0);
  calibTime->SetTriggerMask(-1,-1,kFALSE);        //accept everything

  // max 15000 tracks per event
  calibTime->SetCutTracks(15000);

  myTask->AddJob(calibTime);
}

void AddCalibTracks(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  // Histogram residuals and pulls of the track parameters in bins of track parameters
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCClusterParam * clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();

   AliTPCcalibTracksCuts *cuts = new AliTPCcalibTracksCuts(30, 0.4, 5, 0.13, 0.018);
  //
  AliTPCcalibTracks *calibTracks =  new AliTPCcalibTracks("calibTracks", "Resolution calibration object for tracks", clusterParam, cuts);
  calibTracks->SetDebugLevel(debugLevel);
  calibTracks->SetStreamLevel(streamLevel);
  calibTracks->SetTriggerMask(-1,-1,kTRUE);
  myTask->AddJob(calibTracks);
}

void AddCalibAlign(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibAlign *calibAlign = new AliTPCcalibAlign("alignTPC","Alignment of the TPC sectors");
  calibAlign->SetDebugLevel(debugLevel);
  calibAlign->SetStreamLevel(streamLevel);
  calibAlign->SetTriggerMask(-1,-1,kTRUE);        //accept everything
  myTask->AddJob(calibAlign);
}

void AddCalibAlignInterpolation(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibAlignInterpolation *calibAlign = new AliTPCcalibAlignInterpolation("alignTPCInterpolation","Space point distortion calibration using interpolation",0);
  calibAlign->SetDebugLevel(debugLevel);
  calibAlign->SetStreamLevel(streamLevel);
  calibAlign->SetTriggerMask(-1,-1,kTRUE);        //accept everything
  myTask->AddJob(calibAlign);
}

void AddCalibLaser(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibLaser *calibLaser = new AliTPCcalibLaser("laserTPC","laserTPC");
  calibLaser->SetDebugLevel(debugLevel);
  calibLaser->SetStreamLevel(streamLevel);
  calibLaser->SetTriggerMask(-1,-1,kFALSE);        //accept everything
  myTask->AddJob(calibLaser);
}

void AddCalibCosmic(TObject* task){
  //
  // Responsible: Marian Ivanov
  // Description:
  // Histogram residuals and pulls of the track parameters in bins of track parameters
  // Dump cosmic tracks to the tree
  //
  AliTPCAnalysisTaskcalib* myTask = (AliTPCAnalysisTaskcalib*) task;
  AliTPCcalibCosmic *calibCosmic = new AliTPCcalibCosmic("cosmicTPC","cosmicTPC");
  calibCosmic->SetDebugLevel(debugLevel);
  calibCosmic->SetStreamLevel(1);
  calibCosmic->SetTriggerMask(-1,-1,kTRUE);        //accept everything
  myTask->AddJob(calibCosmic);
}

//_____________________________________________________________________________
void SetupCalibTaskTrain1(TObject* task){
  //
  // Setup tasks for calibration train
  //
  AddCalibCalib(task);
  AddCalibTimeGain(task);
  AddCalibTime(task);
  AddCalibAlignInterpolation(task);
}

void SetupCalibTaskTrainAlign(TObject* task){
  //
  // Setup tasks for calibration train
  //
  AddCalibAlign(task);
  AddCalibLaser(task);
  //AddCalibCosmic(task);
}

void SetupCalibTaskTrainCluster(TObject* task){
  //
  // Setup tasks for calibration train
  //
  AddCalibTracks(task);
}

//_____________________________________________________________________________
void ConfigOCDB(Int_t run){
  //
  // Configure TPC OCDB
  //
  printf("SETUP OCBD for TPC\n");
  printf("SETUP OCBD for TPC\n");
  printf("SETUP OCBD for TPC Run =%d\n", run);
  //
  //
  AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
  param->ReadGeoMatrices();
  //
  AliMagF* magF= TGeoGlobalMagField::Instance()->GetField();
  printf("\n\nSET EXB FIELD\t\n\n");
  AliTPCcalibDB::Instance()->SetExBField(magF);
  //
  //
  //
  AliTPCTransform *transform     = AliTPCcalibDB::Instance()->GetTransform() ;
  //
  //AliTPCRecoParam * tpcRecoParam = AliTPCRecoParam::GetCosmicTestParam(kTRUE);
  //
  AliCDBEntry* entry = AliCDBManager::Instance()->Get("TPC/Calib/RecoParam");
  if (!entry){
    ::Error("AddTaskTPCCalib","TPC reco param not available");
    return;
  }
  TObjArray * array = (TObjArray*)entry->GetObject();
  if (!array){
    ::Error("AddTaskTPCCalib","TPC reco param not available");
    return;
  }

  //get the beam type from OCDB to decide which type of reco param we need -
  //high or low flux
  entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
  TString beamType = grpData->GetBeamType();
  if (beamType==AliGRPObject::GetInvalidString()) {
    ::Error("AddTaskTPCCalib","GRP/GRP/Data entry:  missing value for the beam type ! Using UNKNOWN");
    beamType = "UNKNOWN";
  }
  // 0 - Low Flux (pp), 1- High Flux (Pb-Pb)
  Int_t fluxType=0;
  if (beamType.Contains("p-p")) {fluxType=0;}
  if (beamType.Contains("A-A")) {fluxType=1;}
  AliTPCRecoParam * tpcRecoParam = (AliTPCRecoParam*)array->At(fluxType);
  ::Info("AddTaskTPCCalib","Beam type: %s, using fluxType=%i",beamType.Data(),fluxType);
  tpcRecoParam->Print();

  transform->SetCurrentRecoParam(tpcRecoParam);
  tpcRecoParam->SetUseGainCorrectionTime(0);
  tpcRecoParam->SetUseRPHICorrection(kFALSE);
  tpcRecoParam->SetUseTOFCorrection(kFALSE);
  //
  tpcRecoParam->SetUseDriftCorrectionTime(0);
  tpcRecoParam->SetUseDriftCorrectionGY(0);
  //
  tpcRecoParam->SetUseRadialCorrection(kFALSE);
  tpcRecoParam->SetUseQuadrantAlignment(kFALSE);
  //
  tpcRecoParam->SetUseSectorAlignment(kFALSE);
  tpcRecoParam->SetUseFieldCorrection(kFALSE);
  tpcRecoParam->SetUseExBCorrection(kFALSE);
  //
  tpcRecoParam->SetUseMultiplicityCorrectionDedx(kFALSE);
  tpcRecoParam->SetUseAlignmentTime(kFALSE);
  tpcRecoParam->SetUseComposedCorrection(kFALSE);
  //
  tpcRecoParam->SetCorrectionHVandPTMode(1);

  AliTPCcalibDB::Instance()->SetRun(run);
}
<|endoftext|>


<commit_before>/****************************************************************************
 *
 *   Copyright (c) 2017 PX4 Development Team. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name PX4 nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ****************************************************************************/

#ifndef COMMANDER_HPP_
#define COMMANDER_HPP_

#include <controllib/blocks.hpp>
#include <px4_module.h>

// publications
#include <uORB/Publication.hpp>
#include <uORB/topics/actuator_armed.h>
#include <uORB/topics/home_position.h>
#include <uORB/topics/vehicle_command_ack.h>
#include <uORB/topics/vehicle_control_mode.h>
#include <uORB/topics/vehicle_status.h>
#include <uORB/topics/vehicle_status_flags.h>

// subscriptions
#include <uORB/Subscription.hpp>
#include <uORB/topics/geofence_result.h>
#include <uORB/topics/mission_result.h>
#include <uORB/topics/safety.h>
#include <uORB/topics/vehicle_command.h>
#include <uORB/topics/vehicle_global_position.h>
#include <uORB/topics/vehicle_local_position.h>

using control::BlockParamFloat;
using control::BlockParamInt;
using uORB::Publication;
using uORB::Subscription;

class Commander : public control::SuperBlock, public ModuleBase<Commander>
{
public:
	Commander() :
		SuperBlock(nullptr, "COM"),
		_mission_result_sub(ORB_ID(mission_result), 0, 0, &getSubscriptions())
	{
		updateParams();
	}

	/** @see ModuleBase */
	static int task_spawn(int argc, char *argv[]);

	/** @see ModuleBase */
	static Commander *instantiate(int argc, char *argv[]);

	/** @see ModuleBase */
	static int custom_command(int argc, char *argv[]);

	/** @see ModuleBase */
	static int print_usage(const char *reason = nullptr);

	/** @see ModuleBase::run() */
	void run() override;

	void enable_hil();

private:

	// Subscriptions
	Subscription<mission_result_s> _mission_result_sub;

	bool handle_command(vehicle_status_s *status, const safety_s *safety, vehicle_command_s *cmd,
			    actuator_armed_s *armed, home_position_s *home, vehicle_global_position_s *global_pos,
			    vehicle_local_position_s *local_pos, orb_advert_t *home_pub,
			    orb_advert_t *command_ack_pub, bool *changed);

	bool set_home_position(orb_advert_t &homePub, home_position_s &home,
				const vehicle_local_position_s &localPosition, const vehicle_global_position_s &globalPosition,
				bool set_alt_only_to_lpos_ref);

	void mission_init();

};

#endif /* COMMANDER_HPP_ */
<commit_msg>Commander.hpp: remove usage of BlockParam & SuperBlock<commit_after>/****************************************************************************
 *
 *   Copyright (c) 2017 PX4 Development Team. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name PX4 nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ****************************************************************************/

#ifndef COMMANDER_HPP_
#define COMMANDER_HPP_

#include <controllib/blocks.hpp>
#include <px4_module.h>
#include <px4_module_params.h>

// publications
#include <uORB/Publication.hpp>
#include <uORB/topics/actuator_armed.h>
#include <uORB/topics/home_position.h>
#include <uORB/topics/vehicle_command_ack.h>
#include <uORB/topics/vehicle_control_mode.h>
#include <uORB/topics/vehicle_status.h>
#include <uORB/topics/vehicle_status_flags.h>

// subscriptions
#include <uORB/Subscription.hpp>
#include <uORB/topics/geofence_result.h>
#include <uORB/topics/mission_result.h>
#include <uORB/topics/safety.h>
#include <uORB/topics/vehicle_command.h>
#include <uORB/topics/vehicle_global_position.h>
#include <uORB/topics/vehicle_local_position.h>

using uORB::Publication;
using uORB::Subscription;

class Commander : public ModuleBase<Commander>, public ModuleParams
{
public:
	Commander() :
		ModuleParams(nullptr),
		_mission_result_sub(ORB_ID(mission_result))
	{
	}

	/** @see ModuleBase */
	static int task_spawn(int argc, char *argv[]);

	/** @see ModuleBase */
	static Commander *instantiate(int argc, char *argv[]);

	/** @see ModuleBase */
	static int custom_command(int argc, char *argv[]);

	/** @see ModuleBase */
	static int print_usage(const char *reason = nullptr);

	/** @see ModuleBase::run() */
	void run() override;

	void enable_hil();

private:

	// Subscriptions
	Subscription<mission_result_s> _mission_result_sub;

	bool handle_command(vehicle_status_s *status, const safety_s *safety, vehicle_command_s *cmd,
			    actuator_armed_s *armed, home_position_s *home, vehicle_global_position_s *global_pos,
			    vehicle_local_position_s *local_pos, orb_advert_t *home_pub,
			    orb_advert_t *command_ack_pub, bool *changed);

	bool set_home_position(orb_advert_t &homePub, home_position_s &home,
				const vehicle_local_position_s &localPosition, const vehicle_global_position_s &globalPosition,
				bool set_alt_only_to_lpos_ref);

	void mission_init();

};

#endif /* COMMANDER_HPP_ */
<|endoftext|>


<commit_before>/*
  Copyright (C) 2007 by Jorrit Tyberghein

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "cssysdef.h"
#include "csgeom/sphere.h"
#include "cstool/rviewclipper.h"
#include "ivideo/graph3d.h"
#include "iengine/rview.h"
#include "iengine/camera.h"
#include <ctype.h>

namespace CS
{
  void RenderViewClipper::TestSphereFrustumWorld (
    csRenderContext *ctxt,
    const csVector3 &center,
    float radius,
    bool &inside,
    bool &outside)
  {
    float dist;
    csPlane3 *frust = ctxt->clip_planes;
    outside = true;
    inside = true;

    dist = frust[0].Classify (center);
    if (dist < radius) inside = false;
    if ((-dist) <= radius)
    {
      dist = frust[1].Classify (center);
      if (dist < radius) inside = false;
      if ((-dist) <= radius)
      {
        dist = frust[2].Classify (center);
        if (dist < radius) inside = false;
        if ((-dist) <= radius)
        {
          dist = frust[3].Classify (center);
          if (dist < radius) inside = false;
          if ((-dist) <= radius) outside = false;
        }
      }
    }
  }

  void RenderViewClipper::CalculateClipSettings (
      csRenderContext* ctxt,
      uint32 frustum_mask,
      int &clip_portal, int &clip_plane, int &clip_z_plane)
  {
    if (frustum_mask & 0xf)
      clip_portal = CS_CLIP_NEEDED;
    else
      clip_portal = CS_CLIP_NOT;

    if (frustum_mask & 0x10)
      clip_z_plane = CS_CLIP_NEEDED;
    else
      clip_z_plane = CS_CLIP_NOT;

    // Only if we really need an exact clip plane will we set clip_plane
    // to needed (depending on frustum mask).
    if ((frustum_mask & 0x20) && ctxt->do_clip_plane)
      clip_plane = CS_CLIP_NEEDED;
    else
      clip_plane = CS_CLIP_NOT;
  }

  bool RenderViewClipper::TestBSphere (
    csRenderContext* ctxt,
    const csReversibleTransform &w2c,
    const csSphere &sphere)
  {
    //------
    // First transform bounding sphere from object space to camera space
    // by using the given transform (if needed).
    //------
    csSphere tr_sphere = w2c.Other2This (sphere);
    const csVector3 &tr_center = tr_sphere.GetCenter ();
    float radius = tr_sphere.GetRadius ();

    //------
    // Test if object is behind the camera plane.
    //------
    if (tr_center.z + radius <= 0) return false;

    //------
    // Test against far plane if needed.
    //------
    csPlane3 *far_plane = ctxt->icamera->GetFarPlane ();
    if (far_plane)
    {
      // Ok, so this is not really far plane clipping - we just dont draw this
      // object if the bounding sphere is further away than the D
      // part of the farplane.
      if (tr_center.z - radius > far_plane->D ()) return false;
    }

    //------
    // Check if we're fully inside the bounding sphere.
    //------
    bool fully_inside = csSquaredDist::PointPoint (
        csVector3 (0),
        tr_center) <= radius *
      radius;

    //------
    // Test if there is a chance we must clip to current portal.
    //------
    bool outside, inside;
    if (!fully_inside)
    {
      TestSphereFrustumWorld (
        ctxt,
        sphere.GetCenter (),
        radius,
        inside,
        outside);
      if (outside) return false;
    }

    //------
    // Test if there is a chance we must clip to current plane.
    //------
    if (ctxt->do_clip_plane)
    {
      //bool mirror = GetCamera ()->IsMirrored ();
      float dist = ctxt->clip_plane.Classify (tr_center);
      dist = -dist;
      if ((-dist) > radius) return false;
    }

    return true;
  }

  bool RenderViewClipper::CullBSphere (
    csRenderContext* ctxt,
    const csSphere &cam_sphere,
    const csSphere &world_sphere,
    int &clip_portal,
    int &clip_plane,
    int &clip_z_plane)
  {
    float radius = cam_sphere.GetRadius ();
    float cam_z = cam_sphere.GetCenter ().z;

    //------
    // Test if object is behind the camera plane.
    //------
    if (cam_z + radius <= 0) return false;

    //------
    // Test against far plane if needed.
    //------
    csPlane3 *far_plane = ctxt->icamera->GetFarPlane ();
    if (far_plane)
    {
      // Ok, so this is not really far plane clipping - we just dont draw this
      // object if the bounding sphere is further away than the D
      // part of the farplane.
      if (cam_z - radius > far_plane->D ()) return false;
    }

    //------
    // Check if we're fully inside the bounding sphere.
    //------
    bool fully_inside = csSquaredDist::PointPoint (
          csVector3 (0), cam_sphere.GetCenter ()) <= radius * radius;

    //------
    // Test if there is a chance we must clip to current portal.
    //------
    bool outside, inside;
    if (fully_inside)
    {
      clip_portal = CS_CLIP_NEEDED;
    }
    else
    {
      TestSphereFrustumWorld (
        ctxt,
        world_sphere.GetCenter (),
        radius,
        inside,
        outside);
      if (outside)
        return false;
      if (!inside)
        clip_portal = CS_CLIP_NEEDED;
      else
        clip_portal = CS_CLIP_NOT;
    }

    //------
    // Test if there is a chance we must clip to the z-plane.
    //------
    if (cam_z - radius > 0)
      clip_z_plane = CS_CLIP_NOT;
    else
      clip_z_plane = CS_CLIP_NEEDED;

    //------
    // Test if there is a chance we must clip to current plane.
    //------
    clip_plane = CS_CLIP_NOT;
    if (ctxt->do_clip_plane)
    {
      float dist = ctxt->clip_plane.Classify (cam_sphere.GetCenter ());
      dist = -dist;
      if ((-dist) > radius)
        return false;
      else if (dist <= radius)
        clip_plane = CS_CLIP_NEEDED;
    }

    return true;
  }

  bool RenderViewClipper::CullBBox (
    const csRenderContext* ctxt,
    const csPlane3* planes,
    uint32& frustum_mask,
    const csBox3 &obox,
    int &clip_portal,
    int &clip_plane,
    int &clip_z_plane)
  {
    uint32 outClipMask;
    if (!csIntersect3::BoxFrustum (obox, planes, frustum_mask, outClipMask))
      return false;	// Not visible.
    frustum_mask = outClipMask;

    if (outClipMask & 0xf)
      clip_portal = CS_CLIP_NEEDED;
    else
      clip_portal = CS_CLIP_NOT;

    if (outClipMask & 0x10)
      clip_z_plane = CS_CLIP_NEEDED;
    else
      clip_z_plane = CS_CLIP_NOT;

    // Only if we really need an exact clip plane will we set clip_plane
    // to needed (depending on frustum mask).
    if (ctxt->do_clip_plane && (outClipMask & 0x20))
      clip_plane = CS_CLIP_NEEDED;
    else
      clip_plane = CS_CLIP_NOT;

    return true;
  }

  void RenderViewClipper::SetupClipPlanes (
      csRenderContext* ctxt,
      const csReversibleTransform& tr_o2c,
      csPlane3* planes, uint32& frustum_mask)
  {
    csMatrix3 t2o = tr_o2c.GetT2O();
    csVector3 o2tmult = tr_o2c.GetO2T () * tr_o2c.GetO2TTranslation ();
    uint32 camMask;
    const csPlane3* frust = ctxt->icamera->GetVisibleVolume (camMask);
    frustum_mask = 0;
    uint i;
    for (i = 0; (1 << i) <= camMask; i++)
    {
      if (!(camMask & (1 << i))) continue;
      frustum_mask |= (1 << i);
      planes[i].Set (tr_o2c.GetT2O() * frust[i].norm, -frust[i].norm*o2tmult);
    }
    csPlane3 pznear = ctxt->clip_plane;
    pznear.Invert ();
    planes[i] = tr_o2c.This2Other (pznear);
    frustum_mask |= (1 << i);
  }

  void RenderViewClipper::SetupClipPlanes (csRenderContext* ctxt)
  {
    SetupClipPlanes (ctxt, ctxt->icamera->GetTransform (), ctxt->clip_planes,
      ctxt->clip_planes_mask);
  }

}

<commit_msg>Correct plane transformation in RenderViewClipper::SetupClipPlanes()<commit_after>/*
  Copyright (C) 2007 by Jorrit Tyberghein

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "cssysdef.h"
#include "csgeom/sphere.h"
#include "cstool/rviewclipper.h"
#include "ivideo/graph3d.h"
#include "iengine/rview.h"
#include "iengine/camera.h"
#include <ctype.h>

namespace CS
{
  void RenderViewClipper::TestSphereFrustumWorld (
    csRenderContext *ctxt,
    const csVector3 &center,
    float radius,
    bool &inside,
    bool &outside)
  {
    float dist;
    csPlane3 *frust = ctxt->clip_planes;
    outside = true;
    inside = true;

    dist = frust[0].Classify (center);
    if (dist < radius) inside = false;
    if ((-dist) <= radius)
    {
      dist = frust[1].Classify (center);
      if (dist < radius) inside = false;
      if ((-dist) <= radius)
      {
        dist = frust[2].Classify (center);
        if (dist < radius) inside = false;
        if ((-dist) <= radius)
        {
          dist = frust[3].Classify (center);
          if (dist < radius) inside = false;
          if ((-dist) <= radius) outside = false;
        }
      }
    }
  }

  void RenderViewClipper::CalculateClipSettings (
      csRenderContext* ctxt,
      uint32 frustum_mask,
      int &clip_portal, int &clip_plane, int &clip_z_plane)
  {
    if (frustum_mask & 0xf)
      clip_portal = CS_CLIP_NEEDED;
    else
      clip_portal = CS_CLIP_NOT;

    if (frustum_mask & 0x10)
      clip_z_plane = CS_CLIP_NEEDED;
    else
      clip_z_plane = CS_CLIP_NOT;

    // Only if we really need an exact clip plane will we set clip_plane
    // to needed (depending on frustum mask).
    if ((frustum_mask & 0x20) && ctxt->do_clip_plane)
      clip_plane = CS_CLIP_NEEDED;
    else
      clip_plane = CS_CLIP_NOT;
  }

  bool RenderViewClipper::TestBSphere (
    csRenderContext* ctxt,
    const csReversibleTransform &w2c,
    const csSphere &sphere)
  {
    //------
    // First transform bounding sphere from object space to camera space
    // by using the given transform (if needed).
    //------
    csSphere tr_sphere = w2c.Other2This (sphere);
    const csVector3 &tr_center = tr_sphere.GetCenter ();
    float radius = tr_sphere.GetRadius ();

    //------
    // Test if object is behind the camera plane.
    //------
    if (tr_center.z + radius <= 0) return false;

    //------
    // Test against far plane if needed.
    //------
    csPlane3 *far_plane = ctxt->icamera->GetFarPlane ();
    if (far_plane)
    {
      // Ok, so this is not really far plane clipping - we just dont draw this
      // object if the bounding sphere is further away than the D
      // part of the farplane.
      if (tr_center.z - radius > far_plane->D ()) return false;
    }

    //------
    // Check if we're fully inside the bounding sphere.
    //------
    bool fully_inside = csSquaredDist::PointPoint (
        csVector3 (0),
        tr_center) <= radius *
      radius;

    //------
    // Test if there is a chance we must clip to current portal.
    //------
    bool outside, inside;
    if (!fully_inside)
    {
      TestSphereFrustumWorld (
        ctxt,
        sphere.GetCenter (),
        radius,
        inside,
        outside);
      if (outside) return false;
    }

    //------
    // Test if there is a chance we must clip to current plane.
    //------
    if (ctxt->do_clip_plane)
    {
      //bool mirror = GetCamera ()->IsMirrored ();
      float dist = ctxt->clip_plane.Classify (tr_center);
      dist = -dist;
      if ((-dist) > radius) return false;
    }

    return true;
  }

  bool RenderViewClipper::CullBSphere (
    csRenderContext* ctxt,
    const csSphere &cam_sphere,
    const csSphere &world_sphere,
    int &clip_portal,
    int &clip_plane,
    int &clip_z_plane)
  {
    float radius = cam_sphere.GetRadius ();
    float cam_z = cam_sphere.GetCenter ().z;

    //------
    // Test if object is behind the camera plane.
    //------
    if (cam_z + radius <= 0) return false;

    //------
    // Test against far plane if needed.
    //------
    csPlane3 *far_plane = ctxt->icamera->GetFarPlane ();
    if (far_plane)
    {
      // Ok, so this is not really far plane clipping - we just dont draw this
      // object if the bounding sphere is further away than the D
      // part of the farplane.
      if (cam_z - radius > far_plane->D ()) return false;
    }

    //------
    // Check if we're fully inside the bounding sphere.
    //------
    bool fully_inside = csSquaredDist::PointPoint (
          csVector3 (0), cam_sphere.GetCenter ()) <= radius * radius;

    //------
    // Test if there is a chance we must clip to current portal.
    //------
    bool outside, inside;
    if (fully_inside)
    {
      clip_portal = CS_CLIP_NEEDED;
    }
    else
    {
      TestSphereFrustumWorld (
        ctxt,
        world_sphere.GetCenter (),
        radius,
        inside,
        outside);
      if (outside)
        return false;
      if (!inside)
        clip_portal = CS_CLIP_NEEDED;
      else
        clip_portal = CS_CLIP_NOT;
    }

    //------
    // Test if there is a chance we must clip to the z-plane.
    //------
    if (cam_z - radius > 0)
      clip_z_plane = CS_CLIP_NOT;
    else
      clip_z_plane = CS_CLIP_NEEDED;

    //------
    // Test if there is a chance we must clip to current plane.
    //------
    clip_plane = CS_CLIP_NOT;
    if (ctxt->do_clip_plane)
    {
      float dist = ctxt->clip_plane.Classify (cam_sphere.GetCenter ());
      dist = -dist;
      if ((-dist) > radius)
        return false;
      else if (dist <= radius)
        clip_plane = CS_CLIP_NEEDED;
    }

    return true;
  }

  bool RenderViewClipper::CullBBox (
    const csRenderContext* ctxt,
    const csPlane3* planes,
    uint32& frustum_mask,
    const csBox3 &obox,
    int &clip_portal,
    int &clip_plane,
    int &clip_z_plane)
  {
    uint32 outClipMask;
    if (!csIntersect3::BoxFrustum (obox, planes, frustum_mask, outClipMask))
      return false;	// Not visible.
    frustum_mask = outClipMask;

    if (outClipMask & 0xf)
      clip_portal = CS_CLIP_NEEDED;
    else
      clip_portal = CS_CLIP_NOT;

    if (outClipMask & 0x10)
      clip_z_plane = CS_CLIP_NEEDED;
    else
      clip_z_plane = CS_CLIP_NOT;

    // Only if we really need an exact clip plane will we set clip_plane
    // to needed (depending on frustum mask).
    if (ctxt->do_clip_plane && (outClipMask & 0x20))
      clip_plane = CS_CLIP_NEEDED;
    else
      clip_plane = CS_CLIP_NOT;

    return true;
  }

  void RenderViewClipper::SetupClipPlanes (
      csRenderContext* ctxt,
      const csReversibleTransform& tr_o2c,
      csPlane3* planes, uint32& frustum_mask)
  {
    csMatrix3 t2o = tr_o2c.GetT2O();
    csVector3 o2tmult = tr_o2c.GetO2T () * tr_o2c.GetO2TTranslation ();
    uint32 camMask;
    const csPlane3* frust = ctxt->icamera->GetVisibleVolume (camMask);
    frustum_mask = 0;
    uint i;
    for (i = 0; (1 << i) <= camMask; i++)
    {
      if (!(camMask & (1 << i))) continue;
      frustum_mask |= (1 << i);
      planes[i] = tr_o2c.This2Other (frust[i]);
    }
    csPlane3 pznear = ctxt->clip_plane;
    pznear.Invert ();
    planes[i] = tr_o2c.This2Other (pznear);
    frustum_mask |= (1 << i);
  }

  void RenderViewClipper::SetupClipPlanes (csRenderContext* ctxt)
  {
    SetupClipPlanes (ctxt, ctxt->icamera->GetTransform (), ctxt->clip_planes,
      ctxt->clip_planes_mask);
  }

}

<|endoftext|>


<commit_before>/*!
 * \copyright (c) Nokia Corporation and/or its subsidiary(-ies) (qt-info@nokia.com) and/or contributors
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * \license{This source file is part of QmlOgre abd subject to the BSD license that is bundled
 * with this source code in the file LICENSE.}
 */

#include <RenderSystems/GL/OgreGLTexture.h>
#include <RenderSystems/GL/OgreGLFrameBufferObject.h>
#include <RenderSystems/GL/OgreGLFBORenderTexture.h>

#include "ogrenode.h"

#include <Ogre.h>

#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QSurfaceFormat>
#include <QOpenGLContext>
#include <QOpenGLFunctions>

OgreNode::OgreNode()
    : QSGGeometryNode()
    , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
    , m_texture(0)
    , m_ogreEngineItem(0)
    , m_camera(0)
    , m_renderTarget(0)
    , m_viewport(0)
    , m_window(0)
    , m_ogreFboId(0)
    , m_dirtyFBO(false)
{
    setMaterial(&m_material);
    setOpaqueMaterial(&m_materialO);
    setGeometry(&m_geometry);
    setFlag(UsePreprocess);
}

OgreNode::~OgreNode()
{
    if (m_renderTarget) {
        m_renderTarget->removeAllViewports();
    }
}

void OgreNode::setOgreEngineItem(OgreEngine *ogreRootItem)
{
    m_ogreEngineItem = ogreRootItem;
}

void OgreNode::doneOgreContext()
{
    if (m_ogreFboId != 0)
    {
        Ogre::GLFrameBufferObject *ogreFbo = NULL;
        m_renderTarget->getCustomAttribute("FBO", &ogreFbo);
        Ogre::GLFBOManager *manager = ogreFbo->getManager();
        manager->unbind(m_renderTarget);
    }

    m_ogreEngineItem->doneOgreContext();
}

void OgreNode::activateOgreContext()
{
    m_ogreEngineItem->activateOgreContext();
    m_ogreEngineItem->ogreContext()->functions()->glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_ogreFboId);
}

GLuint OgreNode::getOgreFboId()
{
    if (!m_renderTarget)
        return 0;

    Ogre::GLFrameBufferObject *ogreFbo = 0;
    m_renderTarget->getCustomAttribute("FBO", &ogreFbo);
    Ogre::GLFBOManager *manager = ogreFbo->getManager();
    manager->bind(m_renderTarget);

    GLint id;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &id);

    return id;
}

void OgreNode::preprocess()
{
    activateOgreContext();
    m_renderTarget->update(true);
    doneOgreContext();
}

void OgreNode::update()
{
    if (m_dirtyFBO) {
        activateOgreContext();
        updateFBO();
        m_ogreFboId = getOgreFboId();
        m_dirtyFBO = false;
        doneOgreContext();
    }
}

void OgreNode::updateFBO()
{
    if (m_renderTarget)
        Ogre::TextureManager::getSingleton().remove("RttTex");

    int samples = m_ogreEngineItem->ogreContext()->format().samples();
    m_rttTexture = Ogre::TextureManager::getSingleton().createManual("RttTex",
                                                                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                    Ogre::TEX_TYPE_2D,
                                                                    m_size.width(),
                                                                    m_size.height(),
                                                                    0,
                                                                    Ogre::PF_R8G8B8A8,
                                                                    Ogre::TU_RENDERTARGET, 0, false,
                                                                    samples);

    m_renderTarget = m_rttTexture->getBuffer()->getRenderTarget();

    m_renderTarget->addViewport(m_camera);
    m_renderTarget->getViewport(0)->setClearEveryFrame(true);
    m_renderTarget->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);
    m_renderTarget->getViewport(0)->setOverlaysEnabled(false);

    Ogre::Real aspectRatio = Ogre::Real(m_size.width()) / Ogre::Real(m_size.height());
    m_camera->setAspectRatio(aspectRatio);

    QSGGeometry::updateTexturedRectGeometry(&m_geometry,
                                            QRectF(0, 0, m_size.width(), m_size.height()),
                                            QRectF(0, 0, 1, 1));

    Ogre::GLTexture *nativeTexture = static_cast<Ogre::GLTexture *>(m_rttTexture.get());

    delete m_texture;
    m_texture = m_ogreEngineItem->createTextureFromId(nativeTexture->getGLID(), m_size);

    m_material.setTexture(m_texture);
    m_materialO.setTexture(m_texture);
}

void OgreNode::setSize(const QSize &size)
{
    if (size == m_size)
        return;

    m_size = size;
    m_dirtyFBO = true;
    markDirty(DirtyGeometry);
}
<commit_msg>Added detaching of m_renderTarget on OgreNode destruction.<commit_after>/*!
 * \copyright (c) Nokia Corporation and/or its subsidiary(-ies) (qt-info@nokia.com) and/or contributors
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * \license{This source file is part of QmlOgre abd subject to the BSD license that is bundled
 * with this source code in the file LICENSE.}
 */

#include <RenderSystems/GL/OgreGLTexture.h>
#include <RenderSystems/GL/OgreGLFrameBufferObject.h>
#include <RenderSystems/GL/OgreGLFBORenderTexture.h>

#include "ogrenode.h"

#include <Ogre.h>

#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QSurfaceFormat>
#include <QOpenGLContext>
#include <QOpenGLFunctions>

OgreNode::OgreNode()
    : QSGGeometryNode()
    , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
    , m_texture(0)
    , m_ogreEngineItem(0)
    , m_camera(0)
    , m_renderTarget(0)
    , m_viewport(0)
    , m_window(0)
    , m_ogreFboId(0)
    , m_dirtyFBO(false)
{
    setMaterial(&m_material);
    setOpaqueMaterial(&m_materialO);
    setGeometry(&m_geometry);
    setFlag(UsePreprocess);
}

OgreNode::~OgreNode()
{
    if (m_renderTarget) {
        m_renderTarget->removeAllViewports();
    }

    if (Ogre::Root::getSingletonPtr()) {
        Ogre::Root::getSingletonPtr()->detachRenderTarget(m_renderTarget);
    }
}

void OgreNode::setOgreEngineItem(OgreEngine *ogreRootItem)
{
    m_ogreEngineItem = ogreRootItem;
}

void OgreNode::doneOgreContext()
{
    if (m_ogreFboId != 0)
    {
        Ogre::GLFrameBufferObject *ogreFbo = NULL;
        m_renderTarget->getCustomAttribute("FBO", &ogreFbo);
        Ogre::GLFBOManager *manager = ogreFbo->getManager();
        manager->unbind(m_renderTarget);
    }

    m_ogreEngineItem->doneOgreContext();
}

void OgreNode::activateOgreContext()
{
    m_ogreEngineItem->activateOgreContext();
    m_ogreEngineItem->ogreContext()->functions()->glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_ogreFboId);
}

GLuint OgreNode::getOgreFboId()
{
    if (!m_renderTarget)
        return 0;

    Ogre::GLFrameBufferObject *ogreFbo = 0;
    m_renderTarget->getCustomAttribute("FBO", &ogreFbo);
    Ogre::GLFBOManager *manager = ogreFbo->getManager();
    manager->bind(m_renderTarget);

    GLint id;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &id);

    return id;
}

void OgreNode::preprocess()
{
    activateOgreContext();
    m_renderTarget->update(true);
    doneOgreContext();
}

void OgreNode::update()
{
    if (m_dirtyFBO) {
        activateOgreContext();
        updateFBO();
        m_ogreFboId = getOgreFboId();
        m_dirtyFBO = false;
        doneOgreContext();
    }
}

void OgreNode::updateFBO()
{
    if (m_renderTarget)
        Ogre::TextureManager::getSingleton().remove("RttTex");

    int samples = m_ogreEngineItem->ogreContext()->format().samples();
    m_rttTexture = Ogre::TextureManager::getSingleton().createManual("RttTex",
                                                                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                    Ogre::TEX_TYPE_2D,
                                                                    m_size.width(),
                                                                    m_size.height(),
                                                                    0,
                                                                    Ogre::PF_R8G8B8A8,
                                                                    Ogre::TU_RENDERTARGET, 0, false,
                                                                    samples);

    m_renderTarget = m_rttTexture->getBuffer()->getRenderTarget();

    m_renderTarget->addViewport(m_camera);
    m_renderTarget->getViewport(0)->setClearEveryFrame(true);
    m_renderTarget->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);
    m_renderTarget->getViewport(0)->setOverlaysEnabled(false);

    Ogre::Real aspectRatio = Ogre::Real(m_size.width()) / Ogre::Real(m_size.height());
    m_camera->setAspectRatio(aspectRatio);

    QSGGeometry::updateTexturedRectGeometry(&m_geometry,
                                            QRectF(0, 0, m_size.width(), m_size.height()),
                                            QRectF(0, 0, 1, 1));

    Ogre::GLTexture *nativeTexture = static_cast<Ogre::GLTexture *>(m_rttTexture.get());

    delete m_texture;
    m_texture = m_ogreEngineItem->createTextureFromId(nativeTexture->getGLID(), m_size);

    m_material.setTexture(m_texture);
    m_materialO.setTexture(m_texture);
}

void OgreNode::setSize(const QSize &size)
{
    if (size == m_size)
        return;

    m_size = size;
    m_dirtyFBO = true;
    markDirty(DirtyGeometry);
}
<|endoftext|>


<commit_before>#include <iostream>
#include <algorithm>
using namespace std;

ListNode* reverse(ListNode *A) {
	if (A == NULL) {
		return NULL;
	}
	else {
		ListNode *temp, *prev, *next;
		temp = A;
		prev = NULL;
		while(temp!=NULL) {
			next = temp->next;
			temp->next = prev;
			prev = temp;
			temp = next;
		}
		A = prev;
		return A;
	}
}

int Solution::lPalin(ListNode* A) {
	stack	<int> s;
	ListNode *temp = A;
	while(temp!=NULL) {
		s.push(temp->val);
		temp = temp->next;
	}
	temp = A;
	while(temp!=NULL) {
		if(s.top() !=  temp->val) {
			return 0;
		}
		s.pop();
		temp = temp->next;
	}
	return 1;
}

ListNode* Solution::deleteDuplicates(ListNode* A) {
	ListNode *temp,*prev;
	unordered_map<int, int> m;
	temp = A;
	prev = NULL;
	while(temp!=NULL) {
		if(m.find(temp->val) != m.end()) {
			m[temp->val]++;
		}
		else {
			m[temp->val] = 1;
		}
		temp = temp->next;
	}
	ListNode *head = NULL;
	ListNode *temp2;
	temp = A;
	while(temp!=NULL) {
		if(m[temp->val] == 1) {
			if(head == NULL) {
				temp2 = (ListNode *)malloc(1*sizeof(ListNode));
				temp2->val = temp->val;
				temp2->next = NULL;
				head = temp2;
			}
			else {
				temp2->next = (ListNode *)malloc(1*sizeof(ListNode));
				temp2->next->val = temp->val;
				temp2 = temp2->next;
				temp2->next = NULL;
			}
		}
		temp = temp->next;
	}
	return head;
}

int main() {
	return 0;
}<commit_msg>linkedlist remove nth from end<commit_after>#include <iostream>
#include <algorithm>
using namespace std;

ListNode* reverse(ListNode *A) {
	if (A == NULL) {
		return NULL;
	}
	else {
		ListNode *temp, *prev, *next;
		temp = A;
		prev = NULL;
		while(temp!=NULL) {
			next = temp->next;
			temp->next = prev;
			prev = temp;
			temp = next;
		}
		A = prev;
		return A;
	}
}

int Solution::lPalin(ListNode* A) {
	stack	<int> s;
	ListNode *temp = A;
	while(temp!=NULL) {
		s.push(temp->val);
		temp = temp->next;
	}
	temp = A;
	while(temp!=NULL) {
		if(s.top() !=  temp->val) {
			return 0;
		}
		s.pop();
		temp = temp->next;
	}
	return 1;
}

ListNode* Solution::deleteDuplicates(ListNode* A) {
	ListNode *temp,*prev;
	unordered_map<int, int> m;
	temp = A;
	prev = NULL;
	while(temp!=NULL) {
		if(m.find(temp->val) != m.end()) {
			m[temp->val]++;
		}
		else {
			m[temp->val] = 1;
		}
		temp = temp->next;
	}
	ListNode *head = NULL;
	ListNode *temp2;
	temp = A;
	while(temp!=NULL) {
		if(m[temp->val] > 0) {
			if(head == NULL) {
				temp2 = (ListNode *)malloc(1*sizeof(ListNode));
				temp2->val = temp->val;
				temp2->next = NULL;
				head = temp2;
			}
			else {
				temp2->next = (ListNode *)malloc(1*sizeof(ListNode));
				temp2->next->val = temp->val;
				temp2 = temp2->next;
				temp2->next = NULL;
			}
		}
		temp = temp->next;
	}
	return head;
}

ListNode* Solution::removeNthFromEnd(ListNode* A, int B) {
	ListNode *temp, *temp2, *prev;
	temp = A;
	temp2 = A;
	int count = 0;
	while(temp) {
		count++;
		temp = temp->next;
	}

	if(count >=  B) {
		temp = A;
		A = temp->next;
		temp->next = NULL;
		return A;
	}
	else {

		while(B-- > 0) {
			temp = temp->next;
		}
		while(temp!=NULL) {
			temp = temp->next;
			temp2 = temp2->next;
			prev = temp2;

		}
		prev->next = temp2->next;
		return A;
	}

}

int main() {
	return 0;
}<|endoftext|>


<commit_before>/* Little Init by Alexander Richards
   under MIT; Please compile staticly */

///TODO:
///

//Include stuff

#include <signal.h>
#include <iostream>
#include <cstdlib>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <sstream>
#include <thread>
#include <chrono>
#include <fstream>
#include <string.h>

#define MAX_BUF 1024

// #include <time.h>
using namespace std;

// Declare Vars
int done = 0; // is init procedure complete?
int runlevel = 5; // runlevel, 0 should always be shutdown, default is 5
string version = "little-init v0.3-git";
string rc_script = "/etc/init.d/rc";
// not the final solution, but its the best thing for now, there are more important things :)

// https://www.systutorials.com/5510/catching-the-signal-sent-by-kill-in-c-on-linux/ please don't sue me
void sighandler(int signum, siginfo_t *info, void *ptr) { // so i can turn it off gracefully for now
    	if (signum == SIGTERM) {
      		sync();
      		reboot(RB_POWER_OFF);
    	} else if (signum == SIGHUP) {
      		sync();
      		reboot(RB_AUTOBOOT);
    	}
}

void catch_sig() {
 	static struct sigaction _sigact;
    	memset(&_sigact, 0, sizeof(_sigact));
   	_sigact.sa_sigaction = sighandler;
   	_sigact.sa_flags = SA_SIGINFO;
   	sigaction(SIGTERM, &_sigact, NULL);
   	sigaction(SIGHUP, &_sigact, NULL);
    signal(SIGCHLD, SIG_IGN);
}
//END

void call_rc(int rl) {
  if(rl == 9) {
    system(string(rc_script + string(" S")).c_str());
  } else {
    system(string(rc_script + string(" ") + to_string(rl)).c_str());
  }
}

inline bool exist(const std::string& name) {
	ifstream file(name);
	if (file.good()) {return true;} else {return false;}
} // Simple file checker; This line is probably not required but why not

void init() {
  system("mount -a"); // just mount everything now
	system("mount -o remount,rw /"); // remount root as rw, just in case its ro
  signal(SIGCHLD, SIG_IGN);
  call_rc(9); // call single user first
  call_rc(runlevel);
	done = 1;
	runlevel = 3; // still have to implement switching it
	if(exist("/etc/init.d/shell")) {
		pid_t pid = fork();
		if(pid == 0) { // if child process, run the "shell" symlink, hopefully :)
			execl("/etc/init.d/shell", "/etc/init.d/shell", (char*) 0);
			this_thread::sleep_for(std::chrono::milliseconds(1000));
      kill(getpid(), SIGKILL);
		}
	}
}

// Call said functions
int main(int argc, char** argv) {
  if(getpid() == 1) {
	  cout << version << endl;
    if(argc != 1) {
      runlevel = atoi(argv[1]);
      if(string(argv[1]) == "s" || string(argv[1]) == "S") {
        runlevel = 9;
      }
    }
    init();
    while(true) { // do stuff
      if(exist("/tmp/runlevel")) {
        int tmp_runlevel = 0; // runlevel from /tmp/runlevel. default = 0
        string temp;
        ifstream file("/tmp/runlevel");
        if(file.is_open()) {
          getline(file, temp);
          // temp should have the runlevel in it. 9 is alias for S
          if(temp == "") {
            // nothing, continue
          } else {
            tmp_runlevel = stoi(temp);
            call_rc(tmp_runlevel);
            runlevel = tmp_runlevel;
          }
        }
        file.close();
      }
      this_thread::sleep_for(std::chrono::milliseconds(1000));
    }
  } else {
    // should be reserved for runlevel changes
    if(argc == 1) {
      cout << "Usage: init <runlevel>";
    } else {
      runlevel = atoi(argv[1]);
      ofstream file("/tmp/runlevel");
      file << runlevel;
      file.close();
    }
  }
}
<commit_msg>Final Commit to v0.3<commit_after>/* Little Init by Alexander Richards
   under MIT*/

///TODO:
/// /run/initctl fifo compatability

//Include stuff
#include <signal.h>
#include <iostream>
#include <cstdlib>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <sstream>
#include <thread>
#include <chrono>
#include <fstream>
#include <string.h>

// #include <time.h>
using namespace std;

// Declare Vars
int done = 0; // is init procedure complete?
int runlevel = 5; // runlevel, 0 should always be shutdown, default is 5
pid_t shell_pid;
string version = "little-init v0.3";
string rc_script = "/etc/init.d/rc";
//const char* initctl = "/run/initctl"; // for later

void call_rc(int rl) {
  if(rl == 9) {
    system(string(rc_script + string(" S")).c_str());
  } else {
    system(string(rc_script + string(" ") + to_string(rl)).c_str());
  }
}

inline bool exist(const std::string& name) {
	ifstream file(name);
	if (file.good()) {return true;} else {return false;}
} // Simple file checker; This line is probably not required but why not

void init() {
  system("mount -a"); // just mount everything now
	system("mount -o remount,rw /"); // remount root as rw, just in case its ro
  signal(SIGCHLD, SIG_IGN); // make kernel reap zombies automatically
  call_rc(9); // call single user first
  call_rc(runlevel); // call default runlevel/set runlevel
  //mkfifo(initctl, 0666); // make pipe
	done = 1;
	if(exist("/etc/init.d/shell") || runlevel == 9) { // run a shell if single user
		pid_t pid = fork();
		if(pid == 0) { // if child process, run the "shell" symlink, hopefully :)
			execl("/etc/init.d/shell", "/etc/init.d/shell", (char*) 0); // run shell
			this_thread::sleep_for(std::chrono::milliseconds(1000));
      kill(getpid(), SIGKILL); // really should not be here, unless it is not executable, so kill self
		} else {
      shell_pid = pid;
    }
	}
}

// Call said functions
int main(int argc, char** argv) {
  if(getpid() == 1) { // if running as init, do init stuff
	  cout << version << endl;
    if(argc != 1) { // if runlevel is specified
      runlevel = atoi(argv[1]);
      if(string(argv[1]) == "s" || string(argv[1]) == "S") {
        runlevel = 9;
      }
    }
    init();
    while(true) { // listen for stuff
      if(exist("/tmp/runlevel")) { // if this file exists, read it and switch to its runlevel
        int tmp_runlevel = 0; // runlevel from /tmp/runlevel. default = 0
        string temp;
        ifstream file("/tmp/runlevel");
        if(file.is_open()) {
          getline(file, temp);
          // temp should have the runlevel in it. 9 is alias for S
          if(temp == "") {
            // nothing, continue
          } else {
            tmp_runlevel = stoi(temp);
            call_rc(tmp_runlevel);
            runlevel = tmp_runlevel;
          }
        }
        file.close();
      }
      this_thread::sleep_for(std::chrono::milliseconds(1000)); // dont use the cpu too much :)
    }
  } else {
    // not running as init, switch runlevel
    if(argc == 1) {
      cout << "Usage: init <runlevel>";
    } else {
      runlevel = atoi(argv[1]);
      ofstream file("/tmp/runlevel");
      file << runlevel;
      file.close();
    }
  }
}
<|endoftext|>


<commit_before>/*      _______   __   __   __   ______   __   __   _______   __   __
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
 *
 * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessn and Per Larsson
 *
 *                                                         Js_./
 * Per Larsson a.k.a finalman                          _RqZ{a<^_aa
 * Olof Naessn a.k.a jansem/yakslem                _asww7!uY`>  )\a//
 *                                                 _Qhm`] _f "'c  1!5m
 * Visit: http://guichan.darkbits.org             )Qk<P ` _: :+' .'  "{[
 *                                               .)j(] .d_/ '-(  P .   S
 * License: (BSD)                                <Td/Z <fP"5(\"??"\a.  .L
 * Redistribution and use in source and          _dV>ws?a-?'      ._/L  #'
 * binary forms, with or without                 )4d[#7r, .   '     )d`)[
 * modification, are permitted provided         _Q-5'5W..j/?'   -?!\)cam'
 * that the following conditions are met:       j<<WP+k/);.        _W=j f
 * 1. Redistributions of source code must       .$%w\/]Q  . ."'  .  mj$
 *    retain the above copyright notice,        ]E.pYY(Q]>.   a     J@\
 *    this list of conditions and the           j(]1u<sE"L,. .   ./^ ]{a
 *    following disclaimer.                     4'_uomm\.  )L);-4     (3=
 * 2. Redistributions in binary form must        )_]X{Z('a_"a7'<a"a,  ]"[
 *    reproduce the above copyright notice,       #}<]m7`Za??4,P-"'7. ).m
 *    this list of conditions and the            ]d2e)Q(<Q(  ?94   b-  LQ/
 *    following disclaimer in the                <B!</]C)d_, '(<' .f. =C+m
 *    documentation and/or other materials      .Z!=J ]e []('-4f _ ) -.)m]'
 *    provided with the distribution.          .w[5]' _[ /.)_-"+?   _/ <W"
 * 3. Neither the name of Guichan nor the      :$we` _! + _/ .        j?
 *    names of its contributors may be used     =3)= _f  (_yQmWW$#(    "
 *    to endorse or promote products derived     -   W,  sQQQQmZQ#Wwa]..
 *    from this software without specific        (js, \[QQW$QWW#?!V"".
 *    prior written permission.                    ]y:.<\..          .
 *                                                 -]n w/ '         [.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT       )/ )/           !
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY         <  (; sac    ,    '
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,               ]^ .-  %
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF            c <   r
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR            aga<  <La
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE          5%  )P'-3L
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR        _bQf` y`..)a
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,          ,J?4P'.P"_(\?d'.,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES               _Pa,)!f/<[]/  ?"
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT      _2-..:. .r+_,.. .
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     ?a.<%"'  " -'.a_ _,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                     ^
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * For comments regarding functions please see the header file.
 */

#include "guichan/openlayer/openlayergraphics.hpp"

#include <OpenLayer.hpp>

#include <string>

#include "guichan/exception.hpp"
#include "guichan/openlayer/openlayerimage.hpp"

namespace gcn
{
    OpenLayerGraphics::OpenLayerGraphics()
    {
        setTargetPlane(640, 480);
    }

    OpenLayerGraphics::OpenLayerGraphics(int width, int height)
    {
        setTargetPlane(width, height);
    }

    OpenLayerGraphics::~OpenLayerGraphics()
    {

    }

    void OpenLayerGraphics::_beginDraw()
    {
        pushClipArea(Rectangle(0, 0, mWidth, mHeight));
    }

    void OpenLayerGraphics::_endDraw()
    {
        popClipArea();
    }

    bool OpenLayerGraphics::pushClipArea(Rectangle area)
    {
        bool result = Graphics::pushClipArea(area);

        ol::Transforms::SetPosition(mClipStack.top().xOffset,
                                    mClipStack.top().yOffset);

        ol::Canvas::SetClipping(mClipStack.top().x,
                                mClipStack.top().y,
                                mClipStack.top().width,
                                mClipStack.top().height);

        return result;
    }

    void OpenLayerGraphics::popClipArea()
    {
        Graphics::popClipArea();
        ol::Transforms::SetPosition(0, 0);
        ol::Canvas::DisableClipping();
    }

    void OpenLayerGraphics::setTargetPlane(int width, int height)
    {
        mWidth = width;
        mHeight = height;
    }

    void OpenLayerGraphics::drawImage(const Image* image,
                                      int srcX,
                                      int srcY,
                                      int dstX,
                                      int dstY,
                                      int width,
                                      int height)
    {
        const OpenLayerImage* srcImage = dynamic_cast<const OpenLayerImage*>(image);

        if (srcImage == NULL)
        {
            throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an OpenLayerImage.");
        }

        srcImage->getBitmap()->Blit(dstX - srcX,
                                    dstY - srcY,
                                    ol::ClippedMode(srcX,
                                                    srcY,
                                                    width,
                                                    height),
                                    1.0f);
    }

    void OpenLayerGraphics::drawPoint(int x, int y)
    {
        ol::GfxRend::Point(x + 0.5f, y - 0.5f, mRgba);
    }

    void OpenLayerGraphics::drawLine(int x1, int y1, int x2, int y2)
    {
        mRgba.Select();
        glDisable(GL_TEXTURE_2D);
        glLineWidth(1.0f);

        glBegin(GL_LINES);
        glVertex2f(x1+0.5f, y1+0.5f);
        glVertex2f(x2+0.5f, y2+0.5f);
        glEnd();

        glBegin(GL_POINTS);
        glVertex2f(x1+0.5f, y1+0.5f);
        glEnd();

        glBegin(GL_POINTS);
        glVertex2f(x2+0.5f, y2+0.5f);
        glEnd();

        if (ol::Settings::TextureMappingUsed())
        {
            glEnable(GL_TEXTURE_2D);
        }
    }

    void OpenLayerGraphics::drawRectangle(const Rectangle& rectangle)
    {
        ol::GfxRend::RectOutline(rectangle.x + 0.5f,
                                 rectangle.y + 0.5f,
                                 rectangle.width - 0.5f,
                                 rectangle.height - 0.5f,
                                 mRgba);
    }

    void OpenLayerGraphics::fillRectangle(const Rectangle& rectangle)
    {
        ol::GfxRend::Rect(rectangle.x,
                          rectangle.y,
                          rectangle.width,
                          rectangle.height,
                          mRgba);
    }

    void OpenLayerGraphics::setColor(const Color& color)
    {
        mColor = color;
        mRgba.r = color.r / 255.0f;
        mRgba.g = color.g / 255.0f;
        mRgba.b = color.b / 255.0f;
        mRgba.a = color.a / 255.0f;
        mRgba.Select();
    }

    const Color& OpenLayerGraphics::getColor() const
    {
        return mColor;
    }

    const ol::Rgba& OpenLayerGraphics::getOpenLayerColor() const
    {
        return mRgba;
    }
}
<commit_msg>Fix by macieklen has been applied. Poping of the clip area should no be handled correct.<commit_after>/*      _______   __   __   __   ______   __   __   _______   __   __
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
 *
 * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessn and Per Larsson
 *
 *                                                         Js_./
 * Per Larsson a.k.a finalman                          _RqZ{a<^_aa
 * Olof Naessn a.k.a jansem/yakslem                _asww7!uY`>  )\a//
 *                                                 _Qhm`] _f "'c  1!5m
 * Visit: http://guichan.darkbits.org             )Qk<P ` _: :+' .'  "{[
 *                                               .)j(] .d_/ '-(  P .   S
 * License: (BSD)                                <Td/Z <fP"5(\"??"\a.  .L
 * Redistribution and use in source and          _dV>ws?a-?'      ._/L  #'
 * binary forms, with or without                 )4d[#7r, .   '     )d`)[
 * modification, are permitted provided         _Q-5'5W..j/?'   -?!\)cam'
 * that the following conditions are met:       j<<WP+k/);.        _W=j f
 * 1. Redistributions of source code must       .$%w\/]Q  . ."'  .  mj$
 *    retain the above copyright notice,        ]E.pYY(Q]>.   a     J@\
 *    this list of conditions and the           j(]1u<sE"L,. .   ./^ ]{a
 *    following disclaimer.                     4'_uomm\.  )L);-4     (3=
 * 2. Redistributions in binary form must        )_]X{Z('a_"a7'<a"a,  ]"[
 *    reproduce the above copyright notice,       #}<]m7`Za??4,P-"'7. ).m
 *    this list of conditions and the            ]d2e)Q(<Q(  ?94   b-  LQ/
 *    following disclaimer in the                <B!</]C)d_, '(<' .f. =C+m
 *    documentation and/or other materials      .Z!=J ]e []('-4f _ ) -.)m]'
 *    provided with the distribution.          .w[5]' _[ /.)_-"+?   _/ <W"
 * 3. Neither the name of Guichan nor the      :$we` _! + _/ .        j?
 *    names of its contributors may be used     =3)= _f  (_yQmWW$#(    "
 *    to endorse or promote products derived     -   W,  sQQQQmZQ#Wwa]..
 *    from this software without specific        (js, \[QQW$QWW#?!V"".
 *    prior written permission.                    ]y:.<\..          .
 *                                                 -]n w/ '         [.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT       )/ )/           !
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY         <  (; sac    ,    '
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,               ]^ .-  %
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF            c <   r
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR            aga<  <La
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE          5%  )P'-3L
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR        _bQf` y`..)a
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,          ,J?4P'.P"_(\?d'.,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES               _Pa,)!f/<[]/  ?"
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT      _2-..:. .r+_,.. .
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     ?a.<%"'  " -'.a_ _,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                     ^
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * For comments regarding functions please see the header file.
 */

#include "guichan/openlayer/openlayergraphics.hpp"

#include <OpenLayer.hpp>

#include <string>

#include "guichan/exception.hpp"
#include "guichan/openlayer/openlayerimage.hpp"

namespace gcn
{
    OpenLayerGraphics::OpenLayerGraphics()
    {
        setTargetPlane(640, 480);
    }

    OpenLayerGraphics::OpenLayerGraphics(int width, int height)
    {
        setTargetPlane(width, height);
    }

    OpenLayerGraphics::~OpenLayerGraphics()
    {

    }

    void OpenLayerGraphics::_beginDraw()
    {
        pushClipArea(Rectangle(0, 0, mWidth, mHeight));
    }

    void OpenLayerGraphics::_endDraw()
    {
        popClipArea();
    }

    bool OpenLayerGraphics::pushClipArea(Rectangle area)
    {
        bool result = Graphics::pushClipArea(area);

        ol::Transforms::SetPosition(mClipStack.top().xOffset,
                                    mClipStack.top().yOffset);

        ol::Canvas::SetClipping(mClipStack.top().x,
                                mClipStack.top().y,
                                mClipStack.top().width,
                                mClipStack.top().height);

        return result;
    }

    void OpenLayerGraphics::popClipArea()
    {
        Graphics::popClipArea();

        if (mClipStack.empty())
        {
            ol::Transforms::SetPosition(0, 0);
            ol::Canvas::DisableClipping();
        }
        else
        {
            const ClipRectangle top = mClipStack.top();
            ol::Transforms::SetPosition(top.xOffset,
                                        top.yOffset);
            ol::Canvas::SetClipping(top.x,
                                    top.y,
                                    top.width,
                                    top.height);
        }
    }

    void OpenLayerGraphics::setTargetPlane(int width, int height)
    {
        mWidth = width;
        mHeight = height;
    }

    void OpenLayerGraphics::drawImage(const Image* image,
                                      int srcX,
                                      int srcY,
                                      int dstX,
                                      int dstY,
                                      int width,
                                      int height)
    {
        const OpenLayerImage* srcImage = dynamic_cast<const OpenLayerImage*>(image);

        if (srcImage == NULL)
        {
            throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an OpenLayerImage.");
        }

        srcImage->getBitmap()->Blit(dstX - srcX,
                                    dstY - srcY,
                                    ol::ClippedMode(srcX,
                                                    srcY,
                                                    width,
                                                    height),
                                    1.0f);
    }

    void OpenLayerGraphics::drawPoint(int x, int y)
    {
        ol::GfxRend::Point(x + 0.5f, y - 0.5f, mRgba);
    }

    void OpenLayerGraphics::drawLine(int x1, int y1, int x2, int y2)
    {
        mRgba.Select();
        glDisable(GL_TEXTURE_2D);
        glLineWidth(1.0f);

        glBegin(GL_LINES);
        glVertex2f(x1+0.5f, y1+0.5f);
        glVertex2f(x2+0.5f, y2+0.5f);
        glEnd();

        glBegin(GL_POINTS);
        glVertex2f(x1+0.5f, y1+0.5f);
        glEnd();

        glBegin(GL_POINTS);
        glVertex2f(x2+0.5f, y2+0.5f);
        glEnd();

        if (ol::Settings::TextureMappingUsed())
        {
            glEnable(GL_TEXTURE_2D);
        }
    }

    void OpenLayerGraphics::drawRectangle(const Rectangle& rectangle)
    {
        ol::GfxRend::RectOutline(rectangle.x + 0.5f,
                                 rectangle.y + 0.5f,
                                 rectangle.width - 0.5f,
                                 rectangle.height - 0.5f,
                                 mRgba);
    }

    void OpenLayerGraphics::fillRectangle(const Rectangle& rectangle)
    {
        ol::GfxRend::Rect(rectangle.x,
                          rectangle.y,
                          rectangle.width,
                          rectangle.height,
                          mRgba);
    }

    void OpenLayerGraphics::setColor(const Color& color)
    {
        mColor = color;
        mRgba.r = color.r / 255.0f;
        mRgba.g = color.g / 255.0f;
        mRgba.b = color.b / 255.0f;
        mRgba.a = color.a / 255.0f;
        mRgba.Select();
    }

    const Color& OpenLayerGraphics::getColor() const
    {
        return mColor;
    }

    const ol::Rgba& OpenLayerGraphics::getOpenLayerColor() const
    {
        return mRgba;
    }
}
<|endoftext|>