GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExTracking.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #include "ExTracking.h"
24 #include "TrackedFrame.h"
25 
27 #include "TSystem.h"
28 
29 using namespace ADF;
30 using namespace Gw;
31 
32 // local namespace to this file only
33 namespace {
34  // version number of this Tracking
35  /*
36  allow to set version number of the current tracking
37  */
38  Version gMyVersion(0,0);
39 
40  // Ex on how to set restriction on triggers for a given set of tracked frame
41  // In case the current version # of the given frame on the data flow is not compatible with the analysis, the trigger becomes not running.
42  // in this case the major version number of the tracked frame should be lower or equal that My analysis Version (gMyVersion)
43  /*
44  Bool_t AllowTrackedFrame(const FactoryItem & item_from, const FactoryItem &item_to) {
45  if ( item_to.GetVersion().GetMajor() == gMyVersion.GetMajor() )
46  return true;
47  return false;
48  }
49  */
51 }
52 
54  NarvalFilter(),
55  fTrigger(0x0),
56  fAllocatedPSAFrame(),
57  fCurrentPSA()
58 {
59  Log.GetProcessName() = "ExTracking"; GetFrameIO().SetName("ExTracking");
60 }
61 
63 {
64  // in principle not needed ... just in case reset has not been called by narval
65  UInt_t error = 0u; process_reset(&error) ;
66 }
67 
69 {
70  // clear previous event
71  fCurrentPSA.clear();
72 
73  SharedFP *psa_frames = fTrigger->GetInputSharedFP(1); SharedFP *track_frame = fTrigger->GetOutputSharedFP();
74  // check the event:data:psa frame exists ... in case the trigger is lazy
75  if ( psa_frames == 0x0 ) {
76  return 0u;
77  }
78  else {
79  if ( !psa_frames->IsValid() )
80  return 0u;
81  }
82  track_frame->GetFrame()->Reset();
83 
84  //
85  GammaTrackedInterface *data_track =
86  GetDataPointer<GammaTrackedInterface>(track_frame);
87 
88  // Scan the event:psa frame to extract all the PSAInterface
89  UInt_t nb_psa_frames = psa_frames->GetFrame()->Scan(); SharedFP *psa;
90 
91  for (UInt_t i = 0u; i < nb_psa_frames; i++) {
92  if ( !(i < fAllocatedPSAFrame.size()) ) { // a new frame has to be allocated, aware of re configuration so the trigger utility is used for that
93  psa = fTrigger->AddUtility("data:psa",ConfAgent::theGlobalAgent());
94  if ( psa == 0x0 ) {
95  Log << error << " cannot allocate more that " << fAllocatedPSAFrame.size() << dolog;
96  return fCurrentPSA.size();
97  }
98  else { fAllocatedPSAFrame.push_back(psa); }
99  }
100  psa = fAllocatedPSAFrame[i];
101 
102  PSAInterface *data_psa =
103  fTrigger->GetSubDataFrom<PSAInterface>(1,i,psa,false);
104  if ( data_psa )
105  fCurrentPSA.push_back(data_psa);
106  }
107  //for all hits in the psa frames, apply transformation local -> global
108  for (UInt_t ipsa = 0u; ipsa < fCurrentPSA.size(); ipsa++) {
109 
110  TrackedHit *atracked_hit = data_track->NewGamma(); atracked_hit->SetE(fCurrentPSA[ipsa]->GetE());
111 
112  for (UShort_t ihit = 0u; ihit < fCurrentPSA[ipsa]->GetNbHits(); ihit++) {
113  //
114  Double_t xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal; Double_t max_e = 0.0;
115 
116  fCurrentPSA[ipsa]->GetHit(ihit)->GetXYZ(xLocal, yLocal, zLocal);
117  fTrans->Local2Global(fCurrentPSA[ipsa]->GetUID(), xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal);
118 
119  if ( fCurrentPSA[ipsa]->GetHit(ihit)->GetE() > max_e ) {
120  max_e = fCurrentPSA[ipsa]->GetHit(ihit)->GetE();
121  atracked_hit->SetXYZ(xGlobal, yGlobal, zGlobal);
122  }
123  }
124  }
125  // return the # of data interface for that event
126  return 0u;
127 }
128 
129 
130 void ExTracking::process_config (const Char_t *directory_path, UInt_t *error_code)
131 {
132  // In case your algorithm needs to initiate globals, it should be done here
133 
134  // Globals for ADF are read from ADF.conf (should be in your algo path !!)
135  NarvalInterface::process_config(directory_path,error_code);
136 
137  if ( (*error_code) == 0u ) { // now init your stuff
138 
139  // here could come the reading of a file in which are stored the
140  // units (position,energy) you are working with i.e. modifications
141  // of UnitPosition UnitEnergy defined in the base class AlgoDummy
142  // + ....
143  // NarvalInterface (through process_config(), so don't forget it)
144  // keeps the name of the directory_path. To get it back: GetConfPath()
145  }
146 }
147 
149 {
150  return 0u;
151 }
152 
154 {
155  Frame *trackframe = fTrigger->GetOutputSharedFP()->GetFrame(); Frame *eventdataframe = fTrigger->GetInputSharedFP(1)->GetFrame();
156 
157  ((AgataKey *)trackframe->GetKey())->SetEventNumber( ((AgataKey *)eventdataframe->GetKey())->GetEventNumber() );
158  ((AgataKey *)trackframe->GetKey())->SetTimeStamp( ((AgataKey *)eventdataframe->GetKey())->GetTimeStamp() );
159 
160  trackframe->Write();
161 
162  /*
163  const GammaTrackedInterface *data =
164  GetCstDataPointer<GammaTrackedInterface>(trackframe);
165 
166  UInt_t fold = data->GetNbGamma();
167  for (UShort_t i = 0u; i < fold; i++) {
168 
169  const TrackedHit *gamma1 = data->GetGamma(i);
170  cout << gamma1->GetX() << " " << gamma1->GetY() << " " << gamma1->GetZ() << endl;
171 
172  }
173  */
174 
175  return 0u;
176 }
177 
179 {
180  Log.ClearMessage(); Log.SetProcessMethod("process_block");
181 
182  // attach the input/output buffer to the FrameIO system
183  GetFrameIO().Attach(&in,&out);
184 
185  // start the processing
186  UInt_t error_code = 0u;
187  while ( GetFrameIO().Notify() ) { // process the input
188 
189  if ( ! (SetInput() == 0u && Process() == 0u && SetOutput() == 0u) )
190  { error_code = 1u; break; }
191  else {
192  if ( !GetFrameIO().Record() )
193  { error_code = 2u; break; }
194  }
195  }
196  if ( error_code == 1u ) {
197  Log << error
198  << "During processing : SetInput -> Process -> SetOuput() " << nline;
199  }
200  if ( error_code == 2u ) {
201  Log << error
202  << "During Record() " << nline;
203  }
204  GetFrameIO().Detach(&in,&out);
205 
206  // send messages to the central log
207  Log << dolog;
208  return error_code;
209 }
210 
211 
212 void ExTracking::process_initialise (UInt_t *error_code)
213 {
214  *error_code = 0; Log.ClearMessage(); Log.SetProcessMethod("process_initialise");
215 
216  /*
217  this trigger returns if an event:data frame is found containing en event:data:psa and a data:tracked
218  the data tracked is consumed to be replaced by the new one
219  */
220  fTrigger = AgataFrameTrigger::Build("ExTracking","event:data event:data:psa","data:tracked");
221  if ( fTrigger == 0x0 ) {
222  Log << warning << "Cannot build trigger ExTracking " << nline ;
223  (*error_code) = 1u;
224  }
225  else {
226  // set the data:tracked frame as consumable
227 // fTrigger->SetConsumable(2,true);
228 
229  Log << info << "ExTracking has been registered " << nline ;
230 
231  // once fully defined, register the trigger
233  GetFrameIO().SetStatus(BaseFrameIO::kIdle);
234  }
235 
236  fTrans = new AgataGeometryTransformer(); Bool_t ok = false;
237 
238  if ( gSystem->AccessPathName("CrystalPositionLookUpTable") ) { // does not exist
239  if ( gSystem->AccessPathName("CrystalPositionLookUpTable.dat") ) {
240  Log << error << " CrystalPositionLookUpTable required " << nline;
241  }
242  else {
243  Log << info << " Ge positions extracted from CrystalPositionLookUpTable.dat " << nline;
244  fTrans->ReadTransformations("CrystalPositionLookUpTable.dat");
245 
246  ok = true;
247  }
248  }
249  else {
250  Log << info << " Ge positions extracted from CrystalPositionLookUpTable.dat " << nline;
251  fTrans->ReadTransformations("CrystalPositionLookUpTable");
252 
253  ok = true;
254  }
255  if ( ! ok )
256  (*error_code) = 1u;
257 
258  Log << dolog;
259 }
260 
261 
262 void ExTracking::process_reset (UInt_t * /*error_code*/)
263 {
264  Log.SetProcessMethod("process_reset");
265 
266  GetFrameIO().Print( Log() );
267 
268  Log << dolog;
269 }
270 
271 
272 
273 
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
virtual Key * GetKey()=0
To get the Key associated to this frame.
virtual Frame * GetFrame() const
Definition: Frame.h:625
Base class for a Frame.
Definition: Frame.h:73
LogMessage & error(LogMessage &)
LogMessage & warning(LogMessage &)
header file for TrackedFrame.cpp
Interface to AgataKey.
virtual void SetE(Double_t)
Definition: Hits.h:69
The tracking algorithm produces a stack of TrackedHits.
Definition: TrackedFrame.h:41
A Block of Frames.
Definition: FrameBlock.h:43
virtual UInt_t Process()
process this with the current conditions
Definition: ExTracking.C:148
LogMessage & nline(LogMessage &)
virtual UInt_t SetInput()
read the data from the trigger and put them in local variable
Definition: ExTracking.C:68
AgataGeometryTransformer class that manage geometry transformations.
virtual ~ExTracking()
Definition: ExTracking.C:62
virtual SharedFP * GetInputSharedFP(UInt_t which=0u)
to get back the Shared pointer that define this trigger
Definition: Trigger.h:375
virtual Bool_t Register(DFTrigger *)
To register a trigger.
Definition: FrameIO.cpp:368
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
std::vector< ADF::PSAInterface * > fCurrentPSA
Stack of PSAFrames for the current event.
Definition: ExTracking.h:64
Base class for version numbers.
Definition: Version.h:38
virtual void Detach(FrameBlock *in, FrameBlock *out)
Definition: FrameIO.cpp:741
header file for ExTracking.cpp
void SetStatus(EStatus stat)
Definition: FrameIO.h:110
virtual void SetProcessMethod(const char *)
To set the current method.
LogMessage & dolog(LogMessage &)
virtual UInt_t Write()
It writes to the Frame the content of the dedicated structures.
Definition: Frame.h:206
virtual void ClearMessage()
To clear the current message.
It is a hit associated to a list of Hits.
Definition: Hits.h:256
FrameIO & GetFrameIO()
static void process_config(const Char_t *, UInt_t *)
to init globals (static) from a directory
Definition: ExTracking.C:130
ADF::AgataFrameTrigger * fTrigger
the trigger that exctracts from the data flow the current event and add the output frame ...
Definition: ExTracking.h:58
A Shared Frame Pointer.
Definition: Frame.h:597
virtual void Reset()=0
Reset the current frame.
virtual void process_initialise(UInt_t *error_code)
Constructor implementation.
Definition: ExTracking.C:212
Data_T * GetSubDataFrom(UInt_t which_input, UInt_t which_sub, SharedFP *utility, Bool_t do_scan=false)
Same as GetSubFrameFrom but to get directly a data part.
Definition: Trigger.h:418
virtual void Print(std::ostream &out=std::cout) const
Print some informations (statistics)
Definition: FrameIO.cpp:571
virtual void Attach(FrameBlock *in, FrameBlock *out)
Attach a block to this. Rewind called if DoRewind set to true (Default)
Definition: FrameIO.cpp:724
virtual SharedFP * AddUtility(const FactoryItem &key_item, const FactoryItem &frame_item, const ConfAgent *agent)
Add utilities, used to decode/encode composite frames.
Definition: Trigger.cpp:936
virtual UInt_t Scan()
Scan this Frame. If it is a composite frame, it looks for the keys of sub-frames. ...
Definition: Frame.h:219
virtual std::string & GetProcessName()
To get the Process name.
virtual TrackedHit * NewGamma()=0
Add a gamma on the top of the current stack.
virtual void process_reset(UInt_t *error_code)
Destructor implementation.
Definition: ExTracking.C:262
LogMessage Log
to send messages to the log server
virtual void SetName(const char *name)
Definition: FrameIO.h:102
virtual SharedFP * GetOutputSharedFP()
to get back the output frame
Definition: Trigger.h:429
virtual UInt_t ProcessBlock(ADF::FrameBlock &, ADF::FrameBlock &)
To process just a block of data.
Definition: ExTracking.C:178
It defines the interface needed to be a narval actor (Filter).
virtual UInt_t SetOutput()
compute output of the process
Definition: ExTracking.C:153
virtual void SetXYZ(Double_t, Double_t, Double_t)
Definition: Hits.h:62