<commit_before>
// Simple macro showing capabilities of TGSpeedo widget.
//Author: <NAME>
   
#include "TSystem.h"
#include "TGFrame.h"
#include "TGWindow.h"
#include "TGSpeedo.h"

class TGShapedMain : public TGMainFrame {

protected:
   TGSpeedo          *fSpeedo;          // analog meter
   TTimer            *fTimer;           // update timer
   Int_t              fActInfo;         // actual information value

public:
   TGShapedMain(const TGWindow *p, int w, int h);
   virtual ~TGShapedMain();

   void              CloseWindow();
   TGSpeedo         *GetSpeedo() const { return fSpeedo; }
   Int_t             GetActInfo() const { return fActInfo; }
   void              ToggleInfos();

   ClassDef(TGShapedMain, 0)
};


// globals
TGShapedMain *gMainWindow;
TGSpeedo *gSpeedo;
Float_t prev_load;
Int_t old_memUsage;

//______________________________________________________________________________
TGShapedMain::TGShapedMain(const TGWindow *p, int w, int h) :
   TGMainFrame(p, w, h)
{
   // Constructor.

   fActInfo = 1;

   fSpeedo = new TGSpeedo(this, 0.0, 100.0, "CPU", "[%]");
   fSpeedo->Connect("OdoClicked()", "TGShapedMain", this, "ToggleInfos()");
   fSpeedo->Connect("LedClicked()", "TGShapedMain", this, "CloseWindow()");
   Connect("CloseWindow()", "TGShapedMain", this, "CloseWindow()");
   AddFrame(fSpeedo, new TGLayoutHints(kLHintsCenterX | kLHintsCenterX, 0, 0, 0, 0));
   fSpeedo->SetDisplayText("Used RAM", "[MB]");
   fTimer = new TTimer(100);
   fTimer->SetCommand("Update()");

   MapSubwindows();
   MapWindow();
   // To avoid closing the window while TGSpeedo is drawing
   DontCallClose();
   // To avoid closing the window while TGSpeedo is drawing
   Resize(GetDefaultSize());
   // Set fixed size
   SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), GetDefaultWidth(), GetDefaultHeight(), 1, 1);
   SetWindowName("ROOT CPU Load Meter");
   fTimer->TurnOn();   
}

//______________________________________________________________________________
void TGShapedMain::ToggleInfos()
{
   // Toggle information displayed in Analog Meter

   if (fActInfo < 2)
      fActInfo++;
   else
      fActInfo = 0;
   if (fActInfo == 0)
      fSpeedo->SetDisplayText("Total RAM", "[MB]");
   else if (fActInfo == 1)
      fSpeedo->SetDisplayText("Used RAM", "[MB]");
   else if (fActInfo == 2)
      fSpeedo->SetDisplayText("Free RAM", "[MB]");
}

//______________________________________________________________________________
TGShapedMain::~TGShapedMain()
{
   // Destructor.

}

//______________________________________________________________________________
void TGShapedMain::CloseWindow()
{
   // Close Window.

   if (fTimer)
      fTimer->TurnOff();
   delete fTimer;
   delete fSpeedo;
   delete this;
}

void Update()
{
   MemInfo_t memInfo;
   CpuInfo_t cpuInfo;
   Float_t act_load = 0.0;
   Int_t memUsage = 0;

   // Get CPU informations
   gSystem->GetCpuInfo(&cpuInfo, 100);
   // actual CPU load
   act_load = cpuInfo.fTotal;
   // Get Memory informations
   gSystem->GetMemInfo(&memInfo);
   // choose which value to display
   if (gMainWindow->GetActInfo() == 0)
      memUsage = memInfo.fMemTotal;
   else if (gMainWindow->GetActInfo() == 1)
      memUsage = memInfo.fMemUsed;
   else if (gMainWindow->GetActInfo() == 2)
      memUsage = memInfo.fMemFree;
   // small threshold to avoid "trembling" needle
   if (fabs(act_load-prev_load) > 0.9) {
      gSpeedo->SetScaleValue(act_load, 10);
      prev_load = act_load;
   }
   // update only if value has changed
   if (memUsage != old_memUsage) {
      gSpeedo->SetOdoValue(memUsage);
      old_memUsage = memUsage;
   }
}

