(Marian)
[u/mrichter/AliRoot.git] / TPC / AliTPCBuffer.cxx
CommitLineData
2e9f335b 1/**************************************************************************
2 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
a763ec6d 15/* $Id$ */
2e9f335b 16
a763ec6d 17// Storing digits in a binary file
18// according to the DDL mapping
066782e8 19// To be used in Alice Data Challenges
20// This class is used by AliTPCDDL.C macro
a763ec6d 21// Author: D.Favretto
066782e8 22
b62e2a95 23#include <Riostream.h>
24#include <TObjArray.h>
2e9f335b 25#include "AliTPCBuffer.h"
26#include "AliSimDigits.h"
27
28//#include "TFile.h"
29//#include "TTree.h"
30
31ClassImp(AliTPCBuffer)
32//////////////////////////////////////////////////////////////////////////////////////////////////////////////
0421c3d1 33AliTPCBuffer::AliTPCBuffer(const char* fileName){
a763ec6d 34 // Constructor
30c1018e 35#ifndef __DECCXX
0421c3d1 36 f.open(fileName,ios::binary|ios::out);
30c1018e 37#else
0421c3d1 38 f.open(fileName,ios::out);
30c1018e 39#endif
2e9f335b 40 // fout=new TFile(fileName,"recreate");
41 // tree=new TTree("tree","Values");
a763ec6d 42 fNumberOfDigits=0;
2e9f335b 43 fVerbose=0;
9f992f70 44 remove("TPCdigits.txt");
2e9f335b 45}
46
47//////////////////////////////////////////////////////////////////////////////////////////////////////////////
48AliTPCBuffer::~AliTPCBuffer(){
066782e8 49 // The destructor closes the IO stream
2e9f335b 50 f.close();
51 //delete tree;
52 //delete fout;
53}
54//////////////////////////////////////////////////////////////////////////////////////////////////////////////
176aff27 55AliTPCBuffer::AliTPCBuffer(const AliTPCBuffer &source):TObject(source){
2e9f335b 56 // Copy Constructor
a79660fb 57 this->fVerbose=source.fVerbose;
2e9f335b 58 return;
59}
60//////////////////////////////////////////////////////////////////////////////////////////////////////////////
61AliTPCBuffer& AliTPCBuffer::operator=(const AliTPCBuffer &source){
62 //Assigment operator
a79660fb 63 this->fVerbose=source.fVerbose;
2e9f335b 64 return *this;
65}
66//////////////////////////////////////////////////////////////////////////////////////////////////////////////
67/*
68void AliTPCBuffer::WriteRow(Int_t eth,AliSimDigits *digrow,Int_t minPad,Int_t maxPad,Int_t flag,Int_t sec,Int_t SubSec,Int_t row){
69 //flag=0 the whole row is written to the root file
70 //flag=1 only value in the range [minPad,MaxPasd] are written to the root file
71 //flag=2 complementary case of 1
72 Int_t Pad;
73 Int_t Dig;
74 Int_t Time;
75 tree->Branch("sec",&sec,"sec/I");
76 tree->Branch("SubSec",&SubSec,"SubSec/I");
77 tree->Branch("row",&row,"row/I");
78 tree->Branch("Pad",&Pad,"Pad/I");
79 tree->Branch("Dig",&Dig,"Dig/I");
80 tree->Branch("Time",&Time,"Time/I");
81 digrow->First();
82 do{
83 Dig=digrow->CurrentDigit(); //adc
84 Time=digrow->CurrentRow(); //time
85 Pad =digrow->CurrentColumn(); // pad
86 // cout<<"Sec "<<sec<<" row "<<row<<" Pad "<<Pad<<" Dig "<<Dig<<" Time "<<Time<<endl;
87 if(Dig>eth){
88 switch (flag){
89 case 0:{
90 tree->Fill();
a763ec6d 91 fNumberOfDigits++;
2e9f335b 92 break;
93 }//end case 0
94 case 1:{
95 if((Pad>=minPad)&&(Pad<=maxPad)){
96 tree->Fill();
a763ec6d 97 fNumberOfDigits++;
2e9f335b 98 }
99 break;
100 }//end case 1
101 case 2:{
102 if((Pad<minPad)||(Pad>maxPad)){
103 tree->Fill();
a763ec6d 104 fNumberOfDigits++;
2e9f335b 105 }
106 break;
107 }//end case 2
108 };//end switch
109 }//end if
110 }while (digrow->Next());
111 tree->Write();
112 return;
113}
114*/
115//////////////////////////////////////////////////////////////////////////////////////////////////////////////
116void AliTPCBuffer::WriteRowBinary(Int_t eth,AliSimDigits *digrow,Int_t minPad,Int_t maxPad,Int_t flag,Int_t sec,Int_t SubSec,Int_t row){
a79660fb 117 //It writes TPC digits as par the flag specifications. Being called by AliTPCDDL.C
118 //flag=0 the whole row is written into the file
2e9f335b 119 //flag=1 only value in the range [minPad,MaxPasd] are written into the file
120 //flag=2 complementary case of 1
a79660fb 121
2e9f335b 122 struct DataPad{
123 Int_t Sec;
124 Int_t SubSec;
125 Int_t Row;
126 Int_t Pad;
127 Int_t Dig;
128 Int_t Time;
129 };
130 DataPad data;
131 data.Sec=sec;
132 data.SubSec=SubSec;
133 data.Row=row;
134 digrow->First();
9f992f70 135 Int_t padID=-1;
136 Int_t ddlNumber=0;
137 ofstream ftxt;
138 if (fVerbose==2){
139 ftxt.open("TPCdigits.txt",ios::app);
140 if(sec<36)
141 ddlNumber=sec*2+SubSec;
142 else
143 ddlNumber=72+(sec-36)*4+SubSec;
144 }//end if
2e9f335b 145 do{
9f992f70 146 data.Dig=digrow->CurrentDigit(); //adc
147 data.Time=digrow->CurrentRow(); //time
148 data.Pad =digrow->CurrentColumn(); // pad
149 if(fVerbose==2)
150 if (padID!=data.Pad){
151 ftxt<<"S:"<<data.Sec<<" DDL:"<<ddlNumber<<" R:"<<data.Row<<" P:"<<data.Pad<<endl;
152 padID=data.Pad;
153 }//end if
2e9f335b 154 if(data.Dig>eth){
155 switch (flag){
156 case 0:{
a763ec6d 157 fNumberOfDigits++;
2e9f335b 158 f.write((char*)(&data),sizeof(data));
9f992f70 159 if(fVerbose==2)
160 ftxt<<"A:"<<data.Dig<<" T:"<<data.Time<<endl;
2e9f335b 161 break;
162 }//end case 0
163 case 1:{
164 if((data.Pad>=minPad)&&(data.Pad<=maxPad)){
165 f.write((char*)(&data),sizeof(data));
9f992f70 166 if(fVerbose==2)
167 ftxt<<"A:"<<data.Dig<<" T:"<<data.Time<<endl;
a763ec6d 168 fNumberOfDigits++;
2e9f335b 169 }
170 break;
171 }//end case 1
172 case 2:{
173 if((data.Pad<minPad)||(data.Pad>maxPad)){
174 f.write((char*)(&data),sizeof(data));
9f992f70 175 if(fVerbose==2)
176 ftxt<<"A:"<<data.Dig<<" T:"<<data.Time<<endl;
a763ec6d 177 fNumberOfDigits++;
2e9f335b 178 }
179 break;
180 }//end case 2
181 };//end switch
182 }//end if
183 }while (digrow->Next());
9f992f70 184 if (fVerbose==2)
185 ftxt.close();
2e9f335b 186 return;
187}
188//////////////////////////////////////////////////////////////////////////////////////////////////////////////