// @(#)root/roostats:$Id$
// Author: Kyle Cranmer, George Lewis 
/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//_________________________________________________
/*
BEGIN_HTML
<p>
The RooStats::HistFactory::Measurement class can be used to construct a model
by combining multiple RooStats::HistFactory::Channel objects. It also allows
to set some general properties like the integrated luminosity, its relative
uncertainty or the functional form of constraints on nuisance parameters.
</p>
END_HTML
*/
//


#include <ctime>
#include <iostream>
#include <algorithm>
#include <sys/stat.h>
#include "TSystem.h"
#include "TTimeStamp.h"

#include "RooStats/HistFactory/Measurement.h"
#include "RooStats/HistFactory/HistFactoryException.h"

using namespace std;

ClassImp(RooStats::HistFactory::Measurement) ;


RooStats::HistFactory::Measurement::Measurement() :
  fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ), 
  fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
{
  // standard constructor
}

/*
RooStats::HistFactory::Measurement::Measurement(const Measurement& other) :
  POI( other.POI ), Lumi( other.Lumi ), LumiRelErr( other.LumiRelErr ), 
  BinLow( other.BinLow ), BinHigh( other.BinHigh ), ExportOnly( other.ExportOnly ),
  channels( other.channels ), OutputFilePrefix( other.outputFilePrefix ),
  constantParams( other.constantParams ), { ; }
*/

RooStats::HistFactory::Measurement::Measurement(const char* Name, const char* Title) :
  TNamed( Name, Title ),
  fPOI(), fLumi( 1.0 ), fLumiRelErr( .10 ), 
  fBinLow( 0 ), fBinHigh( 1 ), fExportOnly( false )
{
  // standard constructor specifying name and title of measurement
}


void RooStats::HistFactory::Measurement::AddConstantParam( const std::string& param )
{ 
  // set a parameter in the model to be constant
  // the parameter does not have to exist yet, the information will be used when
  // the model is actually created
  
  // Check if the parameter is already set constant
  // We don't need to set it constant twice,
  // and we issue a warning in case this is a hint
  // of a possible bug

  if( std::find(fConstantParams.begin(), fConstantParams.end(), param) != fConstantParams.end() ) {
    std::cout << "Warning: Setting parameter: " << param 
	      << " to constant, but it is already listed as constant.  "
	      << "You may ignore this warning."
	      << std::endl;
    return;
  }

  fConstantParams.push_back( param ); 

}

void RooStats::HistFactory::Measurement::SetParamValue( const std::string& param, double value )
{
  // set parameter of the model to given value

  // Check if this parameter is already set to a value
  // If so, issue a warning
  // (Not sure if we want to throw an exception here, or
  // issue a warning and move along.  Thoughts?)
  if( fParamValues.find(param) != fParamValues.end() ) {
    std::cout << "Warning: Chainging parameter: " << param
	      << " value from: " << fParamValues[param]
	      << " to: " << value 
	      << std::endl;
  }

  // Store the parameter and its value
  std::cout << "Setting parameter: " << param
	    << " value to " << value
	    << std::endl;

  fParamValues[param] = value;

}

void RooStats::HistFactory::Measurement::AddPreprocessFunction( std::string name, std::string expression, std::string dependencies )
{
  // Add a preprocessed function by giving the function a name,
  // a functional expression, and a string with a bracketed list of dependencies (eg "SigXsecOverSM[0,3]")

  PreprocessFunction func(name, expression, dependencies);
  AddFunctionObject(func);

}


std::vector<std::string> RooStats::HistFactory::Measurement::GetPreprocessFunctions()
{
  // returns a list of defined proprocess function expressions
  
  std::vector<std::string> PreprocessFunctionExpressions;
  for( unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
    std::string expression = fFunctionObjects.at(i).GetCommand();
    PreprocessFunctionExpressions.push_back( expression );
  }
  return PreprocessFunctionExpressions;
}

void RooStats::HistFactory::Measurement::AddGammaSyst(std::string syst, double uncert)
{
  // set constraint term for given systematic to Gamma distribution
  
  fGammaSyst[syst] = uncert;
}

void RooStats::HistFactory::Measurement::AddLogNormSyst(std::string syst, double uncert)
{
  // set constraint term for given systematic to LogNormal distribution
  
  fLogNormSyst[syst] = uncert;
}

void RooStats::HistFactory::Measurement::AddUniformSyst(std::string syst)
{
  // set constraint term for given systematic to uniform distribution

  fUniformSyst[syst] = 1.0; // Is this parameter simply a dummy?
}

void RooStats::HistFactory::Measurement::AddNoSyst(std::string syst)
{
  // define given systematics to have no external constraint
  
  fNoSyst[syst] = 1.0; // dummy value
}


bool RooStats::HistFactory::Measurement::HasChannel( std::string ChanName )
{
  // is the given channel part of this measurement

  for( unsigned int i = 0; i < fChannels.size(); ++i ) {

    Channel& chan = fChannels.at(i);
    if( chan.GetName() == ChanName ) {
      return true;
    }

  }

  return false;

}

