2 MCH DA for online occupancy
4 Contact: Laurent Aphecetche <laurent.aphecetche@subatech.in2p3.fr>, Jean-Luc Charvet <jean-luc.charvet@cea.fr>, Alberto Baldisseri <alberto.baldisseri@cea.fr>
6 Run Type: PHYSICS STANDALONE
8 Number of events needed: all (or at least as much as possible...)
9 Input Files: 10000119041028.20.raw 10000130367042.10.raw 10000120691024.50.raw
10 Output Files: mch.occupancy, to be exported to the DAQ FXS
11 Trigger types used: PHYSICS_EVENT
14 /**************************************************************************
15 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
17 * Author: The ALICE Off-line Project. *
18 * Contributors are mentioned in the code where appropriate. *
20 * Permission to use, copy, modify and distribute this software and its *
21 * documentation strictly for non-commercial purposes is hereby granted *
22 * without fee, provided that the above copyright notice appears in all *
23 * copies and that both the copyright notice and this permission notice *
24 * appear in the supporting documentation. The authors make no claims *
25 * about the suitability of this software for any purpose. It is *
26 * provided "as is" without express or implied warranty. *
27 **************************************************************************/
30 /// MUON TRACKER DA to compute the hit count at manu level.
32 /// In the end, this DA produces an ASCII file containing
33 /// the hit count of all the manus (that were seen in the data flow)
34 /// of the MUON Tracker (and the number of seen events, so we can
35 /// later on compute the occupancy)
40 #include "AliMUON2DMap.h"
41 #include "AliMUONCalibParamNI.h"
42 #include "AliMUONRawStreamTrackerHP.h"
43 #include "AliMpConstants.h"
44 #include "AliRawEventHeaderBase.h"
45 #include "AliRawReaderDate.h"
46 #include "Riostream.h"
47 #include "TPluginManager.h"
50 #include "TTimeStamp.h"
51 #include "TStopwatch.h"
59 #include "TObjString.h"
64 const char* OUTPUT_FILE = "mch.occupancy";
65 const char* DAVERSION = "MUONTRKOCCda v1.61 ($Id$)";
67 //______________________________________________________________________________
68 void Add(AliMUONVStore& destStore, const AliMUONVStore& srcStore)
70 /// Add all elements from srcStore to destStore
71 /// Each element of srcStore is supposed to be an AliMUONCalibParamNI,
72 /// with ID0=busPatchId and ID1=manuId
74 TIter next(srcStore.CreateIterator());
75 AliMUONVCalibParam* source;
77 while ( ( source = static_cast<AliMUONVCalibParam*>(next()) ) )
79 AliMUONCalibParamNI* dest = static_cast<AliMUONCalibParamNI*>(destStore.FindObject(source->ID0(),source->ID1()));
82 dest = static_cast<AliMUONCalibParamNI*>(source->Clone());
87 for ( Int_t i = 0; i < source->Size(); ++i )
89 for ( Int_t j = 0; j < source->Dimension(); ++j )
91 dest->SetValueAsIntFast(i,j,dest->ValueAsIntFast(i,j)+source->ValueAsIntFast(i,j));
98 //______________________________________________________________________________
99 void GenerateOutputFile(const AliMUONVStore& store, ostream& out,
100 Int_t runNumber, Int_t nevents, Int_t numberOfEventsWithMCH)
102 /// Write the channel hit count (grouped by manu) in the output file.
104 TIter next(store.CreateIterator());
105 AliMUONVCalibParam* manu;
107 out << "//===========================================================================" << endl;
108 out << "// Hit counter file calculated by " << __FILE__ << endl;
109 out << "//===========================================================================" << endl;
111 out << "// * Run Number : " << runNumber << endl;
112 out << "// * File Creation Date : " << TTimeStamp().AsString("l") << endl;
113 out << "//---------------------------------------------------------------------------" << endl;
114 out << "// BP MANU SUM_N NEVENTS" << endl;
115 out << "//---------------------------------------------------------------------------" << endl;
119 while ( ( manu = static_cast<AliMUONVCalibParam*>(next()) ) )
123 for ( Int_t i = 0; i < manu->Size(); ++i )
125 sum += manu->ValueAsInt(i);
128 out << Form("%5d %5d %10d %10d",manu->ID0(),manu->ID1(),sum,nevents) << endl;
134 // ok : empty output. Is it because the run was empty ?
135 if ( !numberOfEventsWithMCH )
137 // yes. Let give a hint in the file so the Shuttle preprocessor will know about this...
138 out << Form("%5d %5d %10d %10d",-1,-1,0,0) << endl;
140 // else the preprocessor will fail, and that's good because there's something wrong somewhere...
144 //______________________________________________________________________________
145 int main(int argc, char **argv)
149 /// We loop over all physics events.
150 /// For each event we store the channels that were hit for that event.
151 /// If the event is good, we then increment the list of channels hit for
153 /// We delete the store for a single event and move to next event.
155 /// In the end we output an ASCII file with the necessary information
156 /// to compute the occupancy later on, i.e. the number of times channels
157 /// were seen per manu, and the number of events.
160 signal(SIGSEGV,SIG_DFL); // to be able to get core dumps...
165 ios::sync_with_stdio();
167 cout << "Running " << DAVERSION << endl;
171 cout << "Wrong number of arguments" << endl;
172 cout << "Usage : " << argv[0] << " datasource1 [datasource2] ..." << endl;
176 // needed for streamer application
177 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
183 Int_t numberOfEvents(0);
184 Int_t numberOfPhysicsEvent(0);
185 Int_t numberOfBadEvents(0);
186 Int_t numberOfUsedEvents(0);
188 Int_t numberOfEventsWithMCH(0);
190 AliMUON2DMap oneEventData(kTRUE);
191 AliMUON2DMap accumulatedData(kTRUE);
195 for ( Int_t i = 1; i < argc; ++i )
198 AliRawReaderDate* rawReader(0x0);
200 // define data source :
201 status=monitorSetDataSource(argv[i]);
204 printf("MCH Occupancy DA ERROR: monitorSetDataSource() failed: %s\n", monitorDecodeError(status));
208 // Declare monitoring program
209 status=monitorDeclareMp("MUON_TRK_OCC");
212 printf("MCH Occupancy DA ERROR: monitorDeclareMp() failed: %s\n", monitorDecodeError(status));
215 // Define wait event timeout - 1s max
217 monitorSetNoWaitNetworkTimeout(1000);
221 struct eventHeaderStruct *event(0x0);
222 eventTypeType eventT;
224 status=monitorGetEventDynamic((void **)&event);
227 printf("MCH Occupancy DA ERROR: %s\n", monitorDecodeError(status));
232 /* check shutdown condition */
233 if (daqDA_checkShutdown())
239 /* retry if got no event */
240 if (event==NULL) continue;
244 eventT=event->eventType;
245 if ((eventT == END_OF_RUN)||(eventT == END_OF_RUN_FILES))
250 if (eventT != PHYSICS_EVENT)
256 ++numberOfPhysicsEvent;
258 rawReader = new AliRawReaderDate((void*)event);
260 if ( rawReader->GetRunNumber() != runNumber )
262 if ( runNumber != 0 )
264 cout << "Uh oh. That's bad... Changing of run number ???" << endl;
269 runNumber = rawReader->GetRunNumber();
272 // *without* using the MUONTRK event decoder, we update the number
273 // of events where we have information about MUONTRK.
274 // this should be what is called subevents in the logbook
275 // we do *not* use the MCH decoder on purpose, to not mistakenly
276 // believe there's no event if the data is corrupted (and thus the decoder
279 Bool_t mchThere(kFALSE);
281 for ( int iDDL = 0; iDDL < AliDAQ::NumberOfDdls("MUONTRK") && !mchThere; ++iDDL )
284 rawReader->Select("MUONTRK",iDDL,iDDL);
285 if (rawReader->ReadHeader() )
287 if (rawReader->GetEquipmentSize() ) mchThere = kTRUE;
291 if ( mchThere) ++numberOfEventsWithMCH;
295 // now do our real work with the MCH decoder
297 AliMUONRawStreamTrackerHP stream(rawReader);
299 stream.DisableWarnings();
301 oneEventData.Clear();
310 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
312 AliMUONVCalibParam* one = static_cast<AliMUONVCalibParam*>(oneEventData.FindObject(buspatchId,manuId));
316 one = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),buspatchId,manuId);
317 oneEventData.Add(one);
320 one->SetValueAsInt(manuChannel,0,one->ValueAsInt(manuChannel,0)+1);
323 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
327 ++numberOfUsedEvents;
328 Add(accumulatedData,oneEventData);
342 cout << Form("%12d events processed : %12d physics %d used ones %d bad ones [ %d with MCH information ]",
343 numberOfEvents,numberOfPhysicsEvent,numberOfUsedEvents,numberOfBadEvents,numberOfEventsWithMCH) << endl;
345 ofstream fout(OUTPUT_FILE);
347 GenerateOutputFile(accumulatedData,fout,runNumber,numberOfUsedEvents,numberOfEventsWithMCH);
351 /* store the result file on FXS */
352 if (daqDA_FES_storeFile(OUTPUT_FILE,"OCCUPANCY")) return -9;
356 if ( numberOfUsedEvents ) // do not update the AMORE pool with an empty object...
358 // Send occupancy store (as a big string) to the AMORE DB
359 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
363 GenerateOutputFile(accumulatedData,str,runNumber,numberOfUsedEvents,numberOfEventsWithMCH);
365 TObjString occupancyAsString(str.str().c_str());
367 cout << "will send to amore" << endl;
369 Int_t status = amoreDA.Send("Occupancy",&occupancyAsString);
372 cerr << "ERROR : Failed to write occupancies in the AMORE database : " << status << endl;
379 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());