FACT++  1.0
DataLogger::DataLogger ( ostream &  out)

Setup the allows states, configs and transitions for the data logger.

Default constructor. The name of the machine is given DATA_LOGGER and the state is set to kSM_Ready at the end of the function.

Definition at line 910 of file datalogger.cc.

References StateMachineImp::AddEvent(), AddServer(), AddService(), StateMachineDim::AddStateName(), BackToNightlyOpen(), OpenFileToDim::code, MessageImp::Debug(), fAutoStarted, fCurrentDay, fDimList, OpenFileToDim::fileName, fRunNumberService, fShouldAutoStart, StateMachineImp::GetName(), Time::GetNextSunRise(), GoToReady(), kSM_BadFolder, kSM_DailyWriteError, StateMachineImp::kSM_Error, kSM_Logging, kSM_NightlyOpen, StateMachineImp::kSM_Ready, kSM_RunWriteError, kSM_WaitingRun, lastFlush, Time::Mjd(), NightlyToWaitRun(), NotifyOpenedFile(), NumSubAndFitsType::numOpenFits, NumSubAndFitsType::numSubscriptions, PrintState(), servicesCounter, DimDnsServerList::SetCallbackServerAdd(), DimDnsServiceList::SetCallbackServiceAdd(), SetDebugOnOff(), SetNumSubsAndFitsOnOff(), SetOpenedFilesOnOff(), SetRunTimeoutDelay(), SetStatsPeriod(), setSubscriptionListUpdateTimeLapse(), shouldBackLog, Start(), and DimDnsServiceList::Subscribe().