RooStats::HistFactory::Channel& RooStats::HistFactory::Measurement::GetChannel( std::string ChanName )
{
  // get channel with given name from this measurement
  // throws an exception in case the channel is not found

  for( unsigned int i = 0; i < fChannels.size(); ++i ) {

    Channel& chan = fChannels.at(i);
    if( chan.GetName() == ChanName ) {
      return chan;
    }

  }
  
  // If we get here, we didn't find the channel

  std::cout << "Error: Did not find channel: " << ChanName
	    << " in measurement: " << GetName() << std::endl;
  throw hf_exc();

  // No Need to return after throwing exception
  // return RooStats::HistFactory::BadChannel;


}

/*
  void RooStats::HistFactory::Measurement::Print( Option_t* option ) const {
  RooStats::HistFactory::Measurement::Print( std::cout );
  return;
  }
*/

void RooStats::HistFactory::Measurement::PrintTree( std::ostream& stream )
{
  // print information about measurement object in tree-like structure to given stream
  
  stream << "Measurement Name: " << GetName()
	 << "\t OutputFilePrefix: " << fOutputFilePrefix
	 << "\t POI: ";
  for(unsigned int i = 0; i < fPOI.size(); ++i) {
    stream << fPOI.at(i);
  }
  stream << "\t Lumi: " << fLumi
	 << "\t LumiRelErr: " << fLumiRelErr
	 << "\t BinLow: " << fBinLow
	 << "\t BinHigh: " << fBinHigh
	 << "\t ExportOnly: " << fExportOnly
	 << std::endl;


  if( fConstantParams.size() != 0 ) {
    stream << "Constant Params: ";
    for( unsigned int i = 0; i < fConstantParams.size(); ++i ) {
      stream << " " << fConstantParams.at(i);
    }
    stream << std::endl;
  }

  if( fFunctionObjects.size() != 0 ) {
    stream << "Preprocess Functions: ";
    for( unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
      stream << " " << fFunctionObjects.at(i).GetCommand();
    }
    stream << std::endl;
  }
  
  if( fChannels.size() != 0 ) {
    stream << "Channels:" << std::endl;
    for( unsigned int i = 0; i < fChannels.size(); ++i ) {
      fChannels.at(i).Print( stream );
    }
  }

  std::cout << "End Measurement: " << GetName() << std::endl;

}



