77// 3-running
88// 4-error
99
10- DAQController::DAQController (MongoLog *log){
10+ DAQController::DAQController (MongoLog *log, std::string hostname ){
1111 fLog =log;
1212 fHelper = new DAXHelpers ();
1313 fOptions = NULL ;
@@ -18,6 +18,7 @@ DAQController::DAQController(MongoLog *log){
1818 fRunStartController = NULL ;
1919 fRawDataBuffer = NULL ;
2020 fDatasize =0 .;
21+ fHostname = hostname;
2122}
2223
2324DAQController::~DAQController (){
@@ -39,7 +40,7 @@ std::string DAQController::run_mode(){
3940 }
4041}
4142
42- int DAQController::InitializeElectronics (std::string opts, std::string override ){
43+ int DAQController::InitializeElectronics (std::string opts, std::vector< int >&keys, std:: string override ){
4344
4445 // Load options including override if any
4546 if (fOptions != NULL )
@@ -51,14 +52,18 @@ int DAQController::InitializeElectronics(std::string opts, std::string override)
5152
5253 // Initialize digitizers
5354 fStatus = 1 ;
54- for (auto d : fOptions ->GetBoards (" V1724" )){
55+ for (auto d : fOptions ->GetBoards (" V1724" , fHostname )){
5556
5657 V1724 *digi = new V1724 (fLog );
57- if (digi->Init (d.link , d.crate , d.board , d.vme_address )==0 ){
58- fDigitizers .push_back (digi);
59- std::stringstream mess;
60- mess<<" Initialized digitizer " <<d.board ;
61- fLog ->Entry (mess.str (), MongoLog::Debug);
58+ if (digi->Init (d.link , d.crate , d.board , d.vme_address )==0 ){
59+ fDigitizers [d.link ].push_back (digi);
60+ if (std::find (keys.begin (), keys.end (), d.link ) == keys.end ()){
61+ std::cout<<" Defining new optical link " <<d.link <<std::endl;
62+ keys.push_back (d.link );
63+ }
64+ std::stringstream mess;
65+ mess<<" Initialized digitizer " <<d.board ;
66+ fLog ->Entry (mess.str (), MongoLog::Debug);
6267 }
6368 else {
6469 std::stringstream err;
@@ -70,25 +75,30 @@ int DAQController::InitializeElectronics(std::string opts, std::string override)
7075 }
7176
7277 // Load registers into digitizers
73- for (auto digi : fDigitizers ){
74- int success=0 ;
75- for (auto regi : fOptions ->GetRegisters (digi->bid ())){
76- unsigned int reg = fHelper ->StringToHex (regi.reg );
77- unsigned int val = fHelper ->StringToHex (regi.val );
78- success+=digi->WriteRegister (reg, val);
79- }
80- if (success!=0 ){
81- // LOG
82- fStatus = 0 ;
78+ for ( auto const & link : fDigitizers ) {
79+ for (auto digi : link.second ){
80+ int success=0 ;
81+ for (auto regi : fOptions ->GetRegisters (digi->bid ())){
82+ unsigned int reg = fHelper ->StringToHex (regi.reg );
83+ unsigned int val = fHelper ->StringToHex (regi.val );
84+ success+=digi->WriteRegister (reg, val);
85+ }
86+ if (success!=0 ){
87+ // LOG
88+ fStatus = 0 ;
8389 fLog ->Entry (" Failed to write registers." , MongoLog::Warning);
8490 return -1 ;
91+ }
8592 }
8693 }
8794
8895 // Look at this later! This initializes all boards to SW controlled
8996 // and inactive. Will need option for HW control.
90- for (unsigned int x=0 ;x<fDigitizers .size ();x++)
91- fDigitizers [x]->WriteRegister (0x8100 , 0x0 );
97+ for ( auto const & link : fDigitizers ) {
98+ for (auto digi : link.second ){
99+ digi->WriteRegister (0x8100 , 0x0 );
100+ }
101+ }
92102 fStatus = 2 ;
93103
94104 std::cout<<fOptions ->ExportToString ()<<std::endl;
@@ -97,8 +107,10 @@ int DAQController::InitializeElectronics(std::string opts, std::string override)
97107
98108void DAQController::Start (){
99109 if (fRunStartController ==NULL ){
100- for (unsigned int x=0 ;x<fDigitizers .size (); x++){
101- fDigitizers [x]->WriteRegister (0x8100 , 0x4 );
110+ for ( auto const & link : fDigitizers ){
111+ for (auto digi : link.second ){
112+ digi->WriteRegister (0x8100 , 0x4 );
113+ }
102114 }
103115 }
104116 fStatus = 3 ;
@@ -108,8 +120,11 @@ void DAQController::Start(){
108120void DAQController::Stop (){
109121
110122 if (fRunStartController ==NULL ){
111- for (unsigned int x=0 ;x<fDigitizers .size ();x++)
112- fDigitizers [x]->WriteRegister (0x8100 , 0x0 );
123+ for ( auto const & link : fDigitizers ){
124+ for (auto digi : link.second ){
125+ digi->WriteRegister (0x8100 , 0x0 );
126+ }
127+ }
113128 }
114129 fLog ->Entry (" Stopped digitizers" , MongoLog::Debug);
115130
@@ -119,10 +134,12 @@ void DAQController::Stop(){
119134}
120135void DAQController::End (){
121136 CloseProcessingThreads ();
122- for (unsigned int x=0 ; x<fDigitizers .size (); x++){
123- fDigitizers [x]->End ();
124- delete fDigitizers [x];
125- }
137+ for ( auto const & link : fDigitizers ){
138+ for (auto digi : link.second ){
139+ digi->End ();
140+ delete digi;
141+ }
142+ }
126143 fDigitizers .clear ();
127144 fStatus = 0 ;
128145
@@ -140,13 +157,13 @@ void DAQController::End(){
140157 }
141158}
142159
143- void * DAQController::ReadThreadWrapper (void * data){
160+ void * DAQController::ReadThreadWrapper (void * data, int link ){
144161 DAQController *dc = static_cast <DAQController*>(data);
145- dc->ReadData ();
162+ dc->ReadData (link );
146163 return dc;
147164}
148165
149- void DAQController::ReadData (){
166+ void DAQController::ReadData (int link ){
150167 fReadLoop = true ;
151168 CloseProcessingThreads ();
152169 OpenProcessingThreads ();
@@ -170,12 +187,12 @@ void DAQController::ReadData(){
170187 // lastRead = 0;
171188
172189 vector<data_packet> local_buffer;
173- for (unsigned int x=0 ; x<fDigitizers .size (); x++){
190+ for (unsigned int x=0 ; x<fDigitizers [link] .size (); x++){
174191 data_packet d;
175192 d.buff =NULL ;
176193 d.size =0 ;
177- d.bid = fDigitizers [x]->bid ();
178- d.size = fDigitizers [x]->ReadMBLT (d.buff );
194+ d.bid = fDigitizers [link][ x]->bid ();
195+ d.size = fDigitizers [link][ x]->ReadMBLT (d.buff );
179196
180197 // Here's the fancy part. We gotta grab the header of the first
181198 // event in the buffer and get the clock reset counter from the
@@ -184,7 +201,7 @@ void DAQController::ReadData(){
184201 while (idx < d.size /sizeof (u_int32_t )){
185202 if (d.buff [idx]>>20 ==0xA00 ){
186203 d.header_time = d.buff [idx+3 ]&0x7FFFFFFF ;
187- d.clock_counter = fDigitizers [x]->GetClockCounter (d.header_time );
204+ d.clock_counter = fDigitizers [link][ x]->GetClockCounter (d.header_time );
188205 break ;
189206 }
190207 idx++;
0 commit comments