910  : StateMachineDim(out, "DATA_LOGGER"),
911 fNightlyLogImp(fNightlyLogFile), fFilesStats("DATA_LOGGER", *this)
912 {
913  shouldBackLog = true;
914 
915  servicesCounter=1;
916 
917  //initialize member data
918  fFilePath = ".";
919 
920  fDimList.Subscribe(*this);
921  fDimList.SetCallbackServerAdd(bind(&DataLogger::AddServer, this, placeholders::_1));
922  fDimList.SetCallbackServiceAdd(bind(&DataLogger::AddService, this, placeholders::_1));
923 
924  //calculate time "centered" around noon instead of midnight
925  const Time timeNow;
926 // const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
927  //the "current day" is actually the next closing time of nightly files
928  //the next closing time is 30 minutes after upcoming sunrise.
929  //If we are within 30 minutes after sunrise, closing time is soon
930  fCurrentDay = Time().GetNextSunRise();//GetSunRise(Time()-boost::posix_time::minutes(30)) + boost::posix_time::minutes(30);//(int)(nowMinusTwelve.Mjd());//nowMinusTwelve.M()*31 + nowMinusTwelve.D();//assume 31 days per month. we do not really care, only want unique number per day of the year
931  lastFlush = Time();
932 
933  //Give a name to this machine's specific states
934  AddStateName(kSM_NightlyOpen, "NightlyFileOpen", "The summary files for the night are open.");
935  AddStateName(kSM_WaitingRun, "WaitForRun", "The summary files for the night are open and we wait for a run to be started.");
936  AddStateName(kSM_Logging, "Logging", "The summary files for the night and the files for a single run are open.");
937  AddStateName(kSM_BadFolder, "ErrInvalidFolder", "The folder for the files is not invalid.");
938  AddStateName(kSM_DailyWriteError, "ErrDailyWrite", "An error occured while writing to a daily (and run) file.");
939  AddStateName(kSM_RunWriteError, "ErrRunWrite", "An error occured while writing to a run file.");
940 
941  // Add the possible transitions for this machine
942  AddEvent("START", kSM_Ready, kSM_BadFolder)
943  (bind(&DataLogger::Start, this))
944  ("Start the nightly logging. Nightly file location must be specified already");
945 
947  (bind(&DataLogger::GoToReady, this))
948  ("Stop all data logging, close all files.");
949 
951  (bind(&DataLogger::GoToReady, this))
952  ("Transition to exit error states. Closes the any open file.");
953 
954  AddEvent("START_RUN_LOGGING", /*kSM_Logging,*/ kSM_NightlyOpen, kSM_Ready)
955  (bind(&DataLogger::NightlyToWaitRun, this))
956  ("Go to waiting for run number state. In this state with any received run-number a new file is opened.");
957 
958  AddEvent("STOP_RUN_LOGGING", kSM_WaitingRun, kSM_Logging)
959  (bind(&DataLogger::BackToNightlyOpen, this))
960  ("Go from the wait for run to nightly open state.");
961 
962  // Provide a print command
963  AddEvent("PRINT_INFO")
964  (bind(&DataLogger::PrintState, this, placeholders::_1))
965  ("Print information about the internal status of the data logger.");
966 
967 
968  OpenFileToDim fToDim;
969  fToDim.code = 0;
970  fToDim.fileName[0] = '\0';
971 
972  fOpenedNightlyFiles = new DimDescribedService(GetName() + "/FILENAME_NIGHTLY", "I:1;C", fToDim,
973  "Path and base name used for the nightly files."
974  "|Type[int]:type of open files (1=log, 2=rep, 4=fits)"
975  "|Name[string]:path and base file name");
976 
977  fOpenedRunFiles = new DimDescribedService(GetName() + "/FILENAME_RUN", "I:1;C", fToDim,
978  "Path and base name used for the run files."
979  "|Type[int]:type of open files (1=log, 2=rep, 4=fits)"
980  "|Name[string]:path and base file name");
981 
984  fNumSubAndFits = new DimDescribedService(GetName() + "/NUM_SUBS", "I:2", fNumSubAndFitsData,
985  "Num. open files + num. subscribed services"
986  "|NSubAndOpenFiles[int]:Num. of subs and open files");
987 
988  //services parameters
989  fDebugIsOn = false;
990  fOpenedFilesIsOn = true;
991  fNumSubAndFitsIsOn = true;
992 
993  string emptyString="";
994  //Subscription list service
995  fCurrentSubscription = new DimDescribedService(GetName() + "/SUBSCRIPTIONS", "C", emptyString.c_str(),
996  "List of all the services subscribed by datalogger, except the ones provided by itself."
997  "|Liste[string]:list of logged services and the delay in seconds since last update");
998  fCurrentSubscriptionUpdateRate = 60; //by default, 1 minute between each update
999  fLastSubscriptionUpdate = timeNow;
1000 
1001  // provide services control commands
1002  AddEvent("SET_DEBUG_MODE", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
1003  (bind(&DataLogger::SetDebugOnOff, this, placeholders::_1))
1004  ("Switch debug mode on or off. Debug mode prints information about every service written to a file."
1005  "|Enable[bool]:Enable of disable debug mode (yes/no).");
1006 
1007  AddEvent("SET_STATISTICS_UPDATE_INTERVAL", "S:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
1008  (bind(&DataLogger::SetStatsPeriod, this, placeholders::_1))
1009  ("Interval in which the data-logger statistics service (STATS) is updated."
1010  "|Interval[ms]:Value in milliseconds (<=0: no update).");
1011 
1012  AddEvent("ENABLE_FILENAME_SERVICES", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
1013  (bind(&DataLogger::SetOpenedFilesOnOff ,this, placeholders::_1))
1014  ("Switch service which distributes information about the open files on or off."
1015  "|Enable[bool]:Enable of disable filename services (yes/no).");
1016 
1017  AddEvent("ENABLE_NUMSUBS_SERVICE", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
1018  (bind(&DataLogger::SetNumSubsAndFitsOnOff, this, placeholders::_1))
1019  ("Switch the service which distributes information about the number of subscriptions and open files on or off."
1020  "|Enable[bool]:Enable of disable NUM_SUBS service (yes/no).");
1021 
1022  AddEvent("SET_RUN_TIMEOUT", "L:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun)
1023  (bind(&DataLogger::SetRunTimeoutDelay, this, placeholders::_1))
1024  ("Set the timeout delay for old run numbers."
1025  "|timeout[min]:Time out in minutes after which files for expired runs are closed.");
1026  //Provide access to the duration between two updates of the service list
1027  AddEvent("SET_SERVICE_LIST_UPDATE_INTERVAL", "I:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun)
1028  (bind(&DataLogger::setSubscriptionListUpdateTimeLapse, this, placeholders::_1))
1029  ("Set the min interval between two services-list updates."
1030  "|duration[sec]:The interval between two updates, in seconds.");
1031 
1032  fDestructing = false;
1033 
1035 
1037  fRunNumberTimeout = 60000; //default run-timeout set to 1 minute
1038  fRunNumber.push_back(RunNumberType());
1039  fRunNumber.back().runNumber = -1;
1040  fRunNumber.back().time = Time();
1043 
1044  fRunNumberService = 0;
1045 
1046  fShouldAutoStart = false;
1047  fAutoStarted = false;
1048 
1049 
1050  if(fDebugIsOn)
1051  {
1052  Debug("DataLogger Init Done.");
1053  }
1054 }
int PrintState(const Event &evt)
print the current state of the dataLogger
Definition: datalogger.cc:1564
DimWriteStatistics fFilesStats
Definition: datalogger.cc:235
uint32_t numSubscriptions
Definition: datalogger.cc:96
the folder specified for Nightly logging does not exist or has bad permissions
Definition: datalogger.cc:188
EventImp & AddEvent(const std::string &name, const std::string &states, const std::string &fmt)
int fCurrentSubscriptionUpdateRate
Number of seconds since the last update of the subscribed list.
Definition: datalogger.cc:299
Mainloop running, state machine in operation.
int setSubscriptionListUpdateTimeLapse(const Event &evt)
set the duration between two updates. a zero or negative value disables the service updates ...
Definition: datalogger.cc:467
int SetOpenedFilesOnOff(const Event &evt)
Definition: datalogger.cc:1707
uint32_t numOpenFits
Definition: datalogger.cc:97
void NotifyOpenedFile(const string &name, int type, DimDescribedService *service)
Definition: datalogger.cc:1781
int Debug(const std::string &str)
Definition: MessageImp.h:45
bool fDestructing
boolean to prevent DIM update while desctructing the dataLogger
Definition: datalogger.cc:326
both files openned and writing
Definition: datalogger.cc:187
const std::string & GetName() const
ofstream fNightlyLogFile
ofstream for the NightlyLogfile
Definition: datalogger.cc:203
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
Time GetNextSunRise(double horizon) const
Definition: Time.cc:346
bool fDebugIsOn
configuration flags
Definition: datalogger.cc:315
StateMachineDim(std::ostream &out=std::cout, const std::string &name="DEFAULT")
bool shouldBackLog
Definition: datalogger.cc:392
Time fPreviousOldRunNumberCheck
variable to track when the statistic were last calculated
Definition: datalogger.cc:231
DimDnsServiceList fDimList
Definition: datalogger.cc:400
Denots that an error occured while writing a daily file (text or fits).
Definition: datalogger.cc:190
string fFilePath
ofstream for the Nightly report file
Definition: datalogger.cc:209
char fileName[FILENAME_MAX]
Definition: datalogger.cc:102
bool fAutoStarted
Definition: datalogger.cc:394
bool fNumSubAndFitsIsOn
Definition: datalogger.cc:317
void AddService(const Service &svc)
Add a new service subscription.
Definition: datalogger.cc:566
DimDescribedService * fOpenedNightlyFiles
Service for opened files.
Definition: datalogger.cc:291
distributes which files were opened.
Definition: datalogger.cc:100
int SetRunTimeoutDelay(const Event &evt)
Definition: datalogger.cc:1754
unsigned int fRunNumberService
pointer to the dim&#39;s subscription that should distribute the run numbers.
Definition: datalogger.cc:387
int SetDebugOnOff(const Event &evt)
Definition: datalogger.cc:1669
int GoToReady()
stop and reset transition
Definition: datalogger.cc:2151
Time fCurrentDay
Definition: datalogger.cc:397
uint32_t fRunNumberTimeout
old run numbers time-out delay (in seconds)
Definition: datalogger.cc:213
DimDescribedService * fCurrentSubscription
Service for broadcasting subscription status.
Definition: datalogger.cc:297
void Mjd(double mjd)
Definition: Time.cc:145
int SetNumSubsAndFitsOnOff(const Event &evt)
Definition: datalogger.cc:1731
void SetCallbackServiceAdd(const callback_svc &cb)
Definition: DimState.h:448
bool fShouldAutoStart
Definition: datalogger.cc:393
DimDescribedService * fNumSubAndFits
Definition: datalogger.cc:293
int BackToNightlyOpen()
from wait for run number to nightly open
Definition: datalogger.cc:2218
bool fOpenedFilesIsOn
Definition: datalogger.cc:316
Denotes that an error occured while writing a run file (text or fits).
Definition: datalogger.cc:189
DimDescribedService * fOpenedRunFiles
Definition: datalogger.cc:292
NumSubAndFitsType fNumSubAndFitsData
Definition: datalogger.cc:294
Error states should be between 0x100 and 0xffff.
list< RunNumberType > fRunNumber
run numbers
Definition: datalogger.cc:211
Nightly file openned and writing.
Definition: datalogger.cc:185
void AddServer(const string &server)
Add a new server subscription.
Definition: datalogger.cc:535
uint32_t code
Definition: datalogger.cc:101
MessageImp fNightlyLogImp
Log stream to fNightlyLogFile.
Definition: datalogger.cc:205
int NightlyToWaitRun()
from NightlyOpen to waiting transition
Definition: datalogger.cc:2196
void SetCallbackServerAdd(const callback_srv &cb)
Definition: DimState.h:368
bool AddStateName(const int state, const std::string &name, const std::string &doc="")
int Start()
start transition
Definition: datalogger.cc:1818
unsigned int servicesCounter
Definition: datalogger.cc:404
int SetStatsPeriod(const Event &evt)
Definition: datalogger.cc:1694
Time lastFlush
Definition: datalogger.cc:398
bool fDailyFileDayChangedAlready
boolean to know whether we should close and reopen daily files or not
Definition: datalogger.cc:233
Run number record. Used to keep track of which run numbers are still active.
Definition: datalogger.cc:106
void Subscribe(StateMachineImp &imp)
Definition: DimState.h:442
waiting for the run number to open the run file
Definition: datalogger.cc:186
Time fLastSubscriptionUpdate
The last time in seconds of the day when the service was update.
Definition: datalogger.cc:301

+ Here is the call graph for this function: