//*-- Author :    Damir Buskulic   22/11/00

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// VMetaDBPlayer                                                        //
//                                                                      //
// A metadatabase (of type VVirtualInfoDB) contains metadata of frame data //
// The player will allow one to draw some plots related to this         //
// metadata. Currently, one draws only the selection part of            //
// the metadatabase (triggers)                                          //
// The metadb player is loaded only when needed by the system, it is    //
// not linked at compile time with the program                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "VMetaDBPlayer.h"
#include "TROOT.h"
#include "TH1.h"
#include "VConditionFormula.h"
#include "TString.h"
#include "TCanvas.h"
#include "VConditionSet.h"
#include "TMath.h"
#include "TGraph.h"

ClassImp(VMetaDBPlayer)

//______________________________________________________________________________
  VMetaDBPlayer::VMetaDBPlayer()
{
//*-*-*-*-*-*-*-*-*-*-*Default MeatDB player constructor*-*-*-*-*-*-*-*-*-*
//*-*                  =================================
   fMetaDB         = 0;
}

//______________________________________________________________________________
 Int_t VMetaDBPlayer::Draw(const char* selexp, const char* selection, Option_t* option, Double_t start, Double_t length)
{
//   Draws expression selexp for conditions defined in the database
//   Builds a TGraph representing selexp over time, vetoed by selection
//
//   selexp is an expression (formula) referencing a combination of conditions
//   Example:
//      selexp = trig.amp   simplest case: draw a plot of amplitude of 
//                                          condition named trig
//             = sqrt(trig.p)            : draw distribution of sqrt(trig.p)
//             = x*y/z                   : where x, y and z are conditions
//                                         defined in the database
//   Note that selexp may contain a selection.
//   example, if selexp= x*(y<0), the value plotted will be x if y<0
//   and will be 0 otherwise.
// 
//   selection is an expression with a combination of the conditions.
//   In a selection all the C++ operators are authorized.
//   The value corresponding to the selection expression is used as a veto 
//   to plot the points. If it is not 0, the point is plotted.
//   The value returned is not relevant, only relevant is
//   (selection==0) -> point skipped or (selection!=0) -> point plotted
//
//   Examples:
//       selection1 = "x<y && sqrt(z)>3.2"
//       selection2 = "(x+y)*(sqrt(z)>3.2"
//   selection1 returns a value = 0 or 1
//   selection2 returns a value  = x+y if sqrt(z)>3.2
//              returns a value  = 0 otherwise.
//   Warning : if there is no selection (selection=""), selexp itself
//             will be taken as selection expression, i.e. only points where
//             selexp != 0 will be plotted
// 
//   option is the drawing option
//       see TGraph::Draw for the list of all drawing options.
// 
//   start is the start time of the first conditions to process
//      (default is beginning of database values)
//   length is the length in time of the data to process (default is all data)
//

   Double_t tmin, tmax, ymin, ymax, oldymin, oldymax, delta;
   Double_t* vx, *vy;
   Int_t npoints;
   Double_t globstart, globend;
   Double_t ccostart, ccoend, ccoval;

//  Maximum number of points allowed
   Int_t MAXPOINTS = 100000;
   TH1F* hr;
   VConditionFormula* valform, * selform;
   VConditionSet* condset;
   
   TString opt = option;
   opt.ToUpper();
   if (opt.IsNull()) opt = "AP";

//*-*- Create a default canvas if none exists
   if (!gPad && !opt.Contains("goff")) {
   	if (!gROOT->GetMakeDefCanvas()) return -1;
   	(gROOT->GetMakeDefCanvas())();
   }

// ------ Sets default values for start and end of plot ------
   
   if (start) globstart = start;
   else globstart = fMetaDB->GetStart();
   if (length) globend = globstart+length;
   else globend = fMetaDB->GetEnd();

// Allocation of memory for arrays used in plotting
   vx = new Double_t[MAXPOINTS];
   vy = new Double_t[MAXPOINTS];

// ------ Selects the values to plot in the database ------

   valform = new VConditionFormula("valform", selexp, fMetaDB);
   if (strlen(selection)) {
      selform = new VConditionFormula("selform", selection, fMetaDB);
      condset = fMetaDB->CreateConditionSet(selexp,selection);
   } else {
      selform = new VConditionFormula("selform", selexp, fMetaDB);
      condset = fMetaDB->CreateConditionSet(selexp,selexp);
   }
   npoints = 0;
   ccoend = 0;

// Create a work condition set
//   condset = new VConditionSet(fMetaDB,valform,selform);
   Int_t cok = condset->NearestGESet(globstart);   // Search and load the next set of conditions
   if (!cok) {
      Error("Draw","Error in loading a condition set");
      delete condset;
      return -1;
   }
   if (condset->GetIntersectionStart()<globstart) cok = condset->NextSet();
   if (!cok) {
      Error("Draw","Error in loading a condition set");
      delete condset;
      return -1;
   }
// Look for all conditions satisfying the selection expression
   while (ccoend < globend && cok && npoints<=MAXPOINTS) {
      if (selform->EvalInstance(condset)) {
         ccostart = condset->GetIntersectionStart();
         ccoend = condset->GetIntersectionEnd();
         ccoval = valform->EvalInstance(condset);
//      Remove multiple points at the same position. This can happen with selection
         if (npoints) {
            if (ccostart-globstart != vx[npoints-1] || ccoval != vy[npoints-1]) {
               vx[npoints] = ccostart-globstart;
               vy[npoints] = ccoval;
//      printf("np %d, vx %20f, vy %20f n",npoints,vx[npoints], vy[npoints]);
               npoints++;
            }
         } else {
            vx[npoints] = ccostart-globstart;
            vy[npoints] = ccoval;
//      printf("np %d, vx %20f, vy %20f n",npoints,vx[npoints], vy[npoints]);
            npoints++;
         }
      }
      cok = condset->NextSet();
   }

   delete valform;
   delete selform;
   delete condset;

// ---- Draws a frame if necessary and draws the result -----

   hr = (TH1F*)(gPad->GetListOfPrimitives()->FindObject("hframe"));

// Gets min/max
   if (npoints) {
      tmin = vx[TMath::LocMin(npoints,vx)];
      tmax = vx[TMath::LocMax(npoints,vx)];
      ymin = vy[TMath::LocMin(npoints,vy)];
      ymax = vy[TMath::LocMax(npoints,vy)];
      delta = (ymax-ymin)*0.1;
      if (delta==0) delta = 0.1*ymax*(ymax!=0) + 0.1*(ymax==0);
      ymin = ymin-delta;
      ymax = ymax+delta;
   } else {
      if (hr) {
         tmin = hr->GetXaxis()->GetXmin();
         tmax = hr->GetXaxis()->GetXmax();
         ymin = hr->GetMinimum();
         ymax = hr->GetMaximum();
      } else {
         tmin = 0;
         tmax = 1;
         ymin = -1;
         ymax = 1;
      }
   }
   
// Draw a frame to define the range if option contains "A"
   if (opt.Contains("A")) {
      hr = gPad->DrawFrame(tmin,ymin,tmax,ymax);
      hr->SetBins(1000,tmin,tmax);
      while (opt.Index("A") != kNPOS) opt.Remove(opt.Index("A"),1);
   } else {
      if (hr) {
         oldymin = hr->GetMinimum();
         oldymax = hr->GetMaximum();
         if (oldymin > ymin) hr->SetMinimum(ymin);
         if (oldymax < ymax) hr->SetMaximum(ymax);
      }
   }
   if (opt.Contains("T") && hr) {
      hr->GetXaxis()->SetTimeDisplay(1);
      while (opt.Index("T") != kNPOS) opt.Remove(opt.Index("T"),1);
   }

// Draws the graph
   if (npoints) {     // There is something to draw !
      TGraph *gr = new TGraph(npoints,vx,vy);
      gr->SetBit(kCanDelete);
      gr->Draw(opt.Data());
   }
   
   delete [] vx;
   delete [] vy;
   return 0;
}


- ROOT page - VEGA page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to , or contact with any questions or problems regarding ROOT or VEGA.