CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
smproxy::DataManager Class Reference

#include <DataManager.h>

Public Member Functions

 DataManager (StateMachine *)
 
bool getQueueIDsFromDataEventRetrievers (stor::EventConsRegPtr, stor::QueueIDs &) const
 
bool getQueueIDsFromDQMEventRetrievers (stor::DQMEventConsRegPtr, stor::QueueIDs &) const
 
void start (DataRetrieverParams const &)
 
void stop ()
 
 ~DataManager ()
 

Private Types

typedef EventRetriever
< stor::EventConsumerRegistrationInfo,
EventQueueCollectionPtr
DataEventRetriever
 
typedef std::map
< stor::EventConsRegPtr,
DataEventRetrieverPtr,
stor::utils::ptrComp
< stor::EventConsumerRegistrationInfo > > 
DataEventRetrieverMap
 
typedef boost::shared_ptr
< DataEventRetriever
DataEventRetrieverPtr
 
typedef EventRetriever
< stor::DQMEventConsumerRegistrationInfo,
stor::DQMEventQueueCollectionPtr
DQMEventRetriever
 
typedef std::map
< stor::DQMEventConsRegPtr,
DQMEventRetrieverPtr,
stor::utils::ptrComp
< stor::DQMEventConsumerRegistrationInfo > > 
DQMEventRetrieverMap
 
typedef boost::shared_ptr
< DQMEventRetriever
DQMEventRetrieverPtr
 

Private Member Functions

void activity ()
 
bool addDQMEventConsumer (stor::RegPtr)
 
bool addEventConsumer (stor::RegPtr)
 
void checkForStaleConsumers ()
 
void doIt ()
 
void watchDog ()
 

Private Attributes

DataEventRetrieverMap dataEventRetrievers_
 
DataRetrieverParams dataRetrieverParams_
 
DQMEventRetrieverMap dqmEventRetrievers_
 
stor::RegistrationQueuePtr registrationQueue_
 
StateMachinestateMachine_
 
boost::scoped_ptr< boost::thread > thread_
 
boost::scoped_ptr< boost::thread > watchDogThread_
 

Detailed Description

Manages the data retrieval

Author:
mommsen
Revision:
1.2
Date:
2011/03/07 15:41:54

Definition at line 36 of file DataManager.h.

Member Typedef Documentation

Definition at line 92 of file DataManager.h.

Definition at line 95 of file DataManager.h.

Definition at line 93 of file DataManager.h.

Definition at line 99 of file DataManager.h.

Definition at line 102 of file DataManager.h.

Definition at line 100 of file DataManager.h.

Constructor & Destructor Documentation

smproxy::DataManager::DataManager ( StateMachine stateMachine)

Definition at line 18 of file DataManager.cc.

References checkForStaleConsumers().

20  :
21  stateMachine_(stateMachine),
22  registrationQueue_(stateMachine->getRegistrationQueue())
23  {
24  watchDogThread_.reset(
25  new boost::thread( boost::bind( &DataManager::checkForStaleConsumers, this) )
26  );
27  }
stor::RegistrationQueuePtr registrationQueue_
Definition: DataManager.h:85
boost::scoped_ptr< boost::thread > watchDogThread_
Definition: DataManager.h:89
StateMachine * stateMachine_
Definition: DataManager.h:84
smproxy::DataManager::~DataManager ( )

Definition at line 29 of file DataManager.cc.

References stop(), and watchDogThread_.

30  {
31  stop();
32  watchDogThread_->interrupt();
33  watchDogThread_->join();
34  }
boost::scoped_ptr< boost::thread > watchDogThread_
Definition: DataManager.h:89

Member Function Documentation

void smproxy::DataManager::activity ( )
private

Definition at line 103 of file DataManager.cc.

References doIt(), alignCSCRings::e, cppFunctionSkipper::exception, edm::hlt::Exception, smproxy::StateMachine::moveToFailedState(), and stateMachine_.

104  {
105  try
106  {
107  doIt();
108  }
109  catch(xcept::Exception &e)
110  {
112  }
113  catch(std::exception &e)
114  {
115  XCEPT_DECLARE(exception::Exception,
116  sentinelException, e.what());
117  stateMachine_->moveToFailedState(sentinelException);
118  }
119  catch(...)
120  {
121  std::string errorMsg = "Unknown exception in watch dog";
122  XCEPT_DECLARE(exception::Exception,
123  sentinelException, errorMsg);
124  stateMachine_->moveToFailedState(sentinelException);
125  }
126  }
void moveToFailedState(xcept::Exception &e)
Definition: StateMachine.h:79
StateMachine * stateMachine_
Definition: DataManager.h:84
bool smproxy::DataManager::addDQMEventConsumer ( stor::RegPtr  regPtr)
private

