Diana Software
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
QFileWriter Class Referenceabstract

Base class for diana file writers. More...

Inheritance diagram for QFileWriter:
QWriter QBaseModule QModuleTimeProfiling

Public Member Functions

 QFileWriter (const std::string &extension)
 constructor More...
 
virtual ~QFileWriter ()
 destructor More...
 
virtual void Require (const QEventInspector &evi)
 optional method to set required QObjects, called before Open More...
 
virtual void Open (const std::string &filename, const QEventInspector &evi)=0
 Open File. More...
 
virtual void Dump (const QEventInspector &evi)=0
 Dump ev to file. More...
 
virtual void Close ()=0
 Close file. More...
 
- Public Member Functions inherited from QWriter
 QWriter ()
 constructor More...
 
virtual ~QWriter ()
 destructor More...
 
- Public Member Functions inherited from QBaseModule
 QBaseModule (Type type)
 constructor More...
 
virtual ~QBaseModule ()
 constructor More...
 
double GetDouble (const std::string &parname, double defVal, bool warnCfg=true) const
 Get a double parameter from config file. More...
 
std::vector< double > GetVectorDouble (const std::string &parname, std::vector< double > defVal, bool warnCfg=true) const
 Get a std::vector<double> parameter from config file with syntax "{x,y,z}". More...
 
int GetInt (const std::string &parname, int defVal, bool warnCfg=true) const
 Get an int parameter from config file ( see GetDouble() ) More...
 
std::vector< int > GetVectorInt (const std::string &parname, std::vector< int > defVal, bool warnCfg=true) const
 Get an vector<int> parameter from config file ( see GetVectorDouble() ) More...
 
bool GetBool (const std::string &parname, bool defVal, bool warnCfg=true) const
 Get a bool parameter from config file ( see GetDouble() ) More...
 
std::vector< bool > GetVectorBool (const std::string &parname, std::vector< bool > defVal, bool warnCfg=true) const
 Get a vector<bool> parameter from config file ( see GetVectorDouble() ) More...
 
const std::string & GetString (const std::string &parname, const std::string &defVal, bool warnCfg=true) const
 Get a string parameter from config file ( see GetDouble() ) More...
 
std::vector< std::string > GetVectorString (const std::string &parname, std::vector< std::string > defVal, bool warnCfg=true) const
 Get a vector<string> parameter from config file ( see GetVectorDouble() ) More...
 
void Debug (const char *descr,...) const
 Send a debug message (used to debug the module) with printf syntax. More...
 
void Info (const char *descr,...) const
 Send an info message (information) with printf syntax. More...
 
void Warn (const char *descr,...) const
 Send a warning message (an error that the framework can recover) with printf syntax. More...
 
void Error (const char *descr,...) const
 Send an error message (an error that the framework cannot recover) with printf syntax. More...
 
void Panic (const char *descr,...) const
 Send a panic message (stops the framework) with printf syntax. More...
 
const QGlobalDataManagerGlobalData () const
 interface for saving and loading global QObjects More...
 
bool GetRunAgain () const
 Check if the sequence will be reiterated. More...
 
void SetRunAgain (bool b)
 Set that the sequence will be reiterated. More...
 
unsigned int GetIteration () const
 Get Current sequence iteration. More...
 
unsigned int GetOccurrence () const
 get the number of times the same module is loaded inside a QSequence More...
 
bool isEnabled () const
 check if module is enabled More...
 
std::string GetFullPath () const
 Get Full Path of module "GetName() + "." + GetOccurrence". More...
 
const std::string & GetName () const
 Get Module name. More...
 
const std::string & GetLabel () const
 Get Module name + the optional ExtraLabel ("name_extralabel") More...
 
MsgLevel GetVerbosity ()
 get verbosity level set from config file More...
 
const QSequenceGetSequence () const
 get reference to this sequence More...
 
void Update (QSequence *s, unsigned int occurrence)
 set the occurrence in the same sequence. MV FIXME: should not be public More...
 
bool NeedNeighbours ()
 check wheter this module needs neighbours (available after the first event is processed) More...
 
void BeginBase (QEventAssembler &ev)
 Begin Base method is called before event loop. More...
 
bool ProcessBase (QEventAssembler &ev, QEventList &evl, const bool exec, QEventList &ovl)
 ProcessBase method is called for each event, getting the event and as argument. More...
 
void EndBase ()
 EndBase method is called after event loop. More...
 
const std::vector< QEventLabel > & GetRequiredLabels () const
 Get labels of objects required by this module. More...
 

