3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * for The ALICE Off-line Project. *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
18 /** @file AliHLTFilePublisher.cxx
19 @author Matthias Richter
21 @brief HLT file publisher component implementation. */
27 #include "AliHLTFilePublisher.h"
28 #include <TObjString.h>
32 /** ROOT macro for the implementation of ROOT specific class methods */
33 ClassImp(AliHLTFilePublisher)
35 AliHLTFilePublisher::AliHLTFilePublisher()
40 fDataType(kAliHLTVoidDataType),
41 fSpecification(~(AliHLTUInt32_t)0),
44 // make the lists owners of their objects in order to automatically
45 // de-allocate the objects
46 fFileNames.SetOwner();
50 AliHLTFilePublisher::AliHLTFilePublisher(const AliHLTFilePublisher&)
55 fDataType(kAliHLTVoidDataType),
59 HLTFatal("copy constructor untested");
62 AliHLTFilePublisher& AliHLTFilePublisher::operator=(const AliHLTFilePublisher&)
64 HLTFatal("assignment operator untested");
68 AliHLTFilePublisher::~AliHLTFilePublisher()
70 // file list and file name list are owner of their objects and
71 // delete all the objects
74 const char* AliHLTFilePublisher::GetComponentID()
76 return "FilePublisher";
79 void AliHLTFilePublisher::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
84 AliHLTComponentDataType AliHLTFilePublisher::GetOutputDataType()
86 return (AliHLTComponentDataType){ sizeof(AliHLTComponentDataType), kAliHLTVoidDataTypeID, kAliHLTVoidDataOrigin};
89 void AliHLTFilePublisher::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
95 AliHLTComponent* AliHLTFilePublisher::Spawn()
97 return new AliHLTFilePublisher;
100 int AliHLTFilePublisher::DoInit( int argc, const char** argv )
105 for (int i; i<argc; i++) {
109 if (argument.CompareTo("-datafile")==0) {
110 if ((bMissingParam=(++i>=argc))) break;
111 TObjString* parameter=new TObjString(argv[i]);
113 fFileNames.Add(parameter);
119 } else if (argument.CompareTo("-datafilelist")==0) {
120 if ((bMissingParam=(++i>=argc))) break;
121 HLTWarning("-datafilelist option not yet implemented");
124 } else if (argument.CompareTo("-datatype")==0) {
125 if ((bMissingParam=(++i>=argc))) break;
126 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
129 } else if (argument.CompareTo("-dataspec")==0) {
130 if ((bMissingParam=(++i>=argc))) break;
131 TString parameter(argv[i]);
132 if (parameter.IsDigit()) {
133 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
135 HLTError("wrong parameter for argument %s, number expected", argument.Data());
139 } else if (argument.CompareTo("-dataorigin")==0) {
140 if ((bMissingParam=(++i>=argc))) break;
141 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize,(Int_t)strlen(argv[i])));
143 HLTError("unknown argument %s", argument.Data());
148 HLTError("missing parameter for argument %s", argument.Data());
151 if (fFileNames.GetSize()==0) {
152 HLTError("the publisher needs at least one file argument");
155 if (iResult>=0) iResult=OpenFiles();
162 int AliHLTFilePublisher::OpenFiles()
165 TObjLink *lnk=fFileNames.FirstLink();
166 while (lnk && iResult>=0) {
167 TObjString* pFileName=(TObjString*)lnk->GetObject();
169 TString fullFN= pFileName->GetString() + "?filetype=raw";
170 TFile* pFile = new TFile(fullFN);
172 if (pFile->IsZombie()==0) {
174 if (pFile->GetSize()>fMaxSize) fMaxSize=pFile->GetSize();
176 HLTError("can not open file %s", (pFileName->GetString()).Data());
188 int AliHLTFilePublisher::DoDeinit()
196 int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& evtData,
197 AliHLTComponentTriggerData& trigData,
198 AliHLTUInt8_t* outputPtr,
199 AliHLTUInt32_t& size,
200 vector<AliHLTComponentBlockData>& outputBlocks )
205 if (fpCurrent) lnk=fpCurrent->Next();
206 if (lnk==NULL) lnk=fFiles.FirstLink();
209 TFile* pFile=(TFile*)lnk->GetObject();
211 int iCopy=pFile->GetSize();
214 HLTWarning("buffer to small, data of file %s truncated", pFile->GetName());
216 if (pFile->ReadBuffer((char*)outputPtr, iCopy)!=0) {
217 // ReadBuffer returns 1 in case of failure and 0 in case of success
220 AliHLTComponentBlockData bd;
225 bd.fDataType=fDataType;
226 bd.fSpecification=fSpecification;
227 outputBlocks.push_back(bd);