#include "TMVA/BDT_Reg.h"
#include <iostream>
#include <iomanip>
#include <fstream>



#include "RQ_OBJECT.h"

#include "TROOT.h"
#include "TStyle.h"
#include "TPad.h"
#include "TCanvas.h"
#include "TLine.h"
#include "TFile.h"
#include "TColor.h"
#include "TPaveText.h"
#include "TObjString.h"
#include "TControlBar.h"

#include "TGWindow.h"
#include "TGButton.h"
#include "TGLabel.h"
#include "TGNumberEntry.h"

#include "TMVA/DecisionTree.h"
#include "TMVA/Tools.h"
#include "TXMLEngine.h"


TMVA::StatDialogBDTReg* TMVA::StatDialogBDTReg::fThis = 0;

void TMVA::StatDialogBDTReg::SetItree() 
{
   fItree = Int_t(fInput->GetNumber());
}

void TMVA::StatDialogBDTReg::Redraw() 
{
   UpdateCanvases();
}

void TMVA::StatDialogBDTReg::Close() 
{
   delete this;
}

TMVA::StatDialogBDTReg::StatDialogBDTReg( const TGWindow* p, TString wfile, TString methName, Int_t itree )
   : fMain( 0 ),
     fItree(itree),
     fNtrees(0),
     fCanvas(0),
     fInput(0),
     fButtons(0),
     fDrawButton(0),
     fCloseButton(0),
     fWfile( wfile ),
     fMethName( methName )
{
   UInt_t totalWidth  = 500;
   UInt_t totalHeight = 200;

   fThis = this;

   // read number of decision trees from weight file
   GetNtrees();

   // main frame
   fMain = new TGMainFrame(p, totalWidth, totalHeight, kMainFrame | kVerticalFrame);

   TGLabel *sigLab = new TGLabel( fMain, Form( "Regression tree [%i-%i]",0,fNtrees-1 ) );
   fMain->AddFrame(sigLab, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));

   fInput = new TGNumberEntry(fMain, (Double_t) fItree,5,-1,(TGNumberFormat::EStyle) 5);
   fMain->AddFrame(fInput, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
   fInput->Resize(100,24);
   fInput->SetLimits(TGNumberFormat::kNELLimitMinMax,0,fNtrees-1);

   fButtons = new TGHorizontalFrame(fMain, totalWidth,30);

   fCloseButton = new TGTextButton(fButtons,"&Close");
   fButtons->AddFrame(fCloseButton, new TGLayoutHints(kLHintsLeft | kLHintsTop));

   fDrawButton = new TGTextButton(fButtons,"&Draw");
   fButtons->AddFrame(fDrawButton, new TGLayoutHints(kLHintsRight | kLHintsTop,15));
  
   fMain->AddFrame(fButtons,new TGLayoutHints(kLHintsLeft | kLHintsBottom,5,5,5,5));

   fMain->SetWindowName("Regression tree");
   fMain->SetWMPosition(0,0);
   fMain->MapSubwindows();
   fMain->Resize(fMain->GetDefaultSize());
   fMain->MapWindow();

   fInput->Connect("ValueSet(Long_t)","TMVA::StatDialogBDTReg",this, "SetItree()");
   
   // doesn't seem to exist .. gives an 'error message' and seems to work just fine without ... :)
   //   fDrawButton->Connect("Clicked()","TGNumberEntry",fInput, "ValueSet(Long_t)");
   fDrawButton->Connect("Clicked()", "TMVA::StatDialogBDTReg", this, "Redraw()");   

   fCloseButton->Connect("Clicked()", "TMVA::StatDialogBDTReg", this, "Close()");
}

void TMVA::StatDialogBDTReg::UpdateCanvases() 
{
   DrawTree( fItree );
}

