CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DaqSource.cc
Go to the documentation of this file.
1 
8 #include "DaqSource.h"
9 
13 
16 
25 
26 #include <string>
27 #include <iostream>
28 #include <time.h>
29 #include <sys/time.h>
30 #include <sys/types.h>
31 
32 #include "xgi/Method.h"
33 #include "xgi/Utils.h"
34 
35 #include "cgicc/Cgicc.h"
36 #include "cgicc/FormEntry.h"
37 #include "cgicc/HTMLClasses.h"
38 
39 #include "boost/tokenizer.hpp"
40 
41 
43 // construction/destruction
45 
46 
47 
48 namespace edm {
49  namespace daqsource{
52  }
53 
54  //______________________________________________________________________________
56  const InputSourceDescription& desc)
57  : InputSource(pset,desc)
58  , evf::ModuleWeb("DaqSource")
59  , reader_(0)
60  , lumiSegmentSizeInEvents_(pset.getUntrackedParameter<unsigned int>("evtsPerLS",0))
61  , lumiSegmentSizeInSeconds_(pset.getUntrackedParameter<unsigned int>("secondsPerLS",0))
62  , useEventCounter_(pset.getUntrackedParameter<bool>("useEventCounter",false))
63  , useTimer_(lumiSegmentSizeInSeconds_!=0)
64  , eventCounter_(0)
65  , keepUsingPsidFromTrigger_(pset.getUntrackedParameter<bool>("keepUsingPsidFromTrigger",false))
66  , fakeLSid_(lumiSegmentSizeInEvents_ != 0 || lumiSegmentSizeInSeconds_ != 0)
67  , runNumber_(pset.getUntrackedParameter<unsigned int>("runNumber",RunID::firstValidRun().run()))
68  , luminosityBlockNumber_(LuminosityBlockID::firstValidLuminosityBlock().luminosityBlock())
69  , daqProvenanceHelper_(TypeID(typeid(FEDRawDataCollection)))
70  , noMoreEvents_(false)
71  , alignLsToLast_(false)
72  , lumiSectionIndex_(0)
73  , prescaleSetIndex_(0)
74  , lastLumiPrescaleIndex_(0)
75  , lastLumiUsingEol_(0)
76  , lsTimedOut_(0)
77  , lsToBeRecovered_(0)
78  , is_(0)
79  , mis_(0)
80  , thisEventLSid(0)
81  , goToStopping(false)
82  , immediateStop(false)
83  , forkInfo_(nullptr)
84  , runFork_(false)
85  , beginRunTiming_(false)
86  , bunchCrossing_(EventAuxiliary::invalidBunchXing)
87  , orbitNumber_(EventAuxiliary::invalidBunchXing)
88  , evttype_(EventAuxiliary::Undefined)
89  , eventID_(0,0,0)
90  , fedCollection_(nullptr)
91  {
92  count = 0;
93  pthread_mutex_init(&mutex_,0);
94  pthread_mutex_init(&signal_lock_,0);
95  pthread_cond_init(&cond_,0);
96 
97  std::cout << " DaqSourceFake will use fake ls id ? " << fakeLSid_ << std::endl;
98  if(fakeLSid_) std::cout << " DaqSourceFake set to make a new ls every " << lumiSegmentSizeInEvents_ << " events " << std::endl;
99  if(fakeLSid_) std::cout << " DaqSourceFake set to make a new ls every " << lumiSegmentSizeInSeconds_ << " seconds " << std::endl;
100 
102 
103  // Instantiate the requested data source
104  std::string reader = pset.getUntrackedParameter<std::string>("readerPluginName");
105 
106  try{
107  reader_=
108  DaqReaderPluginFactory::get()->create(reader,
109  pset.getUntrackedParameter<ParameterSet>("readerPset"));
111  }
112  catch(edm::Exception &e) {
113  if(e.category() == "Configuration" && reader_ == 0) {
114  reader_ = DaqReaderPluginFactoryU::get()->create(reader);
115  if(reader_ == 0) throw;
117  }
118  else {
119  throw;
120  }
121  }
122 
123  // Initialize LS timer if requested
124  if(lumiSegmentSizeInSeconds_ != 0) gettimeofday(&startOfLastLumi,0);
125 
126  // Initialize metadata, and save the process history ID for use every event.
128 
129  }
130 
131  //______________________________________________________________________________
133  delete reader_;
134  }
135 
137  forkInfo_ = forkInfoObj;
138  runFork_=true;
139  immediateStop=false;
140  noMoreEvents_=false;
141  }
142 
144  // implementation of member functions
146 
147 
148  //______________________________________________________________________________
150 
151  if (forkInfo_) {
152  while (!immediateStop) {
153  //queue new run to Framework (causes EP beginRun to be executed)
154  if (newRun()) {
155  beginRunTiming_=true;
156  gettimeofday(&tvStat_, NULL);
157  return 2;
158  }
159  //measure time in fwk beginRun
160  if (beginRunTiming_) {
161  timeval tsTmp;
162  gettimeofday(&tsTmp,NULL);
163  long tusecs = (tsTmp.tv_sec-tvStat_.tv_sec)*1000000 + tsTmp.tv_usec - tvStat_.tv_usec;
164  double tsecs = ((double)(tusecs/10000))/100.;
165  std::cout << "DaqSource: FWK beginRun elapsed time: " << tsecs << " seconds in master EP"<< std::endl;
166  edm::LogInfo("DaqSource") << "FWK beginRun elapsed time: " << tsecs << " seconds in master EP";
167  beginRunTiming_=false;
168  usleep(10000);//short sleep before fork
169  }
170  //first or new run init
171  if (forkInfo_->forkParams.isMaster==-1) {
172  forkInfo_->lock();//keeping it locked during init!
173  forkInfo_->forkHandler(forkInfo_->fuAddr); //fork all slaves
174  }
175  if (forkInfo_->forkParams.isMaster==-1) {
176  forkInfo_->unlock();
177  std::cout << "ERROR (DaqSource): not notified to be either in master or slave process after fork" << std::endl;
178  return -2;
179  }
180 
181  //slave process after fork: exit all this
182  if (forkInfo_->forkParams.isMaster==0) {
183  forkInfo_->unlock();
184  return 1;
185  }
186 
187  //master process after fork:
188  if (forkInfo_->forkParams.isMaster==1) {
189  forkInfo_->unlock();
190  int slotToRestart=-1;
191  sem_wait(forkInfo_->control_sem_);
192  forkInfo_->lock();
193 
194  //got unblocked due to next run
195  if (forkInfo_->forkParams.isMaster==-1) {
196  forkInfo_->unlock();
197  continue; // check here for newRun()?
198  }
199  //check if asked to stop
201  if (immediateStop) {
202  forkInfo_->receivedStop_=true;
203  break;
204  }
205 
206  //check if asked to restart
207  slotToRestart = forkInfo_->forkParams.slotId;
208 
209  if (slotToRestart==-1 && forkInfo_->forkParams.restart==0) {
210  //this will deal with spurious semaphore signals when slave is killed
211  forkInfo_->unlock();
212  continue;
213  }
214  //restart single slave
216  }
217  }
218  //loop exit
219  forkInfo_->unlock();
220  return 0;
221  }
222  return -1; //no forkInfo_
223  }
224 
225 
226  //______________________________________________________________________________
229  // std::cout << getpid() << " enter getNextItemType " << std::endl;
230  if (runFork_) {
231  runFork_=false;
232  int queueNext = doMyBeginRun();
233  //check if new run (requires returning IsRun once)
234  if (queueNext == 2) runFork_=true;
235  }
236 
237  //get initial time before beginRun (used with old forking)
238  if (!forkInfo_ && newRun()) {
239  beginRunTiming_=true;
240  gettimeofday(&tvStat_, NULL);
241  }
242 
243  if (immediateStop) return IsStop;
244 
245  // --------------
246  if(goToStopping){noMoreEvents_ = true; goToStopping=false;}
247  if (noMoreEvents_) {
248  pthread_mutex_lock(&mutex_);
249  pthread_cond_signal(&cond_);
250  pthread_mutex_unlock(&mutex_);
251  return IsStop;
252  }
253  if (newRun()) {
254  return IsRun;
255  }
256 
257  //calculate and print the beginRun the timing
258  if (beginRunTiming_) {
259  timeval tsTmp;
260  gettimeofday(&tsTmp,NULL);
261  long tusecs = (tsTmp.tv_sec-tvStat_.tv_sec)*1000000 + tsTmp.tv_usec - tvStat_.tv_usec;
262  double tsecs = ((double)(tusecs/10000))/100.;
263  std::cout << "DaqSource (slave pid "<< getpid() << " ): FWK beginRun elapsed time: "
264  << tsecs << " seconds "<< std::endl;
265  edm::LogInfo("DaqSource") << "DaqSource (slave pid "<< getpid() << " ): FWK beginRun elapsed time: "
266  << tsecs << " seconds ";
267  beginRunTiming_=false;
268  }
269 
270  if (newLumi() && luminosityBlockAuxiliary()) {
271  // std::cout << "newLumi & lumiblock valid " << std::endl;
272  return IsLumi;
273  }
274  if (alignLsToLast_) { //here we are recovering from a gap in Ls number so an event may already be cached but
275  // we hold onto it until we have issued all the necessary endLumi/beginLumi
276  // std::cout << getpid() << "alignLsToLast was set and ls number is "
277  // << luminosityBlockNumber_ << " before signaling" << std::endl;
280  // std::cout << getpid() << "alignLsToLast signaled and incremented "
281  // << luminosityBlockNumber_ << " eventcached "
282  // << eventCached() << std::endl;
283  setNewLumi();
284  if (lumiSectionIndex_!=0)
288  {
289  alignLsToLast_ = false;
290  }
294  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
295 
296  // std::cout << "nextItemType: dealt with new lumi block principal, retval is " << retval << std::endl;
297  }
298  return IsLumi;
299  }
300  if (eventCached()) {
301  // std::cout << "read event already cached " << std::endl;
302  return IsEvent;
303  }
304 
305  if(reader_ == 0) {
307  << "DaqSource is used without a reader. Check your configuration !";
308  }
309  TimeValue_t time = 0LL;
310  timeval stv;
311  gettimeofday(&stv,0);
312  time = stv.tv_sec;
313  time = (time << 32) + stv.tv_usec;
314  Timestamp tstamp(time);
315 
319 
320  // pass a null pointer to fillRawData()!
322 
323 
324  // let reader_ fill the fedCollection
325  int retval = reader_->fillRawData(eventID_, tstamp, fedCollection_);
326  if(retval==0) {
327  // fillRawData() failed, clean up the fedCollection in case it was allocated!
328  if (nullptr != fedCollection_) delete fedCollection_;
329  noMoreEvents_ = true;
330  pthread_mutex_lock(&mutex_);
331  pthread_cond_signal(&cond_);
332  pthread_mutex_unlock(&mutex_);
333  return IsStop;
334  }
335  else if(retval<0)
336  {
337 
338  unsigned int nextLsFromSignal = (-1)*retval+1;
339 // std::cout << getpid() << "::got end-of-lumi for " << (-1)*retval
340 // << " was " << luminosityBlockNumber_ << std::endl;
341  if(luminosityBlockNumber_ == (nextLsFromSignal-1) )
342  {
343  if (lastLumiUsingEol_ != 0)
344  lastLumiUsingEol_->value_ = nextLsFromSignal;
345  if(lsToBeRecovered_ != 0 && lsToBeRecovered_->value_){
346 // std::cout << getpid() << "eol::recover ls::for " << (-1)*retval << std::endl;
349  setNewLumi();
350  if (lumiSectionIndex_ != 0)
353  thisEventLSid = nextLsFromSignal - 1;
355  alignLsToLast_ = true;
356  // std::cout << getpid() << "eol::::alignLsToLast_ " << alignLsToLast_ << std::endl;
357  }
358  else{
359  // std::cout << getpid() << "eol::realign ls::for " << (-1)*retval << std::endl;
360  luminosityBlockNumber_ = nextLsFromSignal;
361  setNewLumi();
362  if (lumiSectionIndex_ != 0)
365  }
366  }
367  else {
368  if(nextLsFromSignal >(luminosityBlockNumber_+100) ) {
369  edm::LogError("DaqSource") << "Got EOL event with value " << retval
370  << " nextLS would be " << nextLsFromSignal
371  << " while we expected " << luminosityBlockNumber_+1 << " - disregarding... ";
372  }
373  if (nextLsFromSignal > luminosityBlockNumber_+2) //recover on delta > 2
374  {
375  if (lastLumiUsingEol_ != 0)
376  lastLumiUsingEol_->value_ = nextLsFromSignal;
377  thisEventLSid=nextLsFromSignal-1;//set new LS
380  setNewLumi();
381  if (lumiSectionIndex_ != 0)
383  alignLsToLast_ = true;
384 
385  //set new lumi block
389  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
390  }
391 
392  }
393  // else
394  // std::cout << getpid() << "::skipping end-of-lumi for " << (-1)*retval << std::endl;
395  }
396  else
397  {
398  if (eventID_.event() == 0) {
400  << "The reader used with DaqSource has returned an invalid (zero) event number!\n"
401  << "Event numbers must begin at 1, not 0.";
402  }
403  EventSourceSentry(*this);
404  setTimestamp(tstamp);
405 
406  unsigned char *gtpFedAddr = fedCollection_->FEDData(daqsource::gtpEvmId_).size()!=0 ? fedCollection_->FEDData(daqsource::gtpEvmId_).data() : 0;
407  uint32_t gtpsize = 0;
408  if(gtpFedAddr !=0) gtpsize = fedCollection_->FEDData(daqsource::gtpEvmId_).size();
409  unsigned char *gtpeFedAddr = fedCollection_->FEDData(daqsource::gtpeId_).size()!=0 ? fedCollection_->FEDData(daqsource::gtpeId_).data() : 0;
410 
411  unsigned int nextFakeLs = 0;
412  eventCounter_++;
413  if (fakeLSid_)
415  bool fakeLSFromEventCount = fakeLSid_ && (lumiSegmentSizeInEvents_ != 0);
416  bool fakeLSFromTimer = fakeLSid_ && (lumiSegmentSizeInSeconds_ != 0);
417  if(fakeLSFromEventCount && luminosityBlockNumber_ !=
418  (nextFakeLs = useEventCounter_ ? ((eventCounter_-1)/lumiSegmentSizeInEvents_ + 1) :
419  ((eventID_.event() - 1)/lumiSegmentSizeInEvents_ + 1))) {
420  if (prescaleSetIndex_ != 0 && lastLumiPrescaleIndex_!= 0) {
421  lastLumiPrescaleIndex_->value_ = prescaleSetIndex_->value_;
422  prescaleSetIndex_->value_ = 0; // since we do not know better but we want to be able to run
423  }
424  if(luminosityBlockNumber_ == nextFakeLs-1)
426  luminosityBlockNumber_ = nextFakeLs;
427  thisEventLSid = nextFakeLs-1;
428  setNewLumi();
429  if (lumiSectionIndex_ != 0)
433  gtpFedAddr!=0 && evf::evtn::evm_board_sense(gtpFedAddr,gtpsize)){
434  if (prescaleSetIndex_ != 0)
435  prescaleSetIndex_->value_ = (evf::evtn::getfdlpsc(gtpFedAddr) & 0xffff);
436  }
437  }
438  else if(fakeLSFromTimer){
439  struct timeval tv;
440  gettimeofday(&tv,0);
441  unsigned int elapsed_time = tv.tv_sec - startOfLastLumi.tv_sec;
442  // std::cout << "daqsource elapsed time " << elapsed_time << std::endl;
444  (nextFakeLs = elapsed_time/lumiSegmentSizeInSeconds_ + 1)) {
445  if(prescaleSetIndex_ != 0){
446  lastLumiPrescaleIndex_->value_ = prescaleSetIndex_->value_;
447  prescaleSetIndex_->value_ = 0; // since we do not know better but we want to be able to run
448  }
449  if(luminosityBlockNumber_ == (nextFakeLs-1))
451  luminosityBlockNumber_ = nextFakeLs;
452  thisEventLSid = nextFakeLs-1;
453  setNewLumi();
454  if(lumiSectionIndex_!=0)
458  gtpFedAddr!=0 && evf::evtn::evm_board_sense(gtpFedAddr,gtpsize)){
459  if(prescaleSetIndex_ != 0)
460  prescaleSetIndex_->value_ = (evf::evtn::getfdlpsc(gtpFedAddr) & 0xffff);
461  }
462  }
463  }
464  else if(!fakeLSid_){
465 
466  if(gtpFedAddr!=0 && evf::evtn::evm_board_sense(gtpFedAddr,gtpsize)){
467  if (lastLumiPrescaleIndex_ != 0 && prescaleSetIndex_ != 0)
468  lastLumiPrescaleIndex_->value_ = prescaleSetIndex_->value_;
469  thisEventLSid = evf::evtn::getlbn(gtpFedAddr);
470  if (prescaleSetIndex_ != 0)
471  prescaleSetIndex_->value_ = (evf::evtn::getfdlpsc(gtpFedAddr) & 0xffff);
474  {
475  //late event,throw fwk exception
476  std::ostringstream excptmsg;
477  excptmsg << "DaqSource::event with late LS (" << thisEventLSid + 1 << ")received.";
478  throw edm::Exception(errors::LogicError,excptmsg.str());
479  }
481  // we got here in a running process and some Ls might have been skipped so set the flag,
482  // increase by one, check and if appropriate set the flag then continue
483  if(lsToBeRecovered_!=0 && lsToBeRecovered_->value_){
484  // std::cout << getpid() << "eve::recover ls::for " << thisEventLSid << std::endl;
487  setNewLumi();
488  if (lumiSectionIndex_ !=0 )
492  // std::cout << getpid() << "eve::::alignLsToLast_ " << alignLsToLast_ << std::endl;
493  }
494  else{ // we got here because the process was restarted. just realign the ls id and proceed with this event
495  // std::cout << getpid() << "eve::realign ls::for " << thisEventLSid << std::endl;
497  setNewLumi();
498  if (lumiSectionIndex_ !=0)
501  if (lsToBeRecovered_ !=0)
502  lsToBeRecovered_->value_ = true;
503  }
504  }
505  }
506  else if(gtpeFedAddr!=0 && evf::evtn::gtpe_board_sense(gtpeFedAddr)){
507  if (lastLumiPrescaleIndex_ != 0 && prescaleSetIndex_ != 0)
508  lastLumiPrescaleIndex_->value_ = prescaleSetIndex_->value_;
509  thisEventLSid = evf::evtn::gtpe_getlbn(gtpeFedAddr);
510  if (prescaleSetIndex_ != 0)
511  prescaleSetIndex_->value_ = 0; //waiting to get a PS index from gtpe
517  setNewLumi();
518  if (lumiSectionIndex_ !=0 )
521  }
522  }
523  }
524  if(gtpFedAddr!=0 && evf::evtn::evm_board_sense(gtpFedAddr,gtpsize)){
525  bunchCrossing_ = int(evf::evtn::getfdlbx(gtpFedAddr));
526  orbitNumber_ = int(evf::evtn::getorbit(gtpFedAddr));
527  TimeValue_t time = evf::evtn::getgpshigh(gtpFedAddr);
528  time = (time << 32) + evf::evtn::getgpslow(gtpFedAddr);
529  Timestamp tstamp(time);
530  setTimestamp(tstamp);
531  }
532  else if(gtpeFedAddr!=0 && evf::evtn::gtpe_board_sense(gtpeFedAddr)){
533  bunchCrossing_ = int(evf::evtn::gtpe_getbx(gtpeFedAddr));
534  orbitNumber_ = int(evf::evtn::gtpe_getorbit(gtpeFedAddr));
535  }
536  }
537 
538  // std::cout << "lumiblockaux = " << luminosityBlockAuxiliary() << std::endl;
539  // If there is no luminosity block principal, make one.
541  setNewLumi();
544  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
545 
546  // std::cout << "nextItemType: dealt with new lumi block principal, retval is " << retval << std::endl;
547  }
548  // std::cout << "here retval = " << retval << std::endl;
549  if(retval<0){
550  // std::cout << getpid() << " returning from getnextitem because retval < 0 - IsLumi "
551  // << IsLumi << std::endl;
552  if(newLumi()) return IsLumi; else return getNextItemType();
553  }
554  if (newLumi()) {
555  return IsLumi;
556  }
557  setEventCached();
558  return IsEvent;
559  }
560 
561  void
563  assert(!eventCached());
564  reset();
565  setNewRun();
566  runNumber_ = r;
568  noMoreEvents_ = false;
570  }
571 
572  boost::shared_ptr<RunAuxiliary>
574  assert(newRun());
575  assert(!noMoreEvents_);
576  resetNewRun();
577  boost::shared_ptr<RunAuxiliary> ra(new RunAuxiliary(runNumber_, timestamp(), Timestamp::invalidTimestamp()));
578  ra->setProcessHistoryID(phid_);
579  return ra;
580  }
581 
582  boost::shared_ptr<LuminosityBlockAuxiliary>
584  assert(!newRun());
585  assert(newLumi());
586  assert(!noMoreEvents_);
587  assert(luminosityBlockAuxiliary());
588  resetNewLumi();
589  return luminosityBlockAuxiliary();
590  }
591 
594  // std::cout << "assert not newRun " << std::endl;
595  assert(!newRun());
596  // std::cout << "assert not newLumi " << std::endl;
597  assert(!newLumi());
598  // std::cout << "assert not noMoreEvents " << std::endl;
599  assert(!noMoreEvents_);
600  // std::cout << "assert eventCached " << std::endl;
601  assert(eventCached());
602  // std::cout << "asserts done " << std::endl;
603 
605 
606  // make a brand new event principal
608  EventAuxiliary eventAux(eventID_, processGUID(),
609  timestamp(),
610  true,
611  evttype_,
614  orbitNumber_);
615  eventAux.setProcessHistoryID(phid_);
616  eventPrincipal.fillEventPrincipal(eventAux);
617 
618  // have fedCollection managed by a std::auto_ptr<>
619  std::auto_ptr<FEDRawDataCollection> bare_product(fedCollection_);
620 
623 
624 /*
625  Event e(eventPrincipal, md_);
626  // put the fed collection into the transient event store
627  e.put(bare_product);
628  // The commit is needed to complete the "put" transaction.
629  e.commit_();
630 */
631  return &eventPrincipal;
632  }
633 
634  void
636  throw edm::Exception(errors::LogicError,"DaqSource::setLumi(LuminosityBlockNumber_t lumiNumber)")
637  << "The luminosity block number cannot be set externally for DaqSource.\n"
638  << "Contact a Framework developer.\n";
639  }
640 
643  throw edm::Exception(errors::LogicError,"DaqSource::readIt(EventID const& eventID)")
644  << "Random access read cannot be used for DaqSource.\n"
645  << "Contact a Framework developer.\n";
646  }
647 
648  void
650  throw edm::Exception(errors::LogicError,"DaqSource::skip(int offset)")
651  << "Random access skip cannot be used for DaqSource\n"
652  << "Contact a Framework developer.\n";
653  }
654 
655  void DaqSource::publish(xdata::InfoSpace *is)
656  {
657  is_ = is;
658  lumiSectionIndex_ = (xdata::UnsignedInteger32*)is_->find("lumiSectionIndex");
659  prescaleSetIndex_ = (xdata::UnsignedInteger32*)is_->find("prescaleSetIndex");
660  lastLumiPrescaleIndex_ = (xdata::UnsignedInteger32*)is_->find("lastLumiPrescaleIndex");
661  lastLumiUsingEol_ = (xdata::UnsignedInteger32*)is_->find("lastLumiUsingEol");
662  lsTimedOut_ = (xdata::Boolean*)is_->find("lsTimedOut");
663  lsToBeRecovered_ = (xdata::Boolean*)is_->find("lsToBeRecovered");
664  }
665  void DaqSource::publishToXmas(xdata::InfoSpace *is)
666  {
667  mis_ = is;
668  }
669 
670  void DaqSource::openBackDoor(unsigned int timeout_sec, bool *running)
671  {
672  count++;
673  if(count==2) throw;
674  pthread_mutex_lock(&mutex_);
675  if (running) *running=true;
676  pthread_mutex_unlock(&signal_lock_);
677  timespec ts;
678 #if _POSIX_TIMERS > 0
679  clock_gettime(CLOCK_REALTIME, &ts);
680 #else
681  struct timeval tv;
682  gettimeofday(&tv, NULL);
683  ts.tv_sec = tv.tv_sec + 0;
684  ts.tv_nsec = 0;
685 #endif
686  ts.tv_sec += timeout_sec;
687 
688  int rc = pthread_cond_timedwait(&cond_, &mutex_, &ts);
689  if(rc == ETIMEDOUT && lsTimedOut_ != 0) lsTimedOut_->value_ = true;
690  }
691 
693  {
694  count--;
695  pthread_cond_signal(&cond_);
696  pthread_mutex_unlock(&mutex_);
697  pthread_mutex_lock(&signal_lock_);
698  if (lsTimedOut_ != 0)
699  lsTimedOut_->value_ = false;
700  }
701 
703  {
704  //check if we are running offline, in which case return immediately
705  if(is_ == 0) return;
706  pthread_mutex_lock(&signal_lock_);
707  pthread_mutex_lock(&mutex_);
708  pthread_mutex_unlock(&signal_lock_);
709  // std::cout << getpid() << " DS::signal from evloop " << std::endl;
710  pthread_cond_signal(&cond_);
711  // std::cout << getpid() << " DS::go to wait for scalers wl " << std::endl;
712  pthread_cond_wait(&cond_, &mutex_);
713  pthread_mutex_unlock(&mutex_);
714  ::usleep(1000);//allow other thread to lock
715  }
716 
718  {
720  std::string urn;
721  std::string mname;
723  std::string original_referrer_;
724  try
725  {
726  cgicc::Cgicc cgi(in);
727  if ( xgi::Utils::hasFormElement(cgi,"gotostopping") )
728  {
729  goToStopping=true;
730  }
731  if ( xgi::Utils::hasFormElement(cgi,"module") )
732  mname = xgi::Utils::getFormElement(cgi, "module")->getValue();
733  cgicc::CgiEnvironment cgie(in);
734  if(original_referrer_ == "")
735  original_referrer_ = cgie.getReferrer();
736  path = cgie.getPathInfo();
737  query = cgie.getQueryString();
738  }
739  catch (const std::exception & e)
740  {
741  // don't care if it did not work
742  }
743 
744  using std::endl;
745  *out << "<html>" << endl;
746  *out << "<head>" << endl;
747 
748 
749  *out << "<STYLE type=\"text/css\"> #T1 {border-width: 2px; border: solid blue; text-align: center} </STYLE> " << endl;
750  *out << "<link type=\"text/css\" rel=\"stylesheet\"";
751  *out << " href=\"/" << urn
752  << "/styles.css\"/>" << endl;
753 
754  *out << "<title>" << moduleName_
755  << " MAIN</title>" << endl;
756 
757  *out << "</head>" << endl;
758  *out << "<body onload=\"loadXMLDoc()\">" << endl;
759  *out << "<table border=\"0\" width=\"100%\">" << endl;
760  *out << "<tr>" << endl;
761  *out << " <td align=\"left\">" << endl;
762  *out << " <img" << endl;
763  *out << " align=\"middle\"" << endl;
764  *out << " src=\"/evf/images/bugicon.jpg\"" << endl;
765  *out << " alt=\"main\"" << endl;
766  *out << " width=\"90\"" << endl;
767  *out << " height=\"64\"" << endl;
768  *out << " border=\"\"/>" << endl;
769  *out << " <b>" << endl;
770  *out << moduleName_ << endl;
771  *out << " </b>" << endl;
772  *out << " </td>" << endl;
773  *out << " <td width=\"32\">" << endl;
774  *out << " <a href=\"/urn:xdaq-application:lid=3\">" << endl;
775  *out << " <img" << endl;
776  *out << " align=\"middle\"" << endl;
777  *out << " src=\"/hyperdaq/images/HyperDAQ.jpg\"" << endl;
778  *out << " alt=\"HyperDAQ\"" << endl;
779  *out << " width=\"32\"" << endl;
780  *out << " height=\"32\"" << endl;
781  *out << " border=\"\"/>" << endl;
782  *out << " </a>" << endl;
783  *out << " </td>" << endl;
784  *out << " <td width=\"32\">" << endl;
785  *out << " </td>" << endl;
786  *out << " <td width=\"32\">" << endl;
787  *out << " <a href=\"" << original_referrer_ << "\">" << endl;
788  *out << " <img" << endl;
789  *out << " align=\"middle\"" << endl;
790  *out << " src=\"/evf/images/spoticon.jpg\"" << endl;
791  *out << " alt=\"main\"" << endl;
792  *out << " width=\"32\"" << endl;
793  *out << " height=\"32\"" << endl;
794  *out << " border=\"\"/>" << endl;
795  *out << " </a>" << endl;
796  *out << " </td>" << endl;
797  *out << "</tr>" << endl;
798  *out << "</table>" << endl;
799 
800  *out << "<hr/>" << endl;
801 
802  *out << cgicc::form().set("method","GET").set("action", path )
803  << std::endl;
804  boost::char_separator<char> sep("&");
805  boost::tokenizer<boost::char_separator<char> > tokens(query, sep);
806  for (boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = tokens.begin();
807  tok_iter != tokens.end(); ++tok_iter){
808  size_t pos = (*tok_iter).find_first_of("=");
809  if(pos != std::string::npos){
810  std::string first = (*tok_iter).substr(0 , pos);
811  std::string second = (*tok_iter).substr(pos+1, (*tok_iter).length()-pos-1);
812  *out << cgicc::input().set("type","hidden").set("name",first).set("value", second)
813  << std::endl;
814  }
815  }
816 
817  *out << cgicc::input().set("type","hidden").set("name","gotostopping").set("value","true")
818  << std::endl;
819  *out << cgicc::input().set("type","submit").set("value","Go To Stopping") << std::endl;
820  *out << cgicc::form() << std::endl;
821 
822  *out << "</body>" << endl;
823  *out << "</html>" << endl;
824  }
825 }
DaqBaseReader * reader_
Definition: DaqSource.h:69
static const char runNumber_[]
xdata::InfoSpace * mis_
Definition: DaqSource.h:95
EventNumber_t event() const
Definition: EventID.h:44
int doMyBeginRun()
Definition: DaqSource.cc:149
T getUntrackedParameter(std::string const &, T const &) const
ProcessHistoryID phid_
Definition: DaqSource.h:81
xdata::Boolean * lsTimedOut_
Definition: DaqSource.h:92
void fillEventPrincipal(EventAuxiliary const &aux, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), DelayedReader *reader=0)
unsigned int getgpshigh(const unsigned char *)
evf::moduleweb::ForkInfoObj * forkInfo_
Definition: DaqSource.h:101
#define Input(cl)
Definition: vmac.h:189
LuminosityBlockNumber_t luminosityBlockNumber_
Definition: DaqSource.h:79
ProductProvenance dummyProvenance_
unsigned int getfdlbx(const unsigned char *)
bool gtpe_board_sense(const unsigned char *p)
virtual void closeBackDoor()
Definition: DaqSource.cc:692
virtual ItemType getNextItemType()
Definition: DaqSource.cc:228
xdata::UnsignedInteger32 * lumiSectionIndex_
Definition: DaqSource.h:88
virtual boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: DaqSource.cc:583
unsigned int eventCounter_
Definition: DaqSource.h:74
bool newLumi() const
Definition: InputSource.h:344
xdata::Boolean * lsToBeRecovered_
Definition: DaqSource.h:93
virtual void publish(xdata::InfoSpace *)
Definition: DaqSource.cc:655
virtual EventPrincipal * readEvent_(EventPrincipal &eventPrincipal)
Definition: DaqSource.cc:593
timeval tvStat_
Definition: DaqSource.h:103
#define nullptr
boost::tokenizer< boost::char_separator< char > > tokenizer
DaqProvenanceHelper daqProvenanceHelper_
Definition: DaqSource.h:80
boost::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:247
virtual void publishToXmas(xdata::InfoSpace *)
Definition: DaqSource.cc:665
std::string const & category() const
Definition: Exception.cc:183
#define NULL
Definition: scimark2.h:8
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
Definition: InputSource.h:314
xdata::UnsignedInteger32 * lastLumiUsingEol_
Definition: DaqSource.h:91
void(* forkHandler)(void *)
Definition: ModuleWeb.h:44
constexpr unsigned int gtpEvmId_
Definition: DaqSource.cc:50
RunNumber_t runNumber_
Definition: DaqSource.h:78
void put(ConstBranchDescription const &bd, WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
unsigned int getfdlpsc(const unsigned char *)
pthread_cond_t cond_
Definition: DaqSource.h:87
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:199
ProcessHistoryID daqInit(ProductRegistry &productRegistry) const
FEDRawDataCollection * fedCollection_
Definition: DaqSource.h:109
U second(std::pair< T, U > const &p)
pthread_mutex_t signal_lock_
Definition: DaqSource.h:86
unsigned int stopCondition
Definition: ModuleWeb.h:46
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static int const invalidBunchXing
unsigned int getlbn(const unsigned char *)
ConstBranchDescription constBranchDescription_
bool fakeLSid_
Definition: DaqSource.h:76
xdata::UnsignedInteger32 * prescaleSetIndex_
Definition: DaqSource.h:89
void setLuminosityBlockAuxiliary(LuminosityBlockAuxiliary *lbp)
Definition: InputSource.h:322
bool newRun() const
Definition: InputSource.h:341
virtual void signalWaitingThreadAndBlock()
Definition: DaqSource.cc:702
bool keepUsingPsidFromTrigger_
Definition: DaqSource.h:75
unsigned long long TimeValue_t
Definition: Timestamp.h:27
virtual void publishForkInfo(evf::moduleweb::ForkInfoObj *forkInfoObj)
Definition: DaqSource.cc:136
bool evm_board_sense(const unsigned char *p, size_t size)
bool goToStopping
Definition: DaqSource.h:98
std::string moduleName_
Definition: ModuleWeb.h:61
void setEventCached()
Called by the framework to merge or ached() const {return eventCached_;}.
Definition: InputSource.h:349
void resetEventCached()
Definition: InputSource.h:350
DaqSource(const ParameterSet &pset, const InputSourceDescription &desc)
Definition: DaqSource.cc:55
constexpr unsigned int gtpeId_
Definition: DaqSource.cc:51
int bunchCrossing_
Definition: DaqSource.h:105
tuple out
Definition: dbtoconf.py:99
EventAuxiliary::ExperimentType evttype_
Definition: DaqSource.h:107
LuminosityBlockNumber_t luminosityBlock() const
Accessor for current luminosity block number.
Definition: InputSource.cc:611
virtual void skip(int offset)
Definition: DaqSource.cc:649
virtual void setRun(RunNumber_t r)
Definition: DaqSource.cc:562
unsigned int getorbit(const unsigned char *)
unsigned int gtpe_getorbit(const unsigned char *)
bool beginRunTiming_
Definition: DaqSource.h:104
static Timestamp const & invalidTimestamp()
Definition: Timestamp.cc:83
void defaultWebPage(xgi::Input *in, xgi::Output *out)
Definition: DaqSource.cc:717
unsigned int lumiSegmentSizeInSeconds_
Definition: DaqSource.h:71
virtual int fillRawData(edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data)=0
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:316
unsigned int lumiSegmentSizeInEvents_
Definition: DaqSource.h:70
Timestamp const & timestamp() const
Accessor for the current time, as seen by the input source.
Definition: InputSource.h:224
virtual void openBackDoor(unsigned int, bool *)
Definition: DaqSource.cc:670
unsigned int getevtyp(const unsigned char *)
virtual EventPrincipal * readIt(EventID const &eventID)
Definition: DaqSource.cc:642
bool useEventCounter_
Definition: DaqSource.h:72
void resetLuminosityBlockAuxiliary(bool isNewLumi=true) const
Definition: InputSource.h:330
static int const invalidStoreNumber
static Timestamp const & beginOfTime()
Definition: Timestamp.cc:96
EventID eventID_
Definition: DaqSource.h:108
unsigned int gtpe_getbx(const unsigned char *)
void reset() const
Definition: InputSource.h:334
#define Output(cl)
Definition: vmac.h:193
virtual ~DaqSource()
Definition: DaqSource.cc:132
pthread_mutex_t mutex_
Definition: DaqSource.h:85
virtual void setRunNumber(edm::RunNumber_t runNumber)
set the run number
Definition: DaqBaseReader.h:37
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:121
struct timeval startOfLastLumi
Definition: DaqSource.h:99
unsigned int thisEventLSid
Definition: DaqSource.h:97
unsigned int RunNumber_t
Definition: EventRange.h:32
unsigned int gtpe_getlbn(const unsigned char *)
bool noMoreEvents_
Definition: DaqSource.h:82
T first(std::pair< T, U > const &p)
virtual void setLumi(LuminosityBlockNumber_t lb)
Definition: DaqSource.cc:635
virtual boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: DaqSource.cc:573
unsigned int getgpslow(const unsigned char *)
bool immediateStop
Definition: DaqSource.h:100
xdata::InfoSpace * is_
Definition: DaqSource.h:94
T get(const Candidate &c)
Definition: component.h:56
#define CLOCK_REALTIME
Definition: TimerService.h:28
#define constexpr
xdata::UnsignedInteger32 * lastLumiPrescaleIndex_
Definition: DaqSource.h:90
bool alignLsToLast_
Definition: DaqSource.h:83
bool eventCached() const
Definition: InputSource.h:347