Definition at line 179 of file DataManager.cc.

References dqmEventRetrievers_, pos, and stateMachine_.

Referenced by doIt().

180  {
181  stor::DQMEventConsRegPtr dqmEventConsumer =
182  boost::dynamic_pointer_cast<stor::DQMEventConsumerRegistrationInfo>(regPtr);
183 
184  if ( ! dqmEventConsumer ) return false;
185 
186  DQMEventRetrieverMap::iterator pos =
187  dqmEventRetrievers_.lower_bound(dqmEventConsumer);
188  if (
189  pos == dqmEventRetrievers_.end() ||
190  (dqmEventRetrievers_.key_comp()(dqmEventConsumer, pos->first)) )
191  {
192  // no retriever found for this DQM event requests
193  DQMEventRetrieverPtr dqmEventRetriever(
194  new DQMEventRetriever(stateMachine_, dqmEventConsumer)
195  );
196  dqmEventRetrievers_.insert(pos,
197  DQMEventRetrieverMap::value_type(dqmEventConsumer, dqmEventRetriever));
198  }
199  else
200  {
201  pos->second->addConsumer( dqmEventConsumer );
202  }
203 
204  return true;
205  }
Container::value_type value_type
DQMEventRetrieverMap dqmEventRetrievers_
Definition: DataManager.h:103
boost::shared_ptr< DQMEventRetriever > DQMEventRetrieverPtr
Definition: DataManager.h:100
StateMachine * stateMachine_
Definition: DataManager.h:84
EventRetriever< stor::DQMEventConsumerRegistrationInfo, stor::DQMEventQueueCollectionPtr > DQMEventRetriever
Definition: DataManager.h:99
boost::shared_ptr< stor::DQMEventConsumerRegistrationInfo > DQMEventConsRegPtr
bool smproxy::DataManager::addEventConsumer ( stor::RegPtr  regPtr)
private

Definition at line 150 of file DataManager.cc.

References dataEventRetrievers_, pos, and stateMachine_.

Referenced by doIt().

151  {
152  stor::EventConsRegPtr eventConsumer =
153  boost::dynamic_pointer_cast<stor::EventConsumerRegistrationInfo>(regPtr);
154 
155  if ( ! eventConsumer ) return false;
156 
157  DataEventRetrieverMap::iterator pos = dataEventRetrievers_.lower_bound(eventConsumer);
158  if (
159  pos == dataEventRetrievers_.end() ||
160  (dataEventRetrievers_.key_comp()(eventConsumer, pos->first))
161  )
162  {
163  // no retriever found for this event requests
164  DataEventRetrieverPtr dataEventRetriever(
165  new DataEventRetriever(stateMachine_, eventConsumer)
166  );
167  dataEventRetrievers_.insert(pos,
168  DataEventRetrieverMap::value_type(eventConsumer, dataEventRetriever));
169  }
170  else
171  {
172  pos->second->addConsumer( eventConsumer );
173  }
174 
175  return true;
176  }
boost::shared_ptr< DataEventRetriever > DataEventRetrieverPtr
Definition: DataManager.h:93
DataEventRetrieverMap dataEventRetrievers_
Definition: DataManager.h:96
boost::shared_ptr< stor::EventConsumerRegistrationInfo > EventConsRegPtr
Container::value_type value_type
EventRetriever< stor::EventConsumerRegistrationInfo, EventQueueCollectionPtr > DataEventRetriever
Definition: DataManager.h:92
StateMachine * stateMachine_
Definition: DataManager.h:84
void smproxy::DataManager::checkForStaleConsumers ( )
private

Definition at line 238 of file DataManager.cc.

References stor::utils::getCurrentTime(), smproxy::StateMachine::getDQMEventQueueCollection(), smproxy::StateMachine::getEventQueueCollection(), cmsPerfSuiteHarvest::now, seconds(), stor::utils::sleep(), and stateMachine_.

Referenced by DataManager(), and watchDog().