void TMVA::StatDialogBDTReg::GetNtrees()
{
   if(!fWfile.EndsWith(".xml") ){
      std::ifstream fin( fWfile );
      if (!fin.good( )) { // file not found --> Error
         std::cout << "*** ERROR: Weight file: " << fWfile << " does not exist" << std::endl;
         return;
      }
   
      TString dummy = "";
      
      // read total number of trees, and check whether requested tree is in range
      Int_t nc = 0;
      while (!dummy.Contains("NTrees")) { 
         fin >> dummy; 
         nc++; 
         if (nc > 200) {
            std::cout << std::endl;
            std::cout << "*** Huge problem: could not locate term \"NTrees\" in BDT weight file: " 
                 << fWfile << std::endl;
            std::cout << "==> panic abort (please contact the TMVA authors)" << std::endl;
            std::cout << std::endl;
            exit(1);
         }
      }
      fin >> dummy; 
      fNtrees = dummy.ReplaceAll("\"","").Atoi();
      fin.close();
   }
   else{
      void* doc = TMVA::gTools().xmlengine().ParseFile(fWfile);
      void* rootnode = TMVA::gTools().xmlengine().DocGetRootElement(doc);
      void* ch = TMVA::gTools().xmlengine().GetChild(rootnode);
      while(ch){
         TString nodeName = TString( TMVA::gTools().xmlengine().GetNodeName(ch) );
         if(nodeName=="Weights") {
            TMVA::gTools().ReadAttr( ch, "NTrees", fNtrees );
            break;
         }
         ch = TMVA::gTools().xmlengine().GetNext(ch);
      }
   }
   std::cout << "--- Found " << fNtrees << " decision trees in weight file" << std::endl;

}

//_______________________________________________________________________
void TMVA::StatDialogBDTReg::DrawNode( TMVA::DecisionTreeNode *n, 
                               Double_t x, Double_t y, 
                               Double_t xscale,  Double_t yscale, TString * vars) 
{
   // recursively puts an entries in the histogram for the node and its daughters
   //
   Float_t xsize=xscale*1.5;
   Float_t ysize=yscale/3;
   if (xsize>0.15) xsize=0.1;
   if (n->GetLeft() != NULL){
      TLine *a1 = new TLine(x-xscale/4,y-ysize,x-xscale,y-ysize*2);
      a1->SetLineWidth(2);
      a1->Draw();
      DrawNode((TMVA::DecisionTreeNode*) n->GetLeft(), x-xscale, y-yscale, xscale/2, yscale, vars);
   }
   if (n->GetRight() != NULL){
      TLine *a1 = new TLine(x+xscale/4,y-ysize,x+xscale,y-ysize*2);
      a1->SetLineWidth(2);
      a1->Draw();
      DrawNode((TMVA::DecisionTreeNode*) n->GetRight(), x+xscale, y-yscale, xscale/2, yscale, vars  );
   }

   //   TPaveText *t = new TPaveText(x-xscale/2,y-yscale/2,x+xscale/2,y+yscale/2, "NDC");
   TPaveText *t = new TPaveText(x-xsize,y-ysize,x+xsize,y+ysize, "NDC");

   t->SetBorderSize(1);

   t->SetFillStyle(1001);
   if      (n->GetNodeType() ==  1) { t->SetFillColor( kSigColorF ); t->SetTextColor( kSigColorT ); }
   else if (n->GetNodeType() == -1) { t->SetFillColor( kBkgColorF ); t->SetTextColor( kBkgColorT ); }
   else if (n->GetNodeType() ==  0) { t->SetFillColor( kIntColorF ); t->SetTextColor( kIntColorT ); }

   char buffer[25];
   //   sprintf( buffer, "N=%f", n->GetNEvents() );
   //   t->AddText(buffer);
   sprintf( buffer, "R=%4.1f +- %4.1f", n->GetResponse(),n->GetRMS() );
   t->AddText(buffer);

   if (n->GetNodeType() == 0){
      if (n->GetCutType()){
         t->AddText(TString(vars[n->GetSelector()]+">"+=::Form("%5.3g",n->GetCutValue())));
      }else{
         t->AddText(TString(vars[n->GetSelector()]+"<"+=::Form("%5.3g",n->GetCutValue())));
      }
   }

   t->Draw();

   return;
}

