StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFpdMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StFpdMaker.cxx,v 1.4 2005/11/26 01:27:00 perev Exp $
4  *
5  * Author: AKIO OGAWA
6  *
7  ***************************************************************************
8  *
9  * Description: FPD offline software: maker to insert FPDp raw data onto StEvent
10  *
11  ***************************************************************************
12  *
13  * $Log: StFpdMaker.cxx,v $
14  * Revision 1.4 2005/11/26 01:27:00 perev
15  * created StEvent added to data. LeakOff
16  *
17  * Revision 1.3 2003/07/18 18:31:47 perev
18  * test for nonexistance of XXXReader added
19  *
20  * Revision 1.2 2002/10/17 02:03:10 akio
21  * modification along with StEvent modification for 2003
22  *
23  * Revision 1.1 2002/01/16 20:21:07 akio
24  * first version
25  *
26  *
27  **************************************************************************/
28 
29 #include "StFpdMaker.h"
30 #include <stdlib.h>
31 #include "StEventTypes.h"
32 //VP#include "StDaqLib/GENERIC/EventReader.hh"
33 #include "StDaqLib/FPD/FPD_Reader.hh"
34 #include "StDAQMaker/StDAQReader.h"
35 #include "TFile.h"
36 #include "TH1.h"
37 
38 ClassImp(StFpdMaker)
39 
40 //_____________________________________________________________________________
41 
42 StFpdMaker::StFpdMaker(const char *name):StMaker(name) {}
43 
44 //_____________________________________________________________________________
45 
46 StFpdMaker::~StFpdMaker(){}
47 
48 //_____________________________________________________________________________
49 
50 Int_t StFpdMaker::Init(){
51  return StMaker::Init();
52 }
53 
54 //_____________________________________________________________________________
55 
57 
58 #ifdef FPDP_DEBUG
59  cout << "===========FPDP_DEBUG=========================================" << endl;
60 #endif
61  //cout << "StFpdMaker Make() starting..................................." << endl;
62 
63  StFpdCollection* fpdCollection;
64  //check for existence of collections
65  mEvent = (StEvent *) GetInputDS("StEvent");
66  if(!mEvent){
67  //create own StEvent
68  cout << "StFpdMaker found no StEvent... Create local StEvent" << endl;
69  mEvent = new StEvent;
70  AddData(mEvent);
71  }
72  //check fpdCollection in StEvent.
73  //If not there, create it and set
74  //cout << "StFpdMaker Checking for Fpd collection in StEvent..." << endl;
75  fpdCollection = mEvent->fpdCollection();
76  if(fpdCollection != 0) {
77  //cout << "StFpdMaker fpdCollection Exists" << endl;
78  } else {
79  cout << "StFpdMaker fpdCollection does not exist" << endl;
80  cout << "StFpdMaker creating fpdCollection in StEvent ... ";
81  fpdCollection = new StFpdCollection();
82  mEvent->setFpdCollection(fpdCollection);
83  fpdCollection = mEvent->fpdCollection();
84  if (fpdCollection) cout << "OK"<< endl;
85  else{
86  cout << "FAILED" << endl;
87  return kStWarn;
88  }
89  }
90 
91  //check bbcTriggerDetector in StEvent->triggerDetectorCollection.
92  //If not there, create it and set
93  //cout << "StFpdMaker Checking for TriggerDetector collection in StEvent..." << endl;
94  StTriggerDetectorCollection* trg = mEvent->triggerDetectorCollection();
95  if(trg == 0){
96  cout << "StFpdMaker found no StTriggerDetectorCollection... Create and add" << endl;
98  mEvent->setTriggerDetectorCollection(trg);
99  }
100  StBbcTriggerDetector& bbcTriggerDetector = trg->bbc();
101 
102  // Get Daq reader
103  cout << "StFapdMaker getting data from FPDDAQ Reader ... " << endl;
104  St_DataSet* daqReaderDS = GetDataSet("StDAQReader");
105  if (!daqReaderDS) {
106  cout << "StFpdMaker No StDAQReader dataset. Event skipped" << endl;
107  return kStWarn;
108  }
109  StDAQReader* daqReader = (StDAQReader*)(daqReaderDS->GetObject());
110  if (!daqReader) {
111  cout << "StFpdMaker No StDAQReader object. Event skipped" << endl;
112  return kStWarn;
113  }
114  if (!(daqReader->FPDPresent())) {
115  cout << "StFpdMaker FPD is not in datastream. Event skipped" << endl;
116  return kStWarn;
117  }
118  StFpdReaderInterface* fpdReader = daqReader->getFPDReader();
119  if (!fpdReader){
120  cout << "StFpdMaker Failed to getFpdReader()...." << endl;
121  }
122  // fpdReader->printRawData();
123 
124  //copy daq data to FPD and BBC collections
125  //cout << "StFpdMaker Unpacking data..." << endl;
126  fpdCollection->setToken(fpdReader->GetEventNumber());
127  for (unsigned int i=0;i<fpdCollection->numberOfADC();i++){
128  fpdCollection->setAdc(i,fpdReader->GetAdc(i));
129  }
130  for (unsigned int i=0;i<fpdCollection->numberOfTDC();i++){
131  fpdCollection->setTdc(i,fpdReader->GetTdc(i));
132  }
133  for (unsigned int i=0;i<fpdCollection->numberOfRegisters();i++){
134  fpdCollection->setRegister(i,fpdReader->GetReg(i));
135  }
136  for (unsigned int i=0;i<fpdCollection->numberOfPedestal();i++){
137  fpdCollection->setPedestal(i,fpdReader->GetPed(i));
138  }
139  for (unsigned int i=0;i<fpdCollection->numberOfScalers();i++){
140  fpdCollection->setScaler(i,fpdReader->GetScl(i));
141  }
142  // for (unsigned int i=0;i<bbcTriggerDetector.numberOfPMTs();i++){
143  for (unsigned int i=0;i<32;i++){
144  bbcTriggerDetector.setAdc(i,fpdReader->GetBbcAdc(i));
145  bbcTriggerDetector.setTdc(i,fpdReader->GetBbcAdc(i+32));
146  }
147  for (unsigned int i=0;i<bbcTriggerDetector.numberOfRegisters();i++){
148  bbcTriggerDetector.setRegister(i,fpdReader->GetBbcAdc(i+64));
149  }
150  for (unsigned int i=0;i<bbcTriggerDetector.numberOfPedestalData();i++){
151  bbcTriggerDetector.setPedestal(i,fpdReader->GetBbcPed(i));
152  }
153  for (unsigned int i=0;i<bbcTriggerDetector.numberOfScalars();i++){
154  bbcTriggerDetector.setScalar(i,fpdReader->GetBbcScl(i));
155  }
156  //cout << "StFpdMaker Make() finished..................................." << endl;
157  //fpdCollection->dump();
158  //bbcTriggerDetector.dump();
159  return kStOK;
160 }
161 
162 //_____________________________________________________________________________
164  // TFile theFile("fpd.root","RECREATE","fpdstudy");
165  // theFile.cd();
166  // nAdcHitHisto->Write();
167  // nTdcHitHisto->Write();
168  return StMaker::Finish();
169 }
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
virtual Int_t Make()
Definition: StFpdMaker.cxx:56
virtual Int_t Finish()
Definition: StFpdMaker.cxx:163
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Definition: Stypes.h:42
Definition: Stypes.h:40
virtual Int_t Finish()
Definition: StMaker.cxx:776