CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/HLTrigger/Timer/src/Timer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    Timer
00004 // Class:      Timer
00005 // 
00014 //
00015 // Original Author:  Christos Leonidopoulos
00016 //         Created:  Mon Jul 10 14:13:58 CEST 2006
00017 // $Id: Timer.cc,v 1.9 2007/03/27 19:10:58 cleonido Exp $
00018 //
00019 //
00020 
00021 
00022 #include "HLTrigger/Timer/interface/Timer.h"
00023 
00024 #include <iostream>
00025 
00026 using edm::ParameterSet; 
00027 using edm::Service;
00028 using edm::ModuleDescription;
00029 //
00030 using edm::ModuleTime;
00031 using edm::EventTime;
00032 
00033 using std::string;
00034 
00035 Timer::Timer(const ParameterSet& iConfig)
00036 {
00037   //  produces<EventTime>("Timing");
00038   produces<EventTime>();
00039   
00040   // whether to include timing info about Timer module (default: false)
00041   includeSelf = iConfig.getUntrackedParameter<bool>("includeSelf", false);
00042 
00043   timing.reset();
00044 
00045   // attach method to Timing service's "new measurement" signal
00046   Service<TimerService> time;
00047   time->newMeasurementSignal.connect(boost::bind(boost::mem_fn(&Timer::newTimingMeasurement), this, _1, _2) );
00048   
00049   self_module_name = string(iConfig.getParameter<string>("@module_type"));
00050 }
00051 
00052 Timer::~Timer()
00053 {
00054   using namespace std;
00055 
00056   if(!includeSelf){
00057     string longLine("=========================================================="); 
00058     cout << longLine << endl;
00059     cout << " Timer Info:\n";
00060     cout << " Timer module was excluded from time measurements\n";
00061     cout << " (to include, set 'bool includeSelf = true' in .cfg file)\n";
00062     cout << longLine << endl << endl;
00063   }
00064 
00065 }
00066 
00067 // fwk calls this method when new module measurement arrives
00068 void Timer::newTimingMeasurement(const ModuleDescription& iMod, double iTime) 
00069 {
00070   // check if module name corresponds to "this" and skip if needed
00071   if(!includeSelf && iMod.moduleName() == self_module_name)
00072      return;
00073 
00074   // new measurement; add to private member
00075   ModuleTime newModuleTime(iMod.moduleLabel(), iTime); 
00076   timing.addModuleTime(newModuleTime);
00077 }
00078 
00079 
00080 //
00081 // member functions
00082 //
00083 
00084 // ------------ method called to produce the data  ------------
00085 void
00086 Timer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00087 {
00088   std::auto_ptr<EventTime> out(new EventTime(timing));
00089   // reset data so that we can start from scratch for next event
00090    timing.reset();
00091    //
00092    iEvent.put(out);
00093 }
00094