CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/Goodies/src/iDie.h

Go to the documentation of this file.
00001 #ifndef EVENTFILTER_GOODIES_IDIE_H
00002 #define EVENTFILTER_GOODIES_IDIE_H
00003 
00004 //XDAQ
00005 #include "xdaq/Application.h"
00006 
00007 #include "xdata/String.h"
00008 #include "xdata/Double.h"
00009 #include "xdata/Float.h"
00010 #include "xdata/UnsignedInteger32.h"
00011 #include "xdata/Boolean.h"
00012 #include "xdata/TimeVal.h"
00013 #include "xdata/ActionListener.h"
00014 
00015 #include "xoap/MessageReference.h"
00016 #include "xoap/MessageFactory.h"
00017 #include "xoap/Method.h"
00018 
00019 #include "xgi/Utils.h"
00020 #include "xgi/Input.h"
00021 #include "xgi/Output.h"
00022 #include "xgi/Method.h"
00023 
00024 #include "toolbox/net/URN.h"
00025 #include "toolbox/fsm/exception/Exception.h"
00026 #include "toolbox/task/TimerListener.h"
00027 
00028 //C++2011
00029 #include <atomic>
00030 
00031 //C++
00032 #include <list>
00033 #include <vector>
00034 #include <deque>
00035 
00036 //C
00037 #include <sys/time.h>
00038 #include <math.h>
00039 
00040 //ROOT
00041 #include "TFile.h"
00042 #include "TTree.h"
00043 
00044 //framework
00045 #include "FWCore/Framework/interface/EventProcessor.h"
00046 #include "DQMServices/Core/src/DQMService.h"
00047 #include "DQMServices/Core/interface/DQMStore.h"
00048 #include "DQMServices/Core/interface/MonitorElement.h"
00049 #include "FWCore/Version/interface/GetReleaseVersion.h"
00050 
00051 //CMSSW EventFilter
00052 #include "EventFilter/Utilities/interface/Exception.h"
00053 #include "EventFilter/Utilities/interface/TriggerReportDef.h"
00054 
00055 #define MODNAMES 25
00056 
00057 namespace evf {
00058 
00059   int modlistSortFunction( const void *a, const void *b);
00060 
00061   namespace internal{
00062    struct fu{
00063       time_t tstamp;
00064       unsigned int ccount;
00065       std::vector<pid_t> cpids;
00066       std::vector<std::string> signals;
00067       std::vector<std::string> stacktraces;
00068     };
00069    struct rate{
00070      int nproc;
00071      int nsub;
00072      int nrep;
00073      int npath;
00074      int nendpath;
00075      int ptimesRun[evf::max_paths];
00076      int ptimesPassedPs[evf::max_paths];
00077      int ptimesPassedL1[evf::max_paths];
00078      int ptimesPassed[evf::max_paths];
00079      int ptimesFailed[evf::max_paths];
00080      int ptimesExcept[evf::max_paths];
00081      int etimesRun[evf::max_endpaths];
00082      int etimesPassedPs[evf::max_endpaths];
00083      int etimesPassedL1[evf::max_endpaths];
00084      int etimesPassed[evf::max_endpaths];
00085      int etimesFailed[evf::max_endpaths];
00086      int etimesExcept[evf::max_endpaths];
00087    };
00088 
00089   }
00090   typedef std::map<std::string,internal::fu> fmap;
00091   typedef fmap::iterator ifmap;
00092   
00093   class iDie :
00094     public xdaq::Application,
00095     public xdata::ActionListener,
00096     public toolbox::task::TimerListener
00097   {
00098   public:
00099     //
00100     // xdaq instantiator macro
00101     //
00102     XDAQ_INSTANTIATOR();
00103   
00104     //
00105     // construction/destruction
00106     //
00107     iDie(xdaq::ApplicationStub *s);
00108     virtual ~iDie();
00109     //UI
00110     void defaultWeb(xgi::Input *in,xgi::Output *out)
00111       throw (xgi::exception::Exception);
00112     void summaryTable(xgi::Input *in,xgi::Output *out)
00113       throw (xgi::exception::Exception);
00114     void detailsTable(xgi::Input *in,xgi::Output *out)
00115       throw (xgi::exception::Exception);
00116     void dumpTable(xgi::Input *in,xgi::Output *out)
00117       throw (xgi::exception::Exception);
00118     void updater(xgi::Input *in,xgi::Output *out)
00119       throw (xgi::exception::Exception);
00120     void iChoke(xgi::Input *in,xgi::Output *out)
00121       throw (xgi::exception::Exception);
00122     void iChokeMiniInterface(xgi::Input *in,xgi::Output *out)
00123       throw (xgi::exception::Exception);
00124     void spotlight(xgi::Input *in,xgi::Output *out)
00125       throw (xgi::exception::Exception);
00126     //AI
00127     void postEntry(xgi::Input*in,xgi::Output*out)
00128       throw (xgi::exception::Exception);
00129     void postEntryiChoke(xgi::Input*in,xgi::Output*out)
00130       throw (xgi::exception::Exception);
00131     
00132     // *fake* fsm soap command callback
00133     xoap::MessageReference fsmCallback(xoap::MessageReference msg)
00134       throw (xoap::exception::Exception);
00135 
00136     // xdata:ActionListener interface
00137     void actionPerformed(xdata::Event& e);
00138 
00139     //toolbox::Task::TimerListener interface
00140     void timeExpired(toolbox::task::TimerEvent& e);
00141 
00142   private:
00143 
00144     struct sorted_indices{
00145       sorted_indices(const std::vector<int> &arr) : arr_(arr)
00146       {
00147         ind_.resize(arr_.size(),0);
00148         unsigned int i = 0;
00149         while(i<ind_.size()) {ind_[i] = i; i++;}
00150         std::sort(ind_.rbegin(),ind_.rend(),*this);
00151       }
00152       int operator[](size_t ind) const {return arr_[ind_[ind]];}
00153       
00154       bool operator()(const size_t a, const size_t b) const
00155       {
00156         return arr_[a]<arr_[b];
00157       }
00158       int ii(size_t ind){return ind_[ind];}
00159       std::vector<int> ind_;
00160       const std::vector<int> &arr_;
00161     };
00162     //
00163     // private member functions
00164     //
00165     class lsStat;
00166     class commonLsStat;
00167 
00168     void reset();
00169     void parseModuleLegenda(std::string);
00170     void parseModuleHisto(const char *, unsigned int);
00171     void parsePathLegenda(std::string);
00172     void parseDatasetLegenda(std::string);
00173     void parsePathHisto(const unsigned char *, unsigned int);
00174     void initFramework();
00175     void deleteFramework();
00176     void initMonitorElements();
00177     void initMonitorElementsStreams();
00178     void initMonitorElementsDatasets();
00179     void fillDQMStatHist(unsigned int nbsIdx, unsigned int lsid);
00180     void fillDQMModFractionHist(unsigned int nbsIdx, unsigned int lsid, unsigned int nonIdle,
00181                                  const std::vector<std::pair<unsigned int, unsigned int>>& offenders);
00182  
00183     void updateRollingHistos(unsigned int nbsIdx, unsigned int lsid, lsStat * lst, commonLsStat * clst, bool roll);
00184     void updateStreamHistos(unsigned int forls, commonLsStat *clst, commonLsStat *prevclst);
00185     void updateDatasetHistos(unsigned int forls, commonLsStat *clst, commonLsStat *prevclst);
00186     void doFlush();
00187     void perLumiFileSaver(unsigned int lsid);
00188     void perTimeFileSaver();
00189     void initDQMEventInfo();
00190     void setRunStartTimeStamp();
00191 
00192     //
00193     // member data
00194     //
00195 
00196     // message logger
00197     Logger                          log_;
00198     std::string                     dqmState_;          
00199     // monitored parameters
00200     xdata::String                   url_;
00201     xdata::String                   class_;
00202     xdata::UnsignedInteger32        instance_;
00203     xdata::String                   hostname_;
00204 
00205     xdata::UnsignedInteger32        runNumber_;
00206     unsigned int                    lastRunNumberSet_;
00207     bool                            runActive_;
00208 
00209     xdata::UnsignedInteger32        flashRunNumber_;
00210 
00211     //CPU load flashlist
00212     std::list<std::string>          monNames_;
00213     xdata::InfoSpace                *cpuInfoSpace_;
00214     xdata::UnsignedInteger32        flashLoadLs_;
00215     std::atomic<unsigned int>       cpuLoadLastLs_;
00216     std::atomic<unsigned int>       cpuLoadSentLs_;
00217 
00218     float                           cpuLoad_[4000];
00219     float                           cpuLoadPS_[4000];
00220 
00221     float                           cpuLoadTime7_[4000];
00222     float                           cpuLoadTime8_[4000];
00223     float                           cpuLoadTime12_[4000];
00224     float                           cpuLoadTime16_[4000];
00225     float                           cpuLoadTime24_[4000];
00226     float                           cpuLoadTime32_[4000];
00227 
00228     float                           cpuLoadRate_[4000];
00229 
00230     float                           cpuLoadRate7_[4000];
00231     float                           cpuLoadRate8_[4000];
00232     float                           cpuLoadRate12_[4000];
00233     float                           cpuLoadRate16_[4000];
00234     float                           cpuLoadRate24_[4000];
00235     float                           cpuLoadRate32_[4000];
00236 
00237     float                           cpuLoadUc7_[4000];
00238     float                           cpuLoadUc8_[4000];
00239     float                           cpuLoadUc12_[4000];
00240     float                           cpuLoadUc16_[4000];
00241     float                           cpuLoadUc24_[4000];
00242     float                           cpuLoadUc32_[4000];
00243 
00244     unsigned int                    cpuLoadReports7_[4000];
00245     unsigned int                    cpuLoadReports8_[4000];
00246     unsigned int                    cpuLoadReports12_[4000];
00247     unsigned int                    cpuLoadReports16_[4000];
00248     unsigned int                    cpuLoadReports24_[4000];
00249     unsigned int                    cpuLoadReports32_[4000];
00250 
00251     xdata::Float                    flashLoad_;
00252     xdata::Float                    flashLoadPS_;
00253 
00254     xdata::Float                    flashLoadTime7_;
00255     xdata::Float                    flashLoadTime8_;
00256     xdata::Float                    flashLoadTime12_;
00257     xdata::Float                    flashLoadTime16_;
00258     xdata::Float                    flashLoadTime24_;
00259     xdata::Float                    flashLoadTime32_;
00260 
00261     xdata::Float                    flashLoadRate_;
00262 
00263     xdata::Float                    flashLoadRate7_;
00264     xdata::Float                    flashLoadRate8_;
00265     xdata::Float                    flashLoadRate12_;
00266     xdata::Float                    flashLoadRate16_;
00267     xdata::Float                    flashLoadRate24_;
00268     xdata::Float                    flashLoadRate32_;
00269 
00270     xdata::Float                    flashLoadUc7_;
00271     xdata::Float                    flashLoadUc8_;
00272     xdata::Float                    flashLoadUc12_;
00273     xdata::Float                    flashLoadUc16_;
00274     xdata::Float                    flashLoadUc24_;
00275     xdata::Float                    flashLoadUc32_;
00276 
00277     xdata::UnsignedInteger32        flashReports7_;
00278     xdata::UnsignedInteger32        flashReports8_;
00279     xdata::UnsignedInteger32        flashReports12_;
00280     xdata::UnsignedInteger32        flashReports16_;
00281     xdata::UnsignedInteger32        flashReports24_;
00282     xdata::UnsignedInteger32        flashReports32_;
00283 
00284     //EventInfo
00285     MonitorElement * runId_;
00286     MonitorElement * lumisecId_;
00287     MonitorElement * eventId_;
00288     MonitorElement * eventTimeStamp_;
00289     MonitorElement * runStartTimeStamp_;
00290 
00291     MonitorElement * processTimeStampMe_;
00292     MonitorElement * processLatencyMe_;
00293     MonitorElement * processEventsMe_;
00294     MonitorElement * processEventRateMe_;
00295     MonitorElement * nUpdatesMe_;
00296     MonitorElement * processIdMe_;
00297     MonitorElement * processStartTimeStampMe_;
00298     MonitorElement * hostNameMe_;
00299     MonitorElement * processNameMe_;
00300     MonitorElement * workingDirMe_;
00301     MonitorElement * cmsswVerMe_;
00302 
00303     float runTS_;
00304     float latencyTS_;
00305 
00306     xdata::String                   dqmCollectorHost_;
00307     xdata::String                   dqmCollectorPort_;
00308     fmap                            fus_;
00309     
00310     unsigned int                    totalCores_;
00311     unsigned int                    nstates_;   
00312     std::vector<int>                cpuentries_;
00313     std::vector<std::vector<int> >  cpustat_;
00314     std::vector<std::string>        mapmod_;
00315     unsigned int                    last_ls_;
00316     std::vector<TriggerReportStatic>trp_;
00317     std::vector<int>                trpentries_;
00318     std::vector<std::string>        mappath_;
00319     //root stuff
00320     TFile                          *f_;
00321     TTree                          *t_;
00322     TBranch                        *b_;
00323     TBranch                        *b1_;
00324     TBranch                        *b2_;
00325     TBranch                        *b3_;
00326     TBranch                        *b4_;
00327     int                            *datap_;
00328     TriggerReportStatic            *trppriv_;
00329     internal::rate                  r_;
00330 
00331     //message statistics 
00332     int                             nModuleLegendaMessageReceived_;
00333     int                             nPathLegendaMessageReceived_;
00334     int                             nModuleLegendaMessageWithDataReceived_;
00335     int                             nPathLegendaMessageWithDataReceived_;
00336     int                             nModuleHistoMessageReceived_;
00337     int                             nPathHistoMessageReceived_;
00338     timeval                         runStartDetectedTimeStamp_;
00339     timeval                         lastModuleLegendaMessageTimeStamp_;
00340     timeval                         lastPathLegendaMessageTimeStamp_;
00341 
00342     int                             nDatasetLegendaMessageReceived_;
00343     int                             nDatasetLegendaMessageWithDataReceived_;
00344     timeval                         lastDatasetLegendaMessageTimeStamp_;
00345 
00346     //DQM histogram statistics
00347     std::vector<unsigned int> epInstances;
00348     std::vector<unsigned int> epMax;
00349     std::vector<float> HTscaling;
00350     std::vector<unsigned int> nbMachines;
00351     std::vector<float> machineWeight;
00352     std::vector<float> machineWeightInst;
00353 
00354     std::vector<std::string > endPathNames_;
00355     std::vector<std::string > datasetNames_;
00356 
00357     class commonLsStat {
00358       
00359       public:
00360       unsigned int ls_;
00361       std::vector<float> rateVec_;
00362       std::vector<float> busyVec_;
00363       std::vector<float> busyCPUVec_;
00364       std::vector<float> busyVecTheor_;
00365       std::vector<float> busyCPUVecTheor_;
00366       std::vector<unsigned int> nbMachines;
00367       std::vector<unsigned int> endPathCounts_; 
00368       std::vector<unsigned int> datasetCounts_; 
00369       commonLsStat(unsigned int lsid,unsigned int classes) {
00370         for (size_t i=0;i<classes;i++) {
00371           rateVec_.push_back(0.);
00372           busyVec_.push_back(0.);
00373           busyCPUVec_.push_back(0.);
00374           busyVecTheor_.push_back(0.);
00375           busyCPUVecTheor_.push_back(0.);
00376           nbMachines.push_back(0);
00377         }
00378         ls_=lsid;
00379       }
00380 
00381       void setBusyForClass(unsigned int classIdx,float rate,float busy,float busyTheor, float busyCPU, float busyCPUTheor, unsigned int nMachineReports) {
00382         rateVec_[classIdx]=rate;
00383         busyVec_[classIdx]=busy;
00384         busyCPUVec_[classIdx]=busyCPU;
00385         busyVecTheor_[classIdx]=busyTheor;
00386         busyCPUVecTheor_[classIdx]=busyCPUTheor;
00387         nbMachines[classIdx]=nMachineReports;
00388       }
00389 
00390       float getTotalRate() {
00391         float totRate=0;
00392         for (size_t i=0;i<rateVec_.size();i++) totRate+=rateVec_[i];
00393         return totRate;
00394       } 
00395 
00396       float getBusyTotalFrac(bool procstat,std::vector<float> & machineWeightInst) {
00397         double sum=0;
00398         double sumMachines=0;
00399         for (size_t i=0;i<busyVec_.size();i++) {
00400           if (!procstat)
00401             sum+=machineWeightInst[i]*nbMachines.at(i)*busyVec_[i];
00402           else
00403             sum+=machineWeightInst[i]*nbMachines.at(i)*busyCPUVec_[i];
00404           sumMachines+=machineWeightInst[i]*nbMachines.at(i);
00405         }
00406         if (sumMachines>0)
00407           return float(sum/sumMachines);
00408         else return 0.;
00409       }
00410 
00411       float getBusyTotalFracTheor(bool procstat,std::vector<float> & machineWeight) {
00412         float sum=0;
00413         float sumMachines=0;
00414         for (size_t i=0;i<busyVecTheor_.size() && i<nbMachines.size();i++) {
00415           if (!procstat)
00416             sum+=machineWeight[i]*nbMachines[i]*busyVecTheor_[i];
00417           else
00418             sum+=machineWeight[i]*nbMachines[i]*busyCPUVecTheor_[i];
00419           sumMachines+=machineWeight[i]*nbMachines[i];
00420         }
00421         if (sumMachines>0)
00422           return sum/sumMachines;
00423         else return 0.;
00424       }
00425 
00426       unsigned int getNReports() {
00427         unsigned int sum=0;
00428         for (size_t i=0;i<nbMachines.size();i++) sum+=nbMachines[i];
00429         return sum;
00430       }
00431 
00432       std::string printInfo() {
00433         std::ostringstream info;
00434         for (size_t i=0;i<rateVec_.size();i++) {
00435           info << i << "/r:" << rateVec_[i] <<"/b:"<<busyVec_[i]<<"/n:"<<nbMachines[i]<<"; ";
00436         }
00437         return info.str();
00438       }
00439     };
00440 
00441     class lsStat {
00442       public:
00443       unsigned int ls_;
00444       bool updated_;
00445       unsigned int nbSubs_;
00446       unsigned int nSampledNonIdle_;
00447       unsigned int nSampledNonIdle2_;
00448       unsigned int nSampledIdle_;
00449       unsigned int nSampledIdle2_;
00450       unsigned int nProc_;
00451       unsigned int nProc2_;
00452       unsigned int nCPUBusy_;
00453       unsigned int nReports_;
00454       unsigned int nMaxReports_;
00455       double rateAvg;
00456       double rateErr;
00457       double evtTimeAvg;
00458       double evtTimeErr;
00459       double fracWaitingAvg;
00460       double fracCPUBusy_;
00461       unsigned int nmodulenames_;
00462       unsigned int sumDeltaTms_;
00463       float avgDeltaT_;
00464       float avgDeltaT2_;
00465       std::pair<unsigned int,unsigned int> *moduleSamplingSums;
00466 
00467       lsStat(unsigned int ls, unsigned int nbSubs,unsigned int maxreps,unsigned int nmodulenames):
00468         ls_(ls),updated_(true),nbSubs_(nbSubs),
00469         nSampledNonIdle_(0),nSampledNonIdle2_(0),nSampledIdle_(0),nSampledIdle2_(0),
00470         nProc_(0),nProc2_(0),nCPUBusy_(0),nReports_(0),nMaxReports_(maxreps),nmodulenames_(nmodulenames),
00471         sumDeltaTms_(0),avgDeltaT_(23),avgDeltaT2_(0)
00472       {
00473         moduleSamplingSums = new std::pair<unsigned int,unsigned int>[nmodulenames_];
00474         for (unsigned int i=0;i<nmodulenames_;i++) {
00475           moduleSamplingSums[i].first=i;
00476           moduleSamplingSums[i].second=0;
00477         }
00478       }
00479 
00480       ~lsStat() {
00481          delete moduleSamplingSums;
00482       }
00483 
00484       void update(unsigned int nSampledNonIdle,unsigned int nSampledIdle, 
00485                   unsigned int nProc,unsigned int ncpubusy, unsigned int deltaTms)
00486       {
00487         nReports_++;
00488         nSampledNonIdle_+=nSampledNonIdle;
00489         nSampledNonIdle2_+=pow(nSampledNonIdle,2);
00490         nSampledIdle_+=nSampledIdle;
00491         nSampledIdle2_+=pow(nSampledIdle,2);
00492         nProc_+=nProc;
00493         nProc2_+=pow(nProc,2);
00494         nCPUBusy_+=ncpubusy;
00495         sumDeltaTms_+=deltaTms;
00496         updated_=true;
00497       }
00498 
00499       std::pair<unsigned int,unsigned int> * getModuleSamplingPtr() {
00500         return moduleSamplingSums;
00501       }
00502 
00503       void deleteModuleSamplingPtr() {
00504         delete moduleSamplingSums;
00505         moduleSamplingSums=nullptr;
00506         nmodulenames_=0;
00507       }
00508 
00509       void calcStat()
00510       {
00511         if (!updated_) return;
00512         if (nReports_) {
00513           float tinv = 0.001/nReports_;
00514           fracCPUBusy_=nCPUBusy_*tinv;
00515           avgDeltaT_ = avgDeltaT2_ = sumDeltaTms_*tinv;
00516           if (avgDeltaT_==0.) {
00517             avgDeltaT_=23.;//default value
00518             avgDeltaT2_=0;
00519           }
00520           rateAvg=nProc_ / avgDeltaT_;
00521           rateErr=sqrt(fabs(nProc2_ - pow(nProc_,2)))/avgDeltaT_;
00522         }
00523         else {
00524           fracCPUBusy_=0.;
00525           rateAvg=0.;
00526           rateErr=0.;
00527           avgDeltaT_=23.;
00528         }
00529 
00530         evtTimeAvg=0.;evtTimeErr=0.;fracWaitingAvg=1.;
00531         unsigned int sampled = nSampledNonIdle_+nSampledIdle_;
00532         if (rateAvg!=0. && sampled) {
00533             float nAllInv = 1./sampled;
00534             fracWaitingAvg= nSampledIdle_*nAllInv;
00535             double nSampledIdleErr2=fabs(nSampledIdle2_ - pow(nSampledIdle_,2));
00536             double nSampledNonIdleErr2=fabs(nSampledNonIdle2_ - pow(nSampledNonIdle_,2));
00537             double fracWaitingAvgErr= sqrt(
00538                                     (pow(nSampledIdle_,2)*nSampledNonIdleErr2
00539                                      + pow(nSampledNonIdle_,2)*nSampledIdleErr2))*pow(nAllInv,2);
00540             float rateAvgInv=1./rateAvg;
00541             evtTimeAvg=nbSubs_ * nReports_ * (1.-fracWaitingAvg)*rateAvgInv;
00542             evtTimeErr = nbSubs_ * nReports_ * sqrt(pow(fracWaitingAvg*rateErr*pow(rateAvgInv,2),2) + pow(fracWaitingAvgErr*rateAvgInv,2));
00543         }
00544         updated_=false;
00545       }
00546 
00547       float getRate() {
00548         if (updated_) calcStat();
00549         return rateAvg;
00550       }
00551 
00552       float getRateErr() {
00553         if (updated_) calcStat();
00554         return rateErr;
00555       }
00556 
00557       float getRatePerMachine() {
00558         if (updated_) calcStat();
00559         if (nReports_)
00560         return rateAvg/(1.*nReports_);
00561         return 0.;
00562       }
00563 
00564       float getRateErrPerMachine() {
00565         if (updated_) calcStat();
00566         if (nReports_)
00567         return rateErr/(1.*nReports_);
00568         return 0.;
00569       }
00570 
00571       float getEvtTime() {
00572         if (updated_) calcStat();
00573         return evtTimeAvg;
00574       }
00575 
00576       float getEvtTimeErr() {
00577         if (updated_) calcStat();
00578         return evtTimeErr;
00579       }
00580 
00581       unsigned int getNSampledNonIdle() {
00582         if (updated_) calcStat();
00583         return nSampledNonIdle_;
00584       }
00585 
00586       float getFracBusy() {
00587         if (updated_) calcStat();
00588         return 1.-fracWaitingAvg;
00589       }
00590 
00591       float getFracCPUBusy() {
00592         if (updated_) calcStat();
00593         return fracCPUBusy_;
00594       }
00595 
00596       unsigned int getReports() {
00597         return nReports_;
00598       }
00599 
00600       float getDt() {
00601         if (updated_) calcStat();
00602         return avgDeltaT2_;
00603       }
00604 
00605       std::vector<std::pair<unsigned int, unsigned int>> getOffendersVector() {
00606         std::vector<std::pair<unsigned int, unsigned int>> ret;
00607         if (updated_) calcStat();
00608         if (moduleSamplingSums) {
00609           //make a copy for sorting
00610           std::pair<unsigned int,unsigned int> *moduleSumsCopy = new std::pair<unsigned int,unsigned int>[nmodulenames_];
00611           memcpy(moduleSumsCopy,moduleSamplingSums,nmodulenames_*sizeof(std::pair<unsigned int,unsigned int>));
00612 
00613           std::qsort((void *)moduleSumsCopy, nmodulenames_,
00614                      sizeof(std::pair<unsigned int,unsigned int>), modlistSortFunction);
00615 
00616           unsigned int count=0;
00617           unsigned int saveidx=0;
00618           while (saveidx < MODNAMES && count<nmodulenames_)
00619           {
00620             if (moduleSumsCopy[count].first==2) {count++;continue;}
00621             ret.push_back(moduleSumsCopy[count]);
00622             saveidx++;
00623             count++;
00624           }
00625           delete moduleSumsCopy;
00626         }
00627         return ret;
00628       }
00629 
00630       float getOffenderFracAt(unsigned int x) {
00631         if (x<nmodulenames_) {
00632           if (updated_) calcStat();
00633           float total = nSampledNonIdle_+nSampledIdle_;
00634           if (total>0.) {
00635             for (size_t i=0;i<nmodulenames_;i++) {
00636               if (moduleSamplingSums[i].first==x)
00637               return moduleSamplingSums[i].second/total;
00638             }
00639           }
00640         }
00641         return 0.;
00642       }
00643     };
00644 
00645 
00646     //DQM
00647     boost::shared_ptr<std::vector<edm::ParameterSet> > pServiceSets_;
00648     edm::ServiceToken               serviceToken_;
00649     edm::EventProcessor             *evtProcessor_;
00650     bool                            meInitialized_;
00651     bool                            meInitializedStreams_;
00652     bool                            meInitializedDatasets_;
00653     DQMService                      *dqmService_;
00654     DQMStore                        *dqmStore_;
00655     std::string                     configString_;
00656     xdata::Boolean                  dqmEnabled_;
00657     xdata::Boolean                  debugMode_;
00658 
00659     std::map<unsigned int,int> nbSubsList;
00660     std::map<int,unsigned int> nbSubsListInv;
00661     unsigned int nbSubsClasses;
00662     std::vector<MonitorElement*> meVecRate_;
00663     std::vector<MonitorElement*> meVecTime_;
00664     std::vector<MonitorElement*> meVecCPU_;
00665     std::vector<MonitorElement*> meVecOffenders_;
00666     MonitorElement * rateSummary_;
00667     MonitorElement * reportPeriodSummary_;
00668     MonitorElement * timingSummary_;
00669     MonitorElement * busySummary_;
00670     MonitorElement * busySummary2_;
00671     MonitorElement * busySummaryUncorr1_;
00672     MonitorElement * busySummaryUncorr2_;
00673     MonitorElement * fuReportsSummary_;
00674     MonitorElement * daqBusySummary_;
00675     MonitorElement * daqBusySummary2_;
00676     MonitorElement * daqTotalRateSummary_;
00677     MonitorElement * busyModules_;
00678     unsigned int summaryLastLs_;
00679     std::vector<std::map<unsigned int, unsigned int> > occupancyNameMap;
00680     //1 queue per number of subProcesses (and one common)
00681     std::deque<commonLsStat*> commonLsHistory;
00682     std::deque<lsStat*> * lsHistory;
00683 
00684     //endpath statistics
00685     std::vector<MonitorElement *> endPathRates_;
00686 
00687     //dataset statistics
00688     std::vector<MonitorElement *> datasetRates_;
00689 
00690     std::vector<unsigned int> currentLs_;
00691 
00692     xdata::UnsignedInteger32 saveLsInterval_;
00693     unsigned int ilumiprev_;
00694     std::list<std::string> pastSavedFiles_;
00695     xdata::String dqmSaveDir_;
00696     xdata::Boolean dqmFilesWritable_;
00697     xdata::String topLevelFolder_;
00698     unsigned int savedForLs_;
00699     std::string fileBaseName_;
00700     bool writeDirectoryPresent_;
00701 
00702     timeval * reportingStart_;
00703     unsigned int lastSavedForTime_;
00704 
00705     unsigned int dsMismatch;
00706   }; // class iDie
00707 
00708   int modlistSortFunction( const void *a, const void *b)
00709   {
00710     std::pair<unsigned int,unsigned int> intOne = *((std::pair<unsigned int,unsigned int>*)a);
00711     std::pair<unsigned int,unsigned int> intTwo = *((std::pair<unsigned int,unsigned int>*)b);
00712     if (intOne.second > intTwo.second)
00713       return -1;
00714     if (intOne.second == intTwo.second)
00715       return 0;
00716     return 1;
00717   }
00718 
00719   float fround(float val, float mod) {
00720     return val - fmod(val,mod);
00721   }
00722 
00723 } // namespace evf
00724 
00725 
00726 #endif