CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/EventFilter/StorageManager/src/DQMFolder.cc

Go to the documentation of this file.
00001 // $Id: DQMFolder.cc,v 1.2 2011/03/07 15:31:32 mommsen Exp $
00003 
00004 #include "EventFilter/StorageManager/interface/DQMFolder.h"
00005 
00006 #include "TH1.h"
00007 #include "TObjString.h"
00008 #include "TProfile.h"
00009 
00010 #include "classlib/utils/Regexp.h"
00011 
00012 // 15-Jul-2008, KAB: copied from DQMStore
00013 static const lat::Regexp s_rxmeval ("^<(.*)>(i|f|s|t|qr)=(.*)</\\1>$");
00014 
00015 using namespace stor;
00016 
00017 
00018 DQMFolder::DQMFolder()
00019 {}
00020 
00021 DQMFolder::~DQMFolder() 
00022 {
00023   for (DQMObjectsMap::const_iterator it = dqmObjects_.begin(),
00024          itEnd = dqmObjects_.end(); it != itEnd; ++it)
00025   {
00026     TObject* object = it->second;
00027     if ( object != NULL ) { delete(object); } 
00028   }
00029   dqmObjects_.clear();
00030 }
00031 
00032 void DQMFolder::addObjects(std::vector<TObject*> toList)
00033 {
00034   for (std::vector<TObject*>::const_iterator it = toList.begin(), itEnd = toList.end();
00035        it != itEnd; ++it)
00036   {
00037     TObject* object = *it;
00038     if (object)
00039     {
00040       std::string objectName = getSafeMEName(object);
00041       
00042       DQMObjectsMap::iterator pos = dqmObjects_.lower_bound(objectName);
00043       if ( pos == dqmObjects_.end() || (dqmObjects_.key_comp()(objectName, pos->first)) )
00044       {
00045         pos = dqmObjects_.insert(pos,
00046           DQMFolder::DQMObjectsMap::value_type(objectName, object));
00047       }
00048       else
00049       {
00050         TObject* storedObject = pos->second;
00051         if ( object->InheritsFrom("TProfile") && 
00052           storedObject->InheritsFrom("TProfile") )
00053         {
00054           TProfile* newProfile    = static_cast<TProfile*>(object);
00055           TProfile* storedProfile = static_cast<TProfile*>(storedObject);
00056           if (newProfile->GetEntries() > 0)
00057           {
00058             storedProfile->Add(newProfile);
00059           }
00060         }
00061         else if ( object->InheritsFrom("TH1") && 
00062           storedObject->InheritsFrom("TH1") )
00063         {
00064           TH1* newHistogram    = static_cast<TH1*>(object);
00065           TH1* storedHistogram = static_cast<TH1*>(storedObject);
00066           if (newHistogram->GetEntries() > 0)
00067           {
00068             storedHistogram->Add(newHistogram);
00069           }
00070         }
00071         else
00072         {
00073           // 15-Jul-2008, KAB - switch to the first instance at the 
00074           // request of Andreas Meyer...
00075           
00077           //delete(storedObject);
00078           //folder->dqmObjects_[objectName] = object->Clone(object->GetName());
00079         }
00080         delete(object);
00081       }
00082     }
00083   }
00084 }
00085 
00086 void DQMFolder::fillObjectVector(std::vector<TObject*>& vector) const
00087 {
00088   for ( DQMObjectsMap::const_iterator it = dqmObjects_.begin(), itEnd = dqmObjects_.end();
00089         it != itEnd; ++it )
00090   {
00091     vector.push_back(it->second);
00092   }
00093 }
00094 
00095 // 15-Jul-2008, KAB - this method should probably exist in DQMStore
00096 // rather than here, but I'm going for expediency...
00097 // The main purpose of the method is to pull out the ME name
00098 // from scalar MEs (ints, floats, strings)
00099 std::string DQMFolder::getSafeMEName(TObject *object)
00100 {
00101   std::string rawName = object->GetName();
00102   std::string safeName = rawName;
00103 
00104   lat::RegexpMatch patternMatch;
00105   if (dynamic_cast<TObjString *>(object) &&
00106       s_rxmeval.match(rawName, 0, 0, &patternMatch)) {
00107     safeName = patternMatch.matchString(rawName, 1);
00108   }
00109 
00110   return safeName;
00111 }
00112 
00113