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 AliHLTComponentDataType AliHLTFilePublisher::GetOutputDataType()
81 AliHLTComponentDataType dt =
82 {sizeof(AliHLTComponentDataType),
83 kAliHLTVoidDataTypeID,
84 kAliHLTVoidDataOrigin};
88 void AliHLTFilePublisher::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
94 AliHLTComponent* AliHLTFilePublisher::Spawn()
96 return new AliHLTFilePublisher;
99 int AliHLTFilePublisher::DoInit( int argc, const char** argv )
101 //HLTDebug("%d %s", argc, argv[0]);
105 for (int i=0; i<argc && iResult>=0; i++) {
107 if (argument.IsNull()) continue;
110 if (argument.CompareTo("-datafile")==0) {
111 if ((bMissingParam=(++i>=argc))) break;
112 TObjString* parameter=new TObjString(argv[i]);
114 fFileNames.Add(parameter);
120 } else if (argument.CompareTo("-datafilelist")==0) {
121 if ((bMissingParam=(++i>=argc))) break;
122 HLTWarning("-datafilelist option not yet implemented");
125 } else if (argument.CompareTo("-datatype")==0) {
126 if ((bMissingParam=(++i>=argc))) break;
127 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
128 if ((bMissingParam=(++i>=argc))) break;
129 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
132 } else if (argument.CompareTo("-dataspec")==0) {
133 if ((bMissingParam=(++i>=argc))) break;
134 TString parameter(argv[i]);
135 parameter.Remove(TString::kLeading, ' '); // remove all blanks
136 if (parameter.IsDigit()) {
137 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
138 } else if (parameter.BeginsWith("0x") &&
139 parameter.Replace(0,2,"",0).IsHex()) {
140 sscanf(parameter.Data(),"%x", &fSpecification);
142 HLTError("wrong parameter for argument %s, number expected", argument.Data());
146 if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
147 HLTError("unknown argument %s", argument.Data());
149 } else if (iResult==-EPROTO) {
152 } else if (iResult>=0) {
159 HLTError("missing parameter for argument %s", argument.Data());
162 if (fFileNames.GetSize()==0) {
163 HLTError("the publisher needs at least one file argument");
166 if (iResult>=0) iResult=OpenFiles();
173 int AliHLTFilePublisher::ScanArgument(int argc, const char** argv)
175 // there are no other arguments than the standard ones
179 int AliHLTFilePublisher::OpenFiles()
182 TObjLink *lnk=fFileNames.FirstLink();
183 while (lnk && iResult>=0) {
184 TObjString* pFileName=(TObjString*)lnk->GetObject();
186 TString fullFN= pFileName->GetString() + "?filetype=raw";
187 TFile* pFile = new TFile(fullFN);
189 if (pFile->IsZombie()==0) {
191 if (pFile->GetSize()>fMaxSize) fMaxSize=pFile->GetSize();
193 HLTError("can not open file %s", (pFileName->GetString()).Data());
205 int AliHLTFilePublisher::DoDeinit()
213 int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& evtData,
214 AliHLTComponentTriggerData& trigData,
215 AliHLTUInt8_t* outputPtr,
216 AliHLTUInt32_t& size,
217 vector<AliHLTComponentBlockData>& outputBlocks )
221 if (fpCurrent) lnk=fpCurrent->Next();
222 if (lnk==NULL) lnk=fFiles.FirstLink();
225 TFile* pFile=(TFile*)lnk->GetObject();
227 int iCopy=pFile->GetSize();
229 if (iCopy>(int)size) {
231 HLTWarning("buffer to small, data of file %s truncated", pFile->GetName());
233 if (pFile->ReadBuffer((char*)outputPtr, iCopy)!=0) {
234 // ReadBuffer returns 1 in case of failure and 0 in case of success
237 AliHLTComponentBlockData bd;
242 bd.fDataType=fDataType;
243 bd.fSpecification=fSpecification;
244 outputBlocks.push_back(bd);
248 HLTError("no file available");