ROOT logo
#ifndef __TMrbSubevent_h__
#define __TMrbSubevent_h__

//_________________________________________________[C++ CLASS DEFINITION FILE]
//////////////////////////////////////////////////////////////////////////////
// Name:           expconf/inc/TMrbSubevent.h
// Purpose:        Define experimental configuration for MARaBOU
// Class:          TMrbSubevent         -- base class for subevents
// Description:    Class definitions to implement a configuration front-end for MARaBOU
// Author:         R. Lutter
// Revision:       $Id: TMrbSubevent.h,v 1.26 2011-12-15 16:33:23 Marabou Exp $
// Date:
// Keywords:
//////////////////////////////////////////////////////////////////////////////

namespace std {} using namespace std;

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>

#include "Rtypes.h"
#include "TSystem.h"
#include "TObject.h"
#include "TNamed.h"
#include "TString.h"

#include "TMrbLofNamedX.h"
#include "TMrbTemplate.h"
#include "TMrbEvent.h"
#include "TMrbModule.h"
#include "TMrbCamacModule.h"
#include "TMrbVMEModule.h"

class TMrbEvent;
class TMrbModule;
class TMrbModuleChannel;

//______________________________________________________[C++ CLASS DEFINITION]
//////////////////////////////////////////////////////////////////////////////
// Name:           TMrbSubevent
// Purpose:        Define methods for a subevent
// Description:    Defines how to generate code for a subevent
// Keywords:
//////////////////////////////////////////////////////////////////////////////

class TMrbSubevent : public TNamed {

	public:

		TMrbSubevent() {};									// default ctor

		TMrbSubevent(const Char_t * SevtName, const Char_t * SevtTitle = "", Int_t Crate = -1);	// explicit ctor

		~TMrbSubevent() {									// dtor
			fLofParams.Delete();							// remove objects stored in TMrbLofNamdeXs
//			fLofModules.Delete();
		};

		TMrbSubevent(const TMrbSubevent &) : TNamed() {};			// default copy ctor

		inline void AddEvent(TMrbEvent * Evt) {		 	// add a parent event
			fLofEvents.Add(Evt);
			fNofEvents++;
		};

		inline TMrbEvent * FindEvent(const Char_t * EvtName) const {	// find a parent
			return ((TMrbEvent *) fLofEvents.FindObject(EvtName));
		};

		Bool_t AddParam(TMrbModuleChannel * Param);			 	// add a new parameter

		inline TMrbModuleChannel * FindParam(const Char_t * ParamName) const {		// find param by its name
			return((TMrbModuleChannel *) fLofParams.FindObject(ParamName));
		};

		inline Bool_t AddModule(TMrbModule * Module) {		 	// add a new module
			fLofModules.Add(Module);
			fNofModules++;
			return(kTRUE);
		};

		inline TMrbModule * NextModule(TMrbModule * After = NULL) const {	// get next module from list
			return((After == NULL) ? (TMrbModule *) fLofModules.First() : (TMrbModule *) fLofModules.After((TObject *) After));
		};

		inline TMrbModule * FindModule(const Char_t * ModuleName) const {	// find a module
			return ((TMrbModule *) fLofModules.FindObject(ModuleName));
		};

		TMrbModule * FindModuleByID(TMrbConfig::EMrbModuleID ModuleID, TMrbModule * After = NULL) const; 		// find module by its id
		inline TMrbModule * FindModuleByID(TMrbNamedX * ModuleID, TMrbModule * After = NULL) const {
			return(this->FindModuleByID((TMrbConfig::EMrbModuleID) ModuleID->GetIndex(), After));
		};

		TMrbModule * FindModuleByType(UInt_t ModuleType, TMrbModule * After = NULL) const; 	// find module by its type
		inline TMrbModule * FindModuleByType(TMrbNamedX * ModuleType, TMrbModule * After = NULL) const {
			return(this->FindModuleByType(ModuleType->GetIndex(), After));
		};

		TMrbModule * FindModuleBySerial(Int_t ModuleSerial) const;				 		// find module by its serial number

