GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AgataKeyFactory.h
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 #ifndef ADF_AgataKeyFactory
24 #define ADF_AgataKeyFactory
25 #define ADF_AGATAKEYFACTORY_H ADF_AgataKeyFactory
26 
27 #ifndef ADF_KeyFactory
28 #include "KeyFactory.h"
29 #endif
30 #ifndef ADF_Key
31 #include "Key.h"
32 #endif
33 #ifndef ADF_DotConf
34 #include "DotConf.h"
35 #endif
36 
37 #include <iostream>
38 #include <string>
39 #include <map>
40 #include <utility>
41 
42 namespace ADF
43 {
45 
60 class AgataKey : public Key
61 {
62 public:
63  friend class AgataKeyFactory;
64 
65 protected:
66  UInt_t kKeyLength ;
67  UInt_t kMaxDataLength ;
68 
69 protected:
70  UInt_t fMessage, fMask;
71 
72 protected:
74  virtual void SetMessage(UInt_t) = 0;
75 
76 public:
77  AgataKey(BaseBuffer::EEndian e, UInt_t s = 4u*aByte) :
78  Key(e,s),
79  fMessage(0x0A000000),
80  fMask(0x0F000000)
81  {
82  kKeyLength = s;
84  }
85  virtual ~AgataKey()
86  {;}
87 
89  virtual UInt_t GetMessage() const = 0;
91  virtual UInt_t GetEventNumber() const = 0;
92 
94  virtual void SetEventNumber(UInt_t) = 0;
95 
97  virtual ULong64_t GetTimeStamp() const = 0;
98  virtual void SetTimeStamp(ULong64_t) = 0;
99 
101 
104  virtual void SetDataLength(UShort_t s)
105  {
106  fBuffer->SetOffset();
107  (*fBuffer) << (UInt_t(s)+kKeyLength);
108  }
109 
111  virtual void SetDataLength(UInt_t i)
112  {
113  UInt_t ri = kKeyLength;
114  if ( i < kMaxDataLength )
115  ri += i;
116  fBuffer->SetOffset();
117  (*fBuffer) << ri;
118  }
119 
120  virtual UInt_t GetDataLength() const
121  {
122  UInt_t i = 0u;
123  fBuffer->SetOffset();
124  (*fBuffer) >> i;
125  if ( i >= kKeyLength )
126  i = i - kKeyLength ;
127 
128  return i;
129  }
130 
131  virtual UInt_t GetFrameLength() const
132  {
133  UInt_t i = kKeyLength;
134  fBuffer->SetOffset();
135  (*fBuffer) >> i;
136  return i;
137  }
138 
140 
143  virtual Bool_t IsAKey(const Key *akey) const
144  {
145  Bool_t ok = false;
146  if ( akey->GetSignature().GetFactoryName() == GetSignature().GetFactoryName() ) { // be sure an agata factory has allocated akey
147  const AgataKey *ckey = dynamic_cast<const AgataKey *> (akey);
148  if ( ckey ) {
149  ok = (fMessage == (ckey->GetMessage() & fMask));
150  }
151  }
152  return ok;
153  }
154 
156  virtual void ChangeType(UInt_t messtype, UInt_t messmask)
157  {
158  fMessage = messtype;
159  fMask = messmask;
160  }
161 
162  virtual void Print(std::ostream &out = std::cout) const;
163 
165 
170  virtual Bool_t Convert(const Key *akey);
171 };
172 
173 
175 
242 class AgataKeyFactory : public AKeyFactory<AgataKeyFactory>
243 {
245 
246 private:
247  // correspondance between a string (human readable) and a message type (UInt_t)
248  std::map<std::string,std::pair<UInt_t,UInt_t> > fMessageTable;
249 
250 private:
252  std::map<std::string,std::pair<UInt_t,UInt_t> > fHardcodedMessageTable;
253 
254 private:
256  Bool_t fIsPatchEvent;
257 
258 private:
259  AgataKeyFactory();
260  virtual ~AgataKeyFactory ()
261  {;}
262 
263 protected:
265 
268  virtual Key *DoNew(const FactoryItem &);
269 
271  virtual Bool_t ProcessLine(const std::string &);
273  virtual void Reset(const Char_t * = "");
274 
275 public:
279 
281  const std::map<std::string,std::pair<UInt_t,UInt_t> > & GetKnownKeys() const
282  {
283  return fMessageTable;
284  }
285 
287  Bool_t GetMessage(std::string keyName, UInt_t &message, UInt_t &mask);
288  Bool_t GetMessage(std::string keyName, UInt_t &message)
289  {
290  UInt_t mask;
291  return GetMessage(keyName,message,mask);
292  }
293 
295  const Char_t *GetMessage(UInt_t);
296 
298  virtual Bool_t DoConfigure(std::ostream &) ;
299  virtual Bool_t DoConfigure(std::istream &in, Bool_t allow_init)
300  { return DotConf::DoConfigure(in, allow_init); }
301 };
302 // AgataKeyFactory inline members //////////////////////////////////////////////////////
303 
304 
305 } // namespace ADF
306 #endif
307 
308 
309 
310 
311 
virtual void Reset(const Char_t *="")
Reset the table.
Base class for a Key.
Definition: Key.h:56
UInt_t kMaxDataLength
header file for KeyFactory.cpp
BufferIO * fBuffer
the buffer that fills in/out the Key
Definition: Key.h:99
const FactoryItem & GetSignature() const
Definition: Key.h:115
virtual void SetDataLength(UInt_t i)
stream in buffer the data length
virtual void SetEndian(BaseBuffer::EEndian)
Agata files are always little endian !!
virtual Bool_t DoConfigure(std::ostream &)
write the message table
virtual Bool_t IsAKey(const Key *akey) const
Compare it to another key.
Interface to AgataKey.
const UInt_t kMaxUInt_t
Definition: ADFConfig.h:100
virtual Bool_t ProcessLine(const std::string &)
During configuration, process a single line.
header file for Key.cpp
virtual void Print(std::ostream &out=std::cout) const
Print the content of the key.
const std::map< std::string, std::pair< UInt_t, UInt_t > > & GetKnownKeys() const
to just browse the list of known keys
virtual Bool_t Convert(const Key *akey)
convert a key to another key ... not an easy task ... use it carefully
virtual ULong64_t GetTimeStamp() const =0
To set the timestamp.
virtual Key * DoNew(const FactoryItem &)
Ask this factory for a new AgataKey.
virtual UInt_t GetEventNumber() const =0
To get the event number encoded.
virtual Bool_t DoConfigure(std::istream &in, Bool_t allow_init)
just call DotConf method
virtual UInt_t GetDataLength() const
virtual void SetTimeStamp(ULong64_t)=0
virtual ~AgataKey()
virtual void SetEventNumber(UInt_t)=0
To set the event number.
virtual Bool_t DoConfigure(std::istream &, Bool_t allow_init)
configure this from an input stream
virtual void ChangeType(UInt_t messtype, UInt_t messmask)
to modify the Agata type for this key
const std::string & GetFactoryName() const
Definition: FactoryItem.h:76
const UInt_t aByte
Definition: BaseBuffer.h:34
header file for DotConf.cpp
AgataKey(BaseBuffer::EEndian e, UInt_t s=4u *aByte)
virtual UInt_t GetFrameLength() const
virtual void SetDataLength(UShort_t s)
stream in buffer the data length
virtual void SetEndian(BaseBuffer::EEndian e)
Set Endian type for the keys delivered by this factory.
Definition: KeyFactory.h:104
Bool_t GetMessage(std::string keyName, UInt_t &message)
virtual void SetMessage(UInt_t)=0
To set the message type.
Bool_t GetMessage(std::string keyName, UInt_t &message, UInt_t &mask)
to check if a given keyname is in the list of known keys (return true in this case, false otherwise) and to access the corresponding message type, mask
Base class for a AgataKeyFactory.
Base class for any KeyFactory implementation.
Definition: KeyFactory.h:215
Base class that described an item in a Factory.
Definition: FactoryItem.h:52
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