239  {
240  EventQueueCollectionPtr eventQueueCollection =
242  stor::DQMEventQueueCollectionPtr dqmEventQueueCollection =
244 
245  while (true)
246  {
249  eventQueueCollection->clearStaleQueues(now);
250  dqmEventQueueCollection->clearStaleQueues(now);
251  }
252  }
TimePoint_t getCurrentTime()
Definition: Utils.h:158
double seconds()
void sleep(Duration_t)
Definition: Utils.h:163
stor::DQMEventQueueCollectionPtr getDQMEventQueueCollection() const
Definition: StateMachine.h:105
boost::shared_ptr< DQMEventQueueCollection > DQMEventQueueCollectionPtr
EventQueueCollectionPtr getEventQueueCollection() const
Definition: StateMachine.h:103
boost::posix_time::ptime TimePoint_t
Definition: Utils.h:35
boost::shared_ptr< EventQueueCollection > EventQueueCollectionPtr
StateMachine * stateMachine_
Definition: DataManager.h:84
void smproxy::DataManager::doIt ( )
private

Definition at line 129 of file DataManager.cc.

References addDQMEventConsumer(), addEventConsumer(), smproxy::DQMArchiver::getRegPtr(), LaserDQM_cfg::process, registrationQueue_, and stateMachine_.

Referenced by activity(), HiHelperTools.MassSearchReplaceAnyInputTagVisitor::doIt(), helpers.MassSearchReplaceAnyInputTagVisitor::doIt(), HiHelperTools.MassSearchReplaceAnyInputTagVisitor::enter(), helpers.MassSearchReplaceAnyInputTagVisitor::enter(), and start().

130  {
131  stor::RegPtr regPtr;
132  bool process(true);
133 
134  DQMArchiver dqmArchiver(stateMachine_);
135  addDQMEventConsumer(dqmArchiver.getRegPtr());
136 
137  do
138  {
139  registrationQueue_->deqWait(regPtr);
140 
141  if ( ! (addEventConsumer(regPtr) || addDQMEventConsumer(regPtr)) )
142  {
143  // base type received, signalling the end of the run
144  process = false;
145  }
146  } while (process);
147  }
stor::RegistrationQueuePtr registrationQueue_
Definition: DataManager.h:85
boost::shared_ptr< RegistrationInfoBase > RegPtr
bool addDQMEventConsumer(stor::RegPtr)
Definition: DataManager.cc:179
bool addEventConsumer(stor::RegPtr)
Definition: DataManager.cc:150
StateMachine * stateMachine_
Definition: DataManager.h:84
tuple process
Definition: LaserDQM_cfg.py:3
bool smproxy::DataManager::getQueueIDsFromDataEventRetrievers ( stor::EventConsRegPtr  eventConsumer,
stor::QueueIDs queueIDs 
) const

Get list of data event consumer queueIDs for given event type. Returns false if the event type is not found.

Definition at line 70 of file DataManager.cc.

References pos.

74  {
75  if ( ! eventConsumer ) return false;
76 
77  DataEventRetrieverMap::const_iterator pos =
78  dataEventRetrievers_.find(eventConsumer);
79  if ( pos == dataEventRetrievers_.end() ) return false;
80 
81  queueIDs = pos->second->getQueueIDs();
82  return true;
83  }
DataEventRetrieverMap dataEventRetrievers_
Definition: DataManager.h:96
bool smproxy::DataManager::getQueueIDsFromDQMEventRetrievers ( stor::DQMEventConsRegPtr  dqmEventConsumer,
stor::QueueIDs queueIDs 
) const

Get list of DQM event consumer queueIDs for given event type. Returns false if the event type is not found.

Definition at line 87 of file DataManager.cc.

References pos.

91  {
92  if ( ! dqmEventConsumer ) return false;
93 
94  DQMEventRetrieverMap::const_iterator pos =
95  dqmEventRetrievers_.find(dqmEventConsumer);
96  if ( pos == dqmEventRetrievers_.end() ) return false;
97 
98  queueIDs = pos->second->getQueueIDs();
99  return true;
100  }
DQMEventRetrieverMap dqmEventRetrievers_
Definition: DataManager.h:103
void smproxy::DataManager::start ( DataRetrieverParams const &  drp)

Start retrieving data

Definition at line 37 of file DataManager.cc.

References dataEventRetrievers_, dataRetrieverParams_, doIt(), dqmEventRetrievers_, edm::shutdown_flag, and thread_.

