3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTFilePublisher.cxx
20 @author Matthias Richter
22 @brief HLT file publisher component implementation. */
28 #include "AliHLTFilePublisher.h"
29 #include <TObjString.h>
33 /** the global object for component registration */
34 AliHLTFilePublisher gAliHLTFilePublisher;
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTFilePublisher)
39 AliHLTFilePublisher::AliHLTFilePublisher()
45 fDataType(kAliHLTVoidDataType),
46 fSpecification(~(AliHLTUInt32_t)0),
49 // see header file for class documentation
51 // refer to README to build package
53 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 // make the lists owners of their objects in order to automatically
56 // de-allocate the objects
57 fFileNames.SetOwner();
61 AliHLTFilePublisher::AliHLTFilePublisher(const AliHLTFilePublisher&)
67 fDataType(kAliHLTVoidDataType),
71 // see header file for class documentation
72 HLTFatal("copy constructor untested");
75 AliHLTFilePublisher& AliHLTFilePublisher::operator=(const AliHLTFilePublisher&)
77 // see header file for class documentation
78 HLTFatal("assignment operator untested");
82 AliHLTFilePublisher::~AliHLTFilePublisher()
84 // see header file for class documentation
86 // file list and file name list are owner of their objects and
87 // delete all the objects
90 const char* AliHLTFilePublisher::GetComponentID()
92 // see header file for class documentation
93 return "FilePublisher";
96 AliHLTComponentDataType AliHLTFilePublisher::GetOutputDataType()
98 // see header file for class documentation
102 void AliHLTFilePublisher::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
104 // see header file for class documentation
109 AliHLTComponent* AliHLTFilePublisher::Spawn()
111 // see header file for class documentation
112 return new AliHLTFilePublisher;
115 int AliHLTFilePublisher::DoInit( int argc, const char** argv )
117 // see header file for class documentation
119 //HLTDebug("%d %s", argc, argv[0]);
123 for (int i=0; i<argc && iResult>=0; i++) {
125 if (argument.IsNull()) continue;
128 if (argument.CompareTo("-datafile")==0) {
129 if ((bMissingParam=(++i>=argc))) break;
130 TObjString* parameter=new TObjString(argv[i]);
132 fFileNames.Add(parameter);
138 } else if (argument.CompareTo("-datafilelist")==0) {
139 if ((bMissingParam=(++i>=argc))) break;
140 HLTWarning("-datafilelist option not yet implemented");
143 } else if (argument.CompareTo("-datatype")==0) {
144 if ((bMissingParam=(++i>=argc))) break;
145 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
146 if ((bMissingParam=(++i>=argc))) break;
147 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
150 } else if (argument.CompareTo("-dataspec")==0) {
151 if ((bMissingParam=(++i>=argc))) break;
152 TString parameter(argv[i]);
153 parameter.Remove(TString::kLeading, ' '); // remove all blanks
154 if (parameter.IsDigit()) {
155 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
156 } else if (parameter.BeginsWith("0x") &&
157 parameter.Replace(0,2,"",0).IsHex()) {
158 sscanf(parameter.Data(),"%x", &fSpecification);
160 HLTError("wrong parameter for argument %s, number expected", argument.Data());
164 if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) {
165 HLTError("unknown argument %s", argument.Data());
167 } else if (iResult==-EPROTO) {
170 } else if (iResult>=0) {
177 HLTError("missing parameter for argument %s", argument.Data());
180 if (fFileNames.GetSize()==0) {
181 HLTError("the publisher needs at least one file argument");
184 if (iResult>=0) iResult=OpenFiles();
191 int AliHLTFilePublisher::ScanArgument(int argc, const char** argv)
193 // see header file for class documentation
195 // there are no other arguments than the standard ones
196 if (argc==0 && argv==NULL) {
197 // this is just to get rid of the warning "unused parameter"
202 int AliHLTFilePublisher::OpenFiles()
204 // see header file for class documentation
206 TObjLink *lnk=fFileNames.FirstLink();
207 while (lnk && iResult>=0) {
208 TObjString* pFileName=(TObjString*)lnk->GetObject();
210 TString fullFN= pFileName->GetString() + "?filetype=raw";
211 TFile* pFile = new TFile(fullFN);
213 if (pFile->IsZombie()==0) {
215 if (pFile->GetSize()>fMaxSize) fMaxSize=pFile->GetSize();
217 HLTError("can not open file %s", (pFileName->GetString()).Data());
229 int AliHLTFilePublisher::DoDeinit()
231 // see header file for class documentation
238 int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& evtData,
239 AliHLTComponentTriggerData& trigData,
240 AliHLTUInt8_t* outputPtr,
241 AliHLTUInt32_t& size,
242 vector<AliHLTComponentBlockData>& outputBlocks )
246 if (fpCurrent) lnk=fpCurrent->Next();
247 if (lnk==NULL) lnk=fFiles.FirstLink();
250 TFile* pFile=(TFile*)lnk->GetObject();
252 int iCopy=pFile->GetSize();
254 if (iCopy>(int)size) {
256 HLTWarning("buffer to small, data of file %s truncated", pFile->GetName());
258 if (pFile->ReadBuffer((char*)outputPtr, iCopy)!=0) {
259 // ReadBuffer returns 1 in case of failure and 0 in case of success
262 AliHLTComponentBlockData bd;
267 bd.fDataType=fDataType;
268 bd.fSpecification=fSpecification;
269 outputBlocks.push_back(bd);
273 HLTError("no file available");
279 if (evtData.fStructSize==0 && trigData.fStructSize==0) {
280 // this is just to get rid of the warning "unused parameter"
285 AliHLTComponentDataType AliHLTFilePublisher::GetCurrentDataType() const
290 AliHLTUInt32_t AliHLTFilePublisher::GetCurrentSpecification() const
292 return fSpecification;