Static Public Member Functions

static const std::list< std::string > & GetFileList ()
 list of output files More...
 

Protected Member Functions

virtual void Init (QEventInspector &evi)
 Init method called by the framework. More...
 
virtual void Done ()
 Done method called by the framework. More...
 
void WriteFilesList ()
 write list of files More...
 
void RemoveFilesList ()
 remove list of files More...
 
virtual void Do (QEventInspector &evi)
 Do method called by the framework. More...
 
virtual bool IsToOpen (const Diana::QEvent &ev) const
 Test to see if a new file needs to be opened. More...
 
virtual const std::string & GetCorrespondingReaderFileName (const Diana::QEvent &ev) const
 Get the file from which this event was read. More...
 
virtual void BuildFileName (const QEvent &evi)
 
virtual int IncrementPartial (const std::string &fileId)
 
- Protected Member Functions inherited from QBaseModule
QModuleConfigGetConfig ()
 Get module config. More...
 
void SetNeedNeighbours (bool need)
 set wheter this module needs neighbours More...
 
- Protected Member Functions inherited from QModuleTimeProfiling
 QModuleTimeProfiling ()
 ctor initialized internal variables More...
 
virtual ~QModuleTimeProfiling ()
 dtor does nothing More...
 
void SetTimeProfilingOn (bool val)
 Set the time profiling on/off. More...
 
bool GetTimeProfilingOn () const
 Check if the time profiling is on. More...
 
void ResetTimer ()
 Reset the timer to now. More...
 
double GetTimer () const
 return the time since the last reset More...
 
virtual void StartProcessCall ()
 Start of a process call. More...
 
virtual void EndProcessCall ()
 End a process call and increment time and calls. More...
 
unsigned long long GetProcessCalls () const
 Return the total number of process calls. More...
 
double GetTotalProcessTime () const
 Return the total processing time. More...
 
double GetProcessCallTime () const
 Return the average time of a single process call. More...
 
std::string GetTimeProfileReport (const std::string &prefix="") const
 Report the time profiling. More...
 

Protected Attributes

int fEventNumber
 current event number More...
 
std::string fFileExtension
 file extension More...
 
std::list< std::string > fFilesList
 List of the full paths of files opened. More...
 
std::list< std::string > fOldFilesList
 List of files opened on the previous iteration. More...
 
std::string fFileNamePrefix
 filename components More...
 
std::string fFileId
 End of the file name to be tacked on to the prefix. More...
 
std::string fFileName
 fFileName = fFileNamePrefix + fFileId More...
 
std::string fOutputDir
 Directory that we are writing to. More...
 
std::string fFileFullPath
 fFileFullPath = fOutputDir + "/" + fFileName + fFileExtension
More...
 
std::string fFilesListName
 
bool fUseEventCachedFileName
 Flag to determine whether to use the file in the event cache. More...
 
bool fSetListForReader
 
std::string fOldFilesListName
 Name of the file list written in the previous iteration. More...
 
std::string fCurrFilesListName
 Name of the file list for this iteration. More...
 
std::string fFileIdentifier
 The file identifier (follows the prefix) More...
 
bool fWriteFilesList
 Flag whether we are writing a files list. More...
 
bool fSaveTempFiles
 Flag to say whether we save the temporary files created. More...
 
int fPartialSize
 Partial size. When reached, automatically create a new file. More...
 
bool fSyncWithReader
 Flag to synchronize the output files with the input. More...
 
bool fSyncWithRun
 Flag to start a new file for each new run. More...
 
bool fDoGetTower
 Flag to get the tower from the current event. More...
 
int fPartial
 Partial number that we are currently working on. More...
 
int fCurrentRun
 Current run being worked on. More...
 
bool fNewPartialOnRerun
 Does rerunning the sequence create new files, or a new partial. More...
 
bool fOneFileOpenOnly
 Can the writer open more than one file at a time? More...
 
bool fWarnRunData
 If the run data is not valid, pass a warning. More...
 
bool fKeepFrameWorkConfig
 Write the Sequence config data to the file. More...
 
std::map< std::string, int > fPartialsByFileId
 Current partial file for a given file ID. More...
 
- Protected Attributes inherited from QWriter
QRWCommonfRWCommon
 object to share file names with QReader More...
 
- Protected Attributes inherited from QBaseModule
bool fExecuted
 
- Protected Attributes inherited from QModuleTimeProfiling
bool fTimeProfilingOn
 Report the time profiling. More...
 
unsigned long long int fProcessCalls
 NUmber of calls to the process. More...
 
