Configuration.cpp
Go to the documentation of this file.
1 /*
2  * File: Configuration.cpp
3  * Author: denis
4  *
5  * Configuration of the job
6  *
7  *
8  * Created on February 1, 2012, 8:41 AM
9  */
10 // ART includes
12 #include "fhiclcpp/ParameterSet.h"
13 
14 #ifdef NOVACMAKE
18 #else
19 #include "MockDataDAQ/Configuration.h"
20 #include "MockDataDAQ/DAQSimulator.h"
21 #include "MockDataDAQ/GlobalEventTime.h"
22 #endif
23 
24 #include "Geometry/Geometry.h"
25 #include "NovaDAQConventions/DAQConventions.h"
26 
27 #include <stdio.h>
28 #include <sys/stat.h>
29 
30 
31 namespace mcdatadaq{
32 
34 
35 //------------------------------------------------------------------------------
37  if(finstanceID == NULL){ // Check if there is an instance active
38  finstanceID = new Configuration(); // If there is not, make a new one
39  }
40  return finstanceID;
41 }
42 
43 //------------------------------------------------------------------------------
44 /// Method to set the class instance with parameters from fhicl
46 
47  /// If the configuration already exists, then we delete it
48  if(!finstanceID) delete finstanceID;
49 
50  /// Issue a brand new Configuration
51  finstanceID = new Configuration(parameters);
52 
53  return true;
54 }
55 
56 //------------------------------------------------------------------------------
62  ,fOutputDir(".")
63  ,fFileName("muon")
66  ,fIsProducingRunObject(false)
70 {
71  print();
72 }
73 
74 //------------------------------------------------------------------------------
77  ,fNumberOfMicroslicesInMilliSlice(parameters.get< uint32_t >("NumberOfMicroslicesInMilliSlice"))
78  ,fMicrosliceDT(parameters.get< uint32_t >("MicrosliceDT"))
79  ,fNumberOfBufferNodes(parameters.get< uint32_t >("NumberOfBufferNodes"))
80  ,fOutputDir(parameters.get< std::string >("OutputDir"))
81  ,fFileName(parameters.get< std::string >("FileName"))
82  ,fEventTimeDifference(parameters.get< uint32_t >("EventTimeDifference"))
83  ,fIsProducingJustMicroSlices(parameters.get< bool >("ProduceJustMicroSlices"))
84  ,fIsProducingRunObject(parameters.get< bool >("FillRunObject"))
85  ,fIsProducingMilliSlices(parameters.get< bool >("FillMilliSlices"))
86  ,fNanoSliceVersion(parameters.get< daqdataformats::version_t >("NanoSliceVersion"))
87  ,fMicroBlockVersion(parameters.get< daqdataformats::version_t >("MicroBlockVersion"))
88 {
89  print();
90  struct stat sb;
91  assert((stat(fOutputDir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) && "Output directory doesn't exist or we don't have permissions to it, fail.");
92 }
93 
94 //------------------------------------------------------------------------------
96 
97 //------------------------------------------------------------------------------
99 
101  fDetector = geo->DetId();
102 
103  /// Checking if detectorID is invalid. If so, return false.
105  fDetector >= novadaq::cnv::kNDetector) return false;
106 
107 
108  std::cout<<"Setting detector to "<<novadaq::cnv::DetInfo::GetName(fDetector)<<"\n";
109 
110  return true;
111 
112 }// end of init
113 
114 //------------------------------------------------------------------------------
115 int Configuration::getDetector() const { return fDetector;}
116 bool Configuration::isDetectorUnknown() const { return (fDetector == novadaq::cnv::kUNKNOWN_DET);}// end of isDetectorUnknown
124 
125 
128 
129 //------------------------------------------------------------------------------
130 std::string Configuration::getFullFileName(const std::string addition_to_file_name) const{
131 
132  const std::string file_extention = ".raw";
133  const std::string full_file_name = getOutputDir()
134  + "/"
135  + getFileName()
136  + "_"
137  + addition_to_file_name
138  + file_extention;
139  return full_file_name;
140 }
141 
142 //------------------------------------------------------------------------------
143 // Print Configuration
144 bool Configuration::print() const{
145 
146  std::cout<<"MockDataDAQ Configuration: ";
147 
148  std::cout<<" Detector="<<fDetector<<std::endl;;
149  std::cout<<" Produce Just MicroSlices="<<fIsProducingJustMicroSlices<<std::endl;
150  std::cout<<" Producing MilliSlices="<<fIsProducingMilliSlices<<std::endl;
151  std::cout<<" Number Of Microslices In MilliSlice="<<fNumberOfMicroslicesInMilliSlice<<std::endl;;
152  std::cout<<" Microslice DT="<<fMicrosliceDT<<std::endl;;
153  std::cout<<" Number Of Buffer Nodes="<<fNumberOfBufferNodes<<std::endl;
154  std::cout<<" Event Time Difference="<<fEventTimeDifference<<std::endl;
155 
156  std::cout<<" Output Directory:"<<fOutputDir<<std::endl;
157  std::cout<<" FileName:"<<fFileName<<std::endl;
158  std::cout<<" NanoSliceVersion:"<<fNanoSliceVersion<<std::endl;
159 
160  return true;
161 }
162 
163 //------------------------------------------------------------------------------
164 /// Write data into a file
165 bool Configuration::writeToFile(FILE* file, const daqdataformats::RawDAQData& daq_data) const{
166 
167  /// If empty file, exit
168  if(!file) return true;
169 
170  const size_t size_of_data_in_words = daq_data.sizeofdata();
171 
172  if(size_of_data_in_words == 0) return true;
173 
174  fwrite (daq_data.getBuffer(), 4, size_of_data_in_words, file);
175  return true;
176 }
177 
178 //------------------------------------------------------------------------------
179 // Open file for binary write access
181  return fopen (file_name.c_str(), "wb");
182 }
183 
184 //------------------------------------------------------------------------------
186 
187 //------------------------------------------------------------------------------
189 
190  const uint32_t daq_sim_version = getDAQSimulatorVersion();
191  fwrite (&daq_sim_version, 4 , 1, file);
192 
193  return true;
194 }
195 
196 }// end of namespace
static std::string GetName(int id)
bool print() const
Print Configuration.
bool isProducingJustMicroSlices() const
Do we produce just microslices?
uint32_t fNumberOfMicroslicesInMilliSlice
!< ipnd, near, far
Definition: Configuration.h:80
static const uint32_t DEFAULT_NUMBER_MICROSLICES_IN_MILLISLICE
Definition: Configuration.h:20
uint32_t getNumberOfBufferNodes() const
Number of buffer nodes.
Configuration()
default constructor
static const uint32_t DEFAULT_DCM_MICROSLICE_DT
Definition: Configuration.h:21
static bool setInstance(fhicl::ParameterSet const &pset)
Method to set the class instance with parameters from fhicl.
daqdataformats::version_t fNanoSliceVersion
!< Are me going to produce MilliSlices?
Definition: Configuration.h:94
std::string fOutputDir
Directory for the output files.
Definition: Configuration.h:85
static Configuration * finstanceID
Definition: Configuration.h:75
FILE * openFile(const std::string file_name) const
Open file for binary write access.
uint32_t fNumberOfBufferNodes
Number of buffer nodes.
Definition: Configuration.h:83
void * getBuffer() const
Definition: RawDAQData.h:131
std::string getOutputDir() const
GetOutput Directory.
bool fIsProducingMilliSlices
!< Are we producing Run Object?
Definition: Configuration.h:92
std::string fFileName
Output file names.
Definition: Configuration.h:86
static Configuration * getInstance()
Method to obtain the class instance.
bool fIsProducingRunObject
!< Are we producing just microslices?
Definition: Configuration.h:91
uint32_t getEventTimeDifference() const
Event time difference in NOvA clock ticks (15.626 ns)
static const uint32_t DEFAULT_NUMBER_OF_BUFFERNODES
Definition: Configuration.h:22
Something conflicts with RandomNumberGenerator. Keep DAQSimulator.h include below Art Framework inclu...
daqdataformats::version_t fMicroBlockVersion
Definition: Configuration.h:95
uint32_t getDAQSimulatorVersion() const
Get Global DAQSimulator version.
int getDetector() const
Get Detector ID.
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
uint32_t fMicrosliceDT
MicroSlice length in NOvA clock ticks (15.626 ns)
Definition: Configuration.h:81
bool isDetectorUnknown() const
Check Detector if it&#39;s unknown ID.
bool writeToFile(FILE *, const daqdataformats::RawDAQData &) const
Utility method of writing DAQ data into a file.
static const uint32_t DEFAULT_TIME_DIFF
OStream cout
Definition: OStream.cxx:6
bool isProducingRunObject() const
Do we produce Run object?
daqdataformats::version_t getNanoSliceVersion() const
Get NanoSlice version.
std::string getFullFileName(const std::string addition_to_file_name) const
std::string getFileName() const
Get File name.
bool init()
initialize detector
static const uint32_t DAQSIMULATION_VERSION
Version of the DAQ simulation.
Definition: DAQSimulator.h:39
int fDetector
!< Instance pointer for singleton class
Definition: Configuration.h:77
int32_t version_t
Definition: RawDAQData.h:72
bool writeDAQSimulatorVersionIntoFile(FILE *) const
Write Global DAQSimulator version into the input file.
uint32_t fEventTimeDifference
Event time difference in NOvA clock ticks (15.626 ns)
Definition: Configuration.h:88
TFile * file
Definition: cellShifts.C:17
assert(nhit_max >=nhit_nbins)
uint32_t getMicrosliceDT() const
MicroSlice DT.
daqdataformats::version_t getMicroBlockVersion() const
Get MicroBlock version.
Class to hold the data from the FEBs in correct formats.
Helper for AttenCurve.
Definition: Path.h:10
uint32_t sizeofdata() const
Sizeof method for the current data block. Returns the size of the data block in 32bit words...
Definition: RawDAQData.cpp:990
Encapsulate the geometry of one entire detector (near, far, ndos)
static const daqdataformats::version_t DEFAULT_NANOSLICE_VERSION
Definition: Configuration.h:23
enum BeamMode string