CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/FWCore/Services/src/LockService.cc

Go to the documentation of this file.
00001 #include "FWCore/Services/src/LockService.h"
00002 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00003 #include "FWCore/Utilities/interface/DebugMacros.h"
00004 #include "FWCore/Utilities/interface/GlobalMutex.h"
00005 //#include "FWCore/Utilities/interface/Algorithms.h"
00006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00008 
00009 #include <iostream>
00010 #include <algorithm>
00011 
00012 using namespace edm::rootfix;
00013 
00014 LockService::LockService(const ParameterSet& iPS, 
00015                          ActivityRegistry& reg):
00016   lock_(*getGlobalMutex()),
00017   locker_(),
00018   labels_(iPS.getUntrackedParameter<Labels>("labels")),
00019   lockSources_(iPS.getUntrackedParameter<bool>("lockSources"))
00020 {
00021   reg.watchPreSourceConstruction(this,&LockService::preSourceConstruction);
00022   reg.watchPostSourceConstruction(this,&LockService::postSourceConstruction);
00023   
00024   // reg.watchPostBeginJob(this,&LockService::postBeginJob);
00025   // reg.watchPostEndJob(this,&LockService::postEndJob);
00026   
00027   // reg.watchPreProcessEvent(this,&LockService::preEventProcessing);
00028   // reg.watchPostProcessEvent(this,&LockService::postEventProcessing);
00029   reg.watchPreSource(this,&LockService::preSource);
00030   reg.watchPostSource(this,&LockService::postSource);
00031   
00032   reg.watchPreModule(this,&LockService::preModule);
00033   reg.watchPostModule(this,&LockService::postModule);
00034   
00035   FDEBUG(4) << "In LockServices" << std::endl;
00036 }
00037 
00038 
00039 LockService::~LockService()
00040 {
00041 }
00042 
00043 void LockService::fillDescriptions(edm::ConfigurationDescriptions & descriptions)
00044 {
00045   edm::ParameterSetDescription desc;
00046   std::vector<std::string> defaultVector;
00047   desc.addUntracked<std::vector<std::string> >("labels",defaultVector);
00048   desc.addUntracked<bool>("lockSources",true);
00049   descriptions.add("LockService", desc);
00050 }
00051 
00052 
00053 void LockService::preSourceConstruction(const ModuleDescription& desc)
00054 {
00055   if(!labels_.empty() &&
00056      find(labels_.begin(), labels_.end(), desc.moduleLabel()) != labels_.end())
00057      //search_all(labels_, desc.moduleLabel()))
00058     {
00059       FDEBUG(4) << "made a new locked in LockService" << std::endl;
00060       locker_.reset(new boost::mutex::scoped_lock(lock_));
00061     }
00062 }
00063 
00064 void LockService::postSourceConstruction(const ModuleDescription& desc)
00065 {
00066   FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00067   locker_.reset();
00068 }
00069 
00070 void LockService::postBeginJob()
00071 {
00072 }
00073 
00074 void LockService::postEndJob()
00075 {
00076 }
00077 
00078 void LockService::preEventProcessing(const edm::EventID& iID,
00079                                      const edm::Timestamp& iTime)
00080 {
00081 }
00082 
00083 void LockService::postEventProcessing(const Event& e, const EventSetup&)
00084 {
00085 }
00086 void LockService::preSource()
00087 {
00088   if(lockSources_)
00089     {
00090       FDEBUG(4) << "made a new locked in LockService" << std::endl;
00091       locker_.reset(new boost::mutex::scoped_lock(lock_));
00092     }
00093 }
00094 
00095 void LockService::postSource()
00096 {
00097   FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00098   locker_.reset();
00099 }
00100 
00101 void LockService::preModule(const ModuleDescription& desc)
00102 {
00103   if(!labels_.empty() &&
00104      find(labels_.begin(), labels_.end(), desc.moduleLabel()) != labels_.end())
00105      //search_all(labels_, desc.moduleLabel()))
00106     {
00107       FDEBUG(4) << "made a new locked in LockService" << std::endl;
00108       locker_.reset(new boost::mutex::scoped_lock(lock_));
00109     }
00110 }
00111 
00112 void LockService::postModule(const ModuleDescription& desc)
00113 {
00114   FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00115   locker_.reset();
00116 }
00117 
00118