CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DrainingQueues.cc
Go to the documentation of this file.
1 // $Id: DrainingQueues.cc,v 1.14 2011/11/08 10:48:40 mommsen Exp $
3 
16 
17 #include <iostream>
18 #include <unistd.h>
19 
20 using namespace std;
21 using namespace stor;
22 
23 DrainingQueues::DrainingQueues( my_context c ): my_base(c)
24 {
26 }
27 
29 {
30  TransitionRecord tr( stateName(), true );
31  outermost_context().updateHistory( tr );
32 }
33 
35 {
37 }
38 
40 {
41  TransitionRecord tr( stateName(), false );
42  outermost_context().updateHistory( tr );
43 }
44 
46 {
47  return std::string( "DrainingQueues" );
48 }
49 
51 {
52  outermost_context().getSharedResources()->alarmHandler_->moveToFailedState( exception );
53 }
54 
56 {
57  outermost_context().unconsumed_event( request );
58 }
59 
60 void
62 {
64  {
65  SharedResourcesPtr sharedResources =
66  outermost_context().getSharedResources();
67  EventPtr_t stMachEvent( new QueuesEmpty() );
68  sharedResources->commandQueue_->enqWait( stMachEvent );
69  }
70 }
71 
72 bool
74 {
75  SharedResourcesPtr sharedResources =
76  outermost_context().getSharedResources();
77 
78  // the order is important here - upstream entities first,
79  // followed by more downstream entities
80 
81  EventDistributor *ed = outermost_context().getEventDistributor();
82  if ( ed->full() ) return false;
83 
85  FragmentStore *fs = outermost_context().getFragmentStore();
86  if ( ! fs->empty() ) return false;
87 
88  if ( ! sharedResources->streamQueue_->empty() ) return false;
89 
90  if ( sharedResources->diskWriterResources_->isBusy() ) return false;
91 
92  //if ( ! sharedResources->dqmEventQueue_->empty() ) return false;
93  // Do not wait for dqmEventQueue to drain, just clear it
94  sharedResources->dqmEventQueue_->clear();
95 
96  return true;
97 }
98 
99 void
101 {
102  I2OChain staleEvent;
103  bool gotStaleEvent = true;
104  int loopCounter = 0;
105 
106  EventDistributor *ed = outermost_context().getEventDistributor();
107 
108  while ( gotStaleEvent && !ed->full() && loopCounter++ < 10 )
109  {
110  gotStaleEvent =
111  outermost_context().getFragmentStore()->getStaleEvent(staleEvent, boost::posix_time::seconds(0));
112  if ( gotStaleEvent )
113  {
114  outermost_context().getSharedResources()->discardManager_->sendDiscardMessage(staleEvent);
115  ed->addEventToRelevantQueues(staleEvent);
116  }
117  }
118 }
119 
120 
void processStaleFragments() const
std::string stateName() const
Definition: Operations.cc:39
double seconds()
virtual std::string do_stateName() const
bool allQueuesAndWorkersAreEmpty() const
boost::shared_ptr< SharedResources > SharedResourcesPtr
const bool full() const
boost::shared_ptr< boost::statechart::event_base > EventPtr_t
Definition: CommandQueue.h:21
void safeExitAction()
Definition: Operations.cc:108
virtual void do_noFragmentToProcess() const
bool empty() const
Definition: FragmentStore.h:74
virtual void do_moveToFailedState(xcept::Exception &exception) const
virtual void do_exitActionWork()
void logEndRunRequest(const EndRun &request)
void addEventToRelevantQueues(I2OChain &)
virtual void do_entryActionWork()
void safeEntryAction()
Definition: Operations.cc:77