SFrame 3.6
core/src/SCycleStatistics.cxx
Go to the documentation of this file.
00001 // $Id: SCycleStatistics.cxx 191 2010-08-04 08:00:45Z krasznaa $
00002 /***************************************************************************
00003  * @Project: SFrame - ROOT-based analysis framework for ATLAS
00004  * @Package: Core
00005  *
00006  * @author Stefan Ask       <Stefan.Ask@cern.ch>           - Manchester
00007  * @author David Berge      <David.Berge@cern.ch>          - CERN
00008  * @author Johannes Haller  <Johannes.Haller@cern.ch>      - Hamburg
00009  * @author A. Krasznahorkay <Attila.Krasznahorkay@cern.ch> - CERN/Debrecen
00010  *
00011  ***************************************************************************/
00012 
00013 // ROOT include(s):
00014 #include <TCollection.h>
00015 #include <TDirectory.h>
00016 
00017 // Local include(s):
00018 #include "../include/SCycleStatistics.h"
00019 
00020 #ifndef DOXYGEN_IGNORE
00021 ClassImp( SCycleStatistics );
00022 #endif // DOXYGEN_IGNORE
00023 
00024 SCycleStatistics::SCycleStatistics( const char* name, Long64_t procEvents,
00025                                     Long64_t skipEvents )
00026    : TNamed( name, "SFrame cycle statistics" ),
00027      m_processedEvents( procEvents ), m_skippedEvents( skipEvents ),
00028      m_logger( "SCycleStatistics" ) {
00029 
00030 }
00031 
00032 Long64_t SCycleStatistics::GetProcessedEvents() const {
00033 
00034    return m_processedEvents;
00035 
00036 }
00037 
00038 void SCycleStatistics::SetProcessedEvents( Long64_t events ) {
00039 
00040    m_processedEvents = events;
00041    return;
00042 
00043 }
00044 
00045 Long64_t SCycleStatistics::GetSkippedEvents() const {
00046 
00047    return m_skippedEvents;
00048 
00049 }
00050 
00051 void SCycleStatistics::SetSkippedEvents( Long64_t events ) {
00052 
00053    m_skippedEvents = events;
00054    return;
00055 
00056 }
00057 
00061 Int_t SCycleStatistics::Merge( TCollection* coll ) {
00062 
00063    //
00064    // Return right away if the input is flawed:
00065    //
00066    if( ! coll ) return 0;
00067    if( coll->IsEmpty() ) return 0;
00068 
00069    m_logger << VERBOSE << "Merging statistics object" << SLogger::endmsg;
00070 
00071    //
00072    // Select the elements from the collection that can actually be merged:
00073    //
00074    TIter next( coll );
00075    TObject* obj = 0;
00076    while( ( obj = next() ) ) {
00077 
00078       //
00079       // See if it is an SCycleStatistics object itself:
00080       //
00081       SCycleStatistics* sobj = dynamic_cast< SCycleStatistics* >( obj );
00082       if( ! sobj ) {
00083          m_logger << ERROR << "Trying to merge \"" << obj->ClassName()
00084                   << "\" object into \"" << this->ClassName() << "\"" << SLogger::endmsg;
00085          continue;
00086       }
00087 
00088       //
00089       // Add the statistics from one worker:
00090       //
00091       m_processedEvents += sobj->m_processedEvents;
00092       m_skippedEvents   += sobj->m_skippedEvents;
00093 
00094       m_logger << VERBOSE << sobj->m_processedEvents << " events processed on one worker"
00095                << SLogger::endmsg;
00096       m_logger << VERBOSE << sobj->m_skippedEvents << " events skipped on one worker"
00097                << SLogger::endmsg;
00098 
00099    }
00100 
00101    m_logger << DEBUG << "Merged statistics objects" << SLogger::endmsg;
00102 
00103    return 1;
00104 
00105 }
00106 
00107 Int_t SCycleStatistics::Write( const char* name, Int_t option, Int_t bufsize ) const {
00108 
00109    TObject* original_obj;
00110    if( ( original_obj = gDirectory->Get( GetName() ) ) ) {
00111       m_logger << DEBUG << "Merging object \"" << GetName()
00112                << "\" with already existing object..." << SLogger::endmsg;
00113 
00114       SCycleStatistics* sobject = dynamic_cast< SCycleStatistics* >( original_obj );
00115       if( ! sobject ) {
00116          m_logger << WARNING << "Already existing object with name \""
00117                   << original_obj->GetName() << "\" is not of type SCycleStatistics!"
00118                   << SLogger::endmsg;
00119          m_logger << WARNING << "Merging is not possible, so it will be overwritten..."
00120                   << SLogger::endmsg;
00121       } else {
00122          TList list;
00123          list.Add( const_cast< SCycleStatistics* >( this ) );
00124          sobject->Merge( &list );
00125          return 1;
00126       }
00127 
00128    }
00129 
00130    // Call the standard ROOT write function:
00131    return TObject::Write( name, option, bufsize );
00132 
00133 }
00134 
00135 Int_t SCycleStatistics::Write( const char* name, Int_t option, Int_t bufsize ) {
00136 
00137    return const_cast< const SCycleStatistics* >( this )->Write( name, option, bufsize );
00138 }