FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PixelDigiWriteToFile.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 /*
9  * PixelDigiWriteToFile.h
10  *
11  * Created on: 19.02.2016
12  * Author: R. Karabowicz
13  */
14 
15 #include "PixelDigiWriteToFile.h"
16 
17 #include "FairLogger.h"
18 #include "FairRootManager.h"
19 #include "PixelDigi.h"
20 
21 #include <TClonesArray.h>
22 
24  : PixelDigiWriteToFile("Pixel DigiWriter", 0)
25 {}
26 
28  : PixelDigiWriteToFile("Pixel DigiWriter", iVerbose)
29 {}
30 
31 PixelDigiWriteToFile::PixelDigiWriteToFile(const char* name, Int_t iVerbose)
32  : FairTask(name, iVerbose)
33  , fDigis(nullptr)
34  , fOutputFileName("test.dat")
35  , fNofOutputFiles(0)
36  , fOutputFiles()
37  , fDivideLevel(0)
38  , fRunId(0)
39  , fMCEntryNo(0)
40  , fPartNo(0)
41 
42 {
43  Reset();
44 }
45 
47 
48 void PixelDigiWriteToFile::Exec(Option_t* /*opt*/)
49 {
50  Reset();
51 
52  Int_t nofDigis = fDigis->GetEntriesFast();
53 
54  for (Int_t ifile = 0; ifile < fNofOutputFiles; ifile++) {
55  fOutputFiles[ifile] << "EVENT BEGIN; RUNID = " << fRunId << "; MCENTRYNO = " << fMCEntryNo
56  << "; PARTNO = " << ifile << ";" << std::endl;
57  }
58 
59  for (Int_t iDigi = 0; iDigi < nofDigis; iDigi++) {
60  PixelDigi* currentDigi = static_cast<PixelDigi*>(fDigis->At(iDigi));
61 
62  Int_t detId = currentDigi->GetDetectorID();
63  Int_t feId = currentDigi->GetFeID();
64  Int_t col = currentDigi->GetCol();
65  Int_t row = currentDigi->GetRow();
66  Double_t charge = currentDigi->GetCharge();
67 
68  Int_t fileToSave = 0;
69  if (fDivideLevel == 1) {
70  fileToSave = detId / 256 - 1;
71  } else if (fDivideLevel == 2) {
72  fileToSave = (detId / 256 - 1) * 4 + (detId % 256 - 1);
73  }
74  fOutputFiles[fileToSave] << detId << " " << feId << " " << col << " " << row << " " << charge << std::endl;
75  }
76 
77  for (Int_t ifile = 0; ifile < fNofOutputFiles; ifile++) {
78  fOutputFiles[ifile] << "EVENT END" << std::endl;
79  }
80 
81  fMCEntryNo++;
82 }
83 
84 InitStatus PixelDigiWriteToFile::Init()
85 {
86  // Get input array
88 
89  if (!ioman)
90  LOG(fatal) << "No FairRootManager";
91  fDigis = static_cast<TClonesArray*>(ioman->GetObject("PixelDigis"));
92 
93  if (!fDigis)
94  LOG(warn) << "PixelDigiWriteToFile::Init() No input PixelDigis array!";
95 
96  LOG(info) << "-I- " << fName.Data() << "::Init(). Initialization succesfull.";
97 
98  fRunId = ioman->GetRunId();
99 
100  if (fDivideLevel == 0) {
101  fNofOutputFiles = 1;
102  fOutputFiles[0].open(fOutputFileName.Data(), std::fstream::out);
103  } else {
104  if (fDivideLevel == 1) {
105  fNofOutputFiles = 3; // 1 file per station (3 stations)
106  } else if (fDivideLevel == 2) {
107  fNofOutputFiles = 12; // 1 file per sensor (3 stations times 4 sensors)
108  } else {
109  LOG(fatal) << "PixelDigiWriteToFile::Init(), fDivideLevel = " << fDivideLevel
110  << " unknown, it has to be in the range <0,2>";
111  return kFATAL;
112  }
113 
114  for (Int_t ifile = 0; ifile < fNofOutputFiles; ifile++) {
115  TString fileName = fOutputFileName;
116  TString uniqFile = Form(".p%d.", ifile);
117  fileName.Replace(fileName.Last('.'), 1, uniqFile.Data());
118  fOutputFiles[ifile].open(fileName.Data(), std::fstream::out);
119  }
120  }
121 
122  return kSUCCESS;
123 }
124 
125 InitStatus PixelDigiWriteToFile::ReInit()
126 {
128 
129  InitStatus Status = kFATAL;
130  if (!ioman) {
131  LOG(fatal) << "No FairRootManager found.";
132  } else {
133  fRunId = ioman->GetRunId();
134  fMCEntryNo = 0;
135  Status = kSUCCESS;
136  }
137  return Status;
138 }
139 
140 void PixelDigiWriteToFile::Finish()
141 {
142  for (Int_t ifile = 0; ifile < fNofOutputFiles; ifile++) {
143  fOutputFiles[ifile].close();
144  }
145 }
146 
InitStatus
Definition: FairTask.h:33
Int_t GetRow()
Definition: PixelDigi.h:49
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
TObject * GetObject(const char *BrName)
Int_t GetDetectorID()
Definition: PixelDigi.h:45
Int_t GetCol()
Definition: PixelDigi.h:48
virtual void Exec(Option_t *opt)
Double_t GetCharge()
Definition: PixelDigi.h:47
Int_t GetFeID()
Definition: PixelDigi.h:46