From 745fce3a3de48e2019473bc6071abb1ea081a08d Mon Sep 17 00:00:00 2001
From: Jochen Meyer <Jochen.Meyer@cern.ch>
Date: Tue, 16 Sep 2014 08:34:21 +0200
Subject: [PATCH] fixing compiler warning (MuonCablingTools-00-01-04)

---
 .../MuonCablingTools/BaseObject.h             | 101 +++
 .../MuonCablingTools/OutputDef.h              |  23 +
 .../MuonCablingTools/RPCdecoder.h             | 115 ++++
 .../MuonCablingTools/RPCdef.h                 |  11 +
 .../MuonCablingTools/ShowRequest.h            |  95 +++
 .../MuonCablingTools/dbline.h                 | 438 +++++++++++++
 .../MuonCablings/MuonCablingTools/README      |  18 +
 .../MuonCablingTools/cmt/requirements         |  29 +
 .../MuonCablingTools/src/BaseObject.cxx       | 166 +++++
 .../MuonCablingTools/src/RPCdecoder.cxx       | 242 +++++++
 .../MuonCablingTools/src/dbline.cxx           | 607 ++++++++++++++++++
 11 files changed, 1845 insertions(+)
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/BaseObject.h
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/OutputDef.h
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/RPCdecoder.h
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/RPCdef.h
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/ShowRequest.h
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/dbline.h
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/README
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/cmt/requirements
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/src/BaseObject.cxx
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/src/RPCdecoder.cxx
 create mode 100755 MuonSpectrometer/MuonCablings/MuonCablingTools/src/dbline.cxx

diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/BaseObject.h b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/BaseObject.h
new file mode 100755
index 0000000000000..84ae0cda0a2f1
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/BaseObject.h
@@ -0,0 +1,101 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef LVL1OBJECT_H
+#define LVL1OBJECT_H
+
+
+#define DISP this->lock(); \
+             m_message->init_message();\
+             m_message->message()
+
+#define DISP_DEBUG display_debug(m_message->message()); \
+                   m_message->delete_message(); \
+		   this->unlock();   
+#define DISP_ERROR display_error(m_message->message()); \
+                   m_message->delete_message(); \
+		   this->unlock();
+#define DISP_WARNING display_warning(m_message->message()); \
+                     m_message->delete_message(); \
+		     this->unlock();
+#define DISP_INFO display_info(m_message->message()); \
+                  m_message->delete_message(); \
+		  this->unlock();
+#include <string>
+#include <iostream>
+
+
+#include "MuonCablingTools/OutputDef.h"
+
+
+
+#ifndef LVL1_STANDALONE
+#include "GaudiKernel/MsgStream.h"
+#include "GaudiKernel/IMessageSvc.h"
+#include "GaudiKernel/ISvcLocator.h"
+#include "GaudiKernel/Bootstrap.h"
+#endif
+
+
+
+enum ObjectType {Logic,Data,Hardware,Monitoring};
+
+
+class MessageStream
+{
+    private:
+#if (__GNUC__) && (__GNUC__ > 2)     // put your gcc 3.2 specific code here
+    __osstream* m_display;
+#else                                // put your gcc 2.95 specific code here
+    char* m_buffer_display;
+    __osstream* m_display;
+#endif
+    public:
+    void init_message(void);
+    void delete_message(void);  
+    __osstream& message(void);
+};
+
+inline __osstream&
+MessageStream::message(void)
+{
+    return *m_display;
+}
+
+class BaseObject
+{
+    private:
+    ObjectType  m_tag;
+    std::string m_name;
+
+    protected:
+    MessageStream* m_message;
+
+
+    public:
+    BaseObject (ObjectType,std::string);
+    BaseObject (ObjectType,const char*);
+    BaseObject (const BaseObject&);
+    ~BaseObject();
+
+    BaseObject operator = (const BaseObject&);
+
+    ObjectType  tag(void)  const {return m_tag;}
+    std::string name(void) const {return m_name;}
+
+    void Print(std::ostream&,bool) const {}
+    void display_warning(__osstream&) const;
+    void display_info(__osstream&) const;
+    void display_error(__osstream&) const;
+    void display_debug(__osstream&) const;
+    
+    void lock(void) const;
+    void unlock(void) const;
+
+#ifndef LVL1_STANDALONE
+    //static IMessageSvc* s_message;
+#endif
+};
+
+#endif
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/OutputDef.h b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/OutputDef.h
new file mode 100755
index 0000000000000..105f436c01974
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/OutputDef.h
@@ -0,0 +1,23 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef OUTPUTDEF_H
+#define OUTPUTDEF_H
+
+
+// for compatibility between gcc2.95 and gcc3.2
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    #include <sstream>
+    typedef std::ostringstream __osstream;
+    #define COUNT str().size()
+#else
+    // put your gcc 2.95 specific code here
+    #include <strstream>
+    typedef ostrstream __osstream;
+    #define COUNT pcount()
+#endif
+
+
+#endif
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/RPCdecoder.h b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/RPCdecoder.h
new file mode 100755
index 0000000000000..4224278c5544c
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/RPCdecoder.h
@@ -0,0 +1,115 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef RPCDECODER_H
+#define RPCDECODER_H
+
+#include "MuonCablingTools/RPCdef.h"
+
+#include <iostream>
+
+
+// for compatibility between gcc2.95 and gcc3.2
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    #include <sstream>
+    typedef std::ostringstream __osstream;
+#else
+    // put your gcc 2.95 specific code here
+    #include <strstream>
+    typedef ostrstream __osstream;
+#endif
+
+
+class RPCdecoder
+{
+    public:
+    enum value_type {Strip_Type,Logic_Sector,LVL1_Station,RPC_Layer};
+
+    private:
+    static const int value_boundaries[4][2];
+    static const char value_descriptions[4][15];
+
+    private:
+    bool m_fail;
+
+    private:
+    unsigned int m_code;
+
+    int m_strip_type;
+    int m_logic_sector;
+    int m_lvl1_station;
+    int m_rpc_layer;
+    int m_rpc_z_index;
+    int m_strip_number;
+
+    void reset (void);
+    void reset_status(void);
+    void reset_data(void);
+
+    void set_indexes(unsigned int);
+    void set_code(int,int,int,int,int,int);
+    void fault_decoding(int,value_type);
+
+    public:
+    RPCdecoder();
+    RPCdecoder(unsigned int);
+    RPCdecoder(int,int,int,int,int,int);
+    RPCdecoder(ViewType,int,int,int,int,int);
+
+    RPCdecoder(const RPCdecoder& deco);
+    RPCdecoder operator = (const RPCdecoder& deco);
+
+    ~RPCdecoder() {}
+
+    public:
+    RPCdecoder& operator ()(unsigned int);
+    RPCdecoder& operator ()(ViewType,int,int,int,int,int);
+    RPCdecoder& operator ()(int,int,int,int,int,int);
+
+    public:
+    operator bool() {return !m_fail;}
+
+    public:
+    bool OK(int,value_type) const;
+
+    unsigned int code(void) const {return m_code;}
+    int strip_type(void)    const {return m_strip_type;}
+    int logic_sector(void)  const {return m_logic_sector;}
+    int lvl1_station(void)  const {return m_lvl1_station;}
+    int rpc_layer(void)     const {return m_rpc_layer;}
+    int rpc_z_index(void)   const {return m_rpc_z_index;}
+    int strip_number(void)  const {return m_strip_number;}
+    int cabling_code(void)  const 
+        {return m_strip_number + m_rpc_z_index*100 + m_rpc_layer*10000;}
+
+    ViewType view(void) const;
+    HalfType half_barrel(void) const;
+    int side2type(ViewType side) const;
+
+    void Print(std::ostream&,bool) const;
+};
+
+/*                                                
+template <class X> X& operator<<(X& stream,const RPCdecoder& decoder)
+{
+
+// for compatibility between gcc2.95 and gcc3.2
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    __osstream display;
+#else
+    // put your gcc 2.95 specific code here
+    char buffer[10000];
+    for (int i=0;i<10000;++i) buffer[i] = '\0';
+    __osstream display(buffer,10000);
+#endif
+
+    decoder.Print(display,false);
+    stream << display.str();
+    return stream;
+}
+*/
+
+#endif
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/RPCdef.h b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/RPCdef.h
new file mode 100755
index 0000000000000..fba6ea579836c
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/RPCdef.h
@@ -0,0 +1,11 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef RPCDEF_H
+#define RPCDEF_H
+
+enum ViewType {Eta,Phi,NoView};
+enum HalfType {Negative,Positive,NoHalf};
+
+#endif
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/ShowRequest.h b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/ShowRequest.h
new file mode 100755
index 0000000000000..57c24ee9f41c5
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/ShowRequest.h
@@ -0,0 +1,95 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef PRINTREQ_H
+#define PRINTREQ_H
+
+#include <iostream>
+
+// for compatibility between gcc2.95 and gcc3.2
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    #include <sstream>
+    typedef std::ostringstream __osstream;
+#else
+    // put your gcc 2.95 specific code here
+    #include <strstream>
+    typedef ostrstream __osstream;
+#endif
+
+
+template <class Type>
+class ShowRequest
+{
+    public:
+    const Type* m_object;
+    bool  m_detail;
+
+    public:
+    ShowRequest(const Type&,bool);
+    ShowRequest(const Type*,bool);
+    ~ShowRequest() {}
+    /*
+    friend ostream& operator<< <Type> (ostream&,const ShowRequest<Type>&);
+#ifndef LVL1_STANDALONE
+    friend MsgStream& operator<< <Type> (MsgStream&,const ShowRequest<Type>&);
+#endif
+    */
+};
+
+template <class Type>
+ShowRequest<Type>::ShowRequest(const Type& obj,bool detail) : 
+    m_object(&obj),m_detail(detail) {}
+
+
+template <class Type>
+ShowRequest<Type>::ShowRequest(const Type* obj,bool detail) : 
+    m_object(obj),m_detail(detail) {}
+
+
+
+template <class Type> std::ostream& operator<<
+    (std::ostream& stream,const ShowRequest<Type>& print)
+{
+
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    __osstream display;
+#else
+    // put your gcc 2.95 specific code here
+    char buffer[50000];
+    for (int i=0;i<50000;++i) buffer[i] = '\0';
+    __osstream display(buffer,50000);
+#endif
+
+    print.m_object->Print(display,print.m_detail);
+    stream << display.str();
+    return stream;
+}
+
+#ifndef LVL1_STANDALONE
+#include "GaudiKernel/MsgStream.h"
+
+template <class Type> MsgStream& operator<<
+    (MsgStream& stream,const ShowRequest<Type>& print)
+{
+
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    __osstream display;
+#else
+    // put your gcc 2.95 specific code here
+    char buffer[50000];
+    for (int i=0;i<50000;++i) buffer[i] = '\0';
+    __osstream display(buffer,50000);
+#endif
+
+    print.m_object->Print(display,print.m_detail);
+    stream << display.str();
+    return stream;
+}
+#endif
+
+
+#endif
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/dbline.h b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/dbline.h
new file mode 100755
index 0000000000000..c26713047502b
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/MuonCablingTools/dbline.h
@@ -0,0 +1,438 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+// INTRODUCTION
+//
+// DBline is a generic class which provides an easy interface to access 
+// formatted data from an input stream. The purpose is to facilitate the 
+// development of the reading routine (for an ASCII database) and, at the same
+// time, to increase its robustness against the varoius changes to which the
+// the database undergoes during the development phase. The flexibility needed
+// to deal with each kind of database, was achieved implementing a set of basic
+// functionalities which can be componed in a easy way to build a generic 
+// reading routine.
+//
+// Considering a generic database whose data are input line by line, each line
+// can be decomposed into a set of small blocks having the following pattern:
+//
+//     <Token>  <set of data>
+//
+// where <Token> can be any character sequence (including the space character)
+// and <set of data> can be one ore more data of different nature that have to
+// be read. DBline implements an "extraction" mechanism which allows to select
+// a <Token> and to read the releted data (only if the token is found) just in 
+// one command line. Since the data input is perfomed line by line, such 
+// "extraction" mechanism requires that the token and the data has to be found
+// in the same line of the database. This matches very well the case in which
+// the database is made of a set of control directives given in any order (i.e.
+// a DATACARD file). 
+// In order to allow the reading of more complex structures of data which can
+// be spanned on more than one line, each "extraction" returns a boolean value
+// that can be checked in logical expresssion. Thus, it is possible to activate
+// a particular reading schema if a Token is found or to read with it until  
+// another Token is found. Moreover is also possible to build logical 
+// expression only with "extraction" procedures:
+//
+//
+// OPERATION MODE
+//
+// DBline receives an input line from a generic istream and held it into an 
+// internal buffer to be processed during the extraction of data. The data 
+// requests are send to DBline and are fulfilled only if the PATTERN (i.e. a 
+// Token, or a set of Tokens) specified by the user is found into the internal
+// buffer. At each succesfull "extraction" the corresponding data (i.e. the 
+// <Token> and the <related data>) are deleted from the internal buffer. 
+//
+// The implemented operation mode, in which the user can read and process data 
+// using this class, is made of three sequential step:
+// 
+// 1 - Input request. On each input request only a data line is read (i.e. 
+//     data are read until the carriage return character) and is subsequently
+//     stored into an internal buffer for further analysis. This operation 
+//     cause the deletation of data previously present into the internal 
+//     buffer. If the input stream is a file it will be automatically connected
+//     to the DBline class to allow incremental input line controlled via class
+//     operators. It is also possible to get input until a token is found; in 
+//     this case the token is only checked but not extracted (deleted) from the
+//     internal  buffer.
+// 
+// 2 - Extraction of data. An extraction request is made of a Token request 
+//     plus a data request. When a Token is found it is extraced from the 
+//     internal buffer and the starting position from which the subsequent data
+//     are extraced is updated to the actual Token position inside the line. If
+//     something goes  wrong (no Token found, or line become empty before all 
+//     the requested data are extracted), the extraction stops returning a 
+//     FALSE status, and all the data extracted from the last succesfull Token
+//     request are restored into the internal buffer. It is possible to request
+//     data without specifying a pattern before; in this case the data are
+//     extracted in a sequential way from the position in which the last 
+//     requested Token was found (if no Token has been succesfully found, the
+//     starting position is the beginning of the line). Finally it is also
+//     implemented a mechanism to request more complex pattern, i.e. pattren 
+//     like  <TOKEN> <data> <SUBTOKEN1> <data> <SUBTOKEN2> <data> .....
+//
+// 3 - Check for error. Before a new input request the internal buffer is 
+//     checked and if there are still data inside an error message is output 
+//     showing the data that are going to be deleted. Such data directives
+//     not understood by the reading routine.
+//
+//
+// SYNTAX
+//
+//              ********      INSTANTIATION      ********
+//----------------------------------------------------------------------------+
+// DBline data              normal instantiantion, no file connected.         |
+//----------------------------------------------------------------------------+
+// DBline data(file)        where file is an ifstream object. Instantiate     |
+//                          DBline object and connect a file to it.           |
+//                          04/08/2009 L. Bellagamba -> updated to works in   |  
+//                          the same way with ifstream and generic istream    |
+//----------------------------------------------------------------------------+
+//              ******** DATA INPUT FROM ISTREAM ********
+//----------------------------------------------------------------------------+
+// data << input            where input is a generic istream. If input is a   |
+//   .. or ..               file, it will be automatically connected with the |
+// input >> data            DBline object.                                    |
+//----------------------------------------------------------------------------+
+// data.connect(file)       connect an ifstream to the DBline object.         |
+//----------------------------------------------------------------------------+
+// data++                   input of 1 more line. Works only with a connected |
+//   .. or ..               input file. Return FALSE if the END OF FILE is    |
+// ++data                   reached                                           |
+//                          04/08/2009 L. Bellagamba -> updated to works also |
+//                          with a generic istream                            |
+//----------------------------------------------------------------------------+
+// data + n                 input of n lines. Works only with a connected     |
+//                          input file.Return FALSE if the END OF FILE is     |
+//                          reached                                           |
+//                          04/08/2009 L. Bellagamba -> updated to works also |
+//                          with a generic istream                            |
+//----------------------------------------------------------------------------+
+//              ********      TOKEN REQUEST      ********
+//----------------------------------------------------------------------------+
+// data.token("TOKEN")      seek the position of the word "TOKEN" into the    |
+//    ... or ...            database line stored internal buffer. If "TOKEN"  |
+//   data("TOKEN")          is found it will return a TRUE value.             |
+//----------------------------------------------------------------------------+
+// data.token("TOKEN #",t)  multiple token seek. Substitute the character #   |
+//       ... or ...         into the string "TOKEN #" with the ASCII type of  |
+//   data("TOKEN #",t)      object t and then look for an occurrence of such  |
+//                          token.                                            |
+//----------------------------------------------------------------------------+
+//              ********       DATA REQUEST      ********
+//----------------------------------------------------------------------------+
+// data >> type             use of extractor operator like in an I/O stream.  |
+//                          Supported type are: (normal/unsigned) int/long int|
+//                          float, double, string. Other type can be added,   |
+//                          but are not currently supported.                  |
+//----------------------------------------------------------------------------+
+// data.setf( .... )        use of the ios flags like in an I/O stream and    |
+//                          setf( ) function works in the same way.           |
+//----------------------------------------------------------------------------+
+// data.hex()               set format flags to get data from an hexadec. base|
+//----------------------------------------------------------------------------+
+// data.oct()               set format flags to get data from an octal base   |
+//----------------------------------------------------------------------------+
+// data.dec()               set format flags to get data from a decimal base  |
+//----------------------------------------------------------------------------+
+// data.reset_fmt()         reset the format flags to default value           |
+//----------------------------------------------------------------------------+
+// data >> hex()            same as data.hex() but can be used in I/O sequence|
+//----------------------------------------------------------------------------+
+// data >> oct()            same as data.oct() but can be used in I/O sequence|
+//----------------------------------------------------------------------------+
+// data >> dec()            same as data.dec() but can be used in I/O sequence|
+//----------------------------------------------------------------------------+
+// data >> setflags ( ..)   same as setf( .. ) but can be used in I/O sequence|
+//----------------------------------------------------------------------------+
+// data >> resetflags()     same as data.reset_fmt()                          |
+//----------------------------------------------------------------------------+
+//                                                                            |
+// Lorenzo Bellagamba: 8 March 2011                                           |
+//                                                                            |
+// data >> data.dbhex()     to be used in I/O sequence as hex(), dec() and    |
+// data >> data.dboct()     oct() but avoids creation and subsequent          |
+// data >> data.dbdec()     destruction of objects for each I/O operation.    |
+//                          Such methods return a pointer to DBfmt* objects   |
+//                          created once for ever when the DBline object is   |
+//                          instantiated. To preserve the previous            |
+//                          functionality a further method                    |
+// data.setdbfmtflag(int)   has been introduced. Such method sets a bool      |
+//                          private variable (del_dbfmt) which controls the   |
+//                          deletion of the DBfmt object in the >> operator.  |
+//                          Such bool variable must be false to use these new |
+//                          methods. By default the old functionality is      |
+//                          preserved and del_dbfmt=true:                     |
+//                          setdbfmtflag(0/1) -> del_dbfmt=false/true         |
+//----------------------------------------------------------------------------+
+//              ********    LOGICAL EXPRESSION    ********                    |
+//----------------------------------------------------------------------------+
+// operators ||, &&         combine the results from several extraction       |
+//                          requests. Keep in mind that, in a logic expression|
+//                          it is possible that some terms are not evaluated  |
+//                          (i.e. some of the extraction requests are not     |
+//                          performed); this depends on the result of the     |
+//                          previos terms in the logic sequence.              |
+//----------------------------------------------------------------------------+
+// operators |, &           combine the results from several extraction       |
+//                          requests forcing all the terms present in the     |
+//                          expression to be evaluated.                       |
+//----------------------------------------------------------------------------+
+//
+//
+// EXAMPLES
+//
+// to read a file until the end:
+//
+//    --| ifstream file("name",0);
+//    --| DBline data(file);
+//    --| while (data++)
+//    --| {
+//    --|     ..... process line ......
+//    --| }
+//
+// to read the folowing line:  < LABEL 1: 12.6 43 "this is a string" >
+//   
+//    --| float fl; int in; string str;
+//    --| data("LABEL 1:") >> fl >> in >> str;
+//
+// in the following line:
+//  
+//        < FIRST 12.6  SECOND 12  "this is a string"  THIRD 8 >
+//
+// each token can be read in an indipendent way with:
+//
+//    --| float fl; int i1,i2; string str;
+//    --| data("FIRST") >> fl;  
+//    --| data("SECOND") >> i1 >> str;
+//    --| data("THIRD") >> i2;
+//
+// or as a whole (i.e. researching the entire sequence in a given order):
+//
+//    --| float fl; int i1,i2; string str;
+//    --| data("FIRST") >> fl >> "SECOND" >> i1 >> str >> "THIRD" >> i2;
+//
+// to read until the occurrence of a TOKEN:
+//
+//    --| do
+//    --| {
+//    --|     ..... process line ......
+//    --|     data++;
+//    --| } while (data("TOKEN"));
+//
+// increase line until the occurrence of a TOKEN:
+//
+//    --| data.go_until("TOKEN");
+//
+// to read complex structure like:
+//           
+//      < START: "new sequence of data" {                      >
+//      <   Token 1  <data>                                    >
+//      <   Token 2  <data>                                    >
+//      < }                                                    >
+//
+//    --| if(data("START:") >> str >> "{")
+//    --| {
+//    --|     data("Token 1") >> <data>;
+//    --|     data("Token 2") >> <data>;
+//    --|     data++;
+//    --| } while (data("}"));
+//
+// to read hexadecimel values:
+//
+//        < value   ff >
+//
+//    --| unsigned long int i1;
+//    --| data("value").hex() >> i1;
+//    --| data.reset_fmt();
+//
+//            OR
+//
+//    --| unsigned long int i1;
+//    --| data("value") >> hex() >> i1 >> resetflags();
+
+
+
+
+
+#ifndef DBLINE_H
+#define DBLINE_H
+
+
+#include <ctype.h>
+#include <iostream>
+#include <iomanip> 
+#include <string>
+#include <fstream>
+#include <typeinfo>
+#include <stdint.h>
+
+// for compatibility between gcc2.95 and gcc3.2
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    #include <sstream>
+    typedef std::ostringstream __osstream;
+    typedef std::istringstream __isstream;
+#else
+    // put your gcc 2.95 specific code here
+    #include <strstream>
+    typedef ostrstream __osstream;
+    typedef istrstream __isstream;
+#endif
+
+
+typedef enum result_extraction {not_extracted,extracted} DBstatus;
+
+class DBfmt: virtual public std::ios {
+    public:
+    DBfmt();
+};
+
+class DBline: virtual public std::ios
+{
+ 
+    private:
+
+    typedef enum exist_quote {no_quote,begin_quote,end_quote,error} quote;
+
+    std::ios::fmtflags     m_default;
+    std::ifstream*         m_file;
+    std::istream*          m_stream;
+    std::string            m_data,m_backup,m_store;
+    unsigned long int      m_pos;
+    int                    m_line;
+    bool                   m_fail;
+    bool                   m_empty;
+    DBstatus               m_extraction;
+
+
+    // Private member functions for setting internal status
+    void reset_data(void);
+    void reset_status(void);
+    void reset(void);
+
+    // Private member functions for setting extraction status
+    void GoodExtraction(void);
+    void BadExtraction(void);
+
+    // Private member functions for managing the internal buffer
+    void erase_comment(void); 
+    void GetToken(unsigned long int pos,const std::string &token);
+    void GetLine(std::istream& input);
+
+    // Private member functions for extracting data
+    template <class type> void GetValue(type &value);
+    quote check_quote(std::string &);
+    void GetStr(std::string &);
+
+    // Check if internal buffer is empty
+    bool check_data(void);
+
+    // Private member to manage the I/O format
+    DBfmt* dbfmt_hex;
+    DBfmt* dbfmt_oct;
+    DBfmt* dbfmt_dec;
+    bool del_dbfmt;
+
+    public:
+
+    DBline();
+    DBline(std::ifstream& file);
+    DBline(std::istream& stream);
+    ~DBline() {delete dbfmt_hex; delete dbfmt_oct; delete dbfmt_dec;}
+    
+    // Function to connect input file/stream
+    void connect(std::ifstream& file);
+    void connect(std::istream& stream);
+
+    // Function to get the token
+    DBline& token (const std::string &);
+    template <class type> DBline& token (const std::string &,type t);
+    template <class type> DBline& token (const std::string &,type t, int size);
+    void go_until (const std::string &token);
+
+    // Check if exits data into the internal buffer
+    bool empty (void);
+
+    // Dump the processed directives
+    const char* dump(void);
+
+    // Public functions to set the I/O format
+    DBline& hex(void);
+    DBline& dec(void);
+    DBline& oct(void);
+    DBline& reset_fmt(void);
+    DBfmt* dbhex();
+    DBfmt* dboct();
+    DBfmt* dbdec();
+    void setdbfmtflag(int);
+
+    // Operators for extracting data
+    //DBline& operator>> (unsigned long int &i);
+    DBline& operator>> (unsigned long int *i);
+    //DBline& operator>> (long int &i);
+    DBline& operator>> (long int *i);
+    //DBline& operator>> (unsigned int &i);
+    DBline& operator>> (unsigned int *i);
+    //DBline& operator>> (unsigned short &i);
+    DBline& operator>> (unsigned short *i);
+    DBline& operator>> (int &i);
+    DBline& operator>> (int *i);
+    DBline& operator>> (float &f);
+    DBline& operator>> (float *f);
+    DBline& operator>> (double &f);
+    DBline& operator>> (double *f);
+    DBline& operator>> (std::string &str);
+    DBline& operator>> (std::string *str);
+    DBline& operator>> (char &c);
+    //DBline& operator>> (unsigned char &c);
+    
+    DBline& operator>> (uint8_t &i8);
+    DBline& operator>> (uint16_t &i16);
+    DBline& operator>> (uint32_t &i32);
+    DBline& operator>> (uint64_t &i64);
+
+
+    // Operator for allowing external manipulation of data
+    DBline& operator>> (DBfmt* f);
+
+    // Operator for subtoken searching
+    DBline& operator>> (const std::string &token);
+
+    // Operators for incremental input
+    DBline& operator++();
+    DBline& operator++(int i);
+    DBline& operator+ (int i);
+
+    // Internal status operators
+    operator bool ();
+    bool operator !();
+    operator DBstatus();
+
+    // Operators for extracting tokens
+    DBline& operator()(const std::string &str);
+    DBline& operator()(const std::string&,int);
+    DBline& operator()(const std::string&,int,int);
+
+    // Member function for unsing input from streams
+    DBline& operator << (std::istream& input);
+    DBline& operator << (std::ifstream& file);
+    
+    // Friend functions for using I/O whit streams
+    friend std::ifstream &operator >> (std::ifstream  &file, DBline &db);
+    friend std::istream  &operator >> (std::istream &stream, DBline &db);
+    friend std::ostream  &operator << (std::ostream &stream, DBline &db);
+
+};
+
+
+DBfmt* hex (void);
+DBfmt* oct(void);
+DBfmt* dec(void);
+DBfmt* resetflags(void);
+DBfmt* setflags(std::ios::fmtflags);
+DBfmt* setflags(std::ios::fmtflags,std::ios::fmtflags);
+
+
+#endif
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/README b/MuonSpectrometer/MuonCablings/MuonCablingTools/README
new file mode 100755
index 0000000000000..e4bc80924bc24
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/README
@@ -0,0 +1,18 @@
+This package contains the base classes of common utility for the MuonCabling
+packages. Moreover the BaseObject class is also inerithed by the classes 
+performing the Level-1 muon trigger simulation. Two sets of library are built:
+MuonCablingTools to be used into the ATHENA framework, and CablingTools to be 
+used into a standalone application.
+
+
+Basic components:
+
+BaseObject : is the base class from which most of the other classes are built.
+             It handles data member of geral use (name,object type) plus the
+             interface with the messaging services.
+
+dbline     : utility class for building a modular reading routine. The
+             type of serch pattern is: <Token> <set of data>.
+
+MessageStream : class that handles the characters set used for composing a 
+                message
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/cmt/requirements b/MuonSpectrometer/MuonCablings/MuonCablingTools/cmt/requirements
new file mode 100755
index 0000000000000..a23d6736309fe
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/cmt/requirements
@@ -0,0 +1,29 @@
+package MuonCablingTools
+
+author Alessandro Di Mattia <alessandro.dimattia@roma1.infn.it>
+
+use AtlasPolicy            AtlasPolicy-*
+
+private 
+#use AthenaKernel  	   AthenaKernel-*          Control
+use GaudiInterface         GaudiInterface-*        External
+
+
+#########################################################
+# ATHENA librariy build                                 #
+#########################################################
+
+public
+macro_append CablingTools_pp_cppflags " -DLVL1_STANDALONE "
+library CablingTools -no_share -suffix=STN *.cxx
+macro_append CablingTools_dependencies " install_includes"
+
+apply_pattern installed_library
+
+library MuonCablingTools *.cxx -s=../src/components *.cxx
+
+apply_pattern declare_runtime
+
+#apply_pattern declare_runtime_extras extras=*.data
+
+
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/src/BaseObject.cxx b/MuonSpectrometer/MuonCablings/MuonCablingTools/src/BaseObject.cxx
new file mode 100755
index 0000000000000..c937810a39330
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/src/BaseObject.cxx
@@ -0,0 +1,166 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "MuonCablingTools/BaseObject.h"
+
+#include <pthread.h>
+
+
+static pthread_mutex_t StopDisplayStream = PTHREAD_MUTEX_INITIALIZER;
+
+using namespace std;
+
+
+void
+MessageStream::init_message()
+{
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    m_display = new __osstream;
+#else
+    // put your gcc 2.95 specific code here
+    const int buffer_length=10000;
+    m_buffer_display = new char[buffer_length];
+    for(int i=0;i<buffer_length;++i) m_buffer_display[i]='\0';
+    m_display = new __osstream(m_buffer_display,buffer_length);
+#endif
+}
+
+void
+MessageStream::delete_message()
+{
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    delete m_display;
+#else
+    // put your gcc 2.95 specific code here
+    delete []m_buffer_display;
+    delete m_display;
+#endif
+}
+
+
+
+BaseObject::BaseObject(ObjectType tag,std::string name) : 
+    m_tag(tag),m_name(name) 
+{
+    m_message = new MessageStream;
+}
+
+BaseObject::BaseObject(ObjectType tag,const char* name) : 
+    m_tag(tag)
+{
+    int i=0;
+    while(name[i]!='\0') ++i;
+    m_name.resize(i);
+    i=0;
+    while(name[i]!='\0')
+    {
+        m_name[i] = name[i];
+	++i;
+    }
+    m_message = new MessageStream;
+}
+
+BaseObject::BaseObject(const BaseObject& obj)
+{
+    m_tag  = obj.tag();
+    m_name = obj.name();
+    m_message = new MessageStream;
+}
+
+BaseObject::~BaseObject()
+{
+    delete m_message;
+}
+
+
+void
+BaseObject::display_error(__osstream& display) const
+{
+#ifdef LVL1_STANDALONE
+    cout << display.str() << endl;
+#else
+    StatusCode sc;    
+    IMessageSvc*  msgSvc;
+    ISvcLocator* svcLoc = Gaudi::svcLocator( );
+    sc = svcLoc->service( "MessageSvc", msgSvc );
+    if(sc.isSuccess()) {
+        MsgStream log(msgSvc, name() );
+        log << MSG::ERROR << display.str() <<endreq; 
+    }
+#endif
+}
+
+void
+BaseObject::display_debug(__osstream& display) const
+{
+#ifdef LVL1_STANDALONE
+    cout << display.str() << endl;
+#else
+    StatusCode sc;
+    IMessageSvc*  msgSvc;
+    ISvcLocator* svcLoc = Gaudi::svcLocator( );
+    sc = svcLoc->service( "MessageSvc", msgSvc );
+    if(sc.isSuccess()) {
+        MsgStream log(msgSvc, name() );
+        log << MSG::DEBUG << display.str() <<endreq; 
+    }
+#endif
+}
+
+void
+BaseObject::display_warning(__osstream& display) const
+{
+#ifdef LVL1_STANDALONE
+    cout << display.str() << endl;
+#else
+    StatusCode sc;    
+    IMessageSvc*  msgSvc;
+    ISvcLocator* svcLoc = Gaudi::svcLocator( );
+    sc = svcLoc->service( "MessageSvc", msgSvc );
+    if(sc.isSuccess()) {
+        MsgStream log(msgSvc, name() );
+        log << MSG::WARNING << display.str() <<endreq; 
+    }
+#endif
+}
+
+void
+BaseObject::display_info(__osstream& display) const
+{
+#ifdef LVL1_STANDALONE
+    cout << display.str() << endl;
+#else
+    StatusCode sc;
+    IMessageSvc*  msgSvc;
+    ISvcLocator* svcLoc = Gaudi::svcLocator( );
+    sc = svcLoc->service( "MessageSvc", msgSvc );
+    if(sc.isSuccess()) {
+        MsgStream log(msgSvc, name() );
+        log << MSG::INFO << display.str() <<endreq; 
+    }
+#endif
+}
+
+void
+BaseObject::lock() const
+{
+    pthread_mutex_lock(&StopDisplayStream);
+}
+
+
+void
+BaseObject::unlock() const
+{
+    pthread_mutex_unlock(&StopDisplayStream);
+}
+
+BaseObject
+BaseObject::operator=(const BaseObject& obj)
+{
+    m_tag  = obj.tag();
+    m_name = obj.name();
+    return*this;
+}
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/src/RPCdecoder.cxx b/MuonSpectrometer/MuonCablings/MuonCablingTools/src/RPCdecoder.cxx
new file mode 100755
index 0000000000000..48ed55c4366d7
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/src/RPCdecoder.cxx
@@ -0,0 +1,242 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include <string>
+//#include <strstream>
+#include "MuonCablingTools/RPCdecoder.h"
+
+using namespace std;
+
+///////////////////////////////////////////////////////////////////////////////
+
+const int RPCdecoder::value_boundaries[4][2] = {
+        {  1 ,  2 },  // Min-Max of strip_type value
+        {  0 , 63 },  // Min-Max of logic_sector value
+        {  1 ,  3 },  // Min-Max of station value
+        {  0 ,  1 }   // Min_max of rpc_layer value
+    };
+const char RPCdecoder::value_descriptions[4][15] =
+        {{"strip_type"},{"logic_sector"},{"lvl1_station"},{"rpc_layer"}};
+
+///////////////////////////////////////////////////////////////////////////////
+RPCdecoder::RPCdecoder() {this->reset_status();}
+
+RPCdecoder::RPCdecoder(unsigned int code)
+{
+    this->reset();
+    this->set_indexes(code);
+}
+
+RPCdecoder::RPCdecoder(int strip_type,int logic_sector,int lvl1_station, 
+int rpc_layer,int rpc_z_index, int strip_number)
+{
+    this->reset();
+    this->set_code(strip_type,logic_sector,lvl1_station,rpc_layer,rpc_z_index,
+                   strip_number);
+}
+
+RPCdecoder::RPCdecoder(ViewType side,int logic_sector,int lvl1_station, 
+int rpc_layer,int rpc_z_index, int strip_number)
+{
+    this->reset();
+    int strip_type = this->side2type(side);
+    this->set_code(strip_type,logic_sector,lvl1_station,rpc_layer,rpc_z_index,
+                   strip_number);
+}
+
+RPCdecoder::RPCdecoder(const RPCdecoder& deco)
+{
+    this->reset();
+    this->set_indexes(deco.code());
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+RPCdecoder RPCdecoder::operator = (const RPCdecoder& deco)
+{
+    this->reset();
+    this->set_indexes(deco.code());
+    return *this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void
+RPCdecoder::reset()
+{
+    this->reset_status();
+    this->reset_data();
+}
+
+void
+RPCdecoder::reset_data()
+{
+    m_code = 0;
+    m_strip_type = -1;
+    m_logic_sector = -1;
+    m_lvl1_station = -1;
+    m_rpc_layer = -1;
+    m_rpc_z_index = -1;
+    m_strip_number = -1;
+}
+
+void
+RPCdecoder::reset_status()
+{
+    m_fail = false;
+}
+
+void
+RPCdecoder::fault_decoding(int value,value_type type)
+{
+#if (__GNUC__) && (__GNUC__ > 2) 
+    // put your gcc 3.2 specific code here
+    __osstream disp;
+#else
+    // put your gcc 2.95 specific code here
+    char buffer[5000];
+    for (int i=0;i<5000;++i) buffer[i] = '\0';
+    __osstream disp(buffer,5000);
+#endif
+    disp << " RPC decoder error: received " << value_descriptions[type]
+         << " = " << value << "  (min = " << value_boundaries[type][0]
+         << ", max = " << value_boundaries[type][1] << ")"<< endl;
+#ifdef LVL1_STANDALONE
+    cout << disp.str();
+#else
+#endif
+    m_fail = true; 
+}
+
+bool
+RPCdecoder::OK(int value,value_type type) const
+{
+    if(value >= value_boundaries[type][0] &&
+       value <= value_boundaries[type][1]   ) return true; 
+    return false;
+}
+
+void
+RPCdecoder::set_code(int strip_type,int logic_sector,int lvl1_station,
+		     int rpc_layer,int rpc_z_index,int strip_number)
+{
+  if(!OK(strip_type,Strip_Type)) fault_decoding(strip_type,Strip_Type);
+  if(!OK(logic_sector,Logic_Sector)) fault_decoding(logic_sector,Logic_Sector);
+  if(!OK(lvl1_station,LVL1_Station)) fault_decoding(lvl1_station,LVL1_Station);
+  if(!OK(rpc_layer,RPC_Layer)) fault_decoding(rpc_layer,RPC_Layer); 
+
+  if(m_fail) { this->reset_data(); return; }
+
+  m_code = strip_type   * 100000000 +
+           logic_sector * 1000000   +
+           lvl1_station * 100000    +
+           rpc_layer    * 10000     +
+           rpc_z_index  * 100       +
+           strip_number;
+
+  m_strip_type   = strip_type;
+  m_logic_sector = logic_sector;
+  m_lvl1_station = lvl1_station;
+  m_rpc_layer    = rpc_layer;
+  m_rpc_z_index  = rpc_z_index;
+  m_strip_number = strip_number;
+}
+
+void
+RPCdecoder::set_indexes(unsigned int code)
+{    
+
+    m_strip_number = code%100;
+    m_rpc_z_index  = (code/100)%100;
+    m_rpc_layer    = (code/10000)%10;
+    m_lvl1_station = (code/100000)%10;
+    m_logic_sector = (code/1000000)%100;
+    m_strip_type   =  code/100000000;
+
+    if(!OK(m_strip_type,Strip_Type)) fault_decoding(m_strip_type,Strip_Type);
+    if(!OK(m_logic_sector,Logic_Sector)) 
+        fault_decoding(m_logic_sector,Logic_Sector);
+    if(!OK(m_lvl1_station,LVL1_Station)) 
+        fault_decoding(m_lvl1_station,LVL1_Station);
+    if(!OK(m_rpc_layer,RPC_Layer)) fault_decoding(m_rpc_layer,RPC_Layer); 
+
+    if(m_fail) { this->reset_data(); return; }
+
+    m_code = code;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+RPCdecoder&
+RPCdecoder::operator()(unsigned int code)
+{
+    this->reset();
+    this->set_indexes(code);
+    return *this;
+}
+
+RPCdecoder&
+RPCdecoder::operator()(int strip_type,int logic_sector,int lvl1_station, 
+int rpc_layer,int rpc_z_index, int strip_number)
+{
+    this->reset();
+    this->set_code(strip_type,logic_sector,lvl1_station,rpc_layer,rpc_z_index,
+                   strip_number);
+    return *this;
+}
+
+RPCdecoder&
+RPCdecoder::operator()(ViewType side,int logic_sector,int lvl1_station, 
+int rpc_layer,int rpc_z_index, int strip_number)
+{
+    this->reset();
+    int strip_type = side2type(side);
+    this->set_code(strip_type,logic_sector,lvl1_station,rpc_layer,rpc_z_index,
+                      strip_number);
+    return *this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+ViewType RPCdecoder::view(void) const 
+{
+    if(m_strip_type == -1) return NoView;
+    return (m_strip_type==1)? Phi : Eta;
+}
+    
+HalfType RPCdecoder::half_barrel(void) const 
+{
+    if(m_logic_sector == -1) return NoHalf;
+    return (m_logic_sector<32)? Negative : Positive;
+}
+
+int RPCdecoder::side2type(ViewType side) const 
+{
+    if(side == NoView) return -1;
+    return (side == Eta)? 2 : 1;
+}
+
+void RPCdecoder::Print(ostream& stream,bool detail) const
+{
+    unsigned int div = 247;
+    std::string half=(half_barrel()==Negative)? "Negative" :"Positive";
+
+    stream << "RPC strip hash code " << code() << ":" << endl;
+    if(detail)
+    {
+        stream << "   half barrel            = " << half << endl;
+        stream << "   type (1=Phi/2=Eta)     = " << strip_type() << endl;
+        stream << "   logic sector (0" << (char)div << "63)    = " 
+               << logic_sector() << endl;
+        stream << "   level-1 station (1" << (char)div << "n)  = "
+               << lvl1_station() << endl;
+        stream << "   RPC layer (0/1)        = " << rpc_layer() << endl;
+        stream << "   RPC z index (0" << (char)div << "n)      = "
+	       << rpc_z_index() << endl;
+        stream << "   RPC strip number (0" << (char)div << "n) = "
+	       << strip_number() << endl;
+        stream << "   strip cabling code     = " << cabling_code() << endl;
+    }
+}
+
diff --git a/MuonSpectrometer/MuonCablings/MuonCablingTools/src/dbline.cxx b/MuonSpectrometer/MuonCablings/MuonCablingTools/src/dbline.cxx
new file mode 100755
index 0000000000000..1b93ac75c6de2
--- /dev/null
+++ b/MuonSpectrometer/MuonCablings/MuonCablingTools/src/dbline.cxx
@@ -0,0 +1,607 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "MuonCablingTools/dbline.h"
+
+using namespace std;
+
+///////////////////////////////////////////////////////////////////////////////
+//////////// PRIVATE MEMBER FUNCTIONS FOR SETTING INTERNAL STATUS /////////////
+///////////////////////////////////////////////////////////////////////////////
+
+void DBline::reset_data(void)    {m_data=""; m_pos=0; m_backup="";}
+void DBline::reset_status(void)  {GoodExtraction();m_empty=false;}
+void DBline::reset(void)         {reset_data(); reset_status();}
+
+
+///////////////////////////////////////////////////////////////////////////////
+//////////// PRIVATE MEMBER FUNCTIONS FOR SETTING EXTRACTION STATUS ///////////
+///////////////////////////////////////////////////////////////////////////////
+ 
+void DBline::GoodExtraction(void){m_extraction = extracted;}
+void DBline::BadExtraction(void){m_extraction = not_extracted;m_data=m_backup;}
+
+
+///////////////////////////////////////////////////////////////////////////////
+////////// PRIVATE MEMBER FUNCTIONS FOR MANAGING THE INTERNAL BUFFER //////////
+///////////////////////////////////////////////////////////////////////////////
+
+void
+DBline::erase_comment()
+{
+    unsigned long int pos = m_data.find("#");
+    if(pos != string::npos) m_data.erase(pos);
+}
+
+void
+DBline::GetToken( unsigned long int pos, const string &token)
+{
+    GoodExtraction();
+    m_data.erase(pos,token.length());
+    m_pos = pos;
+}
+
+void
+DBline::GetLine(istream& input)
+{
+    if(!check_data())
+    {
+        cerr << "line " << setw(4) << m_line << " -|" << m_data.c_str();
+        cerr << "  .. not understood!" << endl;
+    }
+    reset();
+    if(input.eof()) {m_fail = true; return;}
+    m_line++;
+    char ch;
+    while(input.get(ch) && ch !='\n') m_data += ch;
+    //std::string tmp = m_store;
+    // m_store = m_store + m_data;// + '\n';
+    m_store += m_data;
+    erase_comment();
+    check_data();
+    if(input.eof()) m_fail = true;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////// PRIVATE MEMBER FUNCTIONS FOR EXTRACTING DATA ////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+template <class type> void
+DBline::GetValue(type &value)
+{
+    if (!m_extraction||m_fail) return;
+    unsigned long int start = m_data.find_first_not_of(" ",m_pos);
+    if(start == string::npos) {BadExtraction();return;}
+    unsigned long int stop = m_data.find_first_of(" ",start+1) - 1;
+
+    __isstream tmp(m_data.substr(start,stop).c_str());
+
+    tmp.flags(flags());
+    tmp >> value;
+
+    unsigned long int del = (stop - start) + (start - m_pos) + 1;
+    m_data.erase(m_pos,del);
+    check_data();
+}
+
+void 
+DBline::GetStr(string &str)
+{
+    GetValue(str);
+    quote pos = check_quote(str);
+    if(!pos) {return;}
+    if(pos == begin_quote)
+    {
+	unsigned long int pos = m_data.find('"',m_pos);
+        if(pos == string::npos) {str=""; BadExtraction(); return;}
+        str += m_data.substr(m_pos,pos);
+        m_data.erase(m_pos,(pos-m_pos)+1);
+    }
+    else {str=""; BadExtraction();}
+}
+
+DBline::quote
+DBline::check_quote(string &str)
+{
+    std::string::size_type pos = str.find('"');
+    if(pos == string::npos) return no_quote;
+    else if(pos == 0) {str.erase(0,1);return begin_quote;}
+    else if(pos == str.length()-1) {str.erase(pos,1);return end_quote;}
+    return error;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/////////////////////// CHECK IF INTERNAL BUFFER IS EMPTY /////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+bool
+DBline::check_data(void)
+{
+    m_empty = true;
+    int character;
+    const char * ch = m_data.c_str();
+    while ((character = *ch++)) if (!isspace(character)) m_empty = false;
+    return m_empty;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////// FUNCTION TO CONNECT INPUT FILE-STREAM ///////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+void
+DBline::connect(ifstream& file)
+{
+    if((&file) != m_file)
+    {
+        m_store = "";
+        m_line  = 0;
+        m_fail  = 0;
+        m_stream= 0;
+	m_file  = &file;
+    }
+}
+
+void
+DBline::connect(istream& stream)
+{
+    if((&stream) != m_stream)
+    {
+        m_store = "";
+        m_line  = 0;
+        m_fail  = 0;
+        m_file  = 0;
+	m_stream  = &stream;
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/////////////////////////// FUNCTION TO GET THE TOKEN /////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+DBline&
+DBline::token(const string &token)
+{
+    if(m_extraction) m_backup = m_data;
+    if(check_data()) {BadExtraction();return *this;}
+    unsigned long int pos = m_data.find(token);
+
+    if (pos != string::npos) 
+    {
+        unsigned long int finalpos = pos + token.length();
+        char prev = (pos)? m_data[pos-1] : ' ';
+        char foll = (finalpos < m_data.length())? m_data[finalpos] : ' ';
+        if(prev == ' ' && foll == ' ') GetToken(pos,token);
+        else BadExtraction();
+    }
+    else BadExtraction();
+    return *this;
+}
+
+template <class type> DBline&
+DBline::token(const string &str, type t)
+{
+    string new_token = str;
+    unsigned long int pos = new_token.find('#');
+    if (pos != string::npos)
+    {
+      __osstream tmp;
+#if (__GNUC__) && (__GNUC__ > 2) 
+      // put your gcc 3.2 specific code here
+      tmp << t ;
+      string rep = tmp.str();
+#else
+      // put your gcc 2.95 specific code here
+      tmp << t << ends;
+      string rep(tmp.str());
+#endif
+
+      new_token.replace(pos,rep.length(),rep);
+      token(new_token);
+    } else token(new_token);
+
+    return *this;    
+}
+
+template <class type> DBline&
+DBline::token(const string &str, type t, int /*size*/)
+{
+    //size = 0;
+    string new_token = str;
+    unsigned long int pos = new_token.find('#');
+    if (pos != string::npos)
+    {
+      __osstream tmp;
+#if (__GNUC__) && (__GNUC__ > 2) 
+      // put your gcc 3.2 specific code here
+      tmp << setw(2) << setfill('0') << t ;
+      string rep = tmp.str();
+#else
+      // put your gcc 2.95 specific code here
+      tmp << t << ends;
+      string rep(tmp.str());
+#endif
+
+      new_token.replace(pos,rep.length(),rep);
+      token(new_token);
+    } else token(new_token);
+
+    return *this;    
+}    
+
+void 
+DBline::go_until (const string &token)
+{
+    if(m_file) do GetLine(*m_file);while(m_data.find(token) == string::npos);
+    if(m_stream) do GetLine(*m_stream);while(m_data.find(token) == string::npos);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////// CHECKS IF DATA EXIST INTO THE INTERNAL BUFFER ///////////////
+///////////////////////////////////////////////////////////////////////////////
+
+bool DBline::empty (void) {return m_empty;}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////// DUMP THE PROCESSED DIRECTIVES ///////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+const char* DBline::dump(void) {return m_store.c_str();}
+
+
+///////////////////////////////////////////////////////////////////////////////
+//////////////////////// FUNCTIONS TO SET THE I/O FORMAT //////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+DBline& DBline::hex(void){setf(ios::hex,ios::basefield);return*this;}
+DBline& DBline::dec(void){setf(ios::dec,ios::basefield);return*this;}
+DBline& DBline::oct(void){setf(ios::dec,ios::basefield);return*this;}
+DBline& DBline::reset_fmt(void) {flags(m_default);return*this;}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////// OPERATORS FOR EXTRACTING DATA ///////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+//DBline& DBline::operator>> (unsigned long int &i) {GetValue(i);  return*this;}
+DBline& DBline::operator>> (unsigned long int *i) {GetValue(*i); return*this;}
+//DBline& DBline::operator>> (long int &i)          {GetValue(i);  return*this;}
+DBline& DBline::operator>> (long int *i)          {GetValue(*i); return*this;}
+//DBline& DBline::operator>> (unsigned int &i)      {GetValue(i);  return*this;}
+DBline& DBline::operator>> (unsigned int *i)      {GetValue(*i); return*this;}
+//DBline& DBline::operator>> (unsigned short &i)    {GetValue(i);  return*this;}
+DBline& DBline::operator>> (unsigned short *i)    {GetValue(*i); return*this;}
+DBline& DBline::operator>> (int &i)               {GetValue(i);  return*this;}
+DBline& DBline::operator>> (int *i)               {GetValue(*i); return*this;}
+DBline& DBline::operator>> (float &f)             {GetValue(f);  return*this;}
+DBline& DBline::operator>> (float *f)             {GetValue(*f); return*this;}
+DBline& DBline::operator>> (double &f)            {GetValue(f);  return*this;}
+DBline& DBline::operator>> (double *f)            {GetValue(*f); return*this;}
+DBline& DBline::operator>> (string &str)          {GetStr(str);  return*this;}
+DBline& DBline::operator>> (string *str)          {GetStr(*str); return*this;}
+DBline& DBline::operator>> (char &c)              {GetValue(c);  return*this;}
+//DBline& DBline::operator>> (unsigned char &c)     {GetValue(c);  return*this;}
+
+DBline& DBline::operator>> (uint8_t &i8)          {GetValue(i8); return*this;}
+DBline& DBline::operator>> (uint16_t &i16)        {GetValue(i16);return*this;}
+DBline& DBline::operator>> (uint32_t &i32)        {GetValue(i32);return*this;}
+DBline& DBline::operator>> (uint64_t &i64)        {GetValue(i64);return*this;}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////// OPERATOR FOR ALLOWING EXTERNAL MANIPULATION OF DATA /////////////
+///////////////////////////////////////////////////////////////////////////////
+
+DBline& DBline::operator>> (DBfmt* f) {
+  flags(f->flags());
+  if(del_dbfmt)delete f;
+  return*this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//////////////////////// OPERATOR FOR SUBTOKEN SEARCHING //////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+DBline&
+DBline::operator >>(const string &token)
+{
+    if (!m_extraction || check_data() || m_fail) return *this;
+    unsigned long int pos = m_data.find(token,m_pos);
+    if ( pos != string::npos) GetToken(pos,token);
+    else BadExtraction();
+    return *this;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////// OPERATORS FOR INCREMENTAL INPUT /////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+DBline& 
+DBline::operator++()      
+{
+    if(m_file) GetLine(*m_file);
+    if(m_stream) GetLine(*m_stream);
+    return *this;
+}
+
+DBline& 
+DBline::operator++(int i) 
+{
+    for(int j=-1;j<i;j++) {
+      if(m_file) GetLine(*m_file);
+      if(m_stream) GetLine(*m_stream);
+    }
+    return *this;
+}
+
+DBline& 
+DBline::operator+ (int i) 
+{
+    for(int j=0;j<i;j++) {
+      if(m_file) GetLine(*m_file);
+      if(m_stream) GetLine(*m_stream);
+    }
+    return *this;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+//////////////////////////// INTERNAL STATUS OPERATOR /////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+DBline::operator bool ()   {return !(m_fail|!static_cast<bool>(m_extraction));}
+bool DBline::operator !()  {return m_fail|!static_cast<bool>(m_extraction);}
+DBline::operator DBstatus(){return m_extraction;}
+
+
+///////////////////////////////////////////////////////////////////////////////
+//////////////////////// OPERATORS FOR EXTRACTING TOKENS //////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+DBline& DBline::operator()(const string &str) {token(str);return*this;}
+    
+DBline& 
+DBline::operator()(const string& str, int n) {token(str,n);return*this;}
+    
+DBline&
+DBline::operator()(const string& str, int n, int s) {token(str,n,s);return*this;}
+
+///////////////////////////////////////////////////////////////////////////////
+
+DBline::DBline(): 
+  m_file(0),m_stream(0),m_data(""),m_backup(""),m_store(""),
+  m_pos(0), m_line(0), 
+  m_fail(false),m_empty(false),m_extraction(extracted)
+{
+  this->setf  (std::ios::unitbuf |
+               std::ios::dec     );
+  this->unsetf(std::ios::skipws    |
+               std::ios::left      |
+	       std::ios::right     |
+	       std::ios::internal  |
+	       std::ios::oct       |
+	       std::ios::hex       |
+	       std::ios::showbase  |
+	       std::ios::showpoint |
+	       std::ios::uppercase |
+	       std::ios::scientific|
+	       std::ios::fixed     |
+	       std::ios::showpos   |
+	       std::ios::boolalpha  );
+  m_default = flags();
+  dbfmt_hex = new DBfmt();
+  dbfmt_hex->setf(std::ios::hex,std::ios::basefield);
+  dbfmt_oct = new DBfmt();
+  dbfmt_oct->setf(std::ios::oct,std::ios::basefield);
+  dbfmt_dec = new DBfmt();
+  dbfmt_dec->setf(std::ios::dec,std::ios::basefield);
+  del_dbfmt = true;
+}
+
+DBline::DBline(ifstream& file): 
+  m_file(&file),m_stream(0),m_data(""),m_backup(""),m_store(""),
+  m_pos(0), m_line(0), 
+  m_fail(false),m_empty(false),m_extraction(extracted)
+{
+  this->setf  (std::ios::unitbuf |
+               std::ios::dec     );
+  this->unsetf(std::ios::skipws    |
+               std::ios::left      |
+	       std::ios::right     |
+	       std::ios::internal  |
+	       std::ios::oct       |
+	       std::ios::hex       |
+	       std::ios::showbase  |
+	       std::ios::showpoint |
+	       std::ios::uppercase |
+	       std::ios::scientific|
+	       std::ios::fixed     |
+	       std::ios::showpos   |
+	       std::ios::boolalpha  );
+	       
+  m_default = flags();
+  dbfmt_hex = new DBfmt();
+  dbfmt_hex->setf(std::ios::hex,std::ios::basefield);
+  dbfmt_oct = new DBfmt();
+  dbfmt_oct->setf(std::ios::oct,std::ios::basefield);
+  dbfmt_dec = new DBfmt();
+  dbfmt_dec->setf(std::ios::dec,std::ios::basefield);
+  del_dbfmt = true;
+}
+
+DBline::DBline(istream& stream): 
+  m_file(0),m_stream(&stream),m_data(""),m_backup(""),m_store(""),
+  m_pos(0), m_line(0), 
+  m_fail(false),m_empty(false),m_extraction(extracted)
+{
+  this->setf  (std::ios::unitbuf |
+               std::ios::dec     );
+  this->unsetf(std::ios::skipws    |
+               std::ios::left      |
+	       std::ios::right     |
+	       std::ios::internal  |
+	       std::ios::oct       |
+	       std::ios::hex       |
+	       std::ios::showbase  |
+	       std::ios::showpoint |
+	       std::ios::uppercase |
+	       std::ios::scientific|
+	       std::ios::fixed     |
+	       std::ios::showpos   |
+	       std::ios::boolalpha  );
+	       
+  m_default = flags();
+  dbfmt_hex = new DBfmt();
+  dbfmt_hex->setf(std::ios::hex,std::ios::basefield);
+  dbfmt_oct = new DBfmt();
+  dbfmt_oct->setf(std::ios::oct,std::ios::basefield);
+  dbfmt_dec = new DBfmt();
+  dbfmt_dec->setf(std::ios::dec,std::ios::basefield);
+  del_dbfmt = true;
+}
+
+DBline&
+DBline::operator <<(ifstream &file)
+{
+    connect(file);
+    GetLine(file);
+    return *this;
+}
+
+DBline&
+DBline::operator <<(istream &input)
+{
+    connect(input);
+    GetLine(input);
+    return *this;
+}
+
+// LB 29/03/2011 new methods to avoid 
+// continues creation and destruction of DBfmt objects
+
+DBfmt* DBline::dbhex()
+{
+  return dbfmt_hex;
+}
+
+DBfmt* DBline::dboct()
+{
+  return dbfmt_oct;
+}
+
+DBfmt* DBline::dbdec()
+{
+  return dbfmt_dec;
+}
+
+void DBline::setdbfmtflag(int delfl)
+{
+  if(delfl==0)del_dbfmt = false;
+  else del_dbfmt = true;
+  return; 
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+ifstream &operator>>(ifstream &file, DBline &db)
+{ 
+    db.connect(file);
+    db.GetLine(file);
+    return file;
+}
+
+istream &operator>>(istream &stream, DBline &db)
+{ 
+  //    db.m_file = 0;
+  //    db.m_fail = 0;
+    db.connect(stream);
+    db.GetLine(stream);
+    return stream;
+}
+
+ostream &operator<<(ostream &stream, DBline &db) 
+{
+    stream << db.m_data.c_str();
+    return stream;
+}
+
+DBstatus operator |(DBstatus s1, DBstatus s2)
+{
+    if(s1 || s2) return extracted;
+    return not_extracted;
+}
+
+DBstatus operator &(DBstatus s1, DBstatus s2)
+{
+    if(s1 && s2) return extracted;
+    return not_extracted;
+}
+
+
+DBfmt::DBfmt()
+{  
+  this->setf  (std::ios::unitbuf |
+               std::ios::dec     );
+  this->unsetf(std::ios::skipws    |
+               std::ios::left      |
+	       std::ios::right     |
+	       std::ios::internal  |
+	       std::ios::oct       |
+	       std::ios::hex       |
+	       std::ios::showbase  |
+	       std::ios::showpoint |
+	       std::ios::uppercase |
+	       std::ios::scientific|
+	       std::ios::fixed     |
+	       std::ios::showpos   |
+	       std::ios::boolalpha  );
+}
+
+
+DBfmt* hex(void)
+{
+    DBfmt* fmt = new (DBfmt);
+    fmt->setf(ios::hex,ios::basefield);
+    return fmt;
+}
+
+DBfmt* oct(void)
+{
+    DBfmt* fmt = new (DBfmt);
+    fmt->setf(ios::oct,ios::basefield);
+    return fmt;
+}
+DBfmt* dec(void)
+{
+    DBfmt* fmt = new (DBfmt);
+    fmt->setf(ios::dec,ios::basefield);
+    return fmt;
+}
+
+
+DBfmt* resetflags(void)
+{
+  DBfmt* fmt = new (DBfmt);
+  return fmt; 
+}
+
+DBfmt* setflags(ios::fmtflags f)
+{
+  DBfmt* fmt = new (DBfmt);
+  fmt->setf(f);
+  return fmt;
+}
+
+DBfmt* setflags(ios::fmtflags f1,ios::fmtflags f2)
+{
+  DBfmt* fmt = new (DBfmt);
+  fmt->setf(f1,f2);
+  return fmt;
+}
-- 
GitLab