188{
189
190
191
192 bool kBadLB=false;
193 std::vector<unsigned int> LBList;
194 std::ifstream
infile(LBFile.Data());
196
197 std::getline(infile,line,'\n');
199 std::unique_ptr<TObjArray>
list (
filter.Tokenize(
", "));
200 if(
list->GetEntries() == 0){
201 printf("No LB filtering specified, or bad format. Exiting.\n");
202 return nullptr;
203 }
204
205 for(
int k = 0;
k <
list->GetEntries();
k++){
206 TObjString* tobs = (TObjString*)(
list->At(k));
207 LBList.push_back((unsigned int)(tobs->String()).Atoi());
208 }
209 printf("LB List: %d\n",(int)LBList.size());
210
211
212
213 auto newAcc = std::make_unique<TreeAccessor>(
fileName);
214 unsigned int size = 0;
215
216 int evtIndex = 0, runIndex = 0;
217 std::map<std::pair<int, int>, int> evtMap;
218 std::map<int, int> runMap;
219
220 cout << "Merging runs" << endl;
221 for (
const Accessor* accessor : accessors) {
222 if (!accessor) {
223 cout << "Cannot merge: one of the inputs is null!" << endl;
224 return nullptr;
225 }
226 for (
unsigned int i = 0;
i <
accessor->nRuns();
i++) {
228 if (runMap.find(
run) != runMap.end())
continue;
229 runMap[
run] = runIndex;
230 RunData newRun(*
accessor->runData(i));
231 newAcc->addRun(&newRun);
232 runIndex++;
233 }
234 }
235
236 cout << "Merging events" << endl;
237 unsigned int nEventsTotal = 0, iEvt = 0;
238 for (
const Accessor* accessor : accessors)
239 nEventsTotal +=
accessor->nEvents();
240 for (
const Accessor* accessor : accessors) {
241 for (
unsigned int i = 0;
i <
accessor->nEvents();
i++) {
242 iEvt++;
243 if (iEvt % 100000 == 0) cout << "Merging event " << iEvt << "/" << nEventsTotal << endl;
244
245
246
247 kBadLB=false;
248 for(
unsigned int ilb = 0 ;
ilb < LBList.size() ;
ilb++){
249 if(LBList.at(ilb)==
accessor->eventData(i)->lumiBlock()){
250 kBadLB=true;
251
252 break;
253 }
254 }
255 if(kBadLB) continue;
256
257
258 std::pair<int, int> evtId(
accessor->eventData(i)->run(),
accessor->eventData(i)->event());
259 if (evtMap.find(evtId) != evtMap.end()) continue;
260 evtMap[evtId] = evtIndex;
261 std::map<int, int>::const_iterator
idx = runMap.find(
accessor->eventData(i)->run());
262 int newRunIndex = (
idx == runMap.end() ? -999 :
idx->second);
264 newAcc->addEvent(&newEvent);
265 evtIndex++;
266 }
267 }
268
269 cout << "Merging cells" << endl;
270 for (
unsigned int i = 0;
i < newAcc->nChannels();
i++) {
271 if (i % 10000 == 0) {
272 cout <<
"Merging channel " <<
i <<
"/" << newAcc->nChannels() <<
" (current size = " << size <<
")" << endl;
273
274 }
276 CellInfo*
info =
nullptr;
277 for (
const Accessor* accessor : accessors) {
278 const History* history =
accessor->cellHistory(i);
279 if (!history || !history->
isValid())
continue;
283 }
284 for (
unsigned int j = 0;
j < history->
nData();
j++) {
285 auto newDC = std::make_unique<DataContainer>(history->
data(j)->
container());
286 std::map<std::pair<int, int>, int>::const_iterator newIndex
287 = evtMap.find(std::make_pair(history->
data(j)->
run(), history->
data(j)->
event()));
288
289 newDC->setEventIndex(newIndex != evtMap.end() ? newIndex->second : -1);
291 if (not info) continue;
294 if (!shape)
295 cout <<
"Shape not filled for hash = " <<
i <<
", index = " <<
j <<
", gain = " <<
Data::gainStr(history->
data(j)->
gain()) << endl;
296 info->setShape(history->
data(j)->
gain(), (shape ?
new ShapeInfo(*shape) :
nullptr));
297 }
298 }
299 }
302 }
304
305 }
306
307 cout << "Merging SC" << endl;
308 for (
unsigned int i = 0;
i < newAcc->nChannelsSC();
i++) {
309 if (i % 10000 == 0) {
310 cout <<
"Merging channel " <<
i <<
"/" << newAcc->nChannelsSC() <<
" (current size = " << size <<
")" << endl;
311 }
313 CellInfo*
info =
nullptr;
314 for (
const Accessor* accessor : accessors) {
315 std::unique_ptr<const History> history =
accessor->getSCHistory(i);
316 if (!history || !history->isValid()) continue;
318 info =
new CellInfo(*history->cellInfo());
320 }
321 for (
unsigned int j = 0;
j < history->nData();
j++) {
322 auto newDC = std::make_unique<DataContainer>(history->data(j)->container());
323 std::map<std::pair<int, int>, int>::const_iterator newIndex
324 = evtMap.find(std::make_pair(history->data(j)->run(), history->data(j)->event()));
325
326 newDC->setEventIndex(newIndex != evtMap.end() ? newIndex->second : -1);
328 if (not info) continue;
329 if (!
info->shape(history->data(j)->gain())) {
330 const ShapeInfo* shape = history->cellInfo()->shape(history->data(j)->gain());
331 if (!shape)
332 cout <<
"Shape not filled for hash = " <<
i <<
", index = " <<
j <<
", gain = " <<
Data::gainStr(history->data(j)->gain()) << endl;
333 info->setShape(history->data(j)->gain(), (shape ?
new ShapeInfo(*shape) :
nullptr));
334 }
335 }
336 }
339 }
341
342 }
343
344 cout << "Merging done, final size = " << size << endl;
345 newAcc->save();
346 return newAcc;
347}
CaloGain::CaloGain gain() const
static TString gainStr(CaloGain::CaloGain gain)
const DataContainer & container() const