Marlin  1.17.1
 All Classes Namespaces Functions Variables Enumerations Friends Pages
CCProcessor.h
1 #ifndef CCPROCESSOR_H
2 #define CCPROCESSOR_H
3 
4 #include "marlin/Processor.h"
5 
6 #include <set>
7 #include <fstream>
8 
9 #define MAX_ERRORS 3
10 #define ACTIVE true
11 #define INACTIVE false
12 #define NO_PARAMETERS 0
13 #define NOT_INSTALLED 1
14 #define COL_ERRORS 2
15 #define INPUT "lcioInType"
16 #define OUTPUT "lcioOutType"
17 #define UNAVAILABLE "lcioUnavailableType"
18 #define DUPLICATE "lcioDuplicate"
19 
20 namespace marlin {
21 
22  class CCCollection;
23 
24  typedef std::set< std::string > sSet;
25  typedef std::vector< CCCollection* > ColVec;
26  typedef std::map< std::string, std::string > ssMap;
27  typedef std::map< std::string, ssMap > sssMap;
28  typedef std::map< std::string, ColVec > sColVecMap;
29  typedef std::map< std::string, sColVecMap > ssColVecMap;
30 
39  class CCProcessor{
40 
41  public:
42 
43  // Constructor
44  CCProcessor( bool status, const std::string& name, const std::string& type, std::shared_ptr<StringParameters> p);
45 
46  // Copy Constructor
48 
49  // Destructor
50  ~CCProcessor();
51 
52  // assignment operator, unused, verboten
53  CCProcessor& operator=( const CCProcessor &) = delete;
54 
56  bool hasErrors();
57 
59  bool hasParameters(){ return !_error[ NO_PARAMETERS ]; }
60 
62  bool hasErrorCols(){ return _error[ COL_ERRORS ]; }
63 
65  bool isInstalled(){ return !_error[ NOT_INSTALLED ]; }
66 
68  bool isActive(){ return _status; }
69 
71  bool hasCondition( const std::string& condition );
72 
74  const std::string& getName(){ return _name; }
75 
77  const std::string& getType(){ return _type; }
78 
80  sSet& getConditions(){ return _conditions; }
81 
83  const std::string getDescription(){ return (isInstalled() ? _proc->description() :
84  "This processor is NOT installed in your Marlin binary: parameter descriptions and types lost!!");
85  }
86 
87  /* Returns a string vector with the errors of the processor - Obsolete: use getError() instead */
88  //const StringVec& getErrors(){ return _errors; }
89 
91  const std::string getError(){ return ( _errors.size() != 0 ? _errors[0] : "" ); }
92 
94  const std::string getStatusDesc(){ return ( isActive() ? "Active" : "Inactive" ); }
95 
97  bool isErrorCol( const std::string& type, const std::string& value );
98 
100  bool isParamOptional( const std::string& key );
101 
103  std::shared_ptr<StringParameters> getParameters(){ return _param; }
104 
106  const ssMap& getColHeaders( const std::string& iotype ){ return _types[iotype]; }
107 
111  ColVec& getCols( const std::string& iotype, const std::string& type_name="ALL_COLLECTIONS" );
112 
116  sSet& getColTypeNames( const std::string& iotype );
117 
119  void addCol( const std::string& iotype, const std::string& name, const std::string& type, const std::string& value );
120 
122  void remCol( const std::string& iotype, const std::string& name, unsigned int index );
123 
125  void addUCol( CCCollection* c );
126 
128  void addDCol( CCCollection* c );
129 
131  void changeStatus();
132 
134  void setName( const std::string& name ){ _name = name; };
135 
137  void setConditions( const std::string& conditions );
138 
140  void setError( int error );
141 
143  void clearError( int error );
144 
146  void setOptionalParam( const std::string& key, bool optional=true );
147 
149  void writeToXML( std::ofstream& stream );
150 
151  private:
152 
154  // METHODS
156  void addColsFromParam( std::shared_ptr<StringParameters> p );
157  void writeColsToParam();
158  void clearParameters();
159  void setMarlinProc(); //sets error flag NOT_INSTALLED if processor couldn't be set
160  CCCollection* popCol( ColVec& v, CCCollection* c );
161 
163  // VARIABLES
165  bool _status; // false = INACTIVE ; true = ACTIVE
166  std::vector<bool> _error; // 0 = proc has no parameters; 1 = proc is not build in this marlin installation; 2 = unavailable collections
167  std::string _name; // name of the processor
168  std::string _type; // type of the processor
169  std::shared_ptr<StringParameters> _param; // parameters from processor
170  Processor* _proc; // associated Marlin processor
171 
172  const StringVec _error_desc{ "Processor has no Parameters", "Processor not available!", "Some Collections have Errors"}; // error descriptions for all processors
173  StringVec _errors{}; // list of errors found in a processor
174 
175  sSet _conditions; // processor's conditions
176 
177  ssColVecMap _cols; // first key for Types INPUT : OUTPUT : UNAVAILABLE : DUPLICATE
178  // for INPUT/OUPUT the second key is for Collection Names
179  // for UNAVAILABLE/DUPLICATE the second key is for Collection Types
180 
181  sssMap _types; // first key for Types INPUT : OUTPUT
182  // second key is for Collection Names and the third string for Collection Types
183 
184  sSet _optParams; // list of optional parameters that shall be written out as normal parameters
185  };
186 
187 } // end namespace marlin
188 #endif
void addDCol(CCCollection *c)
Adds a duplicate collection to this processor.
Definition: CCProcessor.cc:319
const std::string getError()
Returns a string with the error of the processor.
Definition: CCProcessor.h:91
sSet & getConditions()
Returns the Conditions of the processor.
Definition: CCProcessor.h:80
bool isErrorCol(const std::string &type, const std::string &value)
Returns true if the given collection is in the unavailable or duplicate list of this processor...
Definition: CCProcessor.cc:381
handles information about LCIO collections needed by MarlinSteerCheck
Definition: CCCollection.h:17
void remCol(const std::string &iotype, const std::string &name, unsigned int index)
Removes collection of the given iotype ( INPUT / OUTPUT ) with the given name at the given index...
Definition: CCProcessor.cc:327
void setError(int error)
Activates an error flag in this processor ( NO_PARAMETERS=0, NOT_INSTALLED=1, COL_ERRORS=2 ) ...
Definition: CCProcessor.cc:399
handles information about marlin processors and their collections needed by MarlinSteerCheck ...
Definition: CCProcessor.h:39
sSet & getColTypeNames(const std::string &iotype)
Returns collection&#39;s types/names of a given iotype found in the processor If iotype == INPUT/OUTPUT t...
Definition: CCProcessor.cc:370
void clearError(int error)
Clears an error flag in this processor ( NO_PARAMETERS=0, NOT_INSTALLED=1, COL_ERRORS=2 ) ...
Definition: CCProcessor.cc:406
void setConditions(const std::string &conditions)
Sets the processor&#39;s conditions.
Definition: CCProcessor.cc:153
bool isParamOptional(const std::string &key)
Returns true if a parameter is optional (optional means the parameter will be written out as a commen...
Definition: CCProcessor.cc:437
bool isInstalled()
Returns true if the processor is installed.
Definition: CCProcessor.h:65
void setOptionalParam(const std::string &key, bool optional=true)
Sets a parameter as optional (if optional=true parameter is written out as a comment) ...
Definition: CCProcessor.cc:446
void writeToXML(std::ofstream &stream)
Writes this processor to a stream using the XML format.
Definition: CCProcessor.cc:455
bool hasErrors()
Returns true if the processor has errors.
Definition: CCProcessor.cc:428
const std::string & description()
Description of processor.
Definition: Processor.h:193
const std::string & getType()
Returns the Type of the processor.
Definition: CCProcessor.h:77
bool hasCondition(const std::string &condition)
Returns true if the processor is constrained by the given condition.
Definition: CCProcessor.cc:201
void changeStatus()
Changes the processor status ( ACTIVE-&gt;INACTIVE or INACTIVE-&gt;ACTIVE )
Definition: CCProcessor.cc:281
const std::string & getName()
Returns the Name of the processor.
Definition: CCProcessor.h:74
ColVec & getCols(const std::string &iotype, const std::string &type_name="ALL_COLLECTIONS")
Returns collections of a given iotype ( INPUT, OUTPUT, UNAVAILABLE, DUPLICATE ) for a given name or t...
Definition: CCProcessor.cc:352
void addCol(const std::string &iotype, const std::string &name, const std::string &type, const std::string &value)
Adds a collection of the given iotype ( INPUT / OUTPUT ) with the given name, type and value...
Definition: CCProcessor.cc:290
const ssMap & getColHeaders(const std::string &iotype)
Returns a map with collection names and their respective types for INPUT/OUTPUT collections of this p...
Definition: CCProcessor.h:106
bool hasParameters()
Returns true if the processor has parameters.
Definition: CCProcessor.h:59
Base class for Marlin processors.
Definition: Processor.h:64
void setName(const std::string &name)
Sets the processor&#39;s name.
Definition: CCProcessor.h:134
const std::string getStatusDesc()
Returns a string with the processor status ( &quot;Active&quot;, &quot;Inactive&quot; )
Definition: CCProcessor.h:94
bool isActive()
Returns true if the processor is active.
Definition: CCProcessor.h:68
const std::string getDescription()
Returns the Description of the processor.
Definition: CCProcessor.h:83
bool hasErrorCols()
Returns true if the processor has collection errors.
Definition: CCProcessor.h:62
std::shared_ptr< StringParameters > getParameters()
Returns the string parameters for this processor.
Definition: CCProcessor.h:103
void addUCol(CCCollection *c)
Adds an unavailable collection to this processor.
Definition: CCProcessor.cc:311