void RooStats::HistFactory::Measurement::PrintXML( std::string directory, std::string newOutputPrefix )
{
  // create XML files for this measurement in the given directory
  // XML files can be configured with a different output prefix

  // Create an XML file for this measurement
  // First, create the XML driver
  // Then, create xml files for each channel

  // First, check that the directory exists:

  if( directory != "" && gSystem->OpenDirectory( directory.c_str() ) == 0 ) {
    int success = gSystem->MakeDirectory(directory.c_str() );    
    if( success != 0 ) {
      std::cout << "Error: Failed to make directory: " << directory << std::endl;
      throw hf_exc();
    }
  }

  // If supplied new Prefix, use that one:

  std::cout << "Printing XML Files for measurement: " << GetName() << std::endl;

  std::string XMLName = std::string(GetName()) + ".xml";
  if( directory != "" ) XMLName = directory + "/" + XMLName;

  ofstream xml( XMLName.c_str() );

  if( ! xml.is_open() ) {
    std::cout << "Error opening xml file: " << XMLName << std::endl;
    throw hf_exc();
  }


  // Add the time
  xml << "<!--" << std::endl;
  xml << "This xml file created automatically on: " << std::endl;
/*
  time_t t = time(0);   // get time now
  struct tm * now = localtime( &t );
  xml << (now->tm_year + 1900) << '-'
      << (now->tm_mon + 1) << '-'
      << now->tm_mday
      << std::endl;
*/
  // LM: use TTimeStamp 
  TTimeStamp t; 
  UInt_t year = 0; 
  UInt_t month = 0; 
  UInt_t day = 0; 
  t.GetDate(true, 0, &year, &month, &day);
  xml << year << '-'
      << month << '-'
      << day
      << std::endl;

  xml << "-->" << std::endl;

  // Add the doctype
  xml << "<!DOCTYPE Combination  SYSTEM 'HistFactorySchema.dtd'>" << std::endl << std::endl;

  // Add the combination name
  if (newOutputPrefix.empty() ) newOutputPrefix = fOutputFilePrefix;  
  xml << "<Combination OutputFilePrefix=\"" << newOutputPrefix /*OutputFilePrefix*/ << "\" >" << std::endl << std::endl;

  // Add the Preprocessed Functions
  for( unsigned int i = 0; i < fFunctionObjects.size(); ++i ) {
    RooStats::HistFactory::PreprocessFunction func = fFunctionObjects.at(i);
    func.PrintXML(xml);
    /*
    xml << "<Function Name=\"" << func.GetName() << "\" "
	<< "Expression=\""     << func.GetExpression() << "\" "
	<< "Dependents=\""     << func.GetDependents() << "\" "
	<< "/>" << std::endl;
    */
  }
  
  xml << std::endl;

  // Add the list of channels
  for( unsigned int i = 0; i < fChannels.size(); ++i ) {
     xml << "  <Input>" << "./";
     if (!directory.empty() ) xml << directory << "/";
     xml << GetName() << "_" << fChannels.at(i).GetName() << ".xml" << "</Input>" << std::endl;
  }

  xml << std::endl;

  // Open the Measurement, Set Lumi
  xml << "  <Measurement Name=\"" << GetName() << "\" "
      << "Lumi=\""        << fLumi       << "\" " 
      << "LumiRelErr=\""  << fLumiRelErr << "\" "
    //<< "BinLow=\""      << fBinLow     << "\" "
    // << "BinHigh=\""     << fBinHigh    << "\" "
      << "ExportOnly=\""  << (fExportOnly ? std::string("True") : std::string("False")) << "\" "
      << " >" <<  std::endl;


  // Set the POI
  xml << "    <POI>" ;
  for(unsigned int i = 0; i < fPOI.size(); ++i) {
    if(i==0) xml << fPOI.at(i);
    else     xml << " " << fPOI.at(i);
  } 
  xml << "</POI>  " << std::endl;
  
  // Set the Constant Parameters
  if(fConstantParams.size()) {
    xml << "    <ParamSetting Const=\"True\">";
    for( unsigned int i = 0; i < fConstantParams.size(); ++i ) {
      if (i==0) xml << fConstantParams.at(i);
      else      xml << " " << fConstantParams.at(i);;
    }
    xml << "</ParamSetting>" << std::endl;
  }
  
  // Set the Parameters with new Constraint Terms
  std::map<std::string, double>::iterator ConstrItr;
  
  // Gamma
  for( ConstrItr = fGammaSyst.begin(); ConstrItr != fGammaSyst.end(); ++ConstrItr ) {
    xml << "<ConstraintTerm Type=\"Gamma\" RelativeUncertainty=\""
	<< ConstrItr->second << "\">" << ConstrItr->first
	<< "</ConstraintTerm>" << std::endl; 
  }
  // Uniform
  for( ConstrItr = fUniformSyst.begin(); ConstrItr != fUniformSyst.end(); ++ConstrItr ) {
    xml << "<ConstraintTerm Type=\"Uniform\" RelativeUncertainty=\""
	<< ConstrItr->second << "\">" << ConstrItr->first
	<< "</ConstraintTerm>" << std::endl; 
  }
  // LogNormal
  for( ConstrItr = fLogNormSyst.begin(); ConstrItr != fLogNormSyst.end(); ++ConstrItr ) {
    xml << "<ConstraintTerm Type=\"LogNormal\" RelativeUncertainty=\""
	<< ConstrItr->second << "\">" << ConstrItr->first
	<< "</ConstraintTerm>" << std::endl; 
  }
  // NoSyst
  for( ConstrItr = fNoSyst.begin(); ConstrItr != fNoSyst.end(); ++ConstrItr ) {
    xml << "<ConstraintTerm Type=\"NoSyst\" RelativeUncertainty=\""
	<< ConstrItr->second << "\">" << ConstrItr->first
	<< "</ConstraintTerm>" << std::endl; 
  }


  // Close the Measurement
  xml << "  </Measurement> " << std::endl << std::endl;

  // Close the combination
  xml << "</Combination>" << std::endl;

  xml.close();

  // Now, make the xml files 
  // for the individual channels:

  std::string prefix = std::string(GetName()) + "_";

  for( unsigned int i = 0; i < fChannels.size(); ++i ) {
    fChannels.at(i).PrintXML( directory, prefix );
  }


  std::cout << "Finished printing XML files" << std::endl;

}



void RooStats::HistFactory::Measurement::writeToFile( TFile* file )
{
  // A measurement, once fully configured, can be saved into a ROOT
  // file. This will persitify the Measurement object, along with any
  // channels and samples that have been added to it. It can then be
  // loaded, potentially modified, and used to create new models.
    
  // Write every histogram to the file.
  // Edit the measurement to point to this file
  // and to point to each histogram in this file
  // Then write the measurement itself.

  // Create a tempory measurement
  // (This is the one that is actually written)
  RooStats::HistFactory::Measurement outMeas( *this );

  std::string OutputFileName = file->GetName();

  // Collect all histograms from file:
  // HistCollector collector;


  for( unsigned int chanItr = 0; chanItr < outMeas.fChannels.size(); ++chanItr ) {
    
    // Go to the main directory 
    // in the file
    file->cd();
    file->Flush();

    // Get the name of the channel:
    RooStats::HistFactory::Channel& channel = outMeas.fChannels.at( chanItr );
    std::string chanName = channel.GetName();

    
    if( ! channel.CheckHistograms() ) {
      std::cout << "Measurement.writeToFile(): Channel: " << chanName
		<< " has uninitialized histogram pointers" << std::endl;
      throw hf_exc();
      return;
    }
    
    // Get and cache the histograms for this channel:
    //collector.CollectHistograms( channel );
    // Do I need this...?
    // channel.CollectHistograms();

    // Make a directory to store the histograms
    // for this channel

    TDirectory* chanDir = file->mkdir( (chanName + "_hists").c_str() );
    if( chanDir == NULL ) {
      std::cout << "Error: Cannot create channel " << (chanName + "_hists")
		<< std::endl;
      throw hf_exc();
    }
    chanDir->cd();

    // Save the data:
    TDirectory* dataDir = chanDir->mkdir( "data" );
    if( dataDir == NULL ) {
      std::cout << "Error: Cannot make directory " << chanDir << std::endl;
      throw hf_exc();
    }
    dataDir->cd();

    channel.fData.writeToFile( OutputFileName, GetDirPath(dataDir) );

    /*
    // Write the data file to this directory
    TH1* hData = channel.data.GetHisto();
    hData->Write();

    // Set the location of the data
    // in the output measurement

    channel.data.InputFile = OutputFileName;
    channel.data.HistoName = hData->GetName();
    channel.data.HistoPath = GetDirPath( dataDir );
    */

    // Loop over samples:

    for( unsigned int sampItr = 0; sampItr < channel.GetSamples().size(); ++sampItr ) {

      RooStats::HistFactory::Sample& sample = channel.GetSamples().at( sampItr );
      std::string sampName = sample.GetName();
      
      std::cout << "Writing sample: " << sampName << std::endl;

      file->cd();
      chanDir->cd();
      TDirectory* sampleDir = chanDir->mkdir( sampName.c_str() );
      if( sampleDir == NULL ) {
	std::cout << "Error: Directory " << sampName << " not created properly" << std::endl;
	throw hf_exc();
      }
      std::string sampleDirPath = GetDirPath( sampleDir );

      if( ! sampleDir ) {
	std::cout << "Error making directory: " << sampName 
		  << " in directory: " << chanName
		  << std::endl;
	throw hf_exc();
      }

      // Write the data file to this directory
      sampleDir->cd();      
      
      sample.writeToFile( OutputFileName, sampleDirPath );
      /*
      TH1* hSample = sample.GetHisto();
      if( ! hSample ) {
	std::cout << "Error getting histogram for sample: " 
		  << sampName << std::endl;
	throw -1;
      }
      sampleDir->cd();    
      hSample->Write();

      sample.InputFile = OutputFileName;
      sample.HistoName = hSample->GetName();
      sample.HistoPath = sampleDirPath;
      */

      // Write the histograms associated with
      // systematics

      /*  THIS IS WHAT I"M COMMENTING
      sample.GetStatError().writeToFile( OutputFileName, sampleDirPath );

      // Must write all systematics that contain internal histograms
      // (This is not all systematics)

      for( unsigned int i = 0; i < sample.GetHistoSysList().size(); ++i ) {
	sample.GetHistoSysList().at(i).writeToFile( OutputFileName, sampleDirPath );
      }
      for( unsigned int i = 0; i < sample.GetHistoFactorList().size(); ++i ) {
	sample.GetHistoFactorList().at(i).writeToFile( OutputFileName, sampleDirPath );
      }
      for( unsigned int i = 0; i < sample.GetShapeSysList().size(); ++i ) {
	sample.GetShapeSysList().at(i).writeToFile( OutputFileName, sampleDirPath );
      }
      END COMMENT  */
      /*
      sample.statError.writeToFile( OutputFileName, sampleDirPath );

      // Now, get the Stat config histograms
      if( sample.statError.HistoName != "" ) {
	TH1* hStatError = sample.statError.GetErrorHist();
	if( ! hStatError ) {
	  std::cout << "Error getting stat error histogram for sample: " 
		    << sampName << std::endl;
	  throw -1;
	}
	hStatError->Write();
      
	sample.statError.InputFile = OutputFileName;
	sample.statError.HistoName = hStatError->GetName();
	sample.statError.HistoPath = sampleDirPath;

      }
      */

    }

  }
  
  
  // Finally, write the measurement itself:

  std::cout << "Saved all histograms" << std::endl;
  
  file->cd();
  outMeas.Write();

  std::cout << "Saved Measurement" << std::endl;

}


std::string RooStats::HistFactory::Measurement::GetDirPath( TDirectory* dir )
{
  // Return the directory's path,
  // stripped of unnecessary prefixes

  std::string path = dir->GetPath();

  if( path.find(":") != std::string::npos ) {
    size_t index = path.find(":");
    path.replace( 0, index+1, "" );
  }                   

  path = path + "/";

  return path;

  /*
      if( path.find(":") != std::string::npos ) {
	size_t index = path.find(":");
	SampleName.replace( 0, index, "" );
      }                   

      // Remove the file:
      */

}