		Bool_t Use(const Char_t * ModuleName, const Char_t * Assignment, Bool_t BookHistos = kTRUE); 		// assign parameters
		inline Bool_t Use(const Char_t * Assignment, Bool_t BookHistos = kTRUE) { return(Use(NULL, Assignment, BookHistos)); };

		inline Int_t GetSerial() const { return(fSerial); };  	 					// return unique subevent id

		Bool_t Set(const Char_t * ParamName, const Char_t * RegName, Int_t Value);	// set param register by name
		Bool_t Set(const Char_t * ParamName, Int_t RegIndex, Int_t Value);			// ... by index
		Int_t Get(const Char_t * ParamName, const Char_t * RegName) const;			// get param register by name
		Int_t Get(const Char_t * ParamName, Int_t RegIndex) const;					// ... by index

		inline Int_t GetNofEvents() const { return(fNofEvents); };
		inline Int_t GetNofModules() const { return(fNofModules); };

		inline Int_t GetNofParams() const { return(fNofParams); };					// get number of params
		inline Int_t GetNofShorts() const { return(fNofShorts); };					// get number of 16 bit words
		inline UInt_t GetLegalDataTypes() const { return(fLegalDataTypes); }; // data types subevent is capable of

		inline Int_t GetCrate() const { return(fCrate); };					// return crate number

		inline UInt_t GetType() const { return(fSevtType); }; 				// subevent's type & subtype
		inline UInt_t GetSubtype() const { return(fSevtSubtype); };
		inline const Char_t * GetDescr() { return(fSevtDescr.Data()); };

		virtual Bool_t MakeReadoutCode(ofstream & RdoStrm, TMrbConfig::EMrbReadoutTag TagIndex, TMrbTemplate & Template, const Char_t * Prefix = NULL) { return(kFALSE); };  // generate part of code

		Bool_t MakeAnalyzeCode(ofstream & AnaStrm, TMrbConfig::EMrbAnalyzeTag TagIndex, const Char_t * Extension);	// generate part of analyzing code
		Bool_t MakeAnalyzeCode(ofstream & AnaStrm, TMrbConfig::EMrbAnalyzeTag TagIndex, TMrbEvent * Event, TMrbTemplate & Template, const Char_t * Prefix = NULL);

		virtual Bool_t MakeSpecialAnalyzeCode(ofstream & AnaStrm, TMrbConfig::EMrbAnalyzeTag TagIndex, TMrbTemplate & Template) { return(kFALSE); };  // generate part of code

		Bool_t MakeConfigCode(ofstream & CfgStrm, TMrbConfig::EMrbConfigTag TagIndex, TMrbTemplate & Template, const Char_t * Prefix = NULL);

		virtual Bool_t MakeRcFile(ofstream & RcStrm, TMrbConfig::EMrbRcFileTag TagIndex, const Char_t * ResourceName) { return(kFALSE); };

		Bool_t SetReadoutOptions(Option_t * Options = "");					// set options for MakeReadoutCode()
		Bool_t SetAnalyzeOptions(Option_t * Options = "byName:Histograms");	// set options for MakeAnalyzeCode()
		Bool_t SetConfigOptions(Option_t * Options = "");					// set options for MakeConfigCode()
		UInt_t GetReadoutOptions(TMrbEvent * Parent = NULL) const; 			// return MakeReadoutCode() options
		UInt_t GetAnalyzeOptions(TMrbEvent * Parent = NULL) const; 			// return MakeAnalyzeCode() options
		UInt_t GetConfigOptions(TMrbEvent * Parent = NULL) const;			// return MakeConfigCode() options

		Bool_t SetParamName(Int_t ParamNo, Char_t * ParamName);						// set param name explicitly
		inline void UseExplicitParamNames(Bool_t Flag = kTRUE) { fExplicitParamNames = Flag; };
		inline Bool_t ExplicitParamNamesToBeUsed() { return(fExplicitParamNames); };

