GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScanADF.C
Go to the documentation of this file.
1 
2 
3 // #ifndef ADF_ADFConfig
4 // #include "ADFConfig.h"
5 // #endif
6 #ifndef ADF_AgataKeyFactory
7 #include "AgataKeyFactory.h"
8 #endif
9 #ifndef ADF_AgataFrameFactory
10 #include "AgataFrameFactory.h"
11 #endif
12 #ifndef ADF_BufferIO
13 #include "BufferIO.h"
14 #endif
15 #ifndef ADF_ConfAgent
16 #include "ConfAgent.h"
17 #endif
18 #include "TTree.h"
19 #include <TRandom.h>
20 #include <iostream>
21 
22 using namespace std;
23 using namespace ADF;
24 
25 void ADFAnalyzerPrimary(const char *name)
26 {
27  ConfAgent::theGlobalAgent();
28 
29  const UInt_t MaxSizeFrame = 100u*aMByte;
30  const UInt_t MaxSizeMessage = 20u*aByte;
31 
32  FILE *fp = fopen(name,"r");
33  if ( fp == NULL ) { printf("File %s does not exist \n",name); return; }
34 
35  // neeeded to initiate the message table.
36  KeyFactory &main_key_factory = KeyFactory::theMainFactory();
37  KeyFactory::Register("Agata");
38 
39  // to read a frame
40  ADF::BufferIO fBuffer;
41 
42  // tree to store potential keys informations
43  struct key {
44  UInt_t lengthframe;
45  UInt_t eventnumber;
46  ULong64_t timestamp;
47  Char_t message[MaxSizeMessage];
48  } akey;
49 
50  UInt_t messagetype;
51 
52  TTree *tree = new TTree("AnalyzerPrimary",name);
53  tree->Branch("key",&akey,"FrameLength/i:EventNumber/i:TimeStamp/l:MessageType/C");
54 
55  Bool_t ok = true;
56  while ( ok ) {
57 
58  // reset everyting
59  memset(&akey,0,sizeof(akey));
60  fBuffer.SetOffset();
61 
62  akey.lengthframe = fBuffer.Import(fp,sizeof(akey.lengthframe));
63  if ( akey.lengthframe != sizeof(akey.lengthframe) )
64  break; // cannot read anymore the file
65 
66  fBuffer.SetOffset(); fBuffer >> akey.lengthframe;
67  if ( akey.lengthframe > MaxSizeFrame ) {
68  cout << " limit for a frame to MaxSizeFrame="
69  << MaxSizeFrame/aMByte
70  <<" MBytes, likely to be the wrong endian " << endl;
71  break;
72  }
73  if ( akey.lengthframe == 0u ) return;
74 
75  // add the rest of the frame
76  fBuffer.Import(fp,akey.lengthframe-sizeof(akey.lengthframe));
77 
78  // if the size of the buffer is too small to read
79  // all the field, the corresponding field is unchanged
80  fBuffer.SetOffset();
81  if ( fBuffer.FreeSize() >= sizeof(akey.lengthframe) )
82  fBuffer >> akey.lengthframe;
83  if ( fBuffer.FreeSize() >= sizeof(messagetype) )
84  fBuffer >> messagetype;
85  if ( fBuffer.FreeSize() >= sizeof(akey.eventnumber) )
86  fBuffer >> akey.eventnumber;
87  if ( fBuffer.FreeSize() >= sizeof(akey.timestamp) )
88  fBuffer >> akey.timestamp;
89  strcpy(akey.message,AgataKeyFactory::theFactory()->GetMessage(messagetype));
90 
91  tree->Fill();
92  }
93  cout << "Entries in the tree " << tree->GetEntries() << endl;
94  fclose(fp);
95 
96  ConfAgent::KilltheGlobalAgent();
97 }
98 
99 
101 
106 void ADFAnalyzerEmbbeded(const char *name,
107  const char *keytype = "agata", UShort_t v1 = 0,UShort_t v2 = 0)
108 {
109  ConfAgent::theGlobalAgent();
110 
111  const UInt_t MaxSizeFrame = 100u*aMByte;
112  const UInt_t MaxSizeMessage = 20u*aByte; const Int_t MaxKey = 10u;
113 
114  FILE *fp = fopen(name,"r");
115  if ( fp == NULL ) { printf("File %s does not exist \n",name); return; }
116 
117  // neeeded to initiate the message table.
118  KeyFactory &main_key_factory = KeyFactory::theMainFactory();
119  KeyFactory::Register("Agata");
120  AgataKey *pkey = dynamic_cast<AgataKey *>(main_key_factory.New("Agata",keytype,ADF::Version(v1,v2)));
121 
122  if ( pkey == NULL )
123  { printf("AgataKey %s [%d,%d] does not exist \n",keytype,v1,v2); return; }
124 
125  // to read a frame
126  ADF::BufferIO fBuffer;
127 
128  // tree to store potential keys informations
129  struct key {
130  UInt_t lengthframe;
131  UInt_t eventnumber;
132  ULong64_t timestamp;
133  Char_t message[MaxSizeMessage];
134  } akey, tmpkey;
135 
136  UInt_t N;
137  UInt_t lengthframe[MaxKey];
138  UInt_t eventnumber[MaxKey];
139  ULong64_t timestamp[MaxKey];
140  Char_t message[MaxKey][MaxSizeMessage];
141 
142  UInt_t messagetype;
143 
144  TTree *tree = new TTree("AnalyserEmbedded",name);
145  tree->Branch("PrimaryKey",&akey,"FrameLength/i:EventNumber/i:TimeStamp/l:MessageType/C");
146  tree->Branch("NEmbedded",&N,"NEmbedded/i");
147  tree->Branch("EmbFrameLength",lengthframe,"EmbFrameLength[NEmbedded]/i");
148  tree->Branch("EmbEventNumber",eventnumber,"EmbEventNumber[NEmbedded]/i");
149  tree->Branch("EmbTimeStamp",timestamp,"EmbEventNumber[NEmbedded]/l");
150 
151  for (Int_t i = 0u; i < MaxKey; i++ ) {
152  TString tmp1 = "EmbMessageType", tmp2 = "EmbMessageType";
153  tmp1 += i;
154  tmp2 += i; tmp2 += "/C";
155  tree->Branch(tmp1.Data(),message[i],tmp2.Data());
156  }
157 
158  Bool_t ok = true;
159  while ( ok ) {
160 
161  // reset everyting
162  memset(&akey,0,sizeof(akey));
163  memset(lengthframe,0,MaxKey*sizeof(lengthframe[0]));
164  memset(eventnumber,0,MaxKey*sizeof(eventnumber[0]));
165  memset(timestamp,0,MaxKey*sizeof(timestamp[0]));
166  memset(message,0,MaxKey*MaxSizeMessage);
167  messagetype = 0u;
168 
169  fBuffer.SetOffset();
170 
171  // read the next primary key
172  UInt_t keylength = fBuffer.Import(fp,pkey->GetKeyLength());
173  if ( keylength != pkey->GetKeyLength() )
174  break; // cannot read anymore the file
175 
176  if ( pkey->GetFrameLength() == 0u ) return;
177 
178  fBuffer.SetOffset();
179  pkey->Copy(fBuffer.GetAddress(),pkey->GetKeyLength());
180 
181  akey.lengthframe = pkey->GetFrameLength();
182  messagetype = pkey->GetMessage();
183  akey.eventnumber = pkey->GetEventNumber();
184  akey.timestamp = pkey->GetTimeStamp();
185  strcpy(akey.message,AgataKeyFactory::theFactory()->GetMessage(messagetype));
186 
187  if ( akey.lengthframe > MaxSizeFrame ) {
188  cout << " limit for a frame to MaxSizeFrame="
189  << MaxSizeFrame/aMByte
190  <<" MBytes, likely to be the wrong endian " << endl;
191  break;
192  }
193  // add now the rest of the frame
194  fBuffer.SetOffset();
195  UInt_t rest = fBuffer.Import(fp,pkey->GetDataLength());
196  if ( rest != pkey->GetDataLength() )
197  break;
198  if ( gDebug == 1) pkey->Print();
199 
200  // now guess content of the buffer
201  fBuffer.SetOffset(); fBuffer.SetStatus(BaseBuffer::kGood);
202  N = 0u;
203  while ( fBuffer.IsStatus(BaseBuffer::kGood) && fBuffer.Offset() < pkey->GetDataLength() ) {
204 
205  UInt_t current = fBuffer.Offset();
206  // try to read
207  if ( fBuffer.FreeSize() >= sizeof(tmpkey.lengthframe) )
208  { fBuffer >> tmpkey.lengthframe; }
209  else break;
210  if ( tmpkey.lengthframe == 0u )
211  break;
212  if ( fBuffer.FreeSize() >= sizeof(messagetype) )
213  { fBuffer >> messagetype; }
214  else break;
215  if ( fBuffer.FreeSize() >= sizeof(tmpkey.eventnumber) )
216  { fBuffer >> tmpkey.eventnumber; }
217  else break;
218  if ( fBuffer.FreeSize() >= sizeof(tmpkey.timestamp) )
219  { fBuffer >> tmpkey.timestamp; }
220  else break;
221  // cout << hex << messagetype << " " << tmpkey.lengthframe << dec << endl;
222  //cout << tmpkey.lengthframe << endl;
223 
224  if ( fBuffer.IsStatus(BaseBuffer::kGood) ) {
225  lengthframe[N] = tmpkey.lengthframe;
226  eventnumber[N] = tmpkey.eventnumber;
227  timestamp[N] = tmpkey.timestamp;
228  strcpy(message[N],AgataKeyFactory::theFactory()->GetMessage(messagetype));
229 
230  if ( N < MaxKey )
231  N++;
232 
233  fBuffer.SetOffset(current+tmpkey.lengthframe);
234  //printf("N %d %d\n",N,tmpkey.lengthframe);
235  }
236  else { printf("NO\n"); break; }
237  }
238  if ( N > 0u ) tree->Fill();
239  }
240  cout << "Entries in the tree " << tree->GetEntries() << endl;
241  fclose(fp);
242 
243  ConfAgent::KilltheGlobalAgent();
244 }
245 
246 
247 /*
248 #include "TH1F.h"
249 #include "TH3S.h"
250 
251 #include <FrameIO.h>
252 #include <PSAFrame.h>
253 #include <TrackedFrame.h>
254 #include <Trigger.h>
255 
256 using namespace ADF;
257 
258 void ROOTConsumeTRACK(const char *name = "AFC_0.adf")
259 {
260  // check the file exists
261  FILE *fp = fopen(name,"r");
262  if ( fp == NULL )
263  return;
264 
265  FileBlock inframe; inframe.SetFile(fp);
266  FrameIO fio(name);
267  fio.Attach(&inframe,NULL); fio.SetStatus(BaseFrameIO::kIdle);
268 
269  // built the trigger on a tracked frame
270  AgataFrameTrigger trig(name);
271  trig.Add("event:data",Version(),Version(),true);
272  Frame *frame
273  = trig.Add("data:tracked",Version(),Version(),true,true);
274 
275  if ( frame == NULL )
276  return;
277 
278  EvoTrackedFrame *trackframe = dynamic_cast<EvoTrackedFrame *>(frame);
279  if ( trackframe == NULL )
280  return;
281  fio.Register(&trig);
282 
283  fio.GetConfAgent()->Add( );
284 
285  TH1F *he = new TH1F("emean","emean",2000,0,2000);
286  TH3S *pos = new TH3S("xyzmean","xyzmean",20,0,10,40,0,20,60,0,30);
287 
288  Float_t totbytesR = 0.f; UInt_t nbloop = 0u;
289  while ( fio.Notify() ) {
290 
291  if ( ! trig.IsFired() ) continue; // in principle not needed if only one trigger has registered
292 
293  // Read from the Frame
294  UInt_t bytesr = trackframe->Read(); totbytesR += bytesr;
295 // trackframe->GetKey()->Print();
296  for (UInt_t h = 0; h < trackframe->Data()->GetNbGamma() ; h++) {
297 
298  const TrackedHit *ahit = trackframe->Data()->GetGamma(h);
299 
300  he->Fill(ahit->GetE());
301  pos->Fill(ahit->GetX(),ahit->GetY(),ahit->GetZ());
302  }
303  nbloop++;
304 
305 
306  }
307  // a log is also print out
308  fio.Print(std::cout);
309 
310  he->Draw();
311  fclose(fp);
312 }
313 
314 */
315 
316 
317 
318 
319 
320 
printf("******************************************************************** \n")
void SetStatus(BufferIO::EStatus s=BaseBuffer::kGood)
Definition: BufferIO.h:106
header file for AgataFrameFactory.cpp
Interface to AgataKey.
virtual Bool_t Copy(const Char_t *, UInt_t)
Copy an external buffer to this key.
Definition: Key.cpp:90
virtual void Print(std::ostream &out=std::cout) const
Print the content of the key.
virtual ULong64_t GetTimeStamp() const =0
To set the timestamp.
UInt_t Offset() const
it returns the current position in the buffer
Definition: BufferIO.h:240
const UInt_t aMByte
Definition: BaseBuffer.h:36
void ADFAnalyzerEmbbeded(const char *name, const char *keytype="agata", UShort_t v1=0, UShort_t v2=0)
Definition: ScanADF.C:106
virtual UInt_t GetKeyLength() const
Unique number corresponding to a type of Key.
Definition: Key.h:210
virtual UInt_t GetEventNumber() const =0
To get the event number encoded.
void ADFAnalyzerPrimary(const char *name)
Definition: ScanADF.C:25
Base class for version numbers.
Definition: Version.h:38
virtual UInt_t GetDataLength() const
header file for BufferIO.cpp
UInt_t FreeSize() const
it returns the number of free bytes to the end
Definition: BufferIO.h:236
const Char_t * GetAddress() const
Pointer to the current underlying array of bytes.
Definition: BufferIO.h:216
header file for AgataKeyFactory.cpp
const UInt_t aByte
Definition: BaseBuffer.h:34
virtual Key * New(const FactoryItem &)
build a key using item.
Definition: KeyFactory.cpp:41
ADF::LogMessage & endl(ADF::LogMessage &log)
header file for ConfAgent.cpp
UInt_t Import(const Char_t *from, UInt_t size_ext_buf)
Import the given array in this buffer.
Definition: BufferIO.cpp:298
virtual UInt_t GetFrameLength() const
Bool_t IsStatus(BufferIO::EStatus s) const
Definition: BufferIO.h:104
Base Key factory.
Definition: KeyFactory.h:44
virtual UInt_t GetMessage() const =0
To get the message type encoded.
UInt_t SetOffset(UInt_t off=0u) const
change the current position.
Definition: BufferIO.cpp:122