FACT++  1.0
DataLogger Class Reference

Logs all message and infos between the services. More...

+ Inheritance diagram for DataLogger:
+ Collaboration diagram for DataLogger:

Public Types

enum  {
  kSM_NightlyOpen = 20, kSM_WaitingRun = 30, kSM_Logging = 40, kSM_BadFolder = 0x101,
  kSM_RunWriteError = 0x103, kSM_DailyWriteError = 0x103
 The list of existing states specific to the DataLogger. More...
- Public Types inherited from StateMachineImp
enum  DefaultStates_t {
  kSM_KeepState = -42, kSM_NotAvailable = -2, kSM_NotReady = -1, kSM_Ready = 0,
  kSM_UserMode = 1, kSM_Error = 0x100, kSM_FatalError = 0xffff
- Public Types inherited from MessageImp
enum  Severity {
  kMessage = 10, kInfo = 20, kWarn = 30, kError = 40,
  kAlarm = 45, kFatal = 50, kComment = 90, kDebug = 99
 Severity of a message. More...

Public Member Functions

int Write (const Time &time, const std::string &txt, int qos=kMessage)
- Public Member Functions inherited from StateMachineDim
 StateMachineDim (std::ostream &out=std::cout, const std::string &name="DEFAULT")
int Write (const Time &time, const std::string &txt, int qos=kMessage)
 Redirect our own logging to fLog. More...
bool AddStateName (const int state, const std::string &name, const std::string &doc="")
bool MessageQueueEmpty () const
- Public Member Functions inherited from DimCommandHandler
DimCommandgetCommand ()
virtual ~DimCommandHandler ()
- Public Member Functions inherited from DimInfoHandler
DimInfogetInfo ()
virtual ~DimInfoHandler ()
- Public Member Functions inherited from DimErrorRedirecter
 DimErrorRedirecter (MessageImp &imp)
 ~DimErrorRedirecter ()
- Public Member Functions inherited from DimErrorHandler
virtual ~DimErrorHandler ()
- Public Member Functions inherited from DimExitHandler
virtual ~DimExitHandler ()
- Public Member Functions inherited from StateMachineImp
 StateMachineImp (std::ostream &out=std::cout, const std::string &name="")
 ~StateMachineImp ()
 delete all object stored in fListOfEvent and in fEventQueue More...
std::function< int(const EventImp &)> Wrap (const std::function< int(const EventImp &)> &func)
const std::string & GetName () const
EventImpSubscribe (const std::string &name)
void Unsubscribe (EventImp *evt)
int GetCurrentState () const
 return the current state of the machine More...
void SetReady ()
void SetNotReady ()
virtual int Run (bool dummy)
 Start the mainloop. More...
int Run ()
virtual void Stop (int code=0)
 Request to stop the mainloop. More...
bool IsRunning () const
 Used to check if the main loop is already running or still running. More...
void EnableBuffer (bool b=true)
 Used to enable or disable buffering of events outside of the main loop. More...
bool PostEvent (std::ostream &lout, const std::string &str)
 Post an event to the event queue. More...
bool PostEvent (const std::string &evt)
bool PostEvent (const EventImp &evt)
bool PostEvent (const EventImp &evt, const char *ptr, size_t siz)
bool HasEvent (const EventImp *cmd)
EventImpFindEvent (const std::string &evt)
bool IsQueueEmpty () const
const std::vector< std::string > GetEventNames ()
void PrintListOfEvents (std::ostream &out, const std::string &evt="")
void PrintListOfEvents (const std::string &str="")
void PrintListOfAllowedEvents (std::ostream &out)
void PrintListOfAllowedEvents ()
void PrintListOfStates (std::ostream &out) const
void PrintListOfStates () const
 Print a list of all states with descriptions. More...
int GetStateIndex (const std::string &name) const
bool HasState (int index) const
const std::string GetStateName (int state) const
const std::string GetStateName () const
const std::string GetStateDesc (int state) const
const std::string GetStateDesc () const
const std::string GetStateDescription (int state) const
const std::string GetStateDescription () const
- Public Member Functions inherited from MainImp
virtual ~MainImp ()
- Public Member Functions inherited from MessageImp
 MessageImp (std::ostream &out=std::cout)
virtual ~MessageImp ()
virtual void IndicateStateChange (const Time &, const std::string &)
void StateChanged (const Time &time, const std::string &server, const std::string &msg, int state)
int Update (const std::string &txt, int severity=kMessage)
int Update (const char *txt, int severity=kMessage)
int Update (const std::ostringstream &str, int severity=kMessage)
int Debug (const std::string &str)
int Message (const std::string &str)
int Info (const std::string &str)
int Warn (const std::string &str)
int Error (const std::string &str)
int Alarm (const std::string &str)
int Fatal (const std::string &str)
int Comment (const std::string &str)
int Debug (const char *txt)
int Message (const char *txt)
int Info (const char *txt)
int Warn (const char *txt)
int Error (const char *txt)
int Alarm (const char *txt)
int Fatal (const char *txt)
int Comment (const char *txt)
int Debug (const std::ostringstream &str)
int Message (const std::ostringstream &str)
int Info (const std::ostringstream &str)
int Warn (const std::ostringstream &str)
int Alarm (const std::ostringstream &str)
int Error (const std::ostringstream &str)
int Fatal (const std::ostringstream &str)
int Comment (const std::ostringstream &str)
std::ostream & operator() () const
std::ostream & Out () const

Public Attributes

enum DataLogger:: { ... }  localstates_t
 The list of existing states specific to the DataLogger. More...
- Public Attributes inherited from DimCommandHandler
- Public Attributes inherited from DimInfoHandler

Private Types

typedef map< const string, map< string, SubscriptionType > > SubscriptionsListType
 for obtaining the name of the existing services More...

Private Member Functions

int HandleDescriptions (DimDescriptions *desc)
 the two methods below were copied from StateMachineDimControl.cc More...
vector< DescriptionGetDescription (const string &server, const string &service)
int ConfigureFilePath (const Event &evt)
 Configuration of the nightly file path. More...
void ServicesMonitoring ()
 monitoring notification loop More...
void updateSubscriptionList ()
 update the service More...
int setSubscriptionListUpdateTimeLapse (const Event &evt)
 set the duration between two updates. a zero or negative value disables the service updates More...
void CreateFitsGrouping (map< string, vector< string > > &filesToGroup)
 creates a group fits file based on a list of files to be grouped More...
bool OpenStreamImp (ofstream &stream, const string &filename, bool mightbeopen)
bool OpenStream (shared_ptr< ofstream > stream, const string &filename)
bool CheckForOfstreamError (ofstream &out, bool isDailyStream)
 Checks if the input osftream is in error state, and if so close it. More...
bool DoesPathExist (string path)
 Checks if a given path exist. More...
bool CreateDirectory (const string &path)
 Create a given directory. More...
void AddServer (const string &server)
 Add a new server subscription. More...
void AddService (const Service &svc)
 Add a new service subscription. More...
void RemoveService (const string, const string, bool)
 Remove a given service subscription. More...
void RemoveAllServices (const string &)
 Remove all the services associated with a given server. More...

Private Attributes

ofstream fNightlyLogFile
 ofstream for the NightlyLogfile More...
MessageImp fNightlyLogImp
 Log stream to fNightlyLogFile. More...
string fFilePath
 ofstream for the Nightly report file More...
list< RunNumberTypefRunNumber
 run numbers More...
uint32_t fRunNumberTimeout
 old run numbers time-out delay (in seconds) More...
int fPreviousRunNumber
 previous run number. to check if changed while logging More...
int fQuality
 Current Service Quality. More...
double fMjD
 Modified Julian Date. More...
SubscriptionsListType fServiceSubscriptions
 All the services to which we have subscribed to, sorted by server name. More...
string fFullNightlyLogFileName
 full name of the nightly log file More...
string fFullNightlyReportFileName
 full name of the nightly report file More...
Time fPreviousOldRunNumberCheck
 variable to track when the statistic were last calculated More...
bool fDailyFileDayChangedAlready
 boolean to know whether we should close and reopen daily files or not More...
DimWriteStatistics fFilesStats
map< string, vector< Description > > fServiceDescriptionList
 map and mutex for storing services description More...
mutex fMutex
 Service for opened files. More...
NumSubAndFitsType fNumSubAndFitsData
 Service for broadcasting subscription status. More...
int fCurrentSubscriptionUpdateRate
 Number of seconds since the last update of the subscribed list. More...
Time fLastSubscriptionUpdate
 The last time in seconds of the day when the service was update. More...
set< string > fBlackList
 black/white listing More...
set< string > fWhiteList
set< string > fGrouping
 list of services to be grouped More...
bool fDebugIsOn
 configuration flags More...
bool fOpenedFilesIsOn
bool fNumSubAndFitsIsOn
bool fDestructing
 boolean to prevent DIM update while desctructing the dataLogger More...
map< string, vector< string > > fOpenedNightlyFits
 vectors to keep track of opened Fits files, for grouping purposes. More...
std::vector< int64_t > previousRunNumbers
unsigned int fRunNumberService
 pointer to the dim's subscription that should distribute the run numbers. More...
vector< string > backLogBuffer
bool shouldBackLog
bool fShouldAutoStart
bool fAutoStarted
Time fCurrentDay
Time lastFlush
DimDnsServiceList fDimList
vector< DimDescriptions * > fServerDescriptionsList
unsigned int servicesCounter

the file name

Open a text file and checks for error code

streamthe ofstream for which the file should be opened
 DataLogger (ostream &out)
 Setup the allows states, configs and transitions for the data logger. More...
 ~DataLogger ()
 Destructor. More...
int EvalOptions (Configuration &conf)
int infoCallback (const EventImp &evt, unsigned int infoIndex)
 Inherited from DimInfo. Handles all the Infos to which we subscribed, and log them. More...
void Report (const EventImp &evt, SubscriptionType &sub)
 Reporting method for the services info received. More...
int PrintState (const Event &evt)
 print the current state of the dataLogger More...
void CheckForRunNumber (const EventImp &evt, unsigned int index)
 checks whether or not the current info being treated is a run number More...
int Start ()
 start transition More...
int StopRunLogging ()
 from waiting to logging transition More...
int GoToReady ()
 stop and reset transition More...
int NightlyToWaitRun ()
 from NightlyOpen to waiting transition More...
int BackToNightlyOpen ()
 from wait for run number to nightly open More...
void NotifyOpenedFile (const string &name, int type, DimDescribedService *service)
int SetDebugOnOff (const Event &evt)
int SetStatsPeriod (const Event &evt)
int SetOpenedFilesOnOff (const Event &evt)
int SetNumSubsAndFitsOnOff (const Event &evt)
int SetRunTimeoutDelay (const Event &evt)
void AddNewRunNumber (int64_t newRun, Time time)
 Open the relevant text files related to a particular run. More...
void RemoveOldestRunNumber ()
 removes the oldest run number, and close the relevant files. More...
off_t GetFileSize (const string &)
 retrieves the size of a file More...
string CompileFileNameWithPath (const string &path, const string &service, const string &extension)
 Get the digits of year, month and day for filenames and paths. More...
string CompileFileName (const string &service, const string &extension, const Time &time=Time()) const
 Form the file names only. More...
bool ShouldSubscribe (const string &server, const string &service)
 Check whether service is in black and/or white list. More...
bool OpenTextFile (ofstream &stream, const string &name)
 Subscribe to a given server and service. More...
void GoToRunWriteErrorState ()
 Goes to Write error states. More...
void GoToNightlyWriteErrorState ()
 Go to Nightly Write Error State. More...
void TrimOldRunNumbers ()
 Check if old run numbers can be trimmed, and if so, do it. More...

Additional Inherited Members

- Protected Member Functions inherited from StateMachineDim
std::string SetCurrentState (int state, const char *txt="", const std::string &cmd="")
void Lock ()
void UnLock ()
- Protected Member Functions inherited from DimStart
 DimStart (const std::string &name, MessageImp &imp)
 ~DimStart ()
- Protected Member Functions inherited from StateMachineImp
virtual void PushEvent (Event *cmd)
 This is a flag which is set true if the main loop should stop. More...
std::shared_ptr< EventPopEvent ()
 Pop a command from the fifo. More...
bool HandleNewState (int newstate, const EventImp *evt, const char *txt)
virtual int Execute ()
 Is called continously to execute actions in the current state. More...
bool HandleEvent (const EventImp &evt)
EventImpAddEvent (const std::string &name, const std::string &states, const std::string &fmt)
EventImpAddEvent (const std::string &name, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1)
EventImpAddEvent (const std::string &name, const std::string &fmt, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1)
void SetDefaultStateNames ()
- Protected Attributes inherited from StateMachineImp
StateNames fStateNames
 Human readable names associated with the states. More...
bool fRunning
 Flag if events should be buffered outside the event loop. More...
int fExitRequested
 Machine is in main-loop. More...

Detailed Description

Logs all message and infos between the services.

This is the main logging class facility. It derives from StateMachineDim and DimInfoHandler. the first parent is here to enforce a state machine behaviour, while the second one is meant to make the dataLogger receive dim services to which it subscribed from. The possible states and transitions of the machine are:


For questions or bug report, please contact Etienne Lyard (etien.nosp@m.ne.l.nosp@m.yard@.nosp@m.unig.nosp@m.e.ch) or Thomas Bretz.

Definition at line 177 of file datalogger.cc.

The documentation for this class was generated from the following file: