// ---------------------------------------------------------------------- // // HepHistProfArray.cc // // History: // // Created 4/5/99 Philippe Canal // // HepHistProfArray() // ~HepHistProfArray() // makeClone and makeEmpty // operator[](int) // HepHistProfArray::length() // HepHistProfArray::nBinsX() // HepHistProfArray::minX() // HepHistProfArray::maxX() // HepHistProfArray::minY() // HepHistProfArray::maxY() #ifndef HEPTRACE_H #include "HepTuple/HepTrace.h" #endif #ifndef HEPHBOOKHISTPROFARRAY_H #include "HepTuple/HepHistProfArray.h" #endif #ifndef HEPHBOOKHISTPROF_H #include "HepTuple/HepHistProf.h" #endif USING( std::string ) ZM_BEGIN_NAMESPACE( zmel ) /* namespace zmel { */ // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- HepHistProfArray::HepHistProfArray( // constructor HepFileManager * mgr , const string & title , const dataArray & data ) : HepObj( mgr, title, 0 ), nBinsX_(0), minX_(0), maxX_(0), minY_(0), maxY_(0) { // We assume that if there are any histograms in the dataArray // that the first one defines the meta data of the whole // checking is assume to be done outside of this functions. HEP_DEBUG( "HepHistProfArray::constructor( \"" << title << "\", " << id_ << " )" ); type_ = 'P'; data_ = data; if ( length() > 0 ) { nBinsX_ = data_[0]->nBinsX(); minX_ = data_[0]->minX(); maxX_ = data_[0]->maxX(); minY_ = data_[0]->minY(); maxY_ = data_[0]->maxY(); } else { ZMthrow(ZMxHepIllFormedItem("Can not create empty HepHistProfArray")); isValid(false); } } // Used for dummy construction ... // the object is then not valid ... HepHistProfArray::HepHistProfArray() : HepObj(), nBinsX_(0), minX_(0), maxX_(0), minY_(0), maxY_(0) { HEP_DEBUG( "HepHistProfArray::constructor( )" ); type_ = 'P'; } // ---------------------------------------------------------------------- // Destructors // ---------------------------------------------------------------------- HepHistProfArray::~HepHistProfArray() { HEP_DEBUG( "HepHistProfArray::destructor( \"" << *title_ << "\", " << id_ << " )" ); } // ---------------------------------------------------------------------- // Clone functionnality! // ---------------------------------------------------------------------- ZM_COVARIANT_TYPE(HepObj,HepHistProfArray) & HepHistProfArray::makeClone( // clone existing histogram, filling bins HepFileManager * manager , const string& title , const int id ) const { if ( ! mayUse() || ! isValid() ) { ZMthrow(ZMxHepUnmanagedItem( string("attempt to makeClone() to unmanaged histogram ") +title+string("."))); return HepFileManager::deadHistProfArray(); } // Static cast for platform without covariant return type // for virtual member function HepHistProfArray & clone = static_cast ( makeEmpty( manager, title, id ) ); int len = length(); for ( int i = 0; i < len ; i++ ) { clone[i] += *(data_[i]); } return clone; } ZM_COVARIANT_TYPE(HepObj,HepHistProfArray) & HepHistProfArray::makeEmpty( // clone existing histogram, but zero bins HepFileManager * mgr , const string& title , const int id ) const { if ( ! mayUse() || ! isValid() ) { ZMthrow(ZMxHepUnmanagedItem( string("attempt to makeClone() to unmanaged histogram ") +title+string("."))); return HepFileManager::deadHistProfArray(); } return mgr->histProfArray( length(), title, nBinsX(), minX(), maxX(), minY(), maxY(), " ", id ); } ZM_COVARIANT_TYPE(HepObj,HepHistProfArray) & HepHistProfArray::makeClone( // clone existing histogram, filling bins const string& title , const int id ) const { return makeClone( manager(), title, id ); } ZM_COVARIANT_TYPE(HepObj,HepHistProfArray) & HepHistProfArray::makeEmpty( // clone existing histogram, but zero bins const string& title , const int id ) const { return makeEmpty( manager(), title, id ); } // ---------------------------------------------------------------------- // Reset // ---------------------------------------------------------------------- void HepHistProfArray::reset() { if ( mayUse() && isValid() ) { for ( int i = 0; i < length(); ++i ) { data_[i]->reset(); } } else { if ( !mayUse() ) { ZMthrow(ZMxHepUnmanagedItem( string("attempt to access unmanaged histogram array") +title()+string("."))); return ; } else if ( ! isValid() ) { ZMthrow(ZMxHepUnusableEntity( title()+" is invalid")); } } } // ---------------------------------------------------------------------- // Simple Accessors // ---------------------------------------------------------------------- HepHistProf& HepHistProfArray::operator[](int pos) const { if ( mayUse() && isValid() && ( pos < length() ) ) { return *(data_[pos]); } else { if ( !mayUse() ) { ZMthrow(ZMxHepUnmanagedItem( string("attempt to access unmanaged histogram array") +title()+string("."))); if ( manager() == 0 ) { ZMthrow(ZMxHepTuple("No manager to know how to recover from previous error!!",ZMexPROBLEM)); } return *(HepHistProf*)HepFileManager::deadHepObj(); } else if ( ! ( pos < length() ) ) { ZMthrow(ZMxHepOutOfRangeValue( string("In ")+title()+"index out of range.")); } else if ( ! isValid() ) { ZMthrow(ZMxHepUnusableEntity( title()+" is invalid")); } return manager()->deadHistProf(); } } int HepHistProfArray::length() const { return data_.size(); } int HepHistProfArray::nBinsX() const { return nBinsX_; } float HepHistProfArray::minX() const { return minX_; } float HepHistProfArray::maxX() const { return maxX_; } float HepHistProfArray::minY() const { return minY_; } float HepHistProfArray::maxY() const { return maxY_; } // ---------------------------------------------------------------------- ZM_END_NAMESPACE( zmel ) /* } // namespace zmel */