#endif
#include "AliHLTFilePublisher.h"
+#include "AliLog.h"
#include <TObjString.h>
#include <TMath.h>
#include <TFile.h>
AliHLTDataSource(),
fpCurrent(NULL),
fEvents(),
- fMaxSize(0)
+ fMaxSize(0),
+ fOpenFilesAtStart(false)
{
// see header file for class documentation
// or
int bMissingParam=0;
int bHaveDatatype=0;
int bHaveSpecification=0;
+ fOpenFilesAtStart = false;
AliHLTComponentDataType currDataType=kAliHLTVoidDataType;
AliHLTUInt32_t currSpecification=kAliHLTVoidDataSpec;
EventFiles* pCurrEvent=NULL;
// -nextevent
} else if (argument.CompareTo("-nextevent")==0) {
InsertEvent(pCurrEvent);
+ } else if (argument.CompareTo("-open_files_at_start")==0) {
+ fOpenFilesAtStart = true;
} else {
if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
HLTError("unknown argument %s", argument.Data());
HLTError("the publisher needs at least one file argument");
iResult=-EINVAL;
}
- if (iResult>=0) iResult=OpenFiles();
+ if (iResult>=0) iResult=OpenFiles(fOpenFilesAtStart);
if (iResult<0) {
fEvents.Clear();
}
if (argc==0 && argv==NULL) {
// this is just to get rid of the warning "unused parameter"
}
- return -EPROTO;
+ return -EINVAL;
}
-int AliHLTFilePublisher::OpenFiles()
+int AliHLTFilePublisher::OpenFiles(bool keepOpen)
{
// see header file for class documentation
int iResult=0;
FileDesc* pFileDesc=dynamic_cast<FileDesc*>(flnk->GetObject());
if (pFileDesc) {
int size=pFileDesc->OpenFile();
+ if (not keepOpen) pFileDesc->CloseFile();
if (size<0) {
iResult=size;
HLTError("can not open file %s", pFileDesc->GetName());
int iTotalSize=0;
while (flnk && iResult>=0) {
FileDesc* pFileDesc=dynamic_cast<FileDesc*>(flnk->GetObject());
+ if (not fOpenFilesAtStart) pFileDesc->OpenFile();
TFile* pFile=NULL;
if (pFileDesc && (pFile=*pFileDesc)!=NULL) {
int iCopy=pFile->GetSize();
fMaxSize=iCopy;
iResult=-ENOSPC;
}
+ if (not fOpenFilesAtStart) pFileDesc->CloseFile();
} else {
HLTError("no file available");
iResult=-EFAULT;
fSpecification(spec)
{
}
+
AliHLTFilePublisher::FileDesc::~FileDesc()
{
- if (fpInstance) delete fpInstance;
+ CloseFile();
+}
+
+void AliHLTFilePublisher::FileDesc::CloseFile()
+{
+ if (fpInstance)
+ {
+ // Unfortunately had to use AliLog mechanisms rather that AliHLTLogging because
+ // AliHLTFilePublisher::FileDesc does not derive from AliHLTLogging. It would
+ // become a rather heavy class if it did.
+#ifdef __DEBUG
+ AliDebugGeneral("AliHLTFilePublisher::FileDesc",
+ 2, Form("File %s has been closed.", fName.Data())
+ );
+#endif
+ delete fpInstance;
+ }
fpInstance=NULL;
}
if (fpInstance) {
if (fpInstance->IsZombie()==0) {
iResult=fpInstance->GetSize();
+#ifdef __DEBUG
+ AliDebugGeneral("AliHLTFilePublisher::FileDesc",
+ 2, Form("File %s has been opened.", fName.Data())
+ );
+#endif
} else {
iResult=-ENOENT;
}
* indicate files published by the next event
*
* Optional arguments:<br>
+ * \li -open_files_at_start
+ * Opens all files during component initialisation rather than as needed
+ * during event processing. Note: this feature may result in the system
+ * running out of file handles if a large number of files was specified.
*
* The component needs at least one argument \em -datafile or \em -datafilelist.
* Both can occur multiple times. The \em -datatype and \em -dataspec
/**
* Open all files.
* Opens all files for all events from the event list @ref fEvents and adds TFile
- * opjects to the internal list.
+ * objects to the internal list. It also calculates the maximum event size required.
+ * @param keepOpen If this flag is true then the files are kept open, otherwise
+ * this method will close the files afterwards.
*/
- int OpenFiles();
+ int OpenFiles(bool keepOpen);
protected:
/**
*/
int OpenFile();
+ /**
+ * Close the file handle.
+ */
+ void CloseFile();
+
/**
* Get name of the file.
*/
/** the maximum buffer size i.e. size of the biggest file */
Int_t fMaxSize; //! transient
+
+ /** Flag specifying if all the files should be opened during initialisation. */
+ bool fOpenFilesAtStart; //! transient
ClassDef(AliHLTFilePublisher, 1)
};