//______________________________________________________________________________
void CPUMeter()
{
   // Main application.
<commit_msg>From Bertrand: Added some transparency.<commit_after>
// Simple macro showing capabilities of TGSpeedo widget.
//Author: <NAME>
   
#include "TSystem.h"
#include "TGFrame.h"
#include "TGWindow.h"
#include "TGSpeedo.h"

class TGShapedMain : public TGMainFrame {

protected:
   const TGPicture   *fBgnd;           // picture used as mask
   TGSpeedo          *fSpeedo;          // analog meter
   TTimer            *fTimer;           // update timer
   Int_t              fActInfo;         // actual information value

public:
   TGShapedMain(const TGWindow *p, int w, int h);
   virtual ~TGShapedMain();

   void              CloseWindow();
   TGSpeedo         *GetSpeedo() const { return fSpeedo; }
   Int_t             GetActInfo() const { return fActInfo; }
   void              ToggleInfos();

   ClassDef(TGShapedMain, 0)
};


// globals
TGShapedMain *gMainWindow;
TGSpeedo *gSpeedo;
Float_t prev_load;
Int_t old_memUsage;

//______________________________________________________________________________
TGShapedMain::TGShapedMain(const TGWindow *p, int w, int h) :
   TGMainFrame(p, w, h)
{
   // Constructor.

   fActInfo = 1;

   fSpeedo = new TGSpeedo(this, 0.0, 100.0, "CPU", "[%]");
   fSpeedo->Connect("OdoClicked()", "TGShapedMain", this, "ToggleInfos()");
   fSpeedo->Connect("LedClicked()", "TGShapedMain", this, "CloseWindow()");
   Connect("CloseWindow()", "TGShapedMain", this, "CloseWindow()");
   AddFrame(fSpeedo, new TGLayoutHints(kLHintsCenterX | kLHintsCenterX, 0, 0, 0, 0));
   fSpeedo->SetDisplayText("Used RAM", "[MB]");
   fTimer = new TTimer(100);
   fTimer->SetCommand("Update()");

   fBgnd = fSpeedo->GetPicture();
   gVirtualX->ShapeCombineMask(GetId(), 0, 0, fBgnd->GetMask());
   SetBackgroundPixmap(fBgnd->GetPicture());
   SetWMSizeHints(fBgnd->GetWidth(), fBgnd->GetHeight(), fBgnd->GetWidth(),
                  fBgnd->GetHeight(), 1, 1);

   MapSubwindows();
   MapWindow();
   // To avoid closing the window while TGSpeedo is drawing
   DontCallClose();
   // To avoid closing the window while TGSpeedo is drawing
   Resize(GetDefaultSize());
   // Set fixed size
   SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), GetDefaultWidth(), GetDefaultHeight(), 1, 1);
   SetWindowName("ROOT CPU Load Meter");
   fTimer->TurnOn();   
}

//______________________________________________________________________________
void TGShapedMain::ToggleInfos()
{
   // Toggle information displayed in Analog Meter

   if (fActInfo < 2)
      fActInfo++;
   else
      fActInfo = 0;
   if (fActInfo == 0)
      fSpeedo->SetDisplayText("Total RAM", "[MB]");
   else if (fActInfo == 1)
      fSpeedo->SetDisplayText("Used RAM", "[MB]");
   else if (fActInfo == 2)
      fSpeedo->SetDisplayText("Free RAM", "[MB]");
}

//______________________________________________________________________________
TGShapedMain::~TGShapedMain()
{
   // Destructor.

}

//______________________________________________________________________________
void TGShapedMain::CloseWindow()
{
   // Close Window.

   if (fTimer)
      fTimer->TurnOff();
   delete fTimer;
   delete fSpeedo;
   delete this;
}

void Update()
{
   MemInfo_t memInfo;
   CpuInfo_t cpuInfo;
   Float_t act_load = 0.0;
   Int_t memUsage = 0;
   prev_load = act_load;
   old_memUsage = memUsage;

   // Get CPU informations
   gSystem->GetCpuInfo(&cpuInfo, 100);
   // actual CPU load
   act_load = cpuInfo.fTotal;
   // Get Memory informations
   gSystem->GetMemInfo(&memInfo);
   // choose which value to display
   if (gMainWindow->GetActInfo() == 0)
      memUsage = memInfo.fMemTotal;
   else if (gMainWindow->GetActInfo() == 1)
      memUsage = memInfo.fMemUsed;
   else if (gMainWindow->GetActInfo() == 2)
      memUsage = memInfo.fMemFree;
   // small threshold to avoid "trembling" needle
   if (fabs(act_load-prev_load) > 0.9) {
      gSpeedo->SetScaleValue(act_load, 10);
      prev_load = act_load;
   }
   // update only if value has changed
   if (memUsage != old_memUsage) {
      gSpeedo->SetOdoValue(memUsage);
      old_memUsage = memUsage;
   }
}

//______________________________________________________________________________
void CPUMeter()
{
   // Main application.

{'fraction_non_alphanumeric': 0.12496847414880202, 'fraction_numerical': 0.009331651954602775, 'mean_word_length': 3.4807909604519773, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4406988', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2497, 'n_words': 588}