#endif
#include "AliHLTFilePublisher.h"
+#include "AliLog.h"
#include <TObjString.h>
#include <TMath.h>
#include <TFile.h>
-/** the global object for component registration */
-AliHLTFilePublisher gAliHLTFilePublisher;
/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(AliHLTFilePublisher)
AliHLTDataSource(),
fpCurrent(NULL),
fEvents(),
- fMaxSize(0)
+ fMaxSize(0),
+ fOpenFilesAtStart(false),
+ fOutputDataTypes()
{
// see header file for class documentation
// or
AliHLTComponentDataType AliHLTFilePublisher::GetOutputDataType()
{
// see header file for class documentation
- return kAliHLTVoidDataType;
+ if (fOutputDataTypes.size()==0) return kAliHLTVoidDataType;
+ else if (fOutputDataTypes.size()==1) return fOutputDataTypes[0];
+ return kAliHLTMultipleDataType;
+}
+
+int AliHLTFilePublisher::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
+{
+ tgtList.assign(fOutputDataTypes.begin(), fOutputDataTypes.end());
+ HLTInfo("%s %p provides %d output data types", GetComponentID(), this, fOutputDataTypes.size());
+ return fOutputDataTypes.size();
}
void AliHLTFilePublisher::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
int bMissingParam=0;
int bHaveDatatype=0;
int bHaveSpecification=0;
+ fOpenFilesAtStart = false;
AliHLTComponentDataType currDataType=kAliHLTVoidDataType;
AliHLTUInt32_t currSpecification=kAliHLTVoidDataSpec;
EventFiles* pCurrEvent=NULL;
memcpy(&currDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
if ((bMissingParam=(++i>=argc))) break;
memcpy(&currDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
+
+ // add all different data types to the list
+ AliHLTComponentDataTypeList::iterator element=fOutputDataTypes.begin();
+ while (element!=fOutputDataTypes.end() && *element!=currDataType) element++;
+ if (element==fOutputDataTypes.end()) fOutputDataTypes.push_back(currDataType);
+
if (bHaveDatatype==0 && pCurrEvent && iResult>=0) {
// this is a workaround to make old tutorials working which contain
// the arguments in the wrong sequence
TList& files=*pCurrEvent; // type conversion operator defined
TObjLink *flnk=files.FirstLink();
- int eventSize=0;
while (flnk) {
FileDesc* pFileDesc=dynamic_cast<FileDesc*>(flnk->GetObject());
if (pFileDesc) {
// the arguments in the wrong sequence
TList& files=*pCurrEvent; // type conversion operator defined
TObjLink *flnk=files.FirstLink();
- int eventSize=0;
while (flnk) {
FileDesc* pFileDesc=dynamic_cast<FileDesc*>(flnk->GetObject());
if (pFileDesc) {
// -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();
}
int AliHLTFilePublisher::InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc)
{
+ // see header file for class documentation
int iResult=0;
if (pDesc) {
if (pCurrEvent==NULL) {
int AliHLTFilePublisher::InsertEvent(EventFiles* &pEvent)
{
+ // see header file for class documentation
int iResult=0;
if (pEvent) {
HLTDebug("Inserted event %p", pEvent);
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());
AliHLTUInt32_t& size,
vector<AliHLTComponentBlockData>& outputBlocks )
{
+ // see header file for class documentation
int iResult=0;
TObjLink *lnk=fpCurrent;
if (lnk==NULL) lnk=fEvents.FirstLink();
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();
bd.fSpecification=*pFileDesc; // type conversion operator defined
outputBlocks.push_back(bd);
iTotalSize+=iCopy;
+// TString msg;
+// msg.Form("get file %s ", pFile->GetName());
+// msg+="data type \'%s\'";
+// PrintDataTypeContent(bd.fDataType, msg.Data());
}
} else {
// output buffer too small, update GetOutputDataSize for the second trial
fMaxSize=iCopy;
iResult=-ENOSPC;
}
+ if (not fOpenFilesAtStart) pFileDesc->CloseFile();
} else {
HLTError("no file available");
iResult=-EFAULT;
fDataType(dt),
fSpecification(spec)
{
+ // see header file for class documentation
+ // or
+ // refer to README to build package
+ // or
+ // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
}
+
AliHLTFilePublisher::FileDesc::~FileDesc()
{
- if (fpInstance) delete fpInstance;
+ // see header file for class documentation
+ CloseFile();
+}
+
+void AliHLTFilePublisher::FileDesc::CloseFile()
+{
+ // see header file for class documentation
+ 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;
}
int AliHLTFilePublisher::FileDesc::OpenFile()
{
+ // see header file for class documentation
int iResult=0;
TString fullFN= fName + "?filetype=raw";
fpInstance = new TFile(fullFN);
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;
}