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
00006
00007 #include <iostream>
00008 #include <algorithm>
00009
00010 using namespace edm::rootfix;
00011
00012 LockService::LockService(const ParameterSet& iPS,
00013 ActivityRegistry& reg):
00014 lock_(getGlobalMutex()),
00015 locker_(),
00016 labels_(iPS.getUntrackedParameter<Labels>("labels",Labels())),
00017 lockSources_(iPS.getUntrackedParameter<bool>("lockSources",true))
00018 {
00019 reg.watchPreSourceConstruction(this,&LockService::preSourceConstruction);
00020 reg.watchPostSourceConstruction(this,&LockService::postSourceConstruction);
00021
00022
00023
00024
00025
00026
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
00037 LockService::~LockService()
00038 {
00039 delete locker_;
00040 }
00041 void LockService::preSourceConstruction(const ModuleDescription& desc)
00042 {
00043 if(!labels_.empty() &&
00044 find(labels_.begin(), labels_.end(), desc.moduleLabel_) != labels_.end())
00045
00046 {
00047 FDEBUG(4) << "made a new locked in LockService" << std::endl;
00048 locker_ = new boost::mutex::scoped_lock(*lock_);
00049 }
00050 }
00051
00052 void LockService::postSourceConstruction(const ModuleDescription& desc)
00053 {
00054 FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00055 delete locker_;
00056 locker_=0;
00057 }
00058
00059 void LockService::postBeginJob()
00060 {
00061 }
00062
00063 void LockService::postEndJob()
00064 {
00065 }
00066
00067 void LockService::preEventProcessing(const edm::EventID& iID,
00068 const edm::Timestamp& iTime)
00069 {
00070 }
00071
00072 void LockService::postEventProcessing(const Event& e, const EventSetup&)
00073 {
00074 }
00075 void LockService::preSource()
00076 {
00077 if(lockSources_)
00078 {
00079 FDEBUG(4) << "made a new locked in LockService" << std::endl;
00080 locker_ = new boost::mutex::scoped_lock(*lock_);
00081 }
00082 }
00083
00084 void LockService::postSource()
00085 {
00086 FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00087 delete locker_;
00088 locker_=0;
00089 }
00090
00091 void LockService::preModule(const ModuleDescription& desc)
00092 {
00093 if(!labels_.empty() &&
00094 find(labels_.begin(), labels_.end(), desc.moduleLabel_) != labels_.end())
00095
00096 {
00097 FDEBUG(4) << "made a new locked in LockService" << std::endl;
00098 locker_ = new boost::mutex::scoped_lock(*lock_);
00099 }
00100 }
00101
00102 void LockService::postModule(const ModuleDescription& desc)
00103 {
00104 FDEBUG(4) << "destroyed a locked in LockService" << std::endl;
00105 delete locker_;
00106 locker_=0;
00107 }
00108
00109