CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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/ParameterSet/interface/ConfigurationDescriptions.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00005 #include "FWCore/Utilities/interface/DebugMacros.h"
00006 #include "FWCore/Utilities/interface/GlobalMutex.h"
00007 
00008 #include <algorithm>
00009 #include <iostream>
00010 
00011 using namespace edm::rootfix;
00012 
00013 LockService::LockService(ParameterSet const& iPS,
00014                          ActivityRegistry& reg):
00015   lock_(*getGlobalMutex()),
00016   locker_(),
00017   labels_(iPS.getUntrackedParameter<Labels>("labels")),
00018   lockSources_(iPS.getUntrackedParameter<bool>("lockSources")) {
00019   reg.watchPreSourceConstruction(this,&LockService::preSourceConstruction);
00020   reg.watchPostSourceConstruction(this,&LockService::postSourceConstruction);
00021 
00022   // reg.watchPostBeginJob(this,&LockService::postBeginJob);
00023   // reg.watchPostEndJob(this,&LockService::postEndJob);
00024 
00025   // reg.watchPreProcessEvent(this,&LockService::preEventProcessing);
00026   // reg.watchPostProcessEvent(this,&LockService::postEventProcessing);
00027   reg.watchPreSource(this,&LockService::preSource);
00028   reg.watchPostSource(this,&LockService::postSource);
00029 
00030   reg.watchPreModule(this,&LockService::preModule);
00031   reg.watchPostModule(this,&LockService::postModule);
00032 
00033   FDEBUG(4) << "In LockServices" << std::endl;
00034 }
00035 
00036 LockService::~LockService() {
00037 }
00038 
00039 void LockService::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00040   edm::ParameterSetDescription desc;
00041   std::vector<std::string> defaultVector;
00042   desc.addUntracked<std::vector<std::string> >("labels",defaultVector);
00043   desc.addUntracked<bool>("lockSources",true);
00044   descriptions.add("LockService", desc);
00045 }
00046 
00047 void LockService::preSourceConstruction(ModuleDescription const& desc) {
00048   if(!labels_.empty() &&
00049      find(labels_.begin(), labels_.end(), desc.moduleLabel()) != labels_.end()) {
00050      //search_all(labels_, desc.moduleLabel()))
00051       FDEBUG(4) << "made a new locked in LockService" << std::endl;
00052       locker_.reset(new boost::mutex::scoped_lock(lock_));
00053     }
00054 }
00055 
00056 void LockService::postSourceConstruction(ModuleDescription const&) {
00057   FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00058   locker_.reset();
00059 }
00060 
00061 void LockService::postBeginJob() {
00062 }
00063 
00064 void LockService::postEndJob() {
00065 }
00066 
00067 void LockService::preEventProcessing(edm::EventID const&, edm::Timestamp const&) {
00068 }
00069 
00070 void LockService::postEventProcessing(Event const&, EventSetup const&) {
00071 }
00072 
00073 void LockService::preSource() {
00074   if(lockSources_) {
00075     FDEBUG(4) << "made a new locked in LockService" << std::endl;
00076     locker_.reset(new boost::mutex::scoped_lock(lock_));
00077   }
00078 }
00079 
00080 void LockService::postSource() {
00081   FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00082   locker_.reset();
00083 }
00084 
00085 void LockService::preModule(ModuleDescription const& desc) {
00086   if(!labels_.empty() && find(labels_.begin(), labels_.end(), desc.moduleLabel()) != labels_.end()) {
00087     //search_all(labels_, desc.moduleLabel()))
00088     FDEBUG(4) << "made a new locked in LockService" << std::endl;
00089     locker_.reset(new boost::mutex::scoped_lock(lock_));
00090   }
00091 }
00092 
00093 void LockService::postModule(ModuleDescription const&) {
00094   FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00095   locker_.reset();
00096 }
00097