GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Deprecated/MFM2ADF.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #include "MFM2ADF.h"
24 
25 #include <iostream>
26 #include <iomanip>
27 #include <fstream>
28 
29 using namespace std;
30 
31 #include <fcntl.h>
32 #include "MFMCommonFrame.h"
33 
34 using namespace ADF;
35 
36 namespace {
37  struct ANC_KEY {
38  UInt_t length;
39  UInt_t type;
40  UInt_t eventnumber;
41  ULong64_t timestamp;
42  } the_anc_key;
43 }
44 
47  fCurrentFile(0),
48  fCurrentFileNumber(0u),
49  fFiles2Read(),
50  fMFMFrame(0x0),
51  fMFMVector(0x0),
52  fBufferIO(aMByte),
53  fTotBytesRead(0UL),
54  fEventsRead(0UL)
55 {
56  Log.GetProcessName() = "MFM2ADF";
57 }
58 
60 {
61  // in principle not needed ... just in case reset it has not been called by narval
62  UInt_t error = 0u; process_reset(&error) ;
63 }
64 
66 {
67  Bool_t ok = false;
68 
69  if ( fCurrentFile > 0 ) {
70  ::close(fCurrentFile);
71  fCurrentFile = 0;
72  Log << info << "the input file " << fFiles2Read[fCurrentFileNumber-1]
73  << " has just been closed " << fTotBytesRead << " Bytes read " << nline;
74  }
75 
76  while ( fCurrentFileNumber < fFiles2Read.size() ) {
77 
78  fCurrentFile = ::open(fFiles2Read[fCurrentFileNumber].data(),(O_RDONLY));
79  if ( fCurrentFile < 0 ) {
80  fCurrentFile = 0;
81  Log << warning << "File " << fFiles2Read[fCurrentFileNumber] << " is not a valid file " << nline ;
82  fCurrentFileNumber++;
83  continue;
84  }
85  Log << info << "A new input file has just been open " << fFiles2Read[fCurrentFileNumber] << nline;
86  // decode the header part. For the moment just jump
87 
88  GetFrameIO().SetStatus(BaseFrameIO::kIdle);
89  ok = true;
90  fCurrentFileNumber++;
91  break;
92  }
93  if ( fCurrentFile == 0 ) {
94  GetFrameIO().SetStatus(BaseFrameIO::kFinished);
95  Log << info << "All input file have been read " << nline;
96  }
97  //
98  Log << dolog;
99 
100  return ok;
101 }
102 
103 void MFM2ADF::process_config (const Char_t *directory_path, UInt_t *error_code)
104 {
105  // first init narval and ADF stuff (if required)
106  // NarvalInterface::process_config(directory_path, error_code);
107 
108  if ( (*error_code) == 0u ) {
109  // now init your stuff
110  }
111 }
112 
114 {
115  Log.ClearMessage(); Log.SetProcessMethod("process_block");
116 
117  // make sure length is 0 before starting anything
118  out.Rewind(ConfAgent::kWrite);
119  //
120  if ( GetFrameIO().GetStatus() == BaseFrameIO::kFinished ) { // set in NewFile once list is over
121  out.SetEoB(true);
122  return 0u;
123  }
124 
125  Bool_t ok = true, check_previous = true; Int_t framesize = 0, vectorsize; char **pvector;
126  while (ok) {
127 
128  vectorsize = MFM_BLOB_HEADER_SIZE; pvector = &fMFMVector;
129 
130  if (check_previous) {
131  if ( fBufferIO.Offset() ) { // read previously so stream it out. No check, assume enough place in the newly given out
132  out.AddFrame(fBufferIO);
133  fBufferIO.FastReset();
134  }
135  check_previous = false;
136  }
137 
138  framesize = fMFMFrame->ReadInFile(&fCurrentFile, pvector, &vectorsize);
139  if (framesize <= 0) {
140  // if ( ::eof(fCurrentFile) ) {
141  if ( NewFile() )
142  break ;
143  else return 1u;
144  // }
145  // else return 1u;
146  }
147  //fMFMFrame->HeaderDisplay((char*)"-- Header of Frame --");
148  fEventsRead++;
149  fTotBytesRead+=framesize;
150  //
151  the_anc_key.length = framesize + sizeof(ANC_KEY);
152  the_anc_key.type = 0xFA0201A0;
153  the_anc_key.eventnumber = fMFMFrame->GetEventNumber();
154  the_anc_key.timestamp = fMFMFrame->GetTimeStamp();
155 
156  fBufferIO.Import((Char_t *)(&the_anc_key),20);
157  fBufferIO.Import((Char_t *)fMFMFrame->GetPointHeader(),framesize);
158 
159  fBufferIO.SetEffectiveSize(the_anc_key.length);
160  if ( out.AddFrame(fBufferIO) == false )
161  break;
162  fBufferIO.FastReset();
163  }
164  //
165  out.SetEoB(true);
166 
167  Log << dolog; return 0u;
168 }
169 
170 void MFM2ADF::process_initialise (UInt_t *error_code)
171 {
172  std::string tmp, option, filename;
173  //
174  *error_code = 0u; Log.ClearMessage(); Log.SetProcessMethod("process_initialise");
175 
176  // read an input file to get the base filename and the path
177  std::string conffile = GetConfPath() + "MFM2ADF.conf";
178 
179  std::ifstream filein(conffile.data());
180  if ( filein.is_open() == true ) {
181  getline(filein,tmp);
182  tmp += " ";
183  while ( filein.good() && !filein.eof() ) { // read input stream line by line
184  if ( tmp[0] == '#' ) {
185  getline(filein,tmp);
186  tmp += " ";
187  continue;
188  } // this line is a comment
189 
190  std::istringstream decode(tmp);
191 
192  if( tmp[0] == 'l' ) { // the .conf file contains the list of file to be read
193  decode >> option >> filename;
194  if( decode.good() )
195  fFiles2Read.push_back(filename);
196  }
197  getline(filein,tmp);
198  tmp += " ";
199  }
200  }
201  filein.close();
202 
203  Log << " " << fFiles2Read.size() << " file(s) is(are) to be read by MFM2ADF Producer " << nline;
204 
205  // open the first file, try up to the first good one. if nothing retrun error
206  if ( !NewFile() )
207  *error_code = 1u;
208 
209  // the current read MFM frame
210  fMFMFrame = new MFMCommonFrame();
211  //
212  fMFMVector = (char*) (malloc(MFM_BLOB_HEADER_SIZE));
213 
214  Log << dolog;
215 }
216 
217 
218 void MFM2ADF::process_reset (UInt_t *error_code)
219 {
220  *error_code = 0u;
221  Log.ClearMessage(); Log.SetProcessMethod("process_reset");
222 
223  if ( fCurrentFile ) {
224  ::close(fCurrentFile); fCurrentFile = 0;
225  }
226 
227  Log << fCurrentFileNumber << " file(s) read "
228  << " Total number of events " << fEventsRead << " within " << fTotBytesRead << " bytes read"
229  << dolog;
230 
231  if ( fMFMVector ) {
232  delete fMFMVector; fMFMVector = 0x0;
233  }
234  if ( fMFMFrame ) {
235  delete fMFMFrame; fMFMFrame = 0x0;
236  }
237 }
238 
239 
240 
241 
242 
243 
virtual UInt_t ProcessBlock(ADF::FrameBlock &)
Produce one block of data.
It defines the interface needed to be a narval actor (producer).
LogMessage & error(LogMessage &)
LogMessage & warning(LogMessage &)
A Block of Frames.
Definition: FrameBlock.h:43
void SetEoB(Bool_t b)
Definition: FrameBlock.h:89
static void process_config(const Char_t *, UInt_t *)
to init globals (static) from a directory
virtual void process_initialise(UInt_t *error_code)
Constructor implementation.
LogMessage & nline(LogMessage &)
UInt_t Offset() const
it returns the current position in the buffer
Definition: BufferIO.h:240
const UInt_t aMByte
Definition: BaseBuffer.h:36
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
virtual ~MFM2ADF()
const std::string & GetConfPath()
To get the algo path associated with the current actor.
void SetStatus(EStatus stat)
Definition: FrameIO.h:110
virtual void SetProcessMethod(const char *)
To set the current method.
LogMessage & dolog(LogMessage &)
virtual void ClearMessage()
To clear the current message.
virtual Bool_t AddFrame(const BufferIO &, UInt_t=0u)
Add a Frame to the block.
Definition: FrameBlock.h:154
virtual void process_reset(UInt_t *error_code)
Destructor implementation.
Bool_t NewFile()
UInt_t SetEffectiveSize(UInt_t size=kMaxUInt_t)
in case the buffer is partly filled and you would like to read it again
Definition: BufferIO.cpp:152
UInt_t Import(const Char_t *from, UInt_t size_ext_buf)
Import the given array in this buffer.
Definition: BufferIO.cpp:298
virtual void FastReset()
Definition: BufferIO.cpp:117
virtual std::string & GetProcessName()
To get the Process name.
virtual void Rewind(ConfAgent::EMode mode=ConfAgent::kRead)=0
Rewind to be ready to be used again.
LogMessage Log
to send messages to the log server
header file for MFM2ADF.cpp