double fProcessTime
 Total time spent running the process. More...
 

Static Protected Attributes

static std::list< std::string > fFullPathFilesList
 List of the full paths of files opened by all writers. More...
 

Additional Inherited Members

- Public Types inherited from QBaseModule
enum  Type {
  Module , Filter , Reader , Writer ,
  Driver
}
 

Detailed Description

Base class for diana file writers.

Author
Marco Vignati

This class implements generic interfaces to handle output files. Inheriting classes must implement Open(), Dump() and Close() methods. The filename, filelists etc... are completely handled by methods of this class. Optionally, the Require() method can be implemented to set required QObjects into the QEvent. Config file Parameters defined by this class are:

Definition at line 66 of file QFileWriter.hh.

Constructor & Destructor Documentation

◆ QFileWriter()

QFileWriter::QFileWriter ( const std::string &  extension)

constructor

Definition at line 25 of file QFileWriter.cc.

References fDoGetTower, fFileExtension, fOneFileOpenOnly, and fWarnRunData.

◆ ~QFileWriter()

QFileWriter::~QFileWriter ( )
virtual

destructor

Definition at line 32 of file QFileWriter.cc.

Member Function Documentation

◆ BuildFileName()

void QFileWriter::BuildFileName ( const QEvent evi)
protectedvirtual

◆ Close()

virtual void QFileWriter::Close ( )
pure virtual

Close file.

Needs to be overloaded in inheriting class.

Referenced by Do(), and Done().

◆ Do()

void QFileWriter::Do ( QEventInspector evi)
protectedvirtual

Do method called by the framework.

Checks to see if a new file needs to be opened by calling IsToOpen(). If that returns true, this method creates a name for the new file using a pre-prescribed (i.e. hard coded) method. For a new file, write the Framework config.

Run Dump() and increment the event counter.

Implements QWriter.

Definition at line 101 of file QFileWriter.cc.

References BuildFileName(), Close(), QBaseModule::Debug(), dm, Dump(), fCurrentRun, fEventNumber, fFileFullPath, fFileName, fFilesList, QRWCommon::fFrameWorkConfigOld, fFullPathFilesList, fKeepFrameWorkConfig, QRunData::fNumber, fOneFileOpenOnly, fOutputDir, fPartial, fPartialsByFileId, QWriter::fRWCommon, fSyncWithRun, fWarnRunData, fWriteFilesList, ReadHandle< T >::Get(), GlobalHandle< Q >::Get(), QEvent::Get(), QGlobalDataManager::Get(), QEventInspector::GetEvent(), QBaseModule::GlobalData(), QBaseModule::Info(), IsToOpen(), QHandle< T >::IsValid(), GlobalHandle< Q >::IsValid(), Open(), rHandle, QBaseModule::Warn(), and WriteFilesList().

◆ Done()

void QFileWriter::Done ( )
protectedvirtual

Done method called by the framework.

Calls Close().

If we need to rewrite the files in another iteration, tack an extension on to the files, so that we dont overwrite them. If fNewPartialOnRerun, skip this.

Write a file list if we asked for one or if we are rerunning. Delete this file, if we didn't ask for it and we are not (or are finished) rerunning.

Implements QWriter.

Definition at line 170 of file QFileWriter.cc.

References Close(), QBaseModule::Debug(), fCurrFilesListName, fEventNumber, fFileNamePrefix, fFilesList, fFullPathFilesList, fNewPartialOnRerun, fOldFilesList, fOldFilesListName, fOutputDir, QWriter::fRWCommon, fSaveTempFiles, fSetListForReader, QRWCommon::fTempOutputFileList, fWriteFilesList, QBaseModule::GetIteration(), QBaseModule::GetRunAgain(), and WriteFilesList().

Referenced by QRootFileWriterBase::Done().

◆ Dump()

virtual void QFileWriter::Dump ( const QEventInspector evi)
pure virtual

Dump ev to file.

Needs to be overloaded in inheriting class.

Referenced by Do().

◆ GetCorrespondingReaderFileName()

const std::string & QFileWriter::GetCorrespondingReaderFileName ( const Diana::QEvent &  ev) const
protectedvirtual

Get the file from which this event was read.

Some readers can store the originating file with the QEvent. If fUseEventCachedFileName is true, this method returns that. Otherwise, it will fall back to fRWCommon->fReaderCurrentFileName.

Definition at line 260 of file QFileWriter.cc.

References QRWCommon::fReaderCurrentFileName, QRWCommon::fReaderModuleName, QWriter::fRWCommon, fUseEventCachedFileName, and QEvent::Get().

