CMS 3D CMS Logo

CocoaDaqReaderRoot.cc
Go to the documentation of this file.
1 #include "../interface/CocoaDaqReaderRoot.h"
2 #include "TFile.h"
7 
9 
10 #include <iostream>
11 #include <string>
12 
13 #include "TClonesArray.h"
14 
15 
16 //----------------------------------------------------------------------
18 {
19  if ( ALIUtils::debug >= 3) std::cout << " CocoaDaqReaderRoot opening file: " << m_inFileName << std::endl;
20  // Open root file
21  theFile = new TFile(m_inFileName.c_str());
22  if( !theTree ) {
23  std::cerr << " CocoaDaqReaderRoot TTree file not found " << m_inFileName << std::endl;
25  }
26 
27  // Read TTree named "CocoaDaq" in memory. !! SHOULD BE CALLED Alignment_Cocoa
28  theTree = (TTree*)theFile->Get("CocoaDaq");
29  // theTree = (TTree*)theFile->Get("Alignment_Link_Cocoa");
30 
31  if( !theTree ) {
32  std::cerr << " CocoaDaqReaderRoot TTree in file " << m_inFileName << " should be called 'CocoaDaq' " << std::endl;
34  }
35  TBranch *branch = theTree->GetBranch("Alignment_Cocoa");
36 
37  nev = branch->GetEntries(); // number of entries in Tree
38  //if ( ALIUtils::debug >= 2) std::cout << "CocoaDaqReaderRoot::CocoaDaqReaderRoot: number of entries in Tree " << nev << std::endl;
39 
40  nextEvent = 0;
41 
42  // Event object must be created before setting the branch address
44 
45  // link pointer to Tree branch
46  theTree->SetBranchAddress("Alignment_Cocoa", &theEvent); // !! SHOULD BE CALLED Alignment_Cocoa
47  // theTree->SetBranchAddress("Alignment_Link", &theEvent); // !! SHOULD BE CALLED Alignment_Cocoa
48 
50 
51 }
52 
53 //----------------------------------------------------------------------
55 {
56  theFile->Close();
57 }
58 
59 //----------------------------------------------------------------------
61 {
62  return ReadEvent( nextEvent );
63 }
64 
65 
66 //----------------------------------------------------------------------
68 {
69  std::vector<OpticalAlignMeasurementInfo> measList;
70 
71  int nb = 0; // dummy, number of bytes
72  // Loop over all events
73  nb = theTree->GetEntry(nev); // read in entire event
74 
75  if ( ALIUtils::debug >= 3) std::cout << "CocoaDaqReaderRoot reading event " << nev << " " << nb << std::endl;
76  if( nb == 0 ) return 0; //end of file reached??
77 
78  // Every n events, dump one to screen
79  int n = 1;
80  if(nev%n == 0 && ALIUtils::debug >= 3 ) theEvent->DumpIt();
81 
82  //if ( ALIUtils::debug >= 3) std::cout<<" CocoaDaqReaderRoot::ReadEvent "<< nev <<std::endl;
83 
84  if ( ALIUtils::debug >= 3) std::cout<<" CocoaDaqReaderRoot::ReadEvent npos2D "<< theEvent->GetNumPos2D() << " nCOPS " << theEvent->GetNumPosCOPS() << std::endl;
85 
86  for(int ii=0; ii<theEvent->GetNumPos2D(); ii++) {
88  if ( ALIUtils::debug >= 4) std::cout<<"2D sensor "<<ii<<" has ID = "<<pos2D->GetID()<< std::endl;
89  pos2D->DumpIt("2DSENSOR");
90  measList.push_back( GetMeasFromPosition2D( pos2D ) );
91  }
92  for(int ii=0; ii<theEvent->GetNumPosCOPS(); ii++) {
94  measList.push_back( GetMeasFromPositionCOPS( posCOPS ) );
95  if ( ALIUtils::debug >= 4) {
96  std::cout<<"COPS sensor "<<ii<<" has ID = "<<posCOPS->GetID()<< std::endl;
97  posCOPS->DumpIt("COPS");
98  }
99  }
100  for(int ii=0; ii<theEvent->GetNumTilt(); ii++) {
101  AliDaqTilt* tilt = (AliDaqTilt*) theEvent->GetArray_Tilt()->At(ii);
102  measList.push_back( GetMeasFromTilt( tilt ) );
103  if ( ALIUtils::debug >= 4) {
104  std::cout<<"TILT sensor "<<ii<<" has ID = "<<tilt->GetID()<< std::endl;
105  tilt->DumpIt("TILT");
106  }
107 
108  }
109  for(int ii=0; ii<theEvent->GetNumDist(); ii++) {
111  measList.push_back( GetMeasFromDist( dist ) );
112  if ( ALIUtils::debug >= 4) {
113  std::cout<<"DIST sensor "<<ii<<" has ID = "<<dist->GetID()<< std::endl;
114  dist->DumpIt("DIST");
115  }
116  }
117 
118  nextEvent = nev + 1;
119 
120  BuildMeasurementsFromOptAlign( measList );
121 
122  return 1;
123 
124 }
125 
126 //----------------------------------------------------------------------
128 {
130 
131  meas.type_ = "SENSOR2D";
132  meas.name_ = std::string(pos2D->GetID().Data());
133  //- std::vector<std::string> measObjectNames_;
134  std::vector<bool> isSimu;
135  for( size_t jj = 0; jj < 2; jj++ ){
136  isSimu.push_back(false);
137  }
138  meas.isSimulatedValue_ = isSimu;
139  std::vector<OpticalAlignParam> paramList;
140  OpticalAlignParam oaParam1;
141  oaParam1.name_ = "H:";
142  oaParam1.value_ = pos2D->GetX()/100.;
143  oaParam1.error_ = pos2D->GetXerror()/100.;
144  paramList.push_back(oaParam1);
145 
146  OpticalAlignParam oaParam2;
147  oaParam2.name_ = "V:";
148  oaParam2.value_ = pos2D->GetY()/100.;
149  oaParam2.error_ = pos2D->GetYerror()/100.;
150  paramList.push_back(oaParam2);
151 
152  meas.values_ = paramList;
153 
154  return meas;
155 }
156 
157 
158 //----------------------------------------------------------------------
160 {
162 
163  meas.type_ = "COPS";
164  meas.name_ = std::string(posCOPS->GetID().Data());
165  //- std::vector<std::string> measObjectNames_;
166  std::vector<bool> isSimu;
167  for( size_t jj = 0; jj < 4; jj++ ){
168  isSimu.push_back(false);
169  }
170  meas.isSimulatedValue_ = isSimu;
171 
172  std::vector<OpticalAlignParam> paramList;
173  OpticalAlignParam oaParam1;
174  oaParam1.name_ = "U:";
175  oaParam1.value_ = posCOPS->GetUp()/100.;
176  oaParam1.error_ = posCOPS->GetUpError()/100.;
177  paramList.push_back(oaParam1);
178 
179  OpticalAlignParam oaParam2;
180  oaParam2.name_ = "U:";
181  oaParam2.value_ = posCOPS->GetDown()/100.;
182  oaParam2.error_ = posCOPS->GetDownError()/100.;
183  paramList.push_back(oaParam2);
184 
185  OpticalAlignParam oaParam3;
186  oaParam3.name_ = "U:";
187  oaParam3.value_ = posCOPS->GetRight()/100.;
188  oaParam3.error_ = posCOPS->GetRightError()/100.;
189  paramList.push_back(oaParam3);
190 
191  OpticalAlignParam oaParam4;
192  oaParam4.name_ = "U:";
193  oaParam4.value_ = posCOPS->GetLeft()/100.;
194  oaParam4.error_ = posCOPS->GetLeftError()/100.;
195  paramList.push_back(oaParam4);
196 
197  meas.values_ = paramList;
198 
199  return meas;
200 
201 }
202 
203 //----------------------------------------------------------------------
205 {
207 
208  meas.type_ = "TILTMETER";
209  meas.name_ = std::string(tilt->GetID().Data());
210  //- std::vector<std::string> measObjectNames_;
211  std::vector<bool> isSimu;
212  for( size_t jj = 0; jj < 2; jj++ ){
213  isSimu.push_back(false);
214  }
215  meas.isSimulatedValue_ = isSimu;
216  std::vector<OpticalAlignParam> paramList;
217  OpticalAlignParam oaParam;
218  oaParam.name_ = "T:";
219  oaParam.value_ = tilt->GetTilt();
220  oaParam.error_ = tilt->GetTiltError();
221  paramList.push_back(oaParam);
222 
223  meas.values_ = paramList;
224 
225  return meas;
226 
227 }
228 
229 
230 //----------------------------------------------------------------------
232 {
234 
235  meas.type_ = "DISTANCEMETER";
236  meas.name_ = std::string(dist->GetID().Data());
237  //- std::vector<std::string> measObjectNames_;
238  std::vector<bool> isSimu;
239  for( size_t jj = 0; jj < 2; jj++ ){
240  isSimu.push_back(false);
241  }
242  meas.isSimulatedValue_ = isSimu;
243  std::vector<OpticalAlignParam> paramList;
244  OpticalAlignParam oaParam;
245  oaParam.name_ = "D:";
246  oaParam.value_ = dist->GetDistance()/100.;
247  oaParam.error_ = dist->GetDistanceError()/100.;
248  paramList.push_back(oaParam);
249 
250  meas.values_ = paramList;
251 
252  return meas;
253 }
254 
255 
256 //----------------------------------------------------------------------
257 void CocoaDaqReaderRoot::BuildMeasurementsFromOptAlign( std::vector<OpticalAlignMeasurementInfo>& measList )
258 {
259  if ( ALIUtils::debug >= 3) std::cout << "@@@ CocoaDaqReaderRoot::BuildMeasurementsFromOptAlign " << std::endl;
260 
261  //set date and time of current measurement
262  // if( wordlist[0] == "DATE:" ) {
263  // Measurement::setCurrentDate( wordlist );
264  // }
265 
266  //---------- loop measurements read from ROOT and check for corresponding measurement in Model
267  // ALIint nMeasModel = Model::MeasurementList().size();
268  ALIint nMeasRoot = measList.size();
269  if(ALIUtils::debug >= 4) {
270  std::cout << " Building " << nMeasRoot << " measurements from ROOT file " << std::endl;
271  }
272 
273  //--- Loop to Measurements in Model and check for corresponding measurement in ROOT
274  std::vector< Measurement* >::const_iterator vmcite;
275  for( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite ) {
276  ALIint fcolon = (*vmcite)->name().find(':');
277  ALIstring oname = (*vmcite)->name();
278  oname = oname.substr(fcolon+1,oname.length());
279 
280  //---------- loop measurements read from ROOT
281  ALIint ii;
282  for(ii = 0; ii < nMeasRoot; ii++) {
283  OpticalAlignMeasurementInfo measInfo = measList[ii];
284  std::cout << " measurement name ROOT " << measInfo.name_ << " Model= " << (*vmcite)->name() << " short " << oname << std::endl;
285 
286  if( oname == measInfo.name_ ) {
287  //-------- Measurement found, fill data
288  //---- Check that type is the same
289  if( (*vmcite)->type() != measInfo.type_ ) {
290  std::cerr << "!!! Measurement from ROOT file: type in file is "
291  <<measInfo.type_ << " and should be " << (*vmcite)->type() << std::endl;
292  exit(1);
293  }
294 
295  std::cout << " NOBJECTS IN MEAS " << (*vmcite)->OptOList().size() << " NMEAS " << Model::MeasurementList().size() << std::endl;
296 
297  std::vector<OpticalAlignParam> measValues = measInfo.values_;
298 
299  for( size_t jj= 0; jj < measValues.size(); jj++ ){
300  (*vmcite)->fillData( jj, &(measValues[jj]) );
301  }
302 
303  std::cout << " NOBJECTS IN MEAS after " << (*vmcite)->OptOList().size() << " NMEAS " << Model::MeasurementList().size() << std::endl;
304 
305  break;
306  }
307  }
308  if (ii==nMeasRoot) {
309  std::cerr << "!!! Reading measurement from file: measurement not found! Type in list is " << oname << std::endl;
310  exit(1);
311  }
312  }
313 
314 }
315 
Float_t GetX() const
void DumpIt(const TString &Name)
Float_t GetTilt() const
TClonesArray * GetArray_Tilt() const
OpticalAlignMeasurementInfo GetMeasFromTilt(AliDaqTilt *tilt)
virtual bool ReadEvent(int nev) override
OpticalAlignMeasurementInfo GetMeasFromDist(AliDaqDistance *dist)
int ALIint
Definition: CocoaGlobals.h:15
TClonesArray * GetArray_PositionCOPS() const
static ALIint debug
Definition: ALIUtils.h:36
Float_t GetUpError() const
TString GetID()
TClonesArray * GetArray_Position2D() const
Float_t GetYerror() const
CocoaDaqReaderRoot(const std::string &m_inFileName)
int GetNumTilt() const
CocoaDaqRootEvent * theEvent
Float_t GetDistanceError() const
virtual bool ReadNextEvent() override
Float_t GetLeft() const
Float_t GetRight() const
int GetNumPos2D() const
Float_t GetTiltError() const
void DumpIt(const TString &Name)
OpticalAlignMeasurementInfo GetMeasFromPositionCOPS(AliDaqPositionCOPS *posCOPS)
ii
Definition: cuy.py:588
TClonesArray * GetArray_Dist() const
static void SetDaqReader(CocoaDaqReader *reader)
Float_t GetXerror() const
Float_t GetY() const
Float_t GetLeftError() const
int GetNumDist() const
Float_t GetDistance() const
virtual void BuildMeasurementsFromOptAlign(std::vector< OpticalAlignMeasurementInfo > &measList) override
#define begin
Definition: vmac.h:30
Float_t GetDownError() const
std::string ALIstring
Definition: CocoaGlobals.h:9
std::vector< OpticalAlignParam > values_
void DumpIt(const TString &Name)
OpticalAlignMeasurementInfo GetMeasFromPosition2D(AliDaqPosition2D *pos2D)
Float_t GetDown() const
Float_t GetUp() const
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
Float_t GetRightError() const
void DumpIt(const TString &Name)
int GetNumPosCOPS() const