		inline const Char_t * GetPrefix() const { return(fPrefix.Data()); };
		inline Bool_t PrefixToBePrepended() const { return(fPrependPrefix); };	// prepend an individual prefix?
		void PrependPrefix(const Char_t * Prefix) {
			fPrefix = Prefix;
			fPrefix.ToLower();
			fPrependPrefix = !fPrefix.IsNull();
		};
		inline void PrependPrefix(Bool_t Flag = kTRUE) { fPrependPrefix = fPrefix.IsNull() ? kFALSE : Flag; };

		void Print(Option_t * Option) const { TObject::Print(Option); }
		void Print(ostream & OutStrm, const Char_t * Prefix = "") const;	// show data
		inline virtual void Print() const { Print(cout, ""); };

		inline void AllocateHistograms(Bool_t Flag = kTRUE) { fHistosToBeAllocated = Flag; }; // create histograms?
		inline Bool_t HistosToBeAllocated() const { return(fHistosToBeAllocated); };
		inline void FillHistogramsIfTrueHitOnly(Bool_t Flag = kTRUE) { fHistosToBeFilledIfTrueHit = Flag; };
		inline Bool_t HistosToBeFilledIfTrueHit() const { return(fHistosToBeFilledIfTrueHit); };

		Bool_t SetMbsBranch(Int_t MbsBranchNo, const Char_t * MbsBranchName = NULL);							// mbs branch
		inline Bool_t SetMbsBranch(TMrbNamedX * MbsBranch) { return(this->SetMbsBranch(MbsBranch->GetIndex(), MbsBranch->GetName())); };
		inline TMrbNamedX * GetMbsBranch() { return(&fMbsBranch); };
		inline Int_t GetMbsBranchNo() { return(fMbsBranch.GetIndex()); };

		virtual inline Bool_t HasFixedLengthFormat() const { return(kTRUE); };		// fixed length data
		virtual inline Bool_t AllowsMultipleModules() const { return(kTRUE); };		// format allows multiple modules
		virtual inline Bool_t SerialToBeCreated() const { return(kTRUE); }			// create unique serial internally?
		virtual inline Bool_t IsRaw() const { return(kFALSE); };						// not raw (user-defined) mode
		virtual inline Bool_t CheckModuleID(TMrbModule * Module) const { return(kTRUE); }; // subevent may store any modules

																				// params to be addressed in array mode?
		inline void SetArrayMode(Bool_t ArrayMode = kTRUE) { fArrayMode = ArrayMode; };	// single array to be used?
		inline Bool_t IsInArrayMode() const { return(fArrayMode); };
		inline Bool_t HasIndexedParams() const { return(fHasIndexedParams); };

		Bool_t UseXhit(const Char_t * HitName, Int_t DataLength = -1);			// define a special hit object to be used
		inline Bool_t UseXhit(Int_t DataLength) { return(this->UseXhit("Xhit", DataLength)); };
		inline const Char_t * GetNameOfXhit() { return(fXhit ? fXhit->GetName() : ""); };
		inline Int_t GetHitDataLength() { return(fXhit ? fXhit->GetIndex() : 0); };
		inline Bool_t HasXhit() { return(fXhit != NULL); };

		virtual inline Bool_t NeedsHitBuffer() const { return(kFALSE); }; 			// no hit buffer needed
		virtual inline Bool_t NeedsBranchMode() const { return(kFALSE); }; 			// may run with leaves or branches
		virtual inline Bool_t NeedsModulesToBeAssigned() const { return(kTRUE); };	// normal subevents need modules

		virtual inline Bool_t HasPrivateCode() const { return(kFALSE); }; 			// normal code generation
		virtual inline Bool_t SingleModuleOnly() const { return(kFALSE); }; 		// only module per subevent only
		virtual inline const Char_t * GetPrivateCodeFile() const { return(NULL); };
		virtual inline const Char_t * GetCommonCodeFile() { return(NULL); };

		inline TObjArray * GetLofEvents() { return(&fLofEvents); };			// get address of ...
		inline TObjArray * GetLofModules() { return(&fLofModules); };
		const Char_t * GetLofModulesAsString(TString & LofModules) const;
		inline TObjArray * GetLofParams() { return(&fLofParams); };
		const Char_t * GetLofParamsAsString(TString & LofParams) const;