TMVA::DecisionTree* TMVA::StatDialogBDTReg::ReadTree( TString* &vars, Int_t itree )
{
   std::cout << "--- Reading Tree " << itree << " from weight file: " << fWfile << std::endl;
   TMVA::DecisionTree *d = new TMVA::DecisionTree();


   if(!fWfile.EndsWith(".xml") ){

      std::ifstream fin( fWfile );
      if (!fin.good( )) { // file not found --> Error
         std::cout << "*** ERROR: Weight file: " << fWfile << " does not exist" << std::endl;
         return 0;
      }
      TString dummy = "";
      
      if (itree >= fNtrees) {
         std::cout << "*** ERROR: requested decision tree: " << itree 
              << ", but number of trained trees only: " << fNtrees << std::endl;
         return 0;
      }
      
      // file header with name
      while (!dummy.Contains("#VAR")) fin >> dummy;
      fin >> dummy >> dummy >> dummy; // the rest of header line

      // number of variables
      Int_t nVars;
      fin >> dummy >> nVars;
      
      // variable mins and maxes
      vars = new TString[nVars+1];
      for (Int_t i = 0; i < nVars; i++) fin >> vars[i] >> dummy >> dummy >> dummy >> dummy;
      vars[nVars]="FisherCrit";
      
      char buffer[20];
      char line[256];
      sprintf(buffer,"Tree %d",itree);

      while (!dummy.Contains(buffer)) {
         fin.getline(line,256);
         dummy = TString(line);
      }

      d->Read(fin);
      
      fin.close();
   }
   else{
      if (itree >= fNtrees) {
         std::cout << "*** ERROR: requested decision tree: " << itree 
               << ", but number of trained trees only: " << fNtrees << std::endl;
         return 0;
      }
      Int_t nVars;
      void* doc = TMVA::gTools().xmlengine().ParseFile(fWfile);
      void* rootnode = TMVA::gTools().xmlengine().DocGetRootElement(doc);
      void* ch = TMVA::gTools().xmlengine().GetChild(rootnode);
      while(ch){
         TString nodeName = TString( TMVA::gTools().xmlengine().GetNodeName(ch) );
         if(nodeName=="Variables"){
            TMVA::gTools().ReadAttr( ch, "NVar", nVars);
            vars = new TString[nVars+1]; 
            void* varnode =  TMVA::gTools().xmlengine().GetChild(ch);
            for (Int_t i = 0; i < nVars; i++){
               TMVA::gTools().ReadAttr( varnode, "Expression", vars[i]);
               varnode =  TMVA::gTools().xmlengine().GetNext(varnode);
            }
            vars[nVars]="FisherCrit";
         }
         if(nodeName=="Weights") break;
         ch = TMVA::gTools().xmlengine().GetNext(ch);
      }
      ch = TMVA::gTools().xmlengine().GetChild(ch);
      for (int i=0; i<itree; i++) ch = TMVA::gTools().xmlengine().GetNext(ch);
      d->ReadXML(ch);
   }
   return d;
}

//_______________________________________________________________________
void TMVA::StatDialogBDTReg::DrawTree( Int_t itree )
{
   TString *vars;   

   TMVA::DecisionTree* d = ReadTree( vars, itree );
   if (d == 0) return;

   UInt_t   depth = d->GetTotalTreeDepth();
   Double_t ystep = 1.0/(depth + 1.0);

   std::cout << "--- Tree depth: " << depth << std::endl;

   TStyle* TMVAStyle   = gROOT->GetStyle("Plain"); // our style is based on Plain
   Int_t   canvasColor = TMVAStyle->GetCanvasColor(); // backup

   TString cbuffer = Form( "Reading weight file: %s", fWfile.Data() );
   TString tbuffer = Form( "Regression Tree no.: %d", itree );
   if (!fCanvas) fCanvas = new TCanvas( "c1", cbuffer, 200, 0, 1000, 600 ); 
   else          fCanvas->Clear();
   fCanvas->Draw();   
   DrawNode( (TMVA::DecisionTreeNode*)d->GetRoot(), 0.5, 1.-0.5*ystep, 0.25, ystep ,vars);
  
   // make the legend
   Double_t yup=0.99;
   Double_t ydown=yup-ystep/2.5;
   Double_t dy= ystep/2.5 * 0.2;
 
   TPaveText *whichTree = new TPaveText(0.85,ydown,0.98,yup, "NDC");
   whichTree->SetBorderSize(1);
   whichTree->SetFillStyle(1001);
   whichTree->SetFillColor( TColor::GetColor( "#ffff33" ) );
   whichTree->AddText( tbuffer );
   whichTree->Draw();

   TPaveText *intermediate = new TPaveText(0.02,ydown,0.15,yup, "NDC");
   intermediate->SetBorderSize(1);
   intermediate->SetFillStyle(1001);
   intermediate->SetFillColor( kIntColorF );
   intermediate->AddText("Intermediate Nodes");
   intermediate->SetTextColor( kIntColorT );
   intermediate->Draw();

   ydown = ydown - ystep/2.5 -dy;
   yup   = yup - ystep/2.5 -dy;
   TPaveText *signalleaf = new TPaveText(0.02,ydown ,0.15,yup, "NDC");
   signalleaf->SetBorderSize(1);
   signalleaf->SetFillStyle(1001);
   signalleaf->SetFillColor( kSigColorF );
   signalleaf->AddText("Leaf Nodes");
   signalleaf->SetTextColor( kSigColorT );
   signalleaf->Draw();
/*
   ydown = ydown - ystep/2.5 -dy;
   yup   = yup - ystep/2.5 -dy;
   TPaveText *backgroundleaf = new TPaveText(0.02,ydown,0.15,yup, "NDC");
   backgroundleaf->SetBorderSize(1);
   backgroundleaf->SetFillStyle(1001);
   backgroundleaf->SetFillColor( kBkgColorF );

   backgroundleaf->AddText("Backgr. Leaf Nodes");
   backgroundleaf->SetTextColor( kBkgColorT );
   backgroundleaf->Draw();
*/
   fCanvas->Update();
   TString fname = Form("plots/%s_%i", fMethName.Data(), itree );
   std::cout << "--- Creating image: " << fname << std::endl;
   TMVAGlob::imgconv( fCanvas, fname );   

   TMVAStyle->SetCanvasColor( canvasColor );
}   
      
