er  dev
ERTektronixSource.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERTektronixSource.h"
10 
11 #include "FairRootManager.h"
12 #include "FairRun.h"
13 
14 #include <iostream>
15 using namespace std;
16 
17 Int_t ERTektronixSource::fEvent = 0;
18 //--------------------------------------------------------------------------------------------------
19 ERTektronixSource::ERTektronixSource():
20 fNPoints(1000),
21 fNProcessedFiles(0),
22 fNForProcFiles(0),
23 fNChanels(4),
24 fRawEvents(NULL)
25 {
26 }
27 //--------------------------------------------------------------------------------------------------
28 ERTektronixSource::ERTektronixSource(const ERTektronixSource& source){
29 }
30 //--------------------------------------------------------------------------------------------------
31 ERTektronixSource::~ERTektronixSource(){
32 
33 }
34 //--------------------------------------------------------------------------------------------------
35 Bool_t ERTektronixSource::Init(){
36  //input files opening
37  ifstream* f = new ifstream();
38  for (std::map<int,vector<TString> >::iterator it=fPaths.begin(); it!=fPaths.end(); ++it){
39  Int_t chanel = it->first;
40  vector<TString> chanelFiles = it->second;
41  for (Int_t iFile = 0; iFile < chanelFiles.size(); iFile++ ){
42  f->open(chanelFiles[iFile]);
43  if (!f->is_open()){
44  cerr << "Couldn`t open file " << chanelFiles[iFile] << endl;
45  return kFALSE;
46  }
47  else{
48  f->close();
49  }
50  }
51  }
52  delete f;
53 
54  Int_t eventNb = fPaths.begin()->second.size();
55  for (std::map<int,vector<TString> >::iterator it=fPaths.begin(); it!=fPaths.end(); ++it){
56  if (it->second.size() != eventNb){
57  cerr << "Differen event count in chanels" << endl;
58  return kFALSE;
59  }
60  }
61 
62  //Register new objects in output file
63  fRawEvents = new ERNeuRadRawEvent*[fNChanels];
64  FairRootManager* ioman = FairRootManager::Instance();
65  for (Int_t iChanel = 0; iChanel < fNChanels; iChanel++){
66  fRawEvents[iChanel] = new ERNeuRadRawEvent(fNPoints);
67  TString bName;
68  bName.Form("ch%d.",iChanel+1);
69  ioman->Register(bName, "Tektronix", fRawEvents[iChanel], kTRUE);
70  }
71 
72  return kTRUE;
73 }
74 //--------------------------------------------------------------------------------------------------
75 Int_t ERTektronixSource::ReadEvent(UInt_t id){
76  Reset();
77  //Проверяем есть ли еще события для обработки
78  if (fPaths.begin()->second.size()+1 == fEvent)
79  return 1;
80  if (fEvent == 0){
81  fEvent ++;
82  return 0;
83  }
84 
85  ifstream* f = new ifstream();
86  Double_t amplitude;
87  for (std::map<int,vector<TString> >::iterator it=fPaths.begin(); it!=fPaths.end(); ++it){
88  Int_t chanel = it->first;
89  vector<TString> chanelFiles= it->second;
90  f->open(chanelFiles[fEvent-1]);
91  for (Int_t iPoint = 0; iPoint < fNPoints; iPoint++){
92  if (f->eof()){
93  f->close();
94  cout << "Not enough points in file " << chanelFiles[fEvent-1] << " for " << chanel << " chanel!" <<endl;
95  break;
96  }
97  (*f) >> amplitude;
98  fRawEvents[chanel-1]->SetAmp(amplitude,iPoint);
99  Double_t time = 5e-04+iPoint*1e-01;
100  fRawEvents[chanel-1]->SetTime(time,iPoint);
101  }
102  cout << "File " << chanelFiles[fEvent-1] << " for " << chanel << " chanel finished" <<endl;
103  }
104  delete f;
105  fEvent ++;
106  return 0;
107 }
108 //--------------------------------------------------------------------------------------------------
109 void ERTektronixSource::Close(){
110 }
111 //--------------------------------------------------------------------------------------------------
112 void ERTektronixSource::Reset(){
113  for (Int_t iChanel = 0; iChanel < fNChanels; iChanel++){
114  fRawEvents[iChanel]->Reset();
115  }
116 }
117 //--------------------------------------------------------------------------------------------------
118 void ERTektronixSource::AddFile(Int_t chanel, TString path){
119  fPaths[chanel].push_back(path);
120  cout << "Input file " << path << " added to " << chanel << "chanel" << endl;
121 }
122 //--------------------------------------------------------------------------------------------------
task for reading raw data from text files
class for raw data obtained from measurements or simulations