		inline void CreateHistoArray(const Char_t * ArrayName = NULL) {		// create array of histograms and write .histlist file
			fCreateHistoArray = kTRUE;
			fHistoArrayName = ArrayName ? ArrayName : this->GetName();
		}
		inline Bool_t HistoArrayToBeCreated() { return(fCreateHistoArray); };
		inline const Char_t * GetHistoArrayName() { return(fHistoArrayName.Data()); };

		void Browse(TBrowser * Browser);

		inline void Help() { gSystem->Exec(Form("mrbHelp %s", this->ClassName())); };

	protected:
		UInt_t fSevtType;					// subevent type
		UInt_t fSevtSubtype;				// subevent subtype
		UInt_t fLegalDataTypes; 			// datatypes legal for this type of subevent
		TString fSevtDescr; 				// description

		Int_t fSerial;						// header words: unique subevent id
		Int_t fCrate;						// crate number

		Bool_t fHistosToBeAllocated;		// kTRUE if histograms to be allocated for all params
		Bool_t fHistosToBeFilledIfTrueHit;	// fill histograms if is it true hit

		TMrbNamedX fMbsBranch;				// branch within MBS

		Bool_t fExplicitParamNames;			// kTRUE if explicit param names to be used

		Int_t fNofEvents;					// list of parent events
		TObjArray fLofEvents;

		Int_t fNofParams;					// number of params
		Int_t fNofShorts;					// number of 16 bit words;
		TObjArray fLofParams;				// list of params

		Int_t fNofModules;					// list of modules housing these params
		TObjArray fLofModules;

		UInt_t fReadoutOptions; 			// options used in MakeReadoutCode()
		UInt_t fAnalyzeOptions; 			// ... in MakeAnalyzeCode()
		UInt_t fConfigOptions;  			// ... in MakeConfigCode()

		Bool_t fHasIndexedParams;			// if there are TArrayX params
		Bool_t fArrayMode;					// kTRUE if subevent data are stored in an array

		Bool_t fPrependPrefix;				// kTRUE if subevents has its own prefix
		TString fPrefix;					// prefix to be prepended to params & histos

		TMrbNamedX * fXhit;				// a special (extended) hit

		TString fInheritsFrom;				// subevent parent class
		TString fCommonCodeFile;			// name of common code

		Bool_t fCreateHistoArray;			// kTRUE if histo array / .histlist file is to be created
		TString fHistoArrayName;			// name of histo array / .histlist file

		TMrbModule * fSoftModule;			// internal module name, simulated by software

	ClassDef(TMrbSubevent, 1)		// [Config] Base class describing a MBS subevent
};