// ========================================================================================

// intermediate GUI
void TMVA::BDT_Reg( const TString& fin )
{
   // --- read the available BDT weight files

   // destroy all open cavases
   TMVAGlob::DestroyCanvases(); 

   // checks if file with name "fin" is already open, and if not opens one
   TFile* file = TMVAGlob::OpenFile( fin );  

   TDirectory* dir = file->GetDirectory( "Method_BDT" );
   if (!dir) {
      std::cout << "*** Error in macro \"BDT_Reg.C\": cannot find directory \"Method_BDT\" in file: " << fin << std::endl;
      return;
   }

   // read all directories
   TIter next( dir->GetListOfKeys() );
   TKey *key(0);   
   std::vector<TString> methname;   
   std::vector<TString> path;   
   std::vector<TString> wfile;   
   while ((key = (TKey*)next())) {
      TDirectory* mdir = dir->GetDirectory( key->GetName() );
      if (!mdir) {
         std::cout << "*** Error in macro \"BDT_Reg.C\": cannot find sub-directory: " << key->GetName() 
              << " in directory: " << dir->GetName() << std::endl;
         return;
      }

      // retrieve weight file name and path
      TObjString* strPath = (TObjString*)mdir->Get( "TrainingPath" );
      TObjString* strWFile = (TObjString*)mdir->Get( "WeightFileName" );
      if (!strPath || !strWFile) {
         std::cout << "*** Error in macro \"BDT_Reg.C\": could not find TObjStrings \"TrainingPath\" and/or \"WeightFileName\" *** " << std::endl;
         std::cout << "*** Maybe you are using TMVA >= 3.8.15 with an older training target file ? *** " << std::endl;
         return;
      }

      methname.push_back( key->GetName() );
      path    .push_back( strPath->GetString() );
      wfile   .push_back( strWFile->GetString() );
   }

   // create the control bar
   TControlBar* cbar = new TControlBar( "vertical", "Choose weight file:", 50, 50 );
   BDTReg_Global__cbar.push_back(cbar);

   for (UInt_t im=0; im<path.size(); im++) {
      TString fname = path[im];
      if (fname[fname.Length()-1] != '/') fname += "/";
      fname += wfile[im];
      TString macro = Form( "TMVA::BDT_Reg(0,\"%s\",\"%s\")", fname.Data(), methname[im].Data() );
      cbar->AddButton( fname, macro, "Plot decision trees from this weight file", "button" );
   }

   // *** problems with this button in ROOT 5.19 ***
   #if ROOT_VERSION_CODE < ROOT_VERSION(5,19,0)
   cbar->AddButton( "Close", Form("BDTReg_DeleteTBar(%i)", BDTReg_Global__cbar.size()-1), "Close this control bar", "button" );
   #endif
   // **********************************************

   // set the style 
   cbar->SetTextColor("blue");

   // draw
   cbar->Show();   
}

void TMVA::BDTReg_DeleteTBar(int i)
{
   // destroy all open canvases
   StatDialogBDTReg::Delete();
   TMVAGlob::DestroyCanvases();

   delete BDTReg_Global__cbar[i];
   BDTReg_Global__cbar[i] = 0;
}