◆ GetFileList()

static const std::list<std::string>& QFileWriter::GetFileList ( )
inlinestatic

list of output files

Definition at line 99 of file QFileWriter.hh.

References fFullPathFilesList.

Referenced by LGuiSessionWriter::SetQObject().

◆ IncrementPartial()

int QFileWriter::IncrementPartial ( const std::string &  fileId)
protectedvirtual

Definition at line 352 of file QFileWriter.cc.

References fPartialsByFileId.

Referenced by BuildFileName().

◆ Init()

void QFileWriter::Init ( QEventInspector evi)
protectedvirtual

◆ IsToOpen()

bool QFileWriter::IsToOpen ( const Diana::QEvent &  ev) const
protectedvirtual

Test to see if a new file needs to be opened.

Reasons to open a new file:

  • If we are syncing with the reader, and the reader moved to a new file
  • If we are not syncing with the reader, but we hit the maximum partial size.
  • If we are syncing by run, and the run has changed.

Definition at line 232 of file QFileWriter.cc.

References fCurrentRun, fEventNumber, fFilesList, fPartialSize, QRWCommon::fReaderFileNumber, QWriter::fRWCommon, fSyncWithReader, fSyncWithRun, ReadHandle< T >::Get(), QEvent::Get(), QHandle< T >::IsValid(), and QBaseModule::Warn().

Referenced by Do().

◆ Open()

virtual void QFileWriter::Open ( const std::string &  filename,
const QEventInspector evi 
)
pure virtual

Open File.

Needs to be overloaded in inheriting class.

Referenced by Do().

◆ RemoveFilesList()

void QFileWriter::RemoveFilesList ( )
protected

remove list of files

Definition at line 228 of file QFileWriter.cc.

References fCurrFilesListName, and fWriteFilesList.

◆ Require()

virtual void QFileWriter::Require ( const QEventInspector evi)
inlinevirtual

optional method to set required QObjects, called before Open

Definition at line 75 of file QFileWriter.hh.

Referenced by Init().

◆ WriteFilesList()

void QFileWriter::WriteFilesList ( )
protected

write list of files

Definition at line 222 of file QFileWriter.cc.

References fCurrFilesListName, fFilesList, fOutputDir, QBaseModule::GetString(), and QFileList::Write().

Referenced by Do(), and Done().

Member Data Documentation

◆ fCurrentRun

int QFileWriter::fCurrentRun
protected

Current run being worked on.

Definition at line 229 of file QFileWriter.hh.

Referenced by BuildFileName(), Do(), Init(), and IsToOpen().

◆ fCurrFilesListName

std::string QFileWriter::fCurrFilesListName
protected

Name of the file list for this iteration.

Definition at line 211 of file QFileWriter.hh.

Referenced by BuildFileName(), Done(), Init(), RemoveFilesList(), and WriteFilesList().

◆ fDoGetTower

bool QFileWriter::fDoGetTower
protected

Flag to get the tower from the current event.

Definition at line 225 of file QFileWriter.hh.

Referenced by BuildFileName(), Init(), and QFileWriter().

◆ fEventNumber

int QFileWriter::fEventNumber
protected

current event number

Definition at line 105 of file QFileWriter.hh.

Referenced by Do(), Done(), Init(), and IsToOpen().

◆ fFileExtension

std::string QFileWriter::fFileExtension
protected

file extension

Definition at line 108 of file QFileWriter.hh.

Referenced by BuildFileName(), Init(), and QFileWriter().

◆ fFileFullPath

std::string QFileWriter::fFileFullPath
protected

fFileFullPath = fOutputDir + "/" + fFileName + fFileExtension

Definition at line 193 of file QFileWriter.hh.

Referenced by Do().

◆ fFileId

std::string QFileWriter::fFileId
protected

End of the file name to be tacked on to the prefix.

Definition at line 187 of file QFileWriter.hh.

Referenced by BuildFileName().

◆ fFileIdentifier

std::string QFileWriter::fFileIdentifier
protected

The file identifier (follows the prefix)

Definition at line 213 of file QFileWriter.hh.

Referenced by BuildFileName(), and Init().

◆ fFileName

std::string QFileWriter::fFileName
protected

fFileName = fFileNamePrefix + fFileId

Definition at line 189 of file QFileWriter.hh.

Referenced by BuildFileName(), and Do().

◆ fFileNamePrefix

std::string QFileWriter::fFileNamePrefix
protected

filename components

Definition at line 185 of file QFileWriter.hh.