#endif
 TMrbSubevent.h:1
 TMrbSubevent.h:2
 TMrbSubevent.h:3
 TMrbSubevent.h:4
 TMrbSubevent.h:5
 TMrbSubevent.h:6
 TMrbSubevent.h:7
 TMrbSubevent.h:8
 TMrbSubevent.h:9
 TMrbSubevent.h:10
 TMrbSubevent.h:11
 TMrbSubevent.h:12
 TMrbSubevent.h:13
 TMrbSubevent.h:14
 TMrbSubevent.h:15
 TMrbSubevent.h:16
 TMrbSubevent.h:17
 TMrbSubevent.h:18
 TMrbSubevent.h:19
 TMrbSubevent.h:20
 TMrbSubevent.h:21
 TMrbSubevent.h:22
 TMrbSubevent.h:23
 TMrbSubevent.h:24
 TMrbSubevent.h:25
 TMrbSubevent.h:26
 TMrbSubevent.h:27
 TMrbSubevent.h:28
 TMrbSubevent.h:29
 TMrbSubevent.h:30
 TMrbSubevent.h:31
 TMrbSubevent.h:32
 TMrbSubevent.h:33
 TMrbSubevent.h:34
 TMrbSubevent.h:35
 TMrbSubevent.h:36
 TMrbSubevent.h:37
 TMrbSubevent.h:38
 TMrbSubevent.h:39
 TMrbSubevent.h:40
 TMrbSubevent.h:41
 TMrbSubevent.h:42
 TMrbSubevent.h:43
 TMrbSubevent.h:44
 TMrbSubevent.h:45
 TMrbSubevent.h:46
 TMrbSubevent.h:47
 TMrbSubevent.h:48
 TMrbSubevent.h:49
 TMrbSubevent.h:50
 TMrbSubevent.h:51
 TMrbSubevent.h:52
 TMrbSubevent.h:53
 TMrbSubevent.h:54
 TMrbSubevent.h:55
 TMrbSubevent.h:56
 TMrbSubevent.h:57
 TMrbSubevent.h:58
 TMrbSubevent.h:59
 TMrbSubevent.h:60
 TMrbSubevent.h:61
 TMrbSubevent.h:62
 TMrbSubevent.h:63
 TMrbSubevent.h:64
 TMrbSubevent.h:65
 TMrbSubevent.h:66
 TMrbSubevent.h:67
 TMrbSubevent.h:68
 TMrbSubevent.h:69
 TMrbSubevent.h:70
 TMrbSubevent.h:71
 TMrbSubevent.h:72
 TMrbSubevent.h:73
 TMrbSubevent.h:74
 TMrbSubevent.h:75
 TMrbSubevent.h:76
 TMrbSubevent.h:77
 TMrbSubevent.h:78
 TMrbSubevent.h:79
 TMrbSubevent.h:80
 TMrbSubevent.h:81
 TMrbSubevent.h:82
 TMrbSubevent.h:83
 TMrbSubevent.h:84
 TMrbSubevent.h:85
 TMrbSubevent.h:86
 TMrbSubevent.h:87
 TMrbSubevent.h:88
 TMrbSubevent.h:89
 TMrbSubevent.h:90
 TMrbSubevent.h:91
 TMrbSubevent.h:92
 TMrbSubevent.h:93
 TMrbSubevent.h:94
 TMrbSubevent.h:95
 TMrbSubevent.h:96
 TMrbSubevent.h:97
 TMrbSubevent.h:98
 TMrbSubevent.h:99
 TMrbSubevent.h:100
 TMrbSubevent.h:101
 TMrbSubevent.h:102
 TMrbSubevent.h:103
 TMrbSubevent.h:104
 TMrbSubevent.h:105
 TMrbSubevent.h:106
 TMrbSubevent.h:107
 TMrbSubevent.h:108
 TMrbSubevent.h:109
 TMrbSubevent.h:110
 TMrbSubevent.h:111
 TMrbSubevent.h:112
 TMrbSubevent.h:113
 TMrbSubevent.h:114
 TMrbSubevent.h:115
 TMrbSubevent.h:116
 TMrbSubevent.h:117
 TMrbSubevent.h:118
 TMrbSubevent.h:119
 TMrbSubevent.h:120
 TMrbSubevent.h:121
 TMrbSubevent.h:122
 TMrbSubevent.h:123
 TMrbSubevent.h:124
 TMrbSubevent.h:125
 TMrbSubevent.h:126
 TMrbSubevent.h:127
 TMrbSubevent.h:128
 TMrbSubevent.h:129
 TMrbSubevent.h:130
 TMrbSubevent.h:131
 TMrbSubevent.h:132
 TMrbSubevent.h:133
 TMrbSubevent.h:134
 TMrbSubevent.h:135
 TMrbSubevent.h:136
 TMrbSubevent.h:137
 TMrbSubevent.h:138
 TMrbSubevent.h:139
 TMrbSubevent.h:140
 TMrbSubevent.h:141
 TMrbSubevent.h:142
 TMrbSubevent.h:143
 TMrbSubevent.h:144
 TMrbSubevent.h:145
 TMrbSubevent.h:146
 TMrbSubevent.h:147
 TMrbSubevent.h:148
 TMrbSubevent.h:149
 TMrbSubevent.h:150
 TMrbSubevent.h:151
 TMrbSubevent.h:152
 TMrbSubevent.h:153
 TMrbSubevent.h:154
 TMrbSubevent.h:155
 TMrbSubevent.h:156
 TMrbSubevent.h:157
 TMrbSubevent.h:158
 TMrbSubevent.h:159
 TMrbSubevent.h:160
 TMrbSubevent.h:161
 TMrbSubevent.h:162
 TMrbSubevent.h:163
 TMrbSubevent.h:164
 TMrbSubevent.h:165
 TMrbSubevent.h:166
 TMrbSubevent.h:167
 TMrbSubevent.h:168
 TMrbSubevent.h:169
 TMrbSubevent.h:170
 TMrbSubevent.h:171
 TMrbSubevent.h:172
 TMrbSubevent.h:173
 TMrbSubevent.h:174
 TMrbSubevent.h:175
 TMrbSubevent.h:176
 TMrbSubevent.h:177
 TMrbSubevent.h:178
 TMrbSubevent.h:179
 TMrbSubevent.h:180
 TMrbSubevent.h:181
 TMrbSubevent.h:182
 TMrbSubevent.h:183
 TMrbSubevent.h:184
 TMrbSubevent.h:185
 TMrbSubevent.h:186
 TMrbSubevent.h:187
 TMrbSubevent.h:188
 TMrbSubevent.h:189
 TMrbSubevent.h:190
 TMrbSubevent.h:191
 TMrbSubevent.h:192
 TMrbSubevent.h:193
 TMrbSubevent.h:194
 TMrbSubevent.h:195
 TMrbSubevent.h:196
 TMrbSubevent.h:197
 TMrbSubevent.h:198
 TMrbSubevent.h:199
 TMrbSubevent.h:200
 TMrbSubevent.h:201
 TMrbSubevent.h:202
 TMrbSubevent.h:203
 TMrbSubevent.h:204
 TMrbSubevent.h:205
 TMrbSubevent.h:206
 TMrbSubevent.h:207
 TMrbSubevent.h:208
 TMrbSubevent.h:209
 TMrbSubevent.h:210
 TMrbSubevent.h:211
 TMrbSubevent.h:212
 TMrbSubevent.h:213
 TMrbSubevent.h:214
 TMrbSubevent.h:215
 TMrbSubevent.h:216
 TMrbSubevent.h:217
 TMrbSubevent.h:218
 TMrbSubevent.h:219
 TMrbSubevent.h:220
 TMrbSubevent.h:221
 TMrbSubevent.h:222
 TMrbSubevent.h:223
 TMrbSubevent.h:224
 TMrbSubevent.h:225
 TMrbSubevent.h:226
 TMrbSubevent.h:227
 TMrbSubevent.h:228
 TMrbSubevent.h:229
 TMrbSubevent.h:230
 TMrbSubevent.h:231
 TMrbSubevent.h:232
 TMrbSubevent.h:233
 TMrbSubevent.h:234
 TMrbSubevent.h:235
 TMrbSubevent.h:236
 TMrbSubevent.h:237
 TMrbSubevent.h:238
 TMrbSubevent.h:239
 TMrbSubevent.h:240
 TMrbSubevent.h:241
 TMrbSubevent.h:242
 TMrbSubevent.h:243
 TMrbSubevent.h:244
 TMrbSubevent.h:245
 TMrbSubevent.h:246
 TMrbSubevent.h:247
 TMrbSubevent.h:248
 TMrbSubevent.h:249
 TMrbSubevent.h:250
 TMrbSubevent.h:251
 TMrbSubevent.h:252
 TMrbSubevent.h:253
 TMrbSubevent.h:254
 TMrbSubevent.h:255
 TMrbSubevent.h:256
 TMrbSubevent.h:257
 TMrbSubevent.h:258
 TMrbSubevent.h:259
 TMrbSubevent.h:260
 TMrbSubevent.h:261
 TMrbSubevent.h:262
 TMrbSubevent.h:263
 TMrbSubevent.h:264
 TMrbSubevent.h:265