CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Attributes
xmas2dqm::wse::XmasToDQM Class Reference

#include <XmasToDQM.h>

Inheritance diagram for xmas2dqm::wse::XmasToDQM:

Public Member Functions

void actionPerformed (xdata::Event &e)
 
void Default (xgi::Input *in, xgi::Output *out) throw (xgi::exception::Exception)
 
xoap::MessageReference report (xoap::MessageReference msg) throw (xoap::exception::Exception)
 Receive metrics from a sensor. More...
 
 XDAQ_INSTANTIATOR ()
 
 XmasToDQM (xdaq::ApplicationStub *s) throw (xdaq::exception::Exception)
 
 ~XmasToDQM ()
 

Protected Member Functions

void ConfigureAction (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
 
void EnableAction (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
 
void failedTransition (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
 
xoap::MessageReference fireEvent (xoap::MessageReference msg) throw (xoap::exception::Exception)
 
int getEXDR_LAS (xdata::Table *rtable)
 
void HaltAction (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
 
bool LASReadoutWorkLoop (toolbox::task::WorkLoop *wl)
 
xoap::MessageReference reset (xoap::MessageReference msg) throw (xoap::exception::Exception)
 
void ResumeAction (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
 
void stateChanged (toolbox::fsm::FiniteStateMachine &fsm) throw (toolbox::fsm::exception::Exception)
 
void SuspendAction (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
 
void timeExpired (toolbox::task::TimerEvent &e)
 

Static Protected Member Functions

static void * myrealloc (void *ptr, size_t size)
 
static size_t WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data)
 

Protected Attributes

xdata::String LASQueueSize_
 
xdata::String LASurl_
 
xdata::String Period_
 
xdata::String state_
 

Private Attributes

xmas2dqm::wse::ToDqmdqmHook_
 
toolbox::fsm::FiniteStateMachine fsm_
 
toolbox::task::ActionSignature * LASReadout_
 
toolbox::task::Timer * LASReadoutTimer_
 
toolbox::task::WorkLoop * LASReadoutWorkLoop_
 
toolbox::TimeVal startLASReadout_
 

Detailed Description

Definition at line 78 of file XmasToDQM.h.

Constructor & Destructor Documentation

xmas2dqm::wse::XmasToDQM::XmasToDQM ( xdaq::ApplicationStub *  s)
throw (xdaq::exception::Exception
)

Definition at line 71 of file XmasToDQM.cc.

References EnableAction(), failedTransition(), fireEvent(), HaltAction(), xmas2dqm::wse::ToDqm::instance(), LASReadoutWorkLoop(), reset(), sistrip::runNumber_, and stateChanged().

72  : xdaq::Application(s)
73 {
74  getApplicationDescriptor()->setAttribute("icon", "/xmas2dqm/wse/images/Las.png");
75 
76  LOG4CPLUS_DEBUG(this->getApplicationLogger(),"inside constructor of xmas2dqm::wse::Application");
77 
78 
79  // Activates work loop for las asynchronous operations (SOAP messages)
80  //dispatcher_.addActionListener(this);
81  //(void) toolbox::task::getWorkLoopFactory()->getWorkLoop("urn:xdaq-workloop:las", "waiting")->activate();
82 
83 
84  // bind SOAP interface
85  xoap::bind(this, &xmas2dqm::wse::XmasToDQM::fireEvent, "Enable", XDAQ_NS_URI );
86  xoap::bind(this, &xmas2dqm::wse::XmasToDQM::fireEvent, "Halt", XDAQ_NS_URI );
87  xoap::bind(this, &xmas2dqm::wse::XmasToDQM::reset, "Reset", XDAQ_NS_URI );
88 
89 
90  // Define FSM
91  //
92  fsm_.addState('H', "Halted", this, &xmas2dqm::wse::XmasToDQM::stateChanged);
93  fsm_.addState('E', "Enabled", this, &xmas2dqm::wse::XmasToDQM::stateChanged);
94 
95  fsm_.addStateTransition('H', 'E', "Enable", this,&xmas2dqm::wse::XmasToDQM::EnableAction);
96  fsm_.addStateTransition('H', 'H', "Halt", this, &xmas2dqm::wse::XmasToDQM::HaltAction);
97  fsm_.addStateTransition('E', 'H', "Halt", this, &xmas2dqm::wse::XmasToDQM::HaltAction);
98 
99  // Failure state setting
100  fsm_.setFailedStateTransitionAction( this, &xmas2dqm::wse::XmasToDQM::failedTransition );
101  fsm_.setFailedStateTransitionChanged(this, &xmas2dqm::wse::XmasToDQM::stateChanged );
102 
103  fsm_.setInitialState('H');
104  fsm_.setStateName('F', "Failed"); // give a name to the 'F' state
105 
106  fsm_.reset();
107 
108  // Export a "State" variable that reflects the state of the state machine
109  state_ = fsm_.getStateName (fsm_.getCurrentState());
110  getApplicationInfoSpace()->fireItemAvailable("stateName",&state_);
111  getApplicationInfoSpace()->fireItemAvailable("LASurl",&LASurl_);
112  getApplicationInfoSpace()->fireItemAvailable("Period",&Period_);
113  getApplicationInfoSpace()->fireItemAvailable("LASQueueSize",&LASQueueSize_);
114  getApplicationInfoSpace()->fireItemAvailable("flashlistMonitor",&xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_);
115  getApplicationInfoSpace()->fireItemAvailable("runNumber",&xmas2dqm::wse::ToDqm::instance()->runNumber_);
116 
117  // Add infospace listeners for exporting data values
118  getApplicationInfoSpace()->addItemChangedListener ("stateName", this);
119  getApplicationInfoSpace()->addItemChangedListener ("LASurl", this);
120  getApplicationInfoSpace()->addItemChangedListener ("Period", this);
121  getApplicationInfoSpace()->addItemChangedListener ("LASQueueSize", this);
122  getApplicationInfoSpace()->addItemChangedListener ("flashlistMonitor", this);
123  getApplicationInfoSpace()->addItemChangedListener ("runNumber", this);
124 
125  LASurl_ = "http://srv-c2d04-18.cms:9943/urn:xdaq-application:lid=100/retrieveCollection";
126  Period_ = "10";
127  LASQueueSize_ = "100000";
128 
129  //http://srv-c2d04-18.cms:9943/urn:xdaq-application:lid=100/retrieveCollection
130  //http://fu16.cmsdaqpreseries:9943/urn:xdaq-application:lid=100/retrieveCollection
131 
132 
133  //curl_global_init(CURL_GLOBAL_DEFAULT);
134  curl_global_init(CURL_GLOBAL_ALL);
135 
136  LASReadout_ = toolbox::task::bind (this, &xmas2dqm::wse::XmasToDQM::LASReadoutWorkLoop, "LASReadoutWorkLoop");
137 
138  LASReadoutWorkLoop_ = toolbox::task::getWorkLoopFactory()->getWorkLoop("LASReadoutWaitingWorkLoop", "waiting");
139 
140 
141  if (LASReadoutWorkLoop_->isActive() == false)
142  {
143  LASReadoutWorkLoop_->activate();
144 
145  }
146 
147  //LOG4CPLUS_INFO(this->getApplicationLogger(),"insdie constructor of xmas2dqm::wse::XmasToDQM Period = " << Period_.toString());
148 
149  LASReadoutTimer_ = toolbox::task::getTimerFactory()->createTimer("PeriodicLASReadout");
150 
151  // toolbox::TimeInterval interval(/*10*/atoi(Period_.toString().c_str()),0); // period of 8 secs
152 //
153 // startLASReadout_ = toolbox::TimeVal::gettimeofday();
154 //
155 // LASReadoutTimer_->scheduleAtFixedRate( startLASReadout_, this, interval, 0, std::string("LASReadout") );
156 
157  LOG4CPLUS_DEBUG(this->getApplicationLogger(),"finish of Constructor of xmas2dqm::wse::XmasToDQM");
158 
159 }
static const char runNumber_[]
xoap::MessageReference fireEvent(xoap::MessageReference msg)
Definition: XmasToDQM.cc:490
void stateChanged(toolbox::fsm::FiniteStateMachine &fsm)
Definition: XmasToDQM.cc:611
xdata::String Period_
Definition: XmasToDQM.h:157
xdata::String LASurl_
Definition: XmasToDQM.h:156
void failedTransition(toolbox::Event::Reference e)
Definition: XmasToDQM.cc:618
void HaltAction(toolbox::Event::Reference e)
Definition: XmasToDQM.cc:584
void EnableAction(toolbox::Event::Reference e)
Definition: XmasToDQM.cc:550
static ToDqm * instance()
Definition: ToDqm.cc:6
xdata::String state_
Definition: XmasToDQM.h:155
toolbox::task::ActionSignature * LASReadout_
Definition: XmasToDQM.h:179
bool LASReadoutWorkLoop(toolbox::task::WorkLoop *wl)
Definition: XmasToDQM.cc:162
xoap::MessageReference reset(xoap::MessageReference msg)
Definition: XmasToDQM.cc:531
xdata::String LASQueueSize_
Definition: XmasToDQM.h:158
toolbox::task::Timer * LASReadoutTimer_
Definition: XmasToDQM.h:181
toolbox::fsm::FiniteStateMachine fsm_
Definition: XmasToDQM.h:173
toolbox::task::WorkLoop * LASReadoutWorkLoop_
Definition: XmasToDQM.h:176
xmas2dqm::wse::XmasToDQM::~XmasToDQM ( )

Definition at line 484 of file XmasToDQM.cc.

485 {
486 
487 }

Member Function Documentation

void xmas2dqm::wse::XmasToDQM::actionPerformed ( xdata::Event &  e)

Definition at line 399 of file XmasToDQM.cc.

References alignCSCRings::e, xmas2dqm::wse::ToDqm::instance(), MergeJob_cfg::interval, and sistrip::runNumber_.

400 {
401  LOG4CPLUS_DEBUG(getApplicationLogger(), "start of actionperformed");
402  LOG4CPLUS_DEBUG(getApplicationLogger(), e.type());
403 
404  // update exported parameters
405  if (e.type() == "ItemChangedEvent")
406  {
407  std::string item = dynamic_cast<xdata::ItemChangedEvent&>(e).itemName();
408 
409  if ( item == "Period")
410  {
411 
412  LOG4CPLUS_DEBUG(getApplicationLogger(), "item = " + item);
413 
414  if(fsm_.getStateName (fsm_.getCurrentState()) != "Enabled")
415  {
416  return;
417  }
418 
419  try
420  {
421  LASReadoutTimer_->remove(std::string("LASReadout"));
422  }
423  catch(toolbox::task::exception::NotActive &e)
424  {
425  LOG4CPLUS_WARN(getApplicationLogger(), "toolbox::task::exception::NotActive exception occured...");
426  }
427  catch(toolbox::task::exception::NoJobs)
428  {
429  LOG4CPLUS_WARN(getApplicationLogger(), "toolbox::task::exception::NoJobs exception occured...");
430  }
431  catch(toolbox::task::exception::JobNotFound &e)
432  {
433  LOG4CPLUS_WARN(getApplicationLogger(), "toolbox::task::exception::JobNotFound exception occured...");
434  toolbox::TimeInterval interval(/*10*/atoi(Period_.toString().c_str()),0); // period of 8 secs
435 
436  }
437 
438  //LASReadoutTimer_->stop();
439 
440  toolbox::TimeInterval interval(/*10*/atoi(Period_.toString().c_str()),0); // period of 8 secs
441 
442  startLASReadout_ = toolbox::TimeVal::gettimeofday();
443 
444  LASReadoutTimer_->scheduleAtFixedRate( startLASReadout_, this, interval, 0, std::string("LASReadout") );
445  }
446 
447 
448  if ( item == "flashlistMonitor")
449  {
450 
451  LOG4CPLUS_INFO(getApplicationLogger(), "flashlist = " << xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.flashlist.toString());
452  LOG4CPLUS_INFO(getApplicationLogger(), "element = " << xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.element.toString());
453  LOG4CPLUS_INFO(getApplicationLogger(), "xtitle = " << xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.xtitle.toString());
454  LOG4CPLUS_INFO(getApplicationLogger(), "ytitle = " << xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.ytitle.toString());
455 
456  //flashlistMonitor_.bag.flashlist = "abc";
457  //std::cout << "flashlist = " << flashlistMonitor_.bag.flashlist.toString() << std::endl;
458  }
459 
460  if ( item == "runNumber")
461  {
462 
463  LOG4CPLUS_INFO(getApplicationLogger(), "set runNumber to... = " << xmas2dqm::wse::ToDqm::instance()->runNumber_.toString());
464  }
465 
466  }
467 
468  LOG4CPLUS_DEBUG(getApplicationLogger(), "end of actionperformed");
469 }
static const char runNumber_[]
tuple interval
Definition: MergeJob_cfg.py:20
xdata::String Period_
Definition: XmasToDQM.h:157
static ToDqm * instance()
Definition: ToDqm.cc:6
toolbox::TimeVal startLASReadout_
Definition: XmasToDQM.h:182
toolbox::task::Timer * LASReadoutTimer_
Definition: XmasToDQM.h:181
toolbox::fsm::FiniteStateMachine fsm_
Definition: XmasToDQM.h:173
void xmas2dqm::wse::XmasToDQM::ConfigureAction ( toolbox::Event::Reference  e)
throw (toolbox::fsm::exception::Exception
)
protected
void xmas2dqm::wse::XmasToDQM::Default ( xgi::Input in,
xgi::Output out 
)
throw (xgi::exception::Exception
)
void xmas2dqm::wse::XmasToDQM::EnableAction ( toolbox::Event::Reference  e)
throw (toolbox::fsm::exception::Exception
)
protected

Definition at line 550 of file XmasToDQM.cc.

References alignCSCRings::e, and MergeJob_cfg::interval.

Referenced by XmasToDQM().

551 {
552  LOG4CPLUS_DEBUG (getApplicationLogger(), e->type());
553 
554 
555  try
556  {
557  LASReadoutTimer_->remove(std::string("LASReadout"));
558  }
559  catch(toolbox::task::exception::NotActive &e)
560  {
561  LOG4CPLUS_WARN(getApplicationLogger(), "toolbox::task::exception::NotActive exception occured...");
562  }
563  catch(toolbox::task::exception::NoJobs)
564  {
565  LOG4CPLUS_INFO(getApplicationLogger(), "toolbox::task::exception::NoJobs exception occured...");
566  }
567  catch(toolbox::task::exception::JobNotFound &e)
568  {
569  LOG4CPLUS_INFO(getApplicationLogger(), "toolbox::task::exception::JobNotFound exception occured...");
570  toolbox::TimeInterval interval(/*10*/atoi(Period_.toString().c_str()),0); // period of 8 secs
571 
572  }
573 
574 
575  toolbox::TimeInterval interval(/*10*/atoi(Period_.toString().c_str()),0); // period of 8 secs
576 
577  startLASReadout_ = toolbox::TimeVal::gettimeofday();
578 
579  LASReadoutTimer_->scheduleAtFixedRate( startLASReadout_, this, interval, 0, std::string("LASReadout") );
580 
581 }
tuple interval
Definition: MergeJob_cfg.py:20
xdata::String Period_
Definition: XmasToDQM.h:157
toolbox::TimeVal startLASReadout_
Definition: XmasToDQM.h:182
toolbox::task::Timer * LASReadoutTimer_
Definition: XmasToDQM.h:181
void xmas2dqm::wse::XmasToDQM::failedTransition ( toolbox::Event::Reference  e)
throw (toolbox::fsm::exception::Exception
)
protected

Definition at line 618 of file XmasToDQM.cc.

Referenced by XmasToDQM().

619 {
620  toolbox::fsm::FailedEvent & fe = dynamic_cast<toolbox::fsm::FailedEvent&>(*e);
621  LOG4CPLUS_ERROR (getApplicationLogger(), "Failure occurred when performing transition from: " <<
622  fe.getFromState() << " to: " << fe.getToState() << " exception: " << fe.getException().what() );
623 }
xoap::MessageReference xmas2dqm::wse::XmasToDQM::fireEvent ( xoap::MessageReference  msg)
throw (xoap::exception::Exception
)
protected

Definition at line 490 of file XmasToDQM.cc.

References edmPickEvents::command, alignCSCRings::e, web.browse_db::env, edm::hlt::Exception, i, lumiQueryAPI::msg, and python.Node::node.

Referenced by XmasToDQM().

492 {
493  xoap::SOAPPart part = msg->getSOAPPart();
494  xoap::SOAPEnvelope env = part.getEnvelope();
495  xoap::SOAPBody body = env.getBody();
496  DOMNode* node = body.getDOMNode();
497  DOMNodeList* bodyList = node->getChildNodes();
498  for (unsigned int i = 0; i < bodyList->getLength(); i++)
499  {
500  DOMNode* command = bodyList->item(i);
501 
502  if (command->getNodeType() == DOMNode::ELEMENT_NODE)
503  {
504 
505  std::string commandName = xoap::XMLCh2String (command->getLocalName());
506 
507 
508  try
509  {
510  toolbox::Event::Reference e(new toolbox::Event(commandName,this));
511  fsm_.fireEvent(e);
512  }
514  {
515  XCEPT_RETHROW(xoap::exception::Exception, "invalid command", e);
516  }
517 
518  xoap::MessageReference reply = xoap::createMessage();
519  xoap::SOAPEnvelope envelope = reply->getSOAPPart().getEnvelope();
520  xoap::SOAPName responseName = envelope.createName( commandName +"Response", "xdaq", XDAQ_NS_URI);
521  // xoap::SOAPBodyElement e = envelope.getBody().addBodyElement ( responseName );
522  (void) envelope.getBody().addBodyElement ( responseName );
523  return reply;
524  }
525  }
526 
527  XCEPT_RAISE(xcept::Exception,"command not found");
528 }
int i
Definition: DBlmapReader.cc:9
tuple node
Definition: Node.py:50
part
Definition: HCALResponse.h:21
toolbox::fsm::FiniteStateMachine fsm_
Definition: XmasToDQM.h:173
int xmas2dqm::wse::XmasToDQM::getEXDR_LAS ( xdata::Table *  rtable)
protected

Definition at line 255 of file XmasToDQM.cc.

References data, alignCSCRings::e, edm::hlt::Exception, xmas2dqm::wse::ToDqm::instance(), xmas2dqm::wse::MemoryStruct::memory, NULL, and xmas2dqm::wse::MemoryStruct::size.

Referenced by LASReadoutWorkLoop().

256 {
257  LOG4CPLUS_DEBUG(this->getApplicationLogger(),"inside getEXDR_LAS.........");
258 
259  CURL *curl_handle;
260  CURLcode code;
261 
262  char data[200] = "fmt=exdr&flash=";
263 
264  strcat(data, xmas2dqm::wse::ToDqm::instance()->flashlistMonitor_.bag.flashlist.toString().c_str());
265 
266 
267  struct MemoryStruct chunk;
268 
269  chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
270  chunk.size = 0; /* no data at this point */
271 
272  /* init the curl session */
273  curl_handle = curl_easy_init();
274 
275  if (curl_handle == NULL)
276  {
277  LOG4CPLUS_WARN(getApplicationLogger(), "Failed to create CURL connection");
278 
279  return -2;
280  }
281 
282  code = curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
283  if (code != CURLE_OK)
284  {
285  LOG4CPLUS_WARN (getApplicationLogger(),"Failed to set post fields");
286 
287  return -2;
288  }
289 
290  /* specify URL to get */
291  curl_easy_setopt(curl_handle, CURLOPT_URL, LASurl_.toString().c_str()/*"http://fu16.cmsdaqpreseries:9943/urn:xdaq-application:lid=100/retrieveCollection"*/);
292 
293  /* send all data to this function */
294  curl_easy_setopt(curl_handle, /*CURLOPT_HEADERFUNCTION*/ CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
295 
296  //curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, HeaderMemoryCallback);
297 
298  /* we pass our 'chunk' struct to the callback function */
299  curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
300 
301  /* some servers don't like requests that are made without a user-agent
302  field, so we provide one */
303  curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
304 
305  /* get it! */
306  curl_easy_perform(curl_handle);
307 
308  /* cleanup curl stuff */
309  curl_easy_cleanup(curl_handle);
310 
311  /*
312  * Now, our chunk.memory points to a memory block that is chunk.size
313  * bytes big and contains the remote file.
314  *
315  * Be aware of the fact that at this point we might have an
316  * allocated data block, and nothing has yet deallocated that data. So when
317  * you're done with it, you should free() it as a nice application.
318  */
319 
320  LOG4CPLUS_DEBUG (getApplicationLogger(),"chunk.memory length = " << chunk.size);
321 
322  xdata::exdr::FixedSizeInputStreamBuffer inBuffer(chunk.memory,chunk.size);
323 
324  /*if(chunk.size > 0)
325  free(chunk.memory);*/
326 
327  xdata::exdr::Serializer serializer;
328 
329  try
330  {
331  serializer.import(/*&(*rtable)*/ rtable, &inBuffer );
332  //serializer.import( rtable, &inBuffer );
333  }
335  {
336  LOG4CPLUS_ERROR(this->getApplicationLogger(),"xdata::exdr::Serializer exception occured...");
337  LOG4CPLUS_ERROR(this->getApplicationLogger(),xcept::stdformat_exception_history(e));
338 
339  if(chunk.size > 0)
340  free(chunk.memory);
341 
342  return -1 ;
343  }
344 
345  if(chunk.size > 0)
346  free(chunk.memory);
347 
348  return 0;
349 }
xdata::String LASurl_
Definition: XmasToDQM.h:156
#define NULL
Definition: scimark2.h:8
static ToDqm * instance()
Definition: ToDqm.cc:6
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
Definition: XmasToDQM.cc:381
void xmas2dqm::wse::XmasToDQM::HaltAction ( toolbox::Event::Reference  e)
throw (toolbox::fsm::exception::Exception
)
protected

Definition at line 584 of file XmasToDQM.cc.

References alignCSCRings::e, and MergeJob_cfg::interval.

Referenced by XmasToDQM().

585 {
586  LOG4CPLUS_DEBUG (getApplicationLogger(), e->type());
587 
588  try
589  {
590  LASReadoutTimer_->remove(std::string("LASReadout"));
591  }
592  catch(toolbox::task::exception::NotActive &e)
593  {
594  LOG4CPLUS_WARN(getApplicationLogger(), "toolbox::task::exception::NotActive exception occured...");
595  }
596  catch(toolbox::task::exception::NoJobs)
597  {
598  LOG4CPLUS_WARN(getApplicationLogger(), "toolbox::task::exception::NoJobs exception occured...");
599  }
600  catch(toolbox::task::exception::JobNotFound &e)
601  {
602  LOG4CPLUS_WARN(getApplicationLogger(), "toolbox::task::exception::JobNotFound exception occured...");
603  toolbox::TimeInterval interval(/*10*/atoi(Period_.toString().c_str()),0); // period of 8 secs
604 
605  }
606 
607 }
tuple interval
Definition: MergeJob_cfg.py:20
xdata::String Period_
Definition: XmasToDQM.h:157
toolbox::task::Timer * LASReadoutTimer_
Definition: XmasToDQM.h:181
bool xmas2dqm::wse::XmasToDQM::LASReadoutWorkLoop ( toolbox::task::WorkLoop *  wl)
protected

Definition at line 162 of file XmasToDQM.cc.

References xmas2dqm::wse::ToDqm::digest(), getEXDR_LAS(), i, xmas2dqm::wse::ToDqm::instance(), LASQueueSize_, LASurl_, Period_, run_regression::ret, and create_public_lumi_plots::times.

Referenced by XmasToDQM().

163 {
164  //keep log how many times the workloop was called...
165  static int times = 0;
166  times++;
167 
168  LOG4CPLUS_DEBUG (getApplicationLogger(), "inside WorkLoop...ready to ask LAS for EXDR data : time " << times <<"th");
169  LOG4CPLUS_DEBUG (getApplicationLogger(), "Period = " + Period_.toString() + " LASurl = " + LASurl_.toString());
170 
171 
172  xdata::Table * ptr_table = new xdata::Table();
173 
174  int ret = getEXDR_LAS(ptr_table);
175 
176  LOG4CPLUS_DEBUG (getApplicationLogger(), "return value from getEXDR_LAS = " << ret );
177 
178  if (ret == -1 || ret == -2) //exception during xdata::exdr deserialization occured or during CURL (could log different messages)
179  {
180  //LOG4CPLUS_INFO (getApplicationLogger(), "LASWorkLoop ready to call xdata::Table::Reference destructor..." );
181 
182  //ref_table->~Table();
183 
184 
185  LOG4CPLUS_DEBUG (getApplicationLogger(), "LASWorkLoop freeing xdata::Table * space" );
186 
187  delete ptr_table;
188 
189  LOG4CPLUS_WARN (getApplicationLogger(), "getEXDRLAS didn't complete properly, returning from LASREeadoutWorkLoop" );
190  return false;
191  }
192 
193 
194 
195  LOG4CPLUS_DEBUG (getApplicationLogger(), "inside WorkLoop...lock the mutex ");
196 
197 
198  //BSem_.take();
199  //acquire the mutex - protect access to the queue
200  pthread_mutex_lock(&xmas2dqm::wse::ToDqm::instance()->LASmutex_);
201 
202  LOG4CPLUS_INFO (getApplicationLogger(), "inside WorkLoop...check (...and possible wait) if data queue is full");
203 
204  //check if the queue is full and wait (a signal that informs that an element has been poped)
205  // until there is 'space' in the queue
206  while (xmas2dqm::wse::ToDqm::instance()->MemoryTable_.size() >= (unsigned int) atoi(LASQueueSize_.toString().c_str())/*Qsize_max*/)
207  {
208  pthread_cond_wait(&xmas2dqm::wse::ToDqm::instance()->less_, &xmas2dqm::wse::ToDqm::instance()->LASmutex_);
209  }
210 
211  LOG4CPLUS_DEBUG (getApplicationLogger(), "data queue has available store...proceeding...");
212 
213 
214 
215  std::map<std::string, std::string, std::less<std::string> >::iterator i;
216 
217  //size_t row = ref_table->getRowCount();
218  // size_t row = ptr_table->getRowCount();
219 //
220 // for ( size_t r = 0; r < ptr_table->numberOfRows_ /*ref_table->numberOfRows_*/; r++ )
221 // {
222 // LOG4CPLUS_INFO(this->getApplicationLogger(),"********* Printing table inside XmasToDQM ***************");
223 // LOG4CPLUS_INFO(this->getApplicationLogger(),/*ref_table*/ ptr_table->columnData_["bxHistogram"]->elementAt(r)->toString());
224 //
225 // boost::tokenizer<> tokens(/*ref_table*/ ptr_table->columnData_["bxHistogram"]->elementAt(r)->toString());
226 // for(boost::tokenizer<>::iterator itok=tokens.begin(); itok!=tokens.end();++itok)
227 // {
228 // //LOG4CPLUS_INFO(this->getApplicationLogger, (std::string)(*itok) );
229 // }
230 //
231 // row++;
232 // }
233 
234 
235  LOG4CPLUS_DEBUG (getApplicationLogger(), "inside WorkLoop...ready to call XmastoDQM::ToDQM::digest " );
236 
237  //insert LAS data table to ToDQM objec - queue
238  xmas2dqm::wse::ToDqm::instance()->digest("flashListName", "originator", "tagName", ptr_table /*ref_table*/);
239 
240  LOG4CPLUS_DEBUG (getApplicationLogger(), "inside WorkLoop...signaling new element added to the data queue ");
241 
242  //signal that a new element has been inserted
243  pthread_cond_signal(&xmas2dqm::wse::ToDqm::instance()->more_);
244 
245  LOG4CPLUS_DEBUG (getApplicationLogger(), "inside WorkLoop...release mutex, allow access to the data queue");
246 
247  //allow access to the queue
248  pthread_mutex_unlock(&xmas2dqm::wse::ToDqm::instance()->LASmutex_);
249 
250  return false;
251 }
int i
Definition: DBlmapReader.cc:9
xdata::String Period_
Definition: XmasToDQM.h:157
xdata::String LASurl_
Definition: XmasToDQM.h:156
void digest(const std::string &flashListName, const std::string &originator, const std::string &tag, xdata::Table *table)
Definition: ToDqm.cc:33
static ToDqm * instance()
Definition: ToDqm.cc:6
int getEXDR_LAS(xdata::Table *rtable)
Definition: XmasToDQM.cc:255
xdata::String LASQueueSize_
Definition: XmasToDQM.h:158
void * xmas2dqm::wse::XmasToDQM::myrealloc ( void *  ptr,
size_t  size 
)
staticprotected

Definition at line 369 of file XmasToDQM.cc.

370 {
371  /* There might be a realloc() out there that doesn't like reallocing
372  NULL pointers, so we take care of it here */
373  if(ptr)
374  return realloc(ptr, size);
375  else
376  return malloc(size);
377 }
tuple size
Write out results.
xoap::MessageReference xmas2dqm::wse::XmasToDQM::report ( xoap::MessageReference  msg)
throw (xoap::exception::Exception
)

Receive metrics from a sensor.

xoap::MessageReference xmas2dqm::wse::XmasToDQM::reset ( xoap::MessageReference  msg)
throw (xoap::exception::Exception
)
protected

Definition at line 531 of file XmasToDQM.cc.

Referenced by XmasToDQM().

532 {
533  LOG4CPLUS_DEBUG (getApplicationLogger(), "New state before reset is: " << fsm_.getStateName (fsm_.getCurrentState()) );
534 
535  fsm_.reset();
536  state_ = fsm_.getStateName (fsm_.getCurrentState());
537 
538  xoap::MessageReference reply = xoap::createMessage();
539  xoap::SOAPEnvelope envelope = reply->getSOAPPart().getEnvelope();
540  xoap::SOAPName responseName = envelope.createName("ResetResponse", "xdaq", XDAQ_NS_URI);
541  // xoap::SOAPBodyElement e = envelope.getBody().addBodyElement ( responseName );
542  (void) envelope.getBody().addBodyElement ( responseName );
543 
544  LOG4CPLUS_DEBUG (getApplicationLogger(), "New state after reset is: " << fsm_.getStateName (fsm_.getCurrentState()) );
545 
546  return reply;
547 }
xdata::String state_
Definition: XmasToDQM.h:155
toolbox::fsm::FiniteStateMachine fsm_
Definition: XmasToDQM.h:173
void xmas2dqm::wse::XmasToDQM::ResumeAction ( toolbox::Event::Reference  e)
throw (toolbox::fsm::exception::Exception
)
protected
void xmas2dqm::wse::XmasToDQM::stateChanged ( toolbox::fsm::FiniteStateMachine &  fsm)
throw (toolbox::fsm::exception::Exception
)
protected

Definition at line 611 of file XmasToDQM.cc.

Referenced by XmasToDQM().

612 {
613  // Reflect the new state
614  state_ = fsm.getStateName (fsm.getCurrentState());
615  LOG4CPLUS_DEBUG (getApplicationLogger(), "New state is:" << fsm.getStateName (fsm.getCurrentState()) );
616 }
xdata::String state_
Definition: XmasToDQM.h:155
void xmas2dqm::wse::XmasToDQM::SuspendAction ( toolbox::Event::Reference  e)
throw (toolbox::fsm::exception::Exception
)
protected
void xmas2dqm::wse::XmasToDQM::timeExpired ( toolbox::task::TimerEvent &  e)
protected

Timer method called, this method inject the method dcuReadWorkLoop in the queue to be executed

Definition at line 356 of file XmasToDQM.cc.

References create_public_lumi_plots::times.

357 {
358  //keep log how many times the period for parsing LAS expired...
359  static int times = 0;
360 
361  times++;
362 
363  LOG4CPLUS_DEBUG (getApplicationLogger(), "timeExpired was called... : time " << times <<"th");
365 
366 }
toolbox::task::ActionSignature * LASReadout_
Definition: XmasToDQM.h:179
toolbox::task::WorkLoop * LASReadoutWorkLoop_
Definition: XmasToDQM.h:176
size_t xmas2dqm::wse::XmasToDQM::WriteMemoryCallback ( void *  ptr,
size_t  size,
size_t  nmemb,
void *  data 
)
staticprotected

Definition at line 381 of file XmasToDQM.cc.

References mem, xmas2dqm::wse::MemoryStruct::memory, and xmas2dqm::wse::MemoryStruct::size.

382 {
383  size_t realsize = size * nmemb;
384  struct MemoryStruct *mem = (struct MemoryStruct *)data;
385 
386  mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
387  if (mem->memory)
388  {
389  memcpy(&(mem->memory[mem->size]), ptr, realsize);
390  mem->size += realsize;
391  mem->memory[mem->size] = 0;
392  }
393  return realsize;
394 }
static void * myrealloc(void *ptr, size_t size)
Definition: XmasToDQM.cc:369
uint16_t mem[nChs][nEvts]
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple size
Write out results.
xmas2dqm::wse::XmasToDQM::XDAQ_INSTANTIATOR ( )

Member Data Documentation

xmas2dqm::wse::ToDqm* xmas2dqm::wse::XmasToDQM::dqmHook_
private

Definition at line 167 of file XmasToDQM.h.

toolbox::fsm::FiniteStateMachine xmas2dqm::wse::XmasToDQM::fsm_
private

Definition at line 173 of file XmasToDQM.h.

xdata::String xmas2dqm::wse::XmasToDQM::LASQueueSize_
protected

Definition at line 158 of file XmasToDQM.h.

Referenced by LASReadoutWorkLoop().

toolbox::task::ActionSignature* xmas2dqm::wse::XmasToDQM::LASReadout_
private

Definition at line 179 of file XmasToDQM.h.

toolbox::task::Timer* xmas2dqm::wse::XmasToDQM::LASReadoutTimer_
private

Definition at line 181 of file XmasToDQM.h.

toolbox::task::WorkLoop* xmas2dqm::wse::XmasToDQM::LASReadoutWorkLoop_
private

Definition at line 176 of file XmasToDQM.h.

xdata::String xmas2dqm::wse::XmasToDQM::LASurl_
protected

Definition at line 156 of file XmasToDQM.h.

Referenced by LASReadoutWorkLoop().

xdata::String xmas2dqm::wse::XmasToDQM::Period_
protected

Definition at line 157 of file XmasToDQM.h.

Referenced by LASReadoutWorkLoop().

toolbox::TimeVal xmas2dqm::wse::XmasToDQM::startLASReadout_
private

Definition at line 182 of file XmasToDQM.h.

xdata::String xmas2dqm::wse::XmasToDQM::state_
protected

Definition at line 155 of file XmasToDQM.h.