FACT++  1.0
void DataLogger::AddService ( const Service svc)
private

Add a new service subscription.

Add a new service subscription

Parameters
serverthe server for which the subscription should be created
servicethe service for which the subscription should be created
isCmdwhether this is a Dim Command or not. Commands are not logged

Definition at line 566 of file datalogger.cc.

References Debug, Error(), Service::format, infoCallback(), Service::iscmd, NumSubAndFitsType::numSubscriptions, Service::server, and Service::service.

Referenced by DataLogger().

567 {
568  const string& serverr = svc.server;
569  //FIX in order to get rid of the '+' that sometimes makes it all the way to me
570  string server = serverr;
571  if (server.size() > 0 && server[0] == '+')
572  {
573  server = server.substr(1);
574  Warn("Got a service beginning with +. This is not supposed to happen");
575  }
576 // server = server.substr(1);
577 
578  const string& service = svc.service;
579  const bool isCmd = svc.iscmd;
580 
581  //dataLogger does not subscribe to commands
582  if (isCmd)
583  return;
584 
585  Info("Got request to add service: "+server+"/"+service);
586 
587  //check the given subscription against black and white lists
588  if (!ShouldSubscribe(server, service))
589  return;
590 
591  map<string, SubscriptionType> &list = fServiceSubscriptions[server];
592 
593  if (list.find(service) != list.end())
594  {
595  if (list[service].format != svc.format)
596  {
597  if (list[service].nightlyFile.IsOpen())
598  {
599  string fileName = list[service].nightlyFile.GetName();
600  if (fileName == "")
601  {
602  Error("Something went wrong while dealing with new format of "+server+"/"+service+" file tagged as open but filename is empty. Aborting");
603  return;
604  }
605  list[service].nightlyFile.Close();
606  list[service].increment++;
607  Warn("Format of "+server+"/"+service+" has changed. Closing "+fileName);
608 /* string fileNameWithoutFits = fileName.substr(0, fileName.size()-4);
609  int counter=0;
610  while (counter < 100)
611  {
612  ostringstream newFileName;
613  newFileName << fileNameWithoutFits << counter << ".fits";
614  ifstream testStream(newFileName.str());
615  if (!testStream) //fileName available
616  {
617  rename(fileName.c_str(), newFileName.str().c_str());
618  break;
619  }
620  counter++;
621  }
622  if (counter==100)
623  Error("Could not rename "+fileName+" after 100 trials (because of format change). Aborting");
624 */
625  //reallocate the fits buffer...
626  list[service].fitsBufferAllocated = false;
627  }
628  list[service].fConv = shared_ptr<Converter>(new Converter(Out(), svc.format));
629  list[service].format = svc.format;
630  }
631  if (fDebugIsOn)
632  Debug("Service " + server + "/" + service + " is already in the dataLogger's list... ignoring update.");
633  return;
634  }
635  //DIM_REPLACE
636 // list[service].dimInfo.reset(SubscribeTo(server, service));
637  if (fDebugIsOn)
638  Debug("Subscribing to service "+server+"/"+service);
639  Subscribe(server + "/" + service)
640  (bind(&DataLogger::infoCallback, this, placeholders::_1, servicesCounter));
641  list[service].server = server;
642  list[service].service = service;
643  list[service].format = svc.format;
644  list[service].index = servicesCounter;
646  //check if this is the run numbers service
647  if ((server == "FAD_CONTROL") && (service == "START_RUN"))
649  servicesCounter++;
650  Info("Added subscription to " + server + "/" + service);
651 }
bool iscmd
Definition: Service.h:10
uint32_t numSubscriptions
Definition: datalogger.cc:96
std::string format
Definition: Service.h:9
std::string server
Definition: Service.h:7
int Debug(const std::string &str)
Definition: MessageImp.h:45
bool ShouldSubscribe(const string &server, const string &service)
Check whether service is in black and/or white list.
Definition: datalogger.cc:808
std::string service
Definition: Service.h:8
bool fDebugIsOn
configuration flags
Definition: datalogger.cc:315
std::ostream & Out() const
Definition: MessageImp.h:73
unsigned int fRunNumberService
pointer to the dim&#39;s subscription that should distribute the run numbers.
Definition: datalogger.cc:387
int Error(const std::string &str)
Definition: MessageImp.h:49
int Warn(const std::string &str)
Definition: MessageImp.h:48
int infoCallback(const EventImp &evt, unsigned int infoIndex)
Inherited from DimInfo. Handles all the Infos to which we subscribed, and log them.
Definition: datalogger.cc:1125
SubscriptionsListType fServiceSubscriptions
All the services to which we have subscribed to, sorted by server name.
Definition: datalogger.cc:224
EventImp & Subscribe(const std::string &name)
NumSubAndFitsType fNumSubAndFitsData
Definition: datalogger.cc:294
int Info(const std::string &str)
Definition: MessageImp.h:47
A compiler for the DIM data format string.
Definition: Converter.h:16
unsigned int servicesCounter
Definition: datalogger.cc:404

+ Here is the call graph for this function:

+ Here is the caller graph for this function: