StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtStatusMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StFgtStatusMaker.cxx,v 1.3 2012/01/31 16:49:14 wwitzke Exp $
4  * Author: C. K. Riley, Nov 2011 & S. Gliske, Jan 2012
5  *
6  ***************************************************************************
7  *
8  * Description: See header
9  *
10  ***************************************************************************
11  *
12  * $Log: StFgtStatusMaker.cxx,v $
13  * Revision 1.3 2012/01/31 16:49:14 wwitzke
14  * Changed for cosmic test stand.
15  *
16  * Revision 1.2 2012/01/31 09:15:34 sgliske
17  * includes updated since status and Ped makers moved to Pool
18  *
19  * Revision 1.1 2012/01/31 08:59:43 sgliske
20  * moved StFgtStatus maker to StFgtPool
21  *
22  * Revision 1.8 2012/01/28 13:06:31 sgliske
23  * fixed some indexing issues in StFgtStatusMaker and StFgtPedStatQA
24  *
25  * Revision 1.7 2012/01/26 13:13:12 sgliske
26  * Updated to use StFgtConsts, which
27  * replaces StFgtEnums and StFgtGeomDefs
28  *
29  * Revision 1.6 2012/01/18 18:53:01 sgliske
30  * minor bug fix
31  *
32  * Revision 1.5 2012/01/18 18:07:35 sgliske
33  * directly use elec coord domian--no geoIds
34  *
35  * Revision 1.4 2012/01/17 22:24:46 sgliske
36  * removed hack for DB and
37  * fixed bug in writing status to txt file
38  *
39  * Revision 1.3 2012/01/17 20:13:12 sgliske
40  * Completely new system, based on pedestal and RMS values.
41  *
42  * Revision 1.2 2011/12/07 17:17:54 ckriley
43  * minor update
44  *
45  * Revision 1.1 2011/11/25 20:22:37 ckriley
46  * creation of statusmaker
47  *
48  *
49  *
50  **************************************************************************/
51 
52 #include <string>
53 #include "StFgtStatusMaker.h"
54 #include "StRoot/StFgtDbMaker/StFgtDb.h"
55 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
56 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
57 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
58 #include "StRoot/StFgtUtil/StFgtConsts.h"
59 #include "StRoot/StFgtPool/StFgtPedMaker/StFgtPedMaker.h"
60 
61 // constructor
62 StFgtStatusMaker::StFgtStatusMaker( const Char_t* name, const Char_t* pedMakerName ) :
63  StMaker( name ), mPedMkrName( pedMakerName ), mPedMkr(0), mTimeBin(2),
64  mMinPed( 100 ), mMaxPed( 1200 ), mMinRMS( 10 ), mMaxRMS( 80 ), mMinFrac( 0.6 ), mMaxFrac( 0.95 ), mMaxDead( 64 ), mHasFinished( 0 ) {
65 
66  mStatus = new status_t [ kFgtNumElecIds ];
67  mApvData.resize( kFgtNumRdos * kFgtNumArms * kFgtApvsPerArm );
68 };
69 
70 // deconstructor
71 StFgtStatusMaker::~StFgtStatusMaker(){
72  if( mStatus )
73  delete[] mStatus;
74 };
75 
76 // initialize
77 Int_t StFgtStatusMaker::Init(){
78  Int_t ierr = kStOk;
79 
80  // make sure the file can be opened
81  if( !mFilename.empty() ){
82  std::ofstream fout( mFilename.data() );
83  if( !fout ){
84  LOG_FATAL << "Error opening file '" << mFilename << "'" << endm;
85  ierr = kStFatal;
86  };
87  };
88 
89  // make sure there's a pedmaker
90  mPedMkr = static_cast< StFgtPedMaker* >( GetMaker( mPedMkrName.data() ) );
91  if( !mPedMkr ){
92  LOG_FATAL << "Cannot find StFgtPedMaker" << endm;
93  ierr = kStFatal;
94  };
95 
96  // make sure it will compute the peds for this timebine
97  if( !ierr ){
98  if( !mPedMkr->mTimeBinMask & (1<<mTimeBin) ){
99  LOG_WARN << "StFgtPedMaker is not set to compute the time bin needed for StFgtStatusMaker" << endm;
100  mPedMkr->mTimeBinMask |= (1<<mTimeBin);
101  LOG_WARN << "StFgtPedMaker::mTimeBinMask set to 0x" << std::hex << mPedMkr->mTimeBinMask << std::dec << endm;
102  };
103  };
104 
105  // default to invalid geoId/elecId
106  UChar_t defaultValue = (1<<INVALID_ID); // currently 0x30
107  for( UChar_t *p = mStatus; p != &mStatus[ kFgtNumElecIds ]; ++p )
108  (*p) = defaultValue;
109 
110  mApvData.assign( kFgtNumRdos * kFgtNumArms * kFgtApvsPerArm, apvData_t() );
111 
112  return ierr;
113 };
114 
115 // here is the real computation of the maker
117  Int_t ierr = kStOk;
118 
119  if( !mHasFinished ){
120  mHasFinished = 1;
121 
122  if( !mPedMkr->mHasFinished )
123  ierr = mPedMkr->Finish();
124 
125  StFgtPedMaker::pedDataVec_t& pedVec = mPedMkr->mDataVec;
126  StFgtPedMaker::pedDataVec_t::iterator pedVecIter;
127  StFgtDb *fgtTables = 0;
128 
129  if( !ierr ){
130  cout << "StFgtStatusMaker::Finish()" << endl;
131 
132  if( !mPedMkr->mDbMkrName.empty() ){
133  if( !mPedMkr->mFgtDbMkr ){
134  LOG_FATAL << "Pointer to Fgt DB Maker is null" << endm;
135  ierr = kStFatal;
136  };
137  if( !ierr ){
138  fgtTables = mPedMkr->mFgtDbMkr->getDbTables();
139 
140  if( !fgtTables ){
141  LOG_FATAL << "Pointer to Fgt DB Tables is null" << endm;
142  ierr = kStFatal;
143  };
144  };
145  };
146  };
147 
148  if( !ierr ){
149  Int_t pedIdx = 0;
150  for( pedVecIter = pedVec.begin(); pedVecIter != pedVec.end(); ++pedVecIter, ++pedIdx ){
151  if( pedVecIter->n ){
152  Int_t timebin = pedIdx % kFgtNumTimeBins;
153 
154  if( timebin == mTimeBin ){
155  Int_t elecId = pedIdx / kFgtNumTimeBins;
156  UChar_t& status = mStatus[ elecId ];
157 
158  // reset status
159  status = 0;
160 
161  if( pedVecIter->ped < mMinPed || pedVecIter->ped > mMaxPed )
162  status |= (1<<PED_OUT_OF_RANGE);
163 
164  if( pedVecIter->RMS < mMinRMS || pedVecIter->RMS > mMaxRMS )
165  status |= (1<<RMS_OUT_OF_RANGE);
166 
167  if( pedVecIter->fracClose < mMinFrac || pedVecIter->fracClose > mMaxFrac )
168  status |= (1<<FRAC_OUT_OF_RANGE);
169 
170  apvData_t &data = mApvData[ elecId / kFgtNumChannels ];
171  if( !status )
172  --data.numDead;
173  data.stripStatusVec.push_back( &mStatus[ elecId ] );
174  };
175  };
176  };
177 
178  // now check for APVs with too many dead strips
179  UChar_t deadStatus = (1<<APV_DEAD);
180  apvDataVec_t::iterator apvDataIter;
181  std::vector< status_t* >::iterator statusPtrIter;
182  for( apvDataIter = mApvData.begin(); apvDataIter != mApvData.end(); ++apvDataIter )
183  if( apvDataIter->numDead > mMaxDead )
184  for( statusPtrIter = apvDataIter->stripStatusVec.begin(); statusPtrIter != apvDataIter->stripStatusVec.end(); ++statusPtrIter )
185  *(*statusPtrIter) |= deadStatus;
186  };
187 
188  if( !ierr && !mFilename.empty() )
189  ierr = saveToFile();
190  };
191 
192  return ierr;
193 };
194 
195 // functions that actually do the saving
196 Int_t StFgtStatusMaker::saveToFile(){
197  Int_t ierr = kStOk;
198 
199  if( !mFilename.empty() ){
200  std::ofstream fout( mFilename.data(), std::ios_base::out & std::ios_base::trunc );
201 
202  if( !fout ){
203  LOG_ERROR << "Error opening file '" << mFilename << "'" << endm;
204  //cerr << "Error opening file '" << mFilename << "'" << endl;
205  ierr = kStFatal;
206  };
207 
208  Int_t elecId = 0;
209  UChar_t badId = (1<<INVALID_ID);
210 
211  // do not output those for which no data was present
212  for( UChar_t *statusPtr = mStatus; statusPtr != &mStatus[ kFgtNumElecIds ]; ++statusPtr, ++elecId )
213  if( !( *statusPtr & badId ) )
214  fout << std::dec << elecId << " 0x" << std::hex << (UShort_t)(*statusPtr) << endl;
215  };
216 
217  return ierr;
218 };
219 
220 ClassImp( StFgtStatusMaker );
Definition: Stypes.h:41