void RooStats::HistFactory::Measurement::CollectHistograms()
{
  // The most common way to add histograms to channels is to have them
  // stored in ROOT files and to give HistFactory the location of these
  // files. This means providing the path to the ROOT file and the path
  // and name of the histogram within that file. When providing these
  // in a script, HistFactory doesn't load the histogram from the file
  // right away. Instead, once all such histograms have been supplied,
  // one should run this method to open all ROOT files and to copy and
  // save all necessary histograms.

  for( unsigned int chanItr = 0; chanItr < fChannels.size(); ++chanItr) {

    RooStats::HistFactory::Channel& chan = fChannels.at( chanItr );
    
    chan.CollectHistograms();

  }

}



 Measurement.cxx:1
 Measurement.cxx:2
 Measurement.cxx:3
 Measurement.cxx:4
 Measurement.cxx:5
 Measurement.cxx:6
 Measurement.cxx:7
 Measurement.cxx:8
 Measurement.cxx:9
 Measurement.cxx:10
 Measurement.cxx:11
 Measurement.cxx:12
 Measurement.cxx:13
 Measurement.cxx:14
 Measurement.cxx:15
 Measurement.cxx:16
 Measurement.cxx:17
 Measurement.cxx:18
 Measurement.cxx:19
 Measurement.cxx:20
 Measurement.cxx:21
 Measurement.cxx:22
 Measurement.cxx:23
 Measurement.cxx:24
 Measurement.cxx:25
 Measurement.cxx:26
 Measurement.cxx:27
 Measurement.cxx:28
 Measurement.cxx:29
 Measurement.cxx:30
 Measurement.cxx:31
 Measurement.cxx:32
 Measurement.cxx:33
 Measurement.cxx:34
 Measurement.cxx:35
 Measurement.cxx:36
 Measurement.cxx:37
 Measurement.cxx:38
 Measurement.cxx:39
 Measurement.cxx:40
 Measurement.cxx:41
 Measurement.cxx:42
 Measurement.cxx:43
 Measurement.cxx:44
 Measurement.cxx:45
 Measurement.cxx:46
 Measurement.cxx:47
 Measurement.cxx:48
 Measurement.cxx:49
 Measurement.cxx:50
 Measurement.cxx:51
 Measurement.cxx:52
 Measurement.cxx:53
 Measurement.cxx:54
 Measurement.cxx:55
 Measurement.cxx:56
 Measurement.cxx:57
 Measurement.cxx:58
 Measurement.cxx:59
 Measurement.cxx:60
 Measurement.cxx:61
 Measurement.cxx:62
 Measurement.cxx:63
 Measurement.cxx:64
 Measurement.cxx:65
 Measurement.cxx:66
 Measurement.cxx:67
 Measurement.cxx:68
 Measurement.cxx:69
 Measurement.cxx:70
 Measurement.cxx:71
 Measurement.cxx:72
 Measurement.cxx:73
 Measurement.cxx:74
 Measurement.cxx:75
 Measurement.cxx:76
 Measurement.cxx:77
 Measurement.cxx:78
 Measurement.cxx:79
 Measurement.cxx:80
 Measurement.cxx:81
 Measurement.cxx:82
 Measurement.cxx:83
 Measurement.cxx:84
 Measurement.cxx:85
 Measurement.cxx:86
 Measurement.cxx:87
 Measurement.cxx:88
 Measurement.cxx:89
 Measurement.cxx:90
 Measurement.cxx:91
 Measurement.cxx:92
 Measurement.cxx:93
 Measurement.cxx:94
 Measurement.cxx:95
 Measurement.cxx:96
 Measurement.cxx:97
 Measurement.cxx:98
 Measurement.cxx:99
 Measurement.cxx:100
 Measurement.cxx:101
 Measurement.cxx:102
 Measurement.cxx:103
 Measurement.cxx:104
 Measurement.cxx:105
 Measurement.cxx:106
 Measurement.cxx:107
 Measurement.cxx:108
 Measurement.cxx:109
 Measurement.cxx:110
 Measurement.cxx:111
 Measurement.cxx:112
 Measurement.cxx:113
 Measurement.cxx:114
 Measurement.cxx:115
 Measurement.cxx:116
 Measurement.cxx:117
 Measurement.cxx:118
 Measurement.cxx:119
 Measurement.cxx:120
 Measurement.cxx:121
 Measurement.cxx:122
 Measurement.cxx:123
 Measurement.cxx:124
 Measurement.cxx:125
 Measurement.cxx:126
 Measurement.cxx:127
 Measurement.cxx:128
 Measurement.cxx:129
 Measurement.cxx:130
 Measurement.cxx:131
 Measurement.cxx:132
 Measurement.cxx:133
 Measurement.cxx:134
 Measurement.cxx:135
 Measurement.cxx:136
 Measurement.cxx:137
 Measurement.cxx:138
 Measurement.cxx:139
 Measurement.cxx:140
 Measurement.cxx:141
 Measurement.cxx:142
 Measurement.cxx:143
 Measurement.cxx:144
 Measurement.cxx:145
 Measurement.cxx:146
 Measurement.cxx:147
 Measurement.cxx:148
 Measurement.cxx:149
 Measurement.cxx:150
 Measurement.cxx:151
 Measurement.cxx:152
 Measurement.cxx:153
 Measurement.cxx:154
 Measurement.cxx:155
 Measurement.cxx:156
 Measurement.cxx:157
 Measurement.cxx:158
 Measurement.cxx:159
 Measurement.cxx:160
 Measurement.cxx:161
 Measurement.cxx:162
 Measurement.cxx:163
 Measurement.cxx:164
 Measurement.cxx:165
 Measurement.cxx:166
 Measurement.cxx:167
 Measurement.cxx:168
 Measurement.cxx:169
 Measurement.cxx:170
 Measurement.cxx:171
 Measurement.cxx:172
 Measurement.cxx:173
 Measurement.cxx:174
 Measurement.cxx:175
 Measurement.cxx:176
 Measurement.cxx:177
 Measurement.cxx:178
 Measurement.cxx:179
 Measurement.cxx:180
 Measurement.cxx:181
 Measurement.cxx:182
 Measurement.cxx:183
 Measurement.cxx:184
 Measurement.cxx:185
 Measurement.cxx:186
 Measurement.cxx:187
 Measurement.cxx:188
 Measurement.cxx:189
 Measurement.cxx:190
 Measurement.cxx:191
 Measurement.cxx:192
 Measurement.cxx:193
 Measurement.cxx:194
 Measurement.cxx:195
 Measurement.cxx:196
 Measurement.cxx:197
 Measurement.cxx:198
 Measurement.cxx:199
 Measurement.cxx:200
 Measurement.cxx:201
 Measurement.cxx:202
 Measurement.cxx:203
 Measurement.cxx:204
 Measurement.cxx:205
 Measurement.cxx:206
 Measurement.cxx:207
 Measurement.cxx:208
 Measurement.cxx:209
 Measurement.cxx:210
 Measurement.cxx:211
 Measurement.cxx:212
 Measurement.cxx:213
 Measurement.cxx:214
 Measurement.cxx:215
 Measurement.cxx:216
 Measurement.cxx:217
 Measurement.cxx:218
 Measurement.cxx:219
 Measurement.cxx:220
 Measurement.cxx:221
 Measurement.cxx:222
 Measurement.cxx:223
 Measurement.cxx:224
 Measurement.cxx:225
 Measurement.cxx:226
 Measurement.cxx:227
 Measurement.cxx:228
 Measurement.cxx:229
 Measurement.cxx:230
 Measurement.cxx:231
 Measurement.cxx:232
 Measurement.cxx:233
 Measurement.cxx:234
 Measurement.cxx:235
 Measurement.cxx:236
 Measurement.cxx:237
 Measurement.cxx:238
 Measurement.cxx:239
 Measurement.cxx:240
 Measurement.cxx:241
 Measurement.cxx:242
 Measurement.cxx:243
 Measurement.cxx:244
 Measurement.cxx:245
 Measurement.cxx:246
 Measurement.cxx:247
 Measurement.cxx:248
 Measurement.cxx:249
 Measurement.cxx:250
 Measurement.cxx:251
 Measurement.cxx:252
 Measurement.cxx:253
 Measurement.cxx:254
 Measurement.cxx:255
 Measurement.cxx:256
 Measurement.cxx:257
 Measurement.cxx:258
 Measurement.cxx:259
 Measurement.cxx:260
 Measurement.cxx:261
 Measurement.cxx:262
 Measurement.cxx:263
 Measurement.cxx:264
 Measurement.cxx:265
 Measurement.cxx:266
 Measurement.cxx:267
 Measurement.cxx:268
 Measurement.cxx:269
 Measurement.cxx:270
 Measurement.cxx:271
 Measurement.cxx:272
 Measurement.cxx:273
 Measurement.cxx:274
 Measurement.cxx:275
 Measurement.cxx:276
 Measurement.cxx:277
 Measurement.cxx:278
 Measurement.cxx:279
 Measurement.cxx:280
 Measurement.cxx:281
 Measurement.cxx:282
 Measurement.cxx:283
 Measurement.cxx:284
 Measurement.cxx:285
 Measurement.cxx:286
 Measurement.cxx:287
 Measurement.cxx:288
 Measurement.cxx:289
 Measurement.cxx:290
 Measurement.cxx:291
 Measurement.cxx:292
 Measurement.cxx:293
 Measurement.cxx:294
 Measurement.cxx:295
 Measurement.cxx:296
 Measurement.cxx:297
 Measurement.cxx:298
 Measurement.cxx:299
 Measurement.cxx:300
 Measurement.cxx:301
 Measurement.cxx:302
 Measurement.cxx:303
 Measurement.cxx:304
 Measurement.cxx:305
 Measurement.cxx:306
 Measurement.cxx:307
 Measurement.cxx:308
 Measurement.cxx:309
 Measurement.cxx:310
 Measurement.cxx:311
 Measurement.cxx:312
 Measurement.cxx:313
 Measurement.cxx:314
 Measurement.cxx:315
 Measurement.cxx:316
 Measurement.cxx:317
 Measurement.cxx:318
 Measurement.cxx:319
 Measurement.cxx:320
 Measurement.cxx:321
 Measurement.cxx:322
 Measurement.cxx:323
 Measurement.cxx:324
 Measurement.cxx:325
 Measurement.cxx:326
 Measurement.cxx:327
 Measurement.cxx:328
 Measurement.cxx:329
 Measurement.cxx:330
 Measurement.cxx:331
 Measurement.cxx:332
 Measurement.cxx:333
 Measurement.cxx:334
 Measurement.cxx:335
 Measurement.cxx:336
 Measurement.cxx:337
 Measurement.cxx:338
 Measurement.cxx:339
 Measurement.cxx:340
 Measurement.cxx:341
 Measurement.cxx:342
 Measurement.cxx:343
 Measurement.cxx:344
 Measurement.cxx:345
 Measurement.cxx:346
 Measurement.cxx:347
 Measurement.cxx:348
 Measurement.cxx:349
 Measurement.cxx:350
 Measurement.cxx:351
 Measurement.cxx:352
 Measurement.cxx:353
 Measurement.cxx:354
 Measurement.cxx:355
 Measurement.cxx:356
 Measurement.cxx:357
 Measurement.cxx:358
 Measurement.cxx:359
 Measurement.cxx:360
 Measurement.cxx:361
 Measurement.cxx:362
 Measurement.cxx:363
 Measurement.cxx:364
 Measurement.cxx:365
 Measurement.cxx:366
 Measurement.cxx:367
 Measurement.cxx:368
 Measurement.cxx:369
 Measurement.cxx:370
 Measurement.cxx:371
 Measurement.cxx:372
 Measurement.cxx:373
 Measurement.cxx:374
 Measurement.cxx:375
 Measurement.cxx:376
 Measurement.cxx:377
 Measurement.cxx:378
 Measurement.cxx:379
 Measurement.cxx:380
 Measurement.cxx:381
 Measurement.cxx:382
 Measurement.cxx:383
 Measurement.cxx:384
 Measurement.cxx:385
 Measurement.cxx:386
 Measurement.cxx:387
 Measurement.cxx:388
 Measurement.cxx:389
 Measurement.cxx:390
 Measurement.cxx:391
 Measurement.cxx:392
 Measurement.cxx:393
 Measurement.cxx:394
 Measurement.cxx:395
 Measurement.cxx:396
 Measurement.cxx:397
 Measurement.cxx:398
 Measurement.cxx:399
 Measurement.cxx:400
 Measurement.cxx:401
 Measurement.cxx:402
 Measurement.cxx:403
 Measurement.cxx:404
 Measurement.cxx:405
 Measurement.cxx:406
 Measurement.cxx:407
 Measurement.cxx:408
 Measurement.cxx:409
 Measurement.cxx:410
 Measurement.cxx:411
 Measurement.cxx:412
 Measurement.cxx:413
 Measurement.cxx:414
 Measurement.cxx:415
 Measurement.cxx:416
 Measurement.cxx:417
 Measurement.cxx:418
 Measurement.cxx:419
 Measurement.cxx:420
 Measurement.cxx:421
 Measurement.cxx:422
 Measurement.cxx:423
 Measurement.cxx:424
 Measurement.cxx:425
 Measurement.cxx:426
 Measurement.cxx:427
 Measurement.cxx:428
 Measurement.cxx:429
 Measurement.cxx:430
 Measurement.cxx:431
 Measurement.cxx:432
 Measurement.cxx:433
 Measurement.cxx:434
 Measurement.cxx:435
 Measurement.cxx:436
 Measurement.cxx:437
 Measurement.cxx:438
 Measurement.cxx:439
 Measurement.cxx:440
 Measurement.cxx:441
 Measurement.cxx:442
 Measurement.cxx:443
 Measurement.cxx:444
 Measurement.cxx:445
 Measurement.cxx:446
 Measurement.cxx:447
 Measurement.cxx:448
 Measurement.cxx:449
 Measurement.cxx:450
 Measurement.cxx:451
 Measurement.cxx:452
 Measurement.cxx:453
 Measurement.cxx:454
 Measurement.cxx:455
 Measurement.cxx:456
 Measurement.cxx:457
 Measurement.cxx:458
 Measurement.cxx:459
 Measurement.cxx:460
 Measurement.cxx:461
 Measurement.cxx:462
 Measurement.cxx:463
 Measurement.cxx:464
 Measurement.cxx:465
 Measurement.cxx:466
 Measurement.cxx:467
 Measurement.cxx:468
 Measurement.cxx:469
 Measurement.cxx:470
 Measurement.cxx:471
 Measurement.cxx:472
 Measurement.cxx:473
 Measurement.cxx:474
 Measurement.cxx:475
 Measurement.cxx:476
 Measurement.cxx:477
 Measurement.cxx:478
 Measurement.cxx:479
 Measurement.cxx:480
 Measurement.cxx:481
 Measurement.cxx:482
 Measurement.cxx:483
 Measurement.cxx:484
 Measurement.cxx:485
 Measurement.cxx:486
 Measurement.cxx:487
 Measurement.cxx:488
 Measurement.cxx:489
 Measurement.cxx:490
 Measurement.cxx:491
 Measurement.cxx:492
 Measurement.cxx:493
 Measurement.cxx:494
 Measurement.cxx:495
 Measurement.cxx:496
 Measurement.cxx:497
 Measurement.cxx:498
 Measurement.cxx:499
 Measurement.cxx:500
 Measurement.cxx:501
 Measurement.cxx:502
 Measurement.cxx:503
 Measurement.cxx:504
 Measurement.cxx:505
 Measurement.cxx:506
 Measurement.cxx:507
 Measurement.cxx:508
 Measurement.cxx:509
 Measurement.cxx:510
 Measurement.cxx:511
 Measurement.cxx:512
 Measurement.cxx:513
 Measurement.cxx:514
 Measurement.cxx:515
 Measurement.cxx:516
 Measurement.cxx:517
 Measurement.cxx:518
 Measurement.cxx:519
 Measurement.cxx:520
 Measurement.cxx:521
 Measurement.cxx:522
 Measurement.cxx:523
 Measurement.cxx:524
 Measurement.cxx:525
 Measurement.cxx:526
 Measurement.cxx:527
 Measurement.cxx:528
 Measurement.cxx:529
 Measurement.cxx:530
 Measurement.cxx:531
 Measurement.cxx:532
 Measurement.cxx:533
 Measurement.cxx:534
 Measurement.cxx:535
 Measurement.cxx:536
 Measurement.cxx:537
 Measurement.cxx:538
 Measurement.cxx:539
 Measurement.cxx:540
 Measurement.cxx:541
 Measurement.cxx:542
 Measurement.cxx:543
 Measurement.cxx:544
 Measurement.cxx:545
 Measurement.cxx:546
 Measurement.cxx:547
 Measurement.cxx:548
 Measurement.cxx:549
 Measurement.cxx:550
 Measurement.cxx:551
 Measurement.cxx:552
 Measurement.cxx:553
 Measurement.cxx:554
 Measurement.cxx:555
 Measurement.cxx:556
 Measurement.cxx:557
 Measurement.cxx:558
 Measurement.cxx:559
 Measurement.cxx:560
 Measurement.cxx:561
 Measurement.cxx:562
 Measurement.cxx:563
 Measurement.cxx:564
 Measurement.cxx:565
 Measurement.cxx:566
 Measurement.cxx:567
 Measurement.cxx:568
 Measurement.cxx:569
 Measurement.cxx:570
 Measurement.cxx:571
 Measurement.cxx:572
 Measurement.cxx:573
 Measurement.cxx:574
 Measurement.cxx:575
 Measurement.cxx:576
 Measurement.cxx:577
 Measurement.cxx:578
 Measurement.cxx:579
 Measurement.cxx:580
 Measurement.cxx:581
 Measurement.cxx:582
 Measurement.cxx:583
 Measurement.cxx:584
 Measurement.cxx:585
 Measurement.cxx:586
 Measurement.cxx:587
 Measurement.cxx:588
 Measurement.cxx:589
 Measurement.cxx:590
 Measurement.cxx:591
 Measurement.cxx:592
 Measurement.cxx:593
 Measurement.cxx:594
 Measurement.cxx:595
 Measurement.cxx:596
 Measurement.cxx:597
 Measurement.cxx:598
 Measurement.cxx:599
 Measurement.cxx:600
 Measurement.cxx:601
 Measurement.cxx:602
 Measurement.cxx:603
 Measurement.cxx:604
 Measurement.cxx:605
 Measurement.cxx:606
 Measurement.cxx:607
 Measurement.cxx:608
 Measurement.cxx:609
 Measurement.cxx:610
 Measurement.cxx:611
 Measurement.cxx:612
 Measurement.cxx:613
 Measurement.cxx:614
 Measurement.cxx:615
 Measurement.cxx:616
 Measurement.cxx:617
 Measurement.cxx:618
 Measurement.cxx:619
 Measurement.cxx:620
 Measurement.cxx:621
 Measurement.cxx:622
 Measurement.cxx:623
 Measurement.cxx:624
 Measurement.cxx:625
 Measurement.cxx:626
 Measurement.cxx:627
 Measurement.cxx:628
 Measurement.cxx:629
 Measurement.cxx:630
 Measurement.cxx:631
 Measurement.cxx:632
 Measurement.cxx:633
 Measurement.cxx:634
 Measurement.cxx:635
 Measurement.cxx:636
 Measurement.cxx:637
 Measurement.cxx:638
 Measurement.cxx:639
 Measurement.cxx:640
 Measurement.cxx:641
 Measurement.cxx:642
 Measurement.cxx:643
 Measurement.cxx:644
 Measurement.cxx:645
 Measurement.cxx:646
 Measurement.cxx:647
 Measurement.cxx:648
 Measurement.cxx:649
 Measurement.cxx:650
 Measurement.cxx:651
 Measurement.cxx:652
 Measurement.cxx:653
 Measurement.cxx:654
 Measurement.cxx:655
 Measurement.cxx:656
 Measurement.cxx:657
 Measurement.cxx:658
 Measurement.cxx:659
 Measurement.cxx:660