// input: - No. of tree
//        - the weight file from which the tree is read
void TMVA::BDT_Reg( Int_t itree, TString wfile , TString methName, Bool_t useTMVAStyle  ) 
{
   // destroy possibly existing dialog windows and/or canvases
   StatDialogBDTReg::Delete();
   TMVAGlob::DestroyCanvases(); 

   // quick check if weight file exist
   if(!wfile.EndsWith(".xml") ){
      std::ifstream fin( wfile );
      if (!fin.good( )) { // file not found --> Error
         std::cout << "*** ERROR: Weight file: " << wfile << " does not exist" << std::endl;
         return;
      }
   }
   std::cout << "test1";
   // set style and remove existing canvas'
   TMVAGlob::Initialize( useTMVAStyle );

   StatDialogBDTReg* gGui = new StatDialogBDTReg( gClient->GetRoot(), wfile, methName, itree );

   gGui->DrawTree( itree );

   gGui->RaiseDialog();
}

 BDT_Reg.cxx:1
 BDT_Reg.cxx:2
 BDT_Reg.cxx:3
 BDT_Reg.cxx:4
 BDT_Reg.cxx:5
 BDT_Reg.cxx:6
 BDT_Reg.cxx:7
 BDT_Reg.cxx:8
 BDT_Reg.cxx:9
 BDT_Reg.cxx:10
 BDT_Reg.cxx:11
 BDT_Reg.cxx:12
 BDT_Reg.cxx:13
 BDT_Reg.cxx:14
 BDT_Reg.cxx:15
 BDT_Reg.cxx:16
 BDT_Reg.cxx:17
 BDT_Reg.cxx:18
 BDT_Reg.cxx:19
 BDT_Reg.cxx:20
 BDT_Reg.cxx:21
 BDT_Reg.cxx:22
 BDT_Reg.cxx:23
 BDT_Reg.cxx:24
 BDT_Reg.cxx:25
 BDT_Reg.cxx:26
 BDT_Reg.cxx:27
 BDT_Reg.cxx:28
 BDT_Reg.cxx:29
 BDT_Reg.cxx:30
 BDT_Reg.cxx:31
 BDT_Reg.cxx:32
 BDT_Reg.cxx:33
 BDT_Reg.cxx:34
 BDT_Reg.cxx:35
 BDT_Reg.cxx:36
 BDT_Reg.cxx:37
 BDT_Reg.cxx:38
 BDT_Reg.cxx:39
 BDT_Reg.cxx:40
 BDT_Reg.cxx:41
 BDT_Reg.cxx:42
 BDT_Reg.cxx:43
 BDT_Reg.cxx:44
 BDT_Reg.cxx:45
 BDT_Reg.cxx:46
 BDT_Reg.cxx:47
 BDT_Reg.cxx:48
 BDT_Reg.cxx:49
 BDT_Reg.cxx:50
 BDT_Reg.cxx:51
 BDT_Reg.cxx:52
 BDT_Reg.cxx:53
 BDT_Reg.cxx:54
 BDT_Reg.cxx:55
 BDT_Reg.cxx:56
 BDT_Reg.cxx:57
 BDT_Reg.cxx:58
 BDT_Reg.cxx:59
 BDT_Reg.cxx:60
 BDT_Reg.cxx:61
 BDT_Reg.cxx:62
 BDT_Reg.cxx:63
 BDT_Reg.cxx:64
 BDT_Reg.cxx:65
 BDT_Reg.cxx:66
 BDT_Reg.cxx:67
 BDT_Reg.cxx:68
 BDT_Reg.cxx:69
 BDT_Reg.cxx:70
 BDT_Reg.cxx:71
 BDT_Reg.cxx:72
 BDT_Reg.cxx:73
 BDT_Reg.cxx:74
 BDT_Reg.cxx:75
 BDT_Reg.cxx:76
 BDT_Reg.cxx:77
 BDT_Reg.cxx:78
 BDT_Reg.cxx:79
 BDT_Reg.cxx:80
 BDT_Reg.cxx:81
 BDT_Reg.cxx:82
 BDT_Reg.cxx:83
 BDT_Reg.cxx:84
 BDT_Reg.cxx:85
 BDT_Reg.cxx:86
 BDT_Reg.cxx:87
 BDT_Reg.cxx:88
 BDT_Reg.cxx:89
 BDT_Reg.cxx:90
 BDT_Reg.cxx:91
 BDT_Reg.cxx:92
 BDT_Reg.cxx:93
 BDT_Reg.cxx:94
 BDT_Reg.cxx:95
 BDT_Reg.cxx:96
 BDT_Reg.cxx:97
 BDT_Reg.cxx:98
 BDT_Reg.cxx:99
 BDT_Reg.cxx:100
 BDT_Reg.cxx:101
 BDT_Reg.cxx:102
 BDT_Reg.cxx:103
 BDT_Reg.cxx:104
 BDT_Reg.cxx:105
 BDT_Reg.cxx:106
 BDT_Reg.cxx:107
 BDT_Reg.cxx:108
 BDT_Reg.cxx:109
 BDT_Reg.cxx:110
 BDT_Reg.cxx:111
 BDT_Reg.cxx:112
 BDT_Reg.cxx:113
 BDT_Reg.cxx:114
 BDT_Reg.cxx:115
 BDT_Reg.cxx:116
 BDT_Reg.cxx:117
 BDT_Reg.cxx:118
 BDT_Reg.cxx:119
 BDT_Reg.cxx:120
 BDT_Reg.cxx:121
 BDT_Reg.cxx:122
 BDT_Reg.cxx:123
 BDT_Reg.cxx:124
 BDT_Reg.cxx:125
 BDT_Reg.cxx:126
 BDT_Reg.cxx:127
 BDT_Reg.cxx:128
 BDT_Reg.cxx:129
 BDT_Reg.cxx:130
 BDT_Reg.cxx:131
 BDT_Reg.cxx:132
 BDT_Reg.cxx:133
 BDT_Reg.cxx:134
 BDT_Reg.cxx:135
 BDT_Reg.cxx:136
 BDT_Reg.cxx:137
 BDT_Reg.cxx:138
 BDT_Reg.cxx:139
 BDT_Reg.cxx:140
 BDT_Reg.cxx:141
 BDT_Reg.cxx:142
 BDT_Reg.cxx:143
 BDT_Reg.cxx:144
 BDT_Reg.cxx:145
 BDT_Reg.cxx:146
 BDT_Reg.cxx:147
 BDT_Reg.cxx:148
 BDT_Reg.cxx:149
 BDT_Reg.cxx:150
 BDT_Reg.cxx:151
 BDT_Reg.cxx:152
 BDT_Reg.cxx:153
 BDT_Reg.cxx:154
 BDT_Reg.cxx:155
 BDT_Reg.cxx:156
 BDT_Reg.cxx:157
 BDT_Reg.cxx:158
 BDT_Reg.cxx:159
 BDT_Reg.cxx:160
 BDT_Reg.cxx:161
 BDT_Reg.cxx:162
 BDT_Reg.cxx:163
 BDT_Reg.cxx:164
 BDT_Reg.cxx:165
 BDT_Reg.cxx:166
 BDT_Reg.cxx:167
 BDT_Reg.cxx:168
 BDT_Reg.cxx:169
 BDT_Reg.cxx:170
 BDT_Reg.cxx:171
 BDT_Reg.cxx:172
 BDT_Reg.cxx:173
 BDT_Reg.cxx:174
 BDT_Reg.cxx:175
 BDT_Reg.cxx:176
 BDT_Reg.cxx:177
 BDT_Reg.cxx:178
 BDT_Reg.cxx:179
 BDT_Reg.cxx:180
 BDT_Reg.cxx:181
 BDT_Reg.cxx:182
 BDT_Reg.cxx:183
 BDT_Reg.cxx:184
 BDT_Reg.cxx:185
 BDT_Reg.cxx:186
 BDT_Reg.cxx:187
 BDT_Reg.cxx:188
 BDT_Reg.cxx:189
 BDT_Reg.cxx:190
 BDT_Reg.cxx:191
 BDT_Reg.cxx:192
 BDT_Reg.cxx:193
 BDT_Reg.cxx:194
 BDT_Reg.cxx:195
 BDT_Reg.cxx:196
 BDT_Reg.cxx:197
 BDT_Reg.cxx:198
 BDT_Reg.cxx:199
 BDT_Reg.cxx:200
 BDT_Reg.cxx:201
 BDT_Reg.cxx:202
 BDT_Reg.cxx:203
 BDT_Reg.cxx:204
 BDT_Reg.cxx:205
 BDT_Reg.cxx:206
 BDT_Reg.cxx:207
 BDT_Reg.cxx:208
 BDT_Reg.cxx:209
 BDT_Reg.cxx:210
 BDT_Reg.cxx:211
 BDT_Reg.cxx:212
 BDT_Reg.cxx:213
 BDT_Reg.cxx:214
 BDT_Reg.cxx:215
 BDT_Reg.cxx:216
 BDT_Reg.cxx:217
 BDT_Reg.cxx:218
 BDT_Reg.cxx:219
 BDT_Reg.cxx:220
 BDT_Reg.cxx:221
 BDT_Reg.cxx:222
 BDT_Reg.cxx:223
 BDT_Reg.cxx:224
 BDT_Reg.cxx:225
 BDT_Reg.cxx:226
 BDT_Reg.cxx:227
 BDT_Reg.cxx:228
 BDT_Reg.cxx:229
 BDT_Reg.cxx:230
 BDT_Reg.cxx:231
 BDT_Reg.cxx:232
 BDT_Reg.cxx:233
 BDT_Reg.cxx:234
 BDT_Reg.cxx:235
 BDT_Reg.cxx:236
 BDT_Reg.cxx:237
 BDT_Reg.cxx:238
 BDT_Reg.cxx:239
 BDT_Reg.cxx:240
 BDT_Reg.cxx:241
 BDT_Reg.cxx:242
 BDT_Reg.cxx:243
 BDT_Reg.cxx:244
 BDT_Reg.cxx:245
 BDT_Reg.cxx:246
 BDT_Reg.cxx:247
 BDT_Reg.cxx:248
 BDT_Reg.cxx:249
 BDT_Reg.cxx:250
 BDT_Reg.cxx:251
 BDT_Reg.cxx:252
 BDT_Reg.cxx:253
 BDT_Reg.cxx:254
 BDT_Reg.cxx:255
 BDT_Reg.cxx:256
 BDT_Reg.cxx:257
 BDT_Reg.cxx:258
 BDT_Reg.cxx:259
 BDT_Reg.cxx:260
 BDT_Reg.cxx:261
 BDT_Reg.cxx:262
 BDT_Reg.cxx:263
 BDT_Reg.cxx:264
 BDT_Reg.cxx:265
 BDT_Reg.cxx:266
 BDT_Reg.cxx:267
 BDT_Reg.cxx:268
 BDT_Reg.cxx:269
 BDT_Reg.cxx:270
 BDT_Reg.cxx:271
 BDT_Reg.cxx:272
 BDT_Reg.cxx:273
 BDT_Reg.cxx:274
 BDT_Reg.cxx:275
 BDT_Reg.cxx:276
 BDT_Reg.cxx:277
 BDT_Reg.cxx:278
 BDT_Reg.cxx:279
 BDT_Reg.cxx:280
 BDT_Reg.cxx:281
 BDT_Reg.cxx:282
 BDT_Reg.cxx:283
 BDT_Reg.cxx:284
 BDT_Reg.cxx:285
 BDT_Reg.cxx:286
 BDT_Reg.cxx:287
 BDT_Reg.cxx:288
 BDT_Reg.cxx:289
 BDT_Reg.cxx:290
 BDT_Reg.cxx:291
 BDT_Reg.cxx:292
 BDT_Reg.cxx:293
 BDT_Reg.cxx:294
 BDT_Reg.cxx:295
 BDT_Reg.cxx:296
 BDT_Reg.cxx:297
 BDT_Reg.cxx:298
 BDT_Reg.cxx:299
 BDT_Reg.cxx:300
 BDT_Reg.cxx:301
 BDT_Reg.cxx:302
 BDT_Reg.cxx:303
 BDT_Reg.cxx:304
 BDT_Reg.cxx:305
 BDT_Reg.cxx:306
 BDT_Reg.cxx:307
 BDT_Reg.cxx:308
 BDT_Reg.cxx:309
 BDT_Reg.cxx:310
 BDT_Reg.cxx:311
 BDT_Reg.cxx:312
 BDT_Reg.cxx:313
 BDT_Reg.cxx:314
 BDT_Reg.cxx:315
 BDT_Reg.cxx:316
 BDT_Reg.cxx:317
 BDT_Reg.cxx:318
 BDT_Reg.cxx:319
 BDT_Reg.cxx:320
 BDT_Reg.cxx:321
 BDT_Reg.cxx:322
 BDT_Reg.cxx:323
 BDT_Reg.cxx:324
 BDT_Reg.cxx:325
 BDT_Reg.cxx:326
 BDT_Reg.cxx:327
 BDT_Reg.cxx:328
 BDT_Reg.cxx:329
 BDT_Reg.cxx:330
 BDT_Reg.cxx:331
 BDT_Reg.cxx:332
 BDT_Reg.cxx:333
 BDT_Reg.cxx:334
 BDT_Reg.cxx:335
 BDT_Reg.cxx:336
 BDT_Reg.cxx:337
 BDT_Reg.cxx:338
 BDT_Reg.cxx:339
 BDT_Reg.cxx:340
 BDT_Reg.cxx:341
 BDT_Reg.cxx:342
 BDT_Reg.cxx:343
 BDT_Reg.cxx:344
 BDT_Reg.cxx:345
 BDT_Reg.cxx:346
 BDT_Reg.cxx:347
 BDT_Reg.cxx:348
 BDT_Reg.cxx:349
 BDT_Reg.cxx:350
 BDT_Reg.cxx:351
 BDT_Reg.cxx:352
 BDT_Reg.cxx:353
 BDT_Reg.cxx:354
 BDT_Reg.cxx:355
 BDT_Reg.cxx:356
 BDT_Reg.cxx:357
 BDT_Reg.cxx:358
 BDT_Reg.cxx:359
 BDT_Reg.cxx:360
 BDT_Reg.cxx:361
 BDT_Reg.cxx:362
 BDT_Reg.cxx:363
 BDT_Reg.cxx:364
 BDT_Reg.cxx:365
 BDT_Reg.cxx:366
 BDT_Reg.cxx:367
 BDT_Reg.cxx:368
 BDT_Reg.cxx:369
 BDT_Reg.cxx:370
 BDT_Reg.cxx:371
 BDT_Reg.cxx:372
 BDT_Reg.cxx:373
 BDT_Reg.cxx:374
 BDT_Reg.cxx:375
 BDT_Reg.cxx:376
 BDT_Reg.cxx:377
 BDT_Reg.cxx:378
 BDT_Reg.cxx:379
 BDT_Reg.cxx:380
 BDT_Reg.cxx:381
 BDT_Reg.cxx:382
 BDT_Reg.cxx:383
 BDT_Reg.cxx:384
 BDT_Reg.cxx:385
 BDT_Reg.cxx:386
 BDT_Reg.cxx:387
 BDT_Reg.cxx:388
 BDT_Reg.cxx:389
 BDT_Reg.cxx:390
 BDT_Reg.cxx:391
 BDT_Reg.cxx:392
 BDT_Reg.cxx:393
 BDT_Reg.cxx:394
 BDT_Reg.cxx:395
 BDT_Reg.cxx:396
 BDT_Reg.cxx:397
 BDT_Reg.cxx:398
 BDT_Reg.cxx:399
 BDT_Reg.cxx:400
 BDT_Reg.cxx:401
 BDT_Reg.cxx:402
 BDT_Reg.cxx:403
 BDT_Reg.cxx:404
 BDT_Reg.cxx:405
 BDT_Reg.cxx:406
 BDT_Reg.cxx:407
 BDT_Reg.cxx:408
 BDT_Reg.cxx:409
 BDT_Reg.cxx:410
 BDT_Reg.cxx:411
 BDT_Reg.cxx:412
 BDT_Reg.cxx:413
 BDT_Reg.cxx:414
 BDT_Reg.cxx:415
 BDT_Reg.cxx:416
 BDT_Reg.cxx:417
 BDT_Reg.cxx:418
 BDT_Reg.cxx:419
 BDT_Reg.cxx:420
 BDT_Reg.cxx:421
 BDT_Reg.cxx:422
 BDT_Reg.cxx:423
 BDT_Reg.cxx:424
 BDT_Reg.cxx:425
 BDT_Reg.cxx:426
 BDT_Reg.cxx:427
 BDT_Reg.cxx:428
 BDT_Reg.cxx:429
 BDT_Reg.cxx:430
 BDT_Reg.cxx:431
 BDT_Reg.cxx:432
 BDT_Reg.cxx:433
 BDT_Reg.cxx:434
 BDT_Reg.cxx:435
 BDT_Reg.cxx:436
 BDT_Reg.cxx:437
 BDT_Reg.cxx:438
 BDT_Reg.cxx:439
 BDT_Reg.cxx:440
 BDT_Reg.cxx:441
 BDT_Reg.cxx:442
 BDT_Reg.cxx:443
 BDT_Reg.cxx:444
 BDT_Reg.cxx:445
 BDT_Reg.cxx:446
 BDT_Reg.cxx:447
 BDT_Reg.cxx:448
 BDT_Reg.cxx:449
 BDT_Reg.cxx:450
 BDT_Reg.cxx:451
 BDT_Reg.cxx:452
 BDT_Reg.cxx:453
 BDT_Reg.cxx:454
 BDT_Reg.cxx:455
 BDT_Reg.cxx:456
 BDT_Reg.cxx:457
 BDT_Reg.cxx:458
 BDT_Reg.cxx:459
 BDT_Reg.cxx:460
 BDT_Reg.cxx:461
 BDT_Reg.cxx:462
 BDT_Reg.cxx:463
 BDT_Reg.cxx:464
 BDT_Reg.cxx:465
 BDT_Reg.cxx:466