Cat
Processus.h
Go to the documentation of this file.
1 // $Id: Processus.h,v 1.9 2006/06/05 08:28:14 fmachefe Exp $
2 #ifndef INCLUDE_PROCESSUS_H
3 #define INCLUDE_PROCESSUS_H 1
4 
5 #ifdef _NETWORK_
6 #include <dis.hxx>
7 #endif
8 
9 #include "TFile.h"
10 #include "Application.h"
11 #include "Options.h"
12 #include "Object.h"
13 #include "Element.h"
14 #include "Data.h"
15 #include "ProcTimer.h"
16 
24 struct ProcState {
25  int nevent;
26  int nerrors;
27  float time;
28  char state[256];
29 };
30 
31 
32 class Processus : public Object {
33 public:
34  enum states { ERR=-1 , NOT_OK , OK };
36  Processus ( );
37 
38  virtual ~Processus( );
39 
43  // bool cmdline( std::vector <std::string> );
44 
48  // virtual bool command( std::vector <std::string> ) ;
49 
54  StatusCode startProcessing ();
55 
60  StatusCode endProcessing ();
61 
65  virtual StatusCode initialize( ) = 0 ;
66 
70  virtual StatusCode execute( ) = 0 ;
71 
75  virtual StatusCode finalize( ) = 0 ;
76 
80  virtual Processus* clone( ) = 0 ;
81 
85  void clean()
86  {
87  m_element=0;
88  if (0!=m_state) {
89  delete m_state;
90  m_state=0;
91  }
92 #ifdef _NETWORK_
93  warning("Cleaning state service : should it be done ?","Processus::clean")
94  if (0!=m_stateService)
95  {
96  delete m_stateService;
97  }
98 #endif
99  }
100 
101 
106  void setStorage (std::string storage) {
107  m_storage = storage;
108  }
109 
114  Data* data(){
115  return m_data;
116  }
117 
122  std::vector<double> data(unsigned int row){
123  return m_data->vector(row);
124  }
125 
130  std::vector<double> data(std::string name){
131  return m_data->vector(name);
132  }
133 
138  Histo1D* hist1d(unsigned int row){
139  return m_data->hist1d(row);
140  }
141 
146  Histo2D* hist2d(unsigned int row){
147  return m_data->hist2d(row);
148  }
149 
153  void addDataStream (std::string name, std::string title){
154  m_data->addDataStream(name, title);
155  }
156 
160  void addHisto1d (TH1D* h){
161  m_data->addHisto1d(h);
162  }
163 
167  void addHisto2d (TH2D* h){
168  m_data->addHisto2d(h);
169  }
170 
175  StatusCode dataFill(int i, double val){
176  if (m_data->vectorPtr(i)!=0){
177  m_data->vectorPtr(i)->push_back(val);
178  return StatusCode::SUCCESS;
179  }
180  else {
181  return StatusCode::FAILURE;
182  }
183  }
184 
189  StatusCode dataFill(std::string name, double val){
190  int row=m_data->rowFromName(name);
191  if (row<0) return StatusCode::FAILURE;
192  if (m_data->vectorPtr(row)!=0){
193  m_data->vectorPtr(row)->push_back(val);
194  return StatusCode::SUCCESS;
195  }
196  else {
197  return StatusCode::FAILURE;
198  }
199  }
200 
205  std::string storage () {
206  if ( 0 == m_storage.compare("") )
207  {
208  return name();
209  }
210  return m_storage;
211  }
212 
218  m_state = new ProcState ();
219  m_state->nevent = 0;
220  m_state->nerrors = 0;
221  m_state->time = 0;
222  strcpy( m_state->state,"");
223  // setState( OK );
224  m_element = element;
225  }
226 
232  return m_element;
233  }
234 
235 
236 
240  void incNErrors () ;
241 
246  void setNErrors ( unsigned int ) ;
247 
252  unsigned int nErrors () ;
253 
258  TFile* rootFile () {
259  return m_rootFile;
260  }
261 
265  void openRootFile ( ) ;
266 
270  void closeRootFile ( );
271 
275  void startChrono(){
276  m_start = time(0);
277  }
278 
283  void setLogMsg (std::string logMsg) {
284  m_logMsg = logMsg;
285  }
286 
291  std::string logMsg () {
292  return m_logMsg;
293  }
294 
299  void setState ( int state );
300 
301 #ifdef _NETWORK_
302 
306  bool startServices();
307 
312  virtual bool startService();
313 
318  bool updateServices();
319 
324  void setUpdateDelay (int updateDelay) {
325  m_updateDelay = updateDelay;
326  if ( 0 != m_timerService ){
327  m_timerService->setDelay ( updateDelay );
328  }
329  }
330 
335  int updateDelay () {
336  return m_updateDelay;
337  }
338 
339 #endif
340  double elapsedTime (){
341  return difftime(time(0),m_start);
342  }
343  double elapsedTime (time_t start){
344  return ((time(0)-start));
345  }
346 
347 protected:
348  Element* m_element; //< Element on which the processus is applied
349 
350 #ifdef _NETWORK_
351  bool m_service;
352  int m_updateDelay;
353  ProcTimer *m_timerService;
354  DimService *m_valueService;
355 #endif
356 
357 private:
359  TFile *m_rootFile;
361 
362  time_t m_start;
364  std::string m_storage; //< Storage file name
365  std::string m_logMsg;
366 #ifdef _NETWORK_
367  DimService* m_stateService;
368 #endif
369 };
370 
371 #endif // INCLUDE_PROCESSUS_H
Definition: Object.h:21
void setElement(Element *element)
Definition: Processus.h:217
std::vector< double > data(std::string name)
Definition: Processus.h:130
int nerrors
Definition: Processus.h:26
ProcState * m_state
Definition: Processus.h:363
std::string m_logMsg
Definition: Processus.h:365
void addDataStream(std::string name, std::string title)
Definition: Processus.h:153
std::vector< double > data(unsigned int row)
Definition: Processus.h:122
Options * m_options
Definition: Processus.h:360
void clean()
Definition: Processus.h:85
std::string m_storage
Definition: Processus.h:364
TFile * rootFile()
Definition: Processus.h:258
std::string logMsg()
Definition: Processus.h:291
double elapsedTime()
Definition: Processus.h:340
void setStorage(std::string storage)
Definition: Processus.h:106
Element * m_element
Definition: Processus.h:348
void addHisto2d(TH2D *h)
Definition: Processus.h:167
void startChrono()
Definition: Processus.h:275
Histo1D * hist1d(unsigned int row)
Definition: Processus.h:138
void setLogMsg(std::string logMsg)
Definition: Processus.h:283
float time
Definition: Processus.h:27
time_t m_start
Definition: Processus.h:362
int nevent
Definition: Processus.h:25
void addHisto1d(TH1D *h)
Definition: Processus.h:160
Element * element()
Definition: Processus.h:231
StatusCode dataFill(int i, double val)
Definition: Processus.h:175
Definition: Data.h:16
TFile * m_rootFile
Definition: Processus.h:359
Histo2D * hist2d(unsigned int row)
Definition: Processus.h:146
std::string storage()
Definition: Processus.h:205
StatusCode dataFill(std::string name, double val)
Definition: Processus.h:189
Data * data()
Definition: Processus.h:114
double elapsedTime(time_t start)
Definition: Processus.h:343
char state[256]
Definition: Processus.h:28
Data * m_data
Definition: Processus.h:358