Referenced by progressbar.ProgressBar::__next__(), Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

38  {
40  dataEventRetrievers_.clear();
41  dqmEventRetrievers_.clear();
42  edm::shutdown_flag = false;
43  thread_.reset(
44  new boost::thread( boost::bind( &DataManager::doIt, this) )
45  );
46  }
DataEventRetrieverMap dataEventRetrievers_
Definition: DataManager.h:96
DataRetrieverParams dataRetrieverParams_
Definition: DataManager.h:86
boost::scoped_ptr< boost::thread > thread_
Definition: DataManager.h:88
DQMEventRetrieverMap dqmEventRetrievers_
Definition: DataManager.h:103
volatile bool shutdown_flag
void smproxy::DataManager::stop ( )

Stop retrieving data

Definition at line 49 of file DataManager.cc.

References dataEventRetrievers_, dqmEventRetrievers_, registrationQueue_, edm::shutdown_flag, and thread_.

Referenced by ~DataManager().

50  {
51  // enqueue a dummy RegistrationInfoBase to tell the thread to stop
52  registrationQueue_->enqWait( stor::RegPtr() );
53  thread_->join();
54 
55  edm::shutdown_flag = true;
56 
57  BOOST_FOREACH(
60  ) pair.second->stop();
61 
62  BOOST_FOREACH(
65  ) pair.second->stop();
66  }
stor::RegistrationQueuePtr registrationQueue_
Definition: DataManager.h:85
boost::shared_ptr< RegistrationInfoBase > RegPtr
std::map< stor::DQMEventConsRegPtr, DQMEventRetrieverPtr, stor::utils::ptrComp< stor::DQMEventConsumerRegistrationInfo > > DQMEventRetrieverMap
Definition: DataManager.h:102
DataEventRetrieverMap dataEventRetrievers_
Definition: DataManager.h:96
U second(std::pair< T, U > const &p)
Container::value_type value_type
boost::scoped_ptr< boost::thread > thread_
Definition: DataManager.h:88
string const
Definition: compareJSON.py:14
DQMEventRetrieverMap dqmEventRetrievers_
Definition: DataManager.h:103
volatile bool shutdown_flag
void smproxy::DataManager::watchDog ( )
private

Definition at line 208 of file DataManager.cc.

References checkForStaleConsumers(), alignCSCRings::e, cppFunctionSkipper::exception, edm::hlt::Exception, smproxy::StateMachine::moveToFailedState(), and stateMachine_.

209  {
210  try
211  {
213  }
214  catch(boost::thread_interrupted)
215  {
216  // thread was interrupted.
217  }
218  catch(xcept::Exception &e)
219  {
221  }
222  catch(std::exception &e)
223  {
224  XCEPT_DECLARE(exception::Exception,
225  sentinelException, e.what());
226  stateMachine_->moveToFailedState(sentinelException);
227  }
228  catch(...)
229  {
230  std::string errorMsg = "Unknown exception in watch dog";
231  XCEPT_DECLARE(exception::Exception,
232  sentinelException, errorMsg);
233  stateMachine_->moveToFailedState(sentinelException);
234  }
235  }
void moveToFailedState(xcept::Exception &e)
Definition: StateMachine.h:79
StateMachine * stateMachine_
Definition: DataManager.h:84

Member Data Documentation

DataEventRetrieverMap smproxy::DataManager::dataEventRetrievers_
private

Definition at line 96 of file DataManager.h.

Referenced by addEventConsumer(), start(), and stop().

DataRetrieverParams smproxy::DataManager::dataRetrieverParams_
private

Definition at line 86 of file DataManager.h.

Referenced by start().

DQMEventRetrieverMap smproxy::DataManager::dqmEventRetrievers_
private

Definition at line 103 of file DataManager.h.

Referenced by addDQMEventConsumer(), start(), and stop().

stor::RegistrationQueuePtr smproxy::DataManager::registrationQueue_
private

Definition at line 85 of file DataManager.h.

Referenced by doIt(), and stop().

StateMachine* smproxy::DataManager::stateMachine_
private
boost::scoped_ptr<boost::thread> smproxy::DataManager::thread_
private

Definition at line 88 of file DataManager.h.

Referenced by start(), and stop().

boost::scoped_ptr<boost::thread> smproxy::DataManager::watchDogThread_
private

Definition at line 89 of file DataManager.h.

Referenced by ~DataManager().