GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestFIO.cpp
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 #ifndef ADF_DUMMYFILTER_H
24 #include "TestFIO.h"
25 #endif
26 
27 #ifndef ADF_AgataKeyFactory
28 #include "AgataKeyFactory.h"
29 #endif
30 #ifndef ADF_AgataFrameFactory
31 #include "AgataFrameFactory.h"
32 #endif
33 
34 #include "CrystalFrame.h"
35 
36 #include <iostream>
37 #include <fstream>
38 
39 using namespace ADF;
40 
42  NarvalFilter(),
43  fDoRead(false),
44  fDoOutput(false),
45  fDoWrite(false),
46  fDoRecord(false),
47  fTrigger("Generic Trigger")
48 {
49  Log.GetProcessName() = "TestFIO";
50  GetFrameIO().SetName("TestFIO");
51 
52  // Test exchange of parameters with Narval
53  UShort_t t1 = 12u;
54  SetGlobalParameter("NP_US",t1);
55  std::string t2 = "152Dy";
56  SetGlobalParameter("NP_STRING",t2);
57 }
58 
60 {
61  // in principle not needed ... just in case reset has not been called by narval
62  UInt_t error = 0u; process_reset(&error) ;
63 }
64 
65 void TestFIO::process_config (const Char_t *directory_path, UInt_t *error_code)
66 {
67  // In case your algorithm needs to initiate globals, it should be done here
68  // For instance, if you need an proper FrameFactory:
69  // FrameFactory &main_frame_factory = FrameFactory::theMainFactory();
70  // main_frame_factory.Register( new MyFrameFactory() );
71 
72  // Globals for ADF are read from ADF.conf (should be in your algo path !!)
73  NarvalInterface::process_config(directory_path,error_code);
74 
75  if ( (*error_code) == 0u ) { // now init your stuff
76 
77  // here could come the reading of a file in which are stored the
78  // units (position,energy) you are working with i.e. modifications
79  // of UnitPosition UnitEnergy defined in the base class AlgoDummy
80  // + ....
81  // NarvalInterface (through process_config(), so don't forget it)
82  // keeps the name of the directory_path. To get it back: GetConfPath()
83  }
84 }
85 
86 
87 #include "TrackedFrame.h"
88 
90 {
91 // GammaTrackedInterface *data = GetDataPointer<GammaTrackedInterface>(fTrigger.GetInputFrame(0u));
92 // data->Global()->Print();
93 
94  if ( fDoRead )
95  if ( fTrigger.GetInputFrame(0u)->Read() == 0 )
96  return 1u;
97 
98 // CrystalInterface *data = GetDataPointer<CrystalInterface>(fTrigger.GetInputFrame(0u));
99 
100 // UShort_t val;
101 // for (UInt_t i = 0u ; i < data->GetCore(0)->GetSignal()->GetLength(); i++ )
102 // printf("%d \n",data->GetCore(0)->GetSignal()->Get(val,i));
103 //
104  return 0u;
105 }
106 
108 {
109  return 0u;
110 }
111 
112 #include "PSAFrame.h"
113 #include "CrystalFrame.h"
114 
116 {
117  if ( !fDoOutput )
118  return 0u;
119 
120  Frame *resultframe = fTrigger.GetOutputFrame();
121 
122 // PSAInterface *data = GetDataPointer<PSAInterface>(fTrigger.GetOutputFrame());
123 // CrystalInterface *data = GetDataPointer<CrystalInterface>(fTrigger.GetOutputFrame());
124 // data->Global()->Print();
125 
126  if ( resultframe ) {
127  resultframe->Reset();
128  resultframe->Stallion();
129  }
130  else return 1u;
131 
132  return 0u;
133 }
134 
136 {
137  Log.ClearMessage(); Log.SetProcessMethod("process_block");
138 
139  // attach the input/output buffer to the FrameIO system
140  GetFrameIO().Attach(&in,&out);
141 
142  // start the processing
143  UInt_t error_code = 0u;
144  while ( GetFrameIO().Notify() ) { // process the input
145 
146  if ( ! (SetInput() == 0u && Process() == 0u && SetOutput() == 0u) )
147  { error_code = 1u; break; }
148  else {
149  // ok, so send the produced frame to the ouput
150  if ( fDoRecord )
151  if ( !GetFrameIO().Record() )
152  { error_code = 2u; break; }
153  }
154  }
155  if ( error_code == 1u ) {
156  Log << error
157  << "During processing : SetInput -> Process -> SetOuput() " << nline;
158  }
159  if ( error_code == 2u ) {
160  Log << error
161  << "During Record() " << nline;
162  }
163  GetFrameIO().Detach(&in,&out);
164 
165  // send messages to the central log
166  Log << dolog;
167  return error_code;
168 }
169 
170 void TestFIO::process_initialise (UInt_t *error_code)
171 {
172  *error_code = 0; Log.ClearMessage(); Log.SetProcessMethod("process_initialise");
173 
174  // read an input file to get the base filename and the path
175  std::string conffile = GetConfPath(), tmp, type;
176  conffile += "TestFIO.conf";
177 
178  // if true means the file has the correct format and the trigger could be defined
179  Bool_t ok = false, is_universal = false;
180 
181  std::ifstream filein(conffile.data());
182  // read first the model
183  filein >> tmp;
184  if ( !filein.good() )
185  ok = false;
186  else
187  GetFrameIO().SetModel( ConfAgent::GetModel(tmp) ) ;
188 
189  while ( filein.good() ) {
190 
191  UShort_t kmin, kmaj, fmin, fmaj, cons, proxy; Version vkey, vframe;
192 
193  filein >> tmp >> type >> kmin >> kmaj >> fmin >> fmaj >> cons >> proxy;
194  if ( !filein.good() )
195  break;
196 
197 // std::cout << "read" << tmp << type << kmin << kmaj << fmin << fmaj << cons << proxy;
198 
199  vkey(kmin,kmaj); vframe(fmin,fmaj);
200  if (tmp == "p:" ) {
201  if ( fTrigger.SetOutputFrame(type.data(),vkey,vframe) == 0x0 )
202  Log << "Cannot allocate output frame " << type.data() << nline ;
203  }
204  if (tmp == "c:" ) {
205  ok = true;
206  if ( fTrigger.Add(type.data(),vkey,vframe,cons==1u) == 0x0 )
207  Log << "Cannot allocate input frame " << type.data() << nline ;
208  }
209  if (tmp == "g:" ) {
210  GetFrameIO().SetModel( ConfAgent::GetModel(type) ) ;
211  is_universal = (kmin == 1u);
212  fDoRead = (kmaj == 1u);
213  fDoOutput = (fmin == 1u);
214  fDoWrite = (fmaj == 1u);
215  fDoRecord = (cons == 1u);
216  }
217  };
218 
219  // if ok registers the trigger
220  if ( !ok )
221  *error_code = 1;
222  else {
223  fTrigger.Universal(is_universal);
225  GetFrameIO().SetStatus(BaseFrameIO::kIdle);
226  }
227 
228  Log << dolog;
229 }
230 
231 
232 void TestFIO::process_reset (UInt_t *error_code)
233 {
234  Log.ClearMessage(); Log.SetProcessMethod("process_reset");
235 
236  NarvalFilter::process_reset(error_code);
237 
238  Log << dolog;
239 
240 }
241 void TestFIO::process_start (UInt_t *error_code)
242 {
243  Log.ClearMessage(); Log.SetProcessMethod("process_block");
244  (*error_code) = 0;
245 }
246 
247 void TestFIO::process_stop (UInt_t *error_code)
248 {
249  Log.ClearMessage(); Log.SetProcessMethod("process_stop");
250 
251  *error_code = 0;
252 
253  // Test exchange of parameters with Narval
254  UShort_t t1 = 9u;
255  if ( GetGlobalParameter("NP_US",t1) == 0 )
256  Log << " Parameter NP_US from ADA " << t1 << nline;
257  else
258  Log << " Cannot get Parameter NP_US from ADA " << t1 << nline ;
259 
260  std::string t2 = "-";
261  if ( GetGlobalParameter("NP_STRING",t2) == 0 )
262  Log << " Parameter NP_STRING from ADA " << t2 << nline ;
263  else
264  Log << " Cannot get Parameter NP_STRING from ADA " << t2 << nline ;
265 
266  Log << dolog;
267 }
268 void TestFIO::process_pause (UInt_t *error_code)
269 {
270  std::cout << "process_pause called with GetPID()" << GetPID() << std::endl;
271  *error_code = 0;
272 }
273 void TestFIO::process_resume (UInt_t *error_code)
274 {
275  std::cout << "process_resume called with GetPID()" << GetPID() << std::endl;
276  *error_code = 0;
277 }
278 /*
279 void TestFIO::process_unload (UInt_terror_code)
280 {
281  std::cout << "process_unload called with GetPID()" << GetPID() << std::endl;
282  *error_code = 0;
283 } */
284 
285 #if HAVE_NARVAL_H == 1 && DUMMY_FILTER == 1
286 void process_config (const char *directory_path, UInt_t *error_code)
287 {
288  TestFIO::process_config (directory_path, error_code);
289 }
290 
291 TestFIO *process_register (UInt_t *error_code) { return new TestFIO(); }
292 
293 /*void process_unload (TestFIO *algo_data, UInt_t *error_code)
294 {
295  algo_data->process_unload (error_code);
296 }*/
297 
298 void process_block (TestFIO *algo_data,
299  void *input_buffer,
300  UInt_t size_of_input_buffer,
301  void *output_buffer,
302  UInt_t size_of_output_buffer,
303  UInt_t *used_size_of_output_buffer,
304  UInt_t *error_code)
305 {
306  algo_data->process_block (input_buffer, size_of_input_buffer,
307  output_buffer, size_of_output_buffer,
308  used_size_of_output_buffer, error_code);
309 }
310 
311 void process_initialise (TestFIO *algo_data, UInt_t *error_code)
312 {
313  algo_data->process_initialise (error_code);
314 }
315 void process_reset (TestFIO *algo_data,UInt_t *error_code)
316 {
317  algo_data->process_reset (error_code);
318 }
319 void process_start (TestFIO *algo_data, UInt_t *error_code)
320 {
321  algo_data->process_start (error_code);
322 }
323 void process_stop (TestFIO *algo_data,UInt_t *error_code)
324 {
325  algo_data->process_stop (error_code);
326 }
327 void process_pause (TestFIO *algo_data,UInt_t *error_code)
328 {
329  algo_data->process_pause (error_code);
330 }
331 void process_resume (TestFIO *algo_data, UInt_t *error_code)
332 {
333  algo_data->process_resume (error_code);
334 }
335 #endif
336 
337 
338 
339 
UInt_t GetPID() const
To get the ID number for that algorithm.
header file for AgataFrameFactory.cpp
Base class for a Frame.
Definition: Frame.h:73
LogMessage & error(LogMessage &)
virtual void process_pause(UInt_t *error_code)
This method is called every time the system pauses data acquisition.
Definition: TestFIO.cpp:268
virtual UInt_t Read()
It reads the content into dedicated structures from the Frame (data part)
Definition: Frame.h:199
virtual void process_start(UInt_t *error_code)
This method is called every time the daq starts.
Definition: TestFIO.cpp:241
TestFIO algorithm embedded in Narval.
Definition: TestFIO.h:38
virtual SharedFP * Add(const FactoryItem &key_item, const FactoryItem &frame_item, bool iscons=true, const Char_t *option="")
Add a frame to the list of required frames.
Definition: Trigger.h:492
header file for TrackedFrame.cpp
virtual UInt_t SetOutput()
Definition: TestFIO.cpp:115
A Block of Frames.
Definition: FrameBlock.h:43
virtual ~TestFIO()
Definition: TestFIO.cpp:59
LogMessage & nline(LogMessage &)
void SetModel(ConfAgent::EModel model)
Definition: FrameIO.cpp:93
header file for CrystalFrame.cpp
virtual void process_block(void *input_buffer, UInt_t size_of_input_buffer, void *output_buffer, UInt_t size_of_output_buffer, UInt_t *used_size_of_output_buffer, UInt_t *error_code)
Ask the algorithm to process the data block.
virtual UInt_t Process()
Definition: TestFIO.cpp:107
virtual Bool_t Register(DFTrigger *)
To register a trigger.
Definition: FrameIO.cpp:368
static Int_t GetGlobalParameter(const char *name, UShort_t &val)
to get from narval a parameter () ... IS IT mandatory to have there a static method ...
header file for PSAFrame.cpp
virtual void process_resume(UInt_t *error_code)
this method is called every time the system resumes data acquisition
Definition: TestFIO.cpp:273
const std::string & GetConfPath()
To get the algo path associated with the current actor.
Base class for version numbers.
Definition: Version.h:38
virtual UInt_t SetInput()
Definition: TestFIO.cpp:89
virtual SharedFP * SetOutputFrame(Frame *frame)
Once a trigger has fired, the result of the algorithm is set through this.
Definition: Trigger.h:512
virtual void Detach(FrameBlock *in, FrameBlock *out)
Definition: FrameIO.cpp:741
static Int_t SetGlobalParameter(const char *name, const UShort_t &)
TestFIO()
Definition: TestFIO.cpp:41
void SetStatus(EStatus stat)
Definition: FrameIO.h:110
virtual void SetProcessMethod(const char *)
To set the current method.
header file for AgataKeyFactory.cpp
LogMessage & dolog(LogMessage &)
virtual void process_stop(UInt_t *error_code)
This method is called every time the daq stops.
Definition: TestFIO.cpp:247
virtual void ClearMessage()
To clear the current message.
FrameIO & GetFrameIO()
virtual void process_initialise(UInt_t *error_code)
Constructor implementation.
Definition: TestFIO.cpp:170
ADF::AgataFrameTrigger fTrigger
The Trigger.
Definition: TestFIO.h:52
virtual Frame * GetOutputFrame()
to get back the output frame
Definition: Trigger.h:434
virtual void Reset()=0
Reset the current frame.
virtual void Stallion(UInt_t repetition=4u)=0
Fill the frame with a given pattern (used for ADF test)
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual UInt_t ProcessBlock(ADF::FrameBlock &, ADF::FrameBlock &)
To process just a block of data.
Definition: TestFIO.cpp:135
header file for TestFIO.cpp
static void process_config(const Char_t *, UInt_t *)
to init globals (static) from a directory
Definition: TestFIO.cpp:65
virtual void Attach(FrameBlock *in, FrameBlock *out)
Attach a block to this. Rewind called if DoRewind set to true (Default)
Definition: FrameIO.cpp:724
virtual void process_reset(UInt_t *error_code)
Destructor implementation.
Definition: TestFIO.cpp:232
virtual std::string & GetProcessName()
To get the Process name.
void Universal(Bool_t b=true)
Set this trigger as universal or not.
Definition: Trigger.h:130
virtual Frame * GetInputFrame(UInt_t which=0u)
to get back the frames that define this trigger
Definition: Trigger.h:368
LogMessage Log
to send messages to the log server
virtual void SetName(const char *name)
Definition: FrameIO.h:102
It defines the interface needed to be a narval actor (Filter).