Referenced by BuildFileName(), Done(), and Init().

◆ fFilesList

std::list<std::string> QFileWriter::fFilesList
protected

List of the full paths of files opened.

Definition at line 180 of file QFileWriter.hh.

Referenced by Do(), Done(), Init(), IsToOpen(), and WriteFilesList().

◆ fFilesListName

std::string QFileWriter::fFilesListName
protected

Definition at line 195 of file QFileWriter.hh.

Referenced by BuildFileName(), and Init().

◆ fFullPathFilesList

Q_BEGIN_NAMESPACE std::list< std::string > QFileWriter::fFullPathFilesList
staticprotected

List of the full paths of files opened by all writers.

Definition at line 178 of file QFileWriter.hh.

Referenced by Do(), Done(), GetFileList(), and Init().

◆ fKeepFrameWorkConfig

bool QFileWriter::fKeepFrameWorkConfig
protected

Write the Sequence config data to the file.

Definition at line 237 of file QFileWriter.hh.

Referenced by Do(), and Init().

◆ fNewPartialOnRerun

bool QFileWriter::fNewPartialOnRerun
protected

Does rerunning the sequence create new files, or a new partial.

Definition at line 231 of file QFileWriter.hh.

Referenced by Done(), and Init().

◆ fOldFilesList

std::list<std::string> QFileWriter::fOldFilesList
protected

List of files opened on the previous iteration.

Definition at line 182 of file QFileWriter.hh.

Referenced by Done().

◆ fOldFilesListName

std::string QFileWriter::fOldFilesListName
protected

Name of the file list written in the previous iteration.

Definition at line 209 of file QFileWriter.hh.

Referenced by Done().

◆ fOneFileOpenOnly

bool QFileWriter::fOneFileOpenOnly
protected

Can the writer open more than one file at a time?

Definition at line 233 of file QFileWriter.hh.

Referenced by Do(), and QFileWriter().

◆ fOutputDir

std::string QFileWriter::fOutputDir
protected

Directory that we are writing to.

Definition at line 191 of file QFileWriter.hh.

Referenced by BuildFileName(), Do(), Done(), Init(), and WriteFilesList().

◆ fPartial

int QFileWriter::fPartial
protected

Partial number that we are currently working on.

Definition at line 227 of file QFileWriter.hh.

Referenced by Do(), and Init().

◆ fPartialsByFileId

std::map<std::string,int> QFileWriter::fPartialsByFileId
protected

Current partial file for a given file ID.

Definition at line 239 of file QFileWriter.hh.

Referenced by Do(), and IncrementPartial().

◆ fPartialSize

int QFileWriter::fPartialSize
protected

Partial size. When reached, automatically create a new file.

Definition at line 219 of file QFileWriter.hh.

Referenced by Init(), and IsToOpen().

◆ fSaveTempFiles

bool QFileWriter::fSaveTempFiles
protected

Flag to say whether we save the temporary files created.

Definition at line 217 of file QFileWriter.hh.

Referenced by Done(), and Init().

◆ fSetListForReader

bool QFileWriter::fSetListForReader
protected

Definition at line 207 of file QFileWriter.hh.

Referenced by Done(), and Init().

◆ fSyncWithReader

bool QFileWriter::fSyncWithReader
protected

Flag to synchronize the output files with the input.

Definition at line 221 of file QFileWriter.hh.

Referenced by Init(), and IsToOpen().

◆ fSyncWithRun

bool QFileWriter::fSyncWithRun
protected

Flag to start a new file for each new run.

Definition at line 223 of file QFileWriter.hh.

Referenced by Do(), Init(), and IsToOpen().

◆ fUseEventCachedFileName

bool QFileWriter::fUseEventCachedFileName
protected

Flag to determine whether to use the file in the event cache.

Some readers can store the originating file with the QEvent. This flag specifies whether to use that. Otherwise, it will fall back to fRWCommon->fReaderCurrentFileName.

Definition at line 204 of file QFileWriter.hh.

Referenced by GetCorrespondingReaderFileName(), and Init().

◆ fWarnRunData

bool QFileWriter::fWarnRunData
protected

If the run data is not valid, pass a warning.

Definition at line 235 of file QFileWriter.hh.

Referenced by BuildFileName(), Do(), and QFileWriter().

◆ fWriteFilesList

bool QFileWriter::fWriteFilesList
protected

Flag whether we are writing a files list.

Definition at line 215 of file QFileWriter.hh.

Referenced by Do(), Done(), Init(), and RemoveFilesList().


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