Line data Source code
1 : // $Id$
2 :
3 : ///**************************************************************************
4 : ///* This file is property of and copyright by the *
5 : ///* ALICE Experiment at CERN, All rights reserved. *
6 : ///* *
7 : ///* Permission to use, copy, modify and distribute this software and its *
8 : ///* documentation strictly for non-commercial purposes is hereby granted *
9 : ///* without fee, provided that the above copyright notice appears in all *
10 : ///* copies and that both the copyright notice and this permission notice *
11 : ///* appear in the supporting documentation. The authors make no claims *
12 : ///* about the suitability of this software for any purpose. It is *
13 : ///* provided "as is" without express or implied warranty. *
14 : ///**************************************************************************/
15 :
16 : /// @file AliHLTFXSFileWriter.cxx
17 : /// @author Timo Breitner
18 : /// @date
19 : /// @brief HLT FXS file writer component implementation.
20 : #include <fstream>
21 : #include <TSystem.h>
22 : #include "AliHLTFXSFileWriter.h"
23 :
24 : using namespace std;
25 :
26 : /** ROOT macro for the implementation of ROOT specific class methods */
27 8 : ClassImp(AliHLTFXSFileWriter)
28 :
29 : const Int_t AliHLTFXSFileWriter::gkCalibObjectMaxVersion=65000;
30 :
31 : AliHLTFXSFileWriter::AliHLTFXSFileWriter()
32 3 : : AliHLTDataSink()
33 3 : , fDirectory("FXS")
34 15 : {
35 : // An HLT data sink component which writes FXS data to file(s).
36 : //
37 : // Component ID: \b FXSFileWriter <br>
38 : // Library: \b libAliHLTUtil.so <br>
39 : // Input Data Types: ::kAliHLTDataTypeFXSCalib <br>
40 : // Output Data Types: none <br>
41 6 : }
42 :
43 : AliHLTFXSFileWriter::~AliHLTFXSFileWriter()
44 18 : {
45 : // destructor
46 9 : }
47 :
48 : const char* AliHLTFXSFileWriter::GetComponentID()
49 : {
50 : // overloaded from AliHLTComponent
51 636 : return "FXSFileWriter";
52 : }
53 :
54 : void AliHLTFXSFileWriter::GetInputDataTypes( AliHLTComponentDataTypeList& list)
55 : {
56 : // overloaded from AliHLTComponent
57 0 : list.clear();
58 0 : list.push_back(kAliHLTDataTypeFXSCalib);
59 0 : }
60 :
61 : AliHLTComponent* AliHLTFXSFileWriter::Spawn()
62 : {
63 : // overloaded from AliHLTComponent
64 0 : return new AliHLTFXSFileWriter;
65 0 : }
66 :
67 : int AliHLTFXSFileWriter::DoInit( int argc, const char** argv )
68 : {
69 : // overloaded from AliHLTComponent: initialization
70 0 : TString argument="";
71 : int bMissingParam=0;
72 : int i=0;
73 0 : for (; i<argc; i++) {
74 0 : argument=argv[i];
75 0 : if (argument.IsNull()) continue;
76 :
77 0 : if (argument.CompareTo("-directory")==0) {
78 0 : if ((bMissingParam=(++i>=argc))) break;
79 0 : fDirectory=argv[i];
80 : }
81 : }
82 :
83 0 : if (bMissingParam) {
84 0 : HLTError("missing parameter for argument %s", argument.Data());
85 0 : return -EINVAL;
86 : }
87 :
88 0 : if (!fDirectory.IsNull()) {
89 0 : if ( gSystem->mkdir(fDirectory) != 0 )
90 0 : return -EPERM;
91 : }
92 :
93 0 : return 0;
94 0 : }
95 :
96 : int AliHLTFXSFileWriter::DumpEvent( const AliHLTComponentEventData& evtData,
97 : AliHLTComponentTriggerData& /*trigData*/ )
98 : {
99 : // overloaded from AliHLTDataSink: event processing
100 : int iResult=0;
101 :
102 : const AliHLTComponentBlockData* pDesc=NULL;
103 :
104 : int blockno=0;
105 0 : for (pDesc=GetFirstInputBlock(); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++) {
106 0 : if (pDesc->fDataType!=(kAliHLTDataTypeFXSCalib|kAliHLTDataOriginAny))
107 : continue;
108 : HLTDebug("block %d out of %d", blockno, evtData.fBlockCnt);
109 0 : if(pDesc->fSize <= sizeof(AliHLTFXSHeader)){
110 0 : HLTError("Block size (%d) not larger than FXS header size (%d).",pDesc->fSize, sizeof(AliHLTFXSHeader));
111 0 : return -EINVAL;
112 : }
113 0 : AliHLTFXSHeader* header=reinterpret_cast<AliHLTFXSHeader*>(pDesc->fPtr);
114 0 : const char* data=static_cast<const char*>(pDesc->fPtr) + sizeof(AliHLTFXSHeader);
115 0 : int datasize=pDesc->fSize - sizeof(AliHLTFXSHeader);
116 :
117 0 : TString runNumber;
118 0 : runNumber += header->fRunNumber;
119 0 : TString detector = header->fOrigin;
120 0 : TString fileID = header->fFileID;
121 0 : TString ddlNumber;
122 0 : for (int ddl=0; ddl<gkAliHLTFXSHeaderfDDLNumberSize; ++ddl) {
123 0 : ddlNumber += header->fDDLNumber[ddl];
124 : }
125 0 : TString sep="/";
126 :
127 0 : TString basedir = fDirectory + sep + runNumber + sep + detector + sep + ddlNumber;
128 0 : TString basefile = basedir + sep + fileID;
129 :
130 0 : gSystem->mkdir(basedir, kTRUE);
131 :
132 0 : TString targetfile;
133 :
134 0 : for(int version=0; version<gkCalibObjectMaxVersion; ++version){
135 0 : TString tmpfile=basefile+ "_";
136 0 : tmpfile += version;
137 0 : ifstream test(tmpfile.Data());
138 0 : if(! test.good()){
139 0 : targetfile=tmpfile;
140 0 : break;
141 : }
142 0 : test.close();
143 0 : }
144 :
145 0 : if(targetfile.IsNull()){
146 0 : HLTError("Maximum version (%d) reached, cannot store any more objects.", gkCalibObjectMaxVersion);
147 0 : return -1;
148 : }
149 :
150 0 : ofstream dump(targetfile.Data(), ofstream::out );
151 0 : if (dump.good()) {
152 0 : dump.write(data, datasize);
153 : HLTDebug("wrote %d byte(s) to file %s", datasize, targetfile.Data());
154 : } else {
155 0 : HLTError("can not open file %s for writing", targetfile.Data());
156 : iResult=-EBADF;
157 : }
158 0 : dump.close();
159 0 : }
160 0 : return